os/mm/mmlibs/mmfw/MIDI/src/midicustomcommandparser.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/MIDI/src/midicustomcommandparser.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1009 @@
     1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <mmf/common/midistandardcustomcommands.h>
    1.20 +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    1.21 +#include <mmf/common/midieventreceiver.h>
    1.22 +#include <mmf/common/mmfmidiconfig.h>
    1.23 +#endif
    1.24 +const TInt KMimeTypeLength = 256;
    1.25 +
    1.26 +
    1.27 +/**
    1.28 +Creates a new MIDI custom command parser capable of handling MIDI controller commands.
    1.29 +
    1.30 +@param	aImplementor A reference to the controller plugin that owns this new object.
    1.31 +@leave	This function may leave with one of the system-wide error codes.
    1.32 +*/
    1.33 +EXPORT_C CMidiCustomCommandParser* CMidiCustomCommandParser::NewL(MMidiCustomCommandImplementor& aImplementor)
    1.34 +	{
    1.35 +	return new(ELeave) CMidiCustomCommandParser(aImplementor);
    1.36 +	}
    1.37 +
    1.38 +CMidiCustomCommandParser::CMidiCustomCommandParser(MMidiCustomCommandImplementor& aImplementor) :
    1.39 +	CMMFCustomCommandParserBase(KUidInterfaceMidi),
    1.40 +	iImplementor(aImplementor)
    1.41 +	{
    1.42 +	}
    1.43 +
    1.44 +/**
    1.45 +Destructor.
    1.46 +*/
    1.47 +EXPORT_C CMidiCustomCommandParser::~CMidiCustomCommandParser()
    1.48 +	{
    1.49 +	delete iMidiEventReceiver;
    1.50 +	delete iInstrumentName;
    1.51 +	delete iPercussionKeyName;
    1.52 +	iMidiEvents.ResetAndDestroy();
    1.53 +	iMidiEvents.Close();
    1.54 +	}
    1.55 +
    1.56 +/**
    1.57 +Handles a request from the client. Called by the controller framework.
    1.58 +
    1.59 +@param aMessage The message to be handled.
    1.60 +*/
    1.61 +void CMidiCustomCommandParser::HandleRequest(TMMFMessage& aMessage)
    1.62 +	{
    1.63 +	if (aMessage.Destination().InterfaceId() == KUidInterfaceMidi)
    1.64 +		{
    1.65 +		TRAPD(error, DoHandleRequestL(aMessage));
    1.66 +		if (error)
    1.67 +			aMessage.Complete(error);
    1.68 +		}
    1.69 +	else
    1.70 +		{
    1.71 +		aMessage.Complete(KErrNotSupported);
    1.72 +		}
    1.73 +	}
    1.74 +
    1.75 +void CMidiCustomCommandParser::DoHandleRequestL(TMMFMessage& aMessage)
    1.76 +	{
    1.77 +	TBool complete = ETrue;
    1.78 +	switch (aMessage.Function())
    1.79 +		{
    1.80 +	case EMMFMidiControllerSetPositionMicroBeats:
    1.81 +		complete = DoSetPositionMicroBeatsL(aMessage);
    1.82 +		break;
    1.83 +	case EMMFMidiControllerPositionMicroBeats:
    1.84 +		complete = DoPositionMicroBeatsL(aMessage);
    1.85 +		break;
    1.86 +	case EMMFMidiControllerPlayNote:
    1.87 +		complete = DoPlayNoteL(aMessage);
    1.88 +		break;
    1.89 +	case EMMFMidiControllerPlayNoteWithStartTime:
    1.90 +		complete = DoPlayNoteWithStartTimeL(aMessage);
    1.91 +		break;
    1.92 +	case EMMFMidiControllerStopNotes:
    1.93 +		complete = DoStopNotesL(aMessage);
    1.94 +		break;
    1.95 +	case EMMFMidiControllerNoteOn:
    1.96 +		complete = DoNoteOnL(aMessage);
    1.97 +		break;
    1.98 +	case EMMFMidiControllerNoteOff:
    1.99 +		complete = DoNoteOffL(aMessage);
   1.100 +		break;
   1.101 +	case EMMFMidiControllerPlaybackRate:
   1.102 +		complete = DoPlaybackRateL(aMessage);
   1.103 +		break;
   1.104 +	case EMMFMidiControllerSetPlaybackRate:
   1.105 +		complete = DoSetPlaybackRateL(aMessage);
   1.106 +		break;
   1.107 +	case EMMFMidiControllerMaxPlaybackRate:
   1.108 +		complete = DoMaxPlaybackRateL(aMessage);
   1.109 +		break;
   1.110 +	case EMMFMidiControllerMinPlaybackRate:
   1.111 +		complete = DoMinPlaybackRateL(aMessage);
   1.112 +		break;
   1.113 +	case EMMFMidiControllerTempo:
   1.114 +		complete = DoTempoMicroBeatsPerMinuteL(aMessage);
   1.115 +		break;
   1.116 +	case EMMFMidiControllerSetTempo:
   1.117 +		complete = DoSetTempoL(aMessage);
   1.118 +		break;
   1.119 +	case EMMFMidiControllerPitch:
   1.120 +		complete = DoPitchTranspositionCentsL(aMessage);
   1.121 +		break;
   1.122 +	case EMMFMidiControllerSetPitch:
   1.123 +		complete = DoSetPitchTranspositionL(aMessage);
   1.124 +		break;
   1.125 +	case EMMFMidiControllerDurationMicroBeats:
   1.126 +		complete = DoDurationMicroBeatsL(aMessage);
   1.127 +		break;
   1.128 +	case EMMFMidiControllerNumTracks:
   1.129 +		complete = DoNumTracksL(aMessage);
   1.130 +		break;
   1.131 +	case EMMFMidiControllerSetTrackMute:
   1.132 +		complete = DoSetTrackMuteL(aMessage);
   1.133 +		break;
   1.134 +	case EMMFMidiControllerMimeType:
   1.135 +		complete = DoMimeTypeL(aMessage);
   1.136 +		break;
   1.137 +	case EMMFMidiControllerSetSyncUpdateCallbackInterval:
   1.138 +		complete = DoSetSyncUpdateCallbackIntervalL(aMessage);
   1.139 +		break;
   1.140 +	case EMMFMidiControllerSendMessage:
   1.141 +		complete = DoSendMessageL(aMessage);
   1.142 +		break;
   1.143 +	case EMMFMidiControllerSendMessageWithTimeStamp:
   1.144 +		complete = DoSendMessageWithTimeStampL(aMessage);
   1.145 +		break;
   1.146 +	case EMMFMidiControllerSendMipMessage:
   1.147 +		complete = DoSendMipMessageL(aMessage);
   1.148 +		break;
   1.149 +	case EMMFMidiControllerNumberOfBanks:
   1.150 +		complete = DoNumberOfBanksL(aMessage);
   1.151 +		break;
   1.152 +	case EMMFMidiControllerGetBankId:
   1.153 +		complete = DoGetBankIdL(aMessage);
   1.154 +		break;
   1.155 +	case EMMFMidiControllerLoadCustomBank:
   1.156 +		complete = DoLoadCustomBankL(aMessage);
   1.157 +		break;
   1.158 +	case EMMFMidiControllerLoadCustomBankData:
   1.159 +		complete = DoLoadCustomBankDataL(aMessage);
   1.160 +		break;
   1.161 +	case EMMFMidiControllerUnloadCustomBank:
   1.162 +		complete = DoUnloadCustomBankL(aMessage);
   1.163 +		break;
   1.164 +	case EMMFMidiControllerCustomBankLoaded:
   1.165 +		complete = DoCustomBankLoadedL(aMessage);
   1.166 +		break;
   1.167 +	case EMMFMidiControllerUnloadAllCustomBanks:
   1.168 +		complete = DoUnloadAllCustomBanksL(aMessage);
   1.169 +		break;
   1.170 +	case EMMFMidiControllerNumberOfInstruments:
   1.171 +		complete = DoNumberOfInstrumentsL(aMessage);
   1.172 +		break;
   1.173 +	case EMMFMidiControllerGetInstrumentId:
   1.174 +		complete = DoGetInstrumentIdL(aMessage);
   1.175 +		break;
   1.176 +	case EMMFMidiControllerInstrumentName:
   1.177 +		complete = DoInstrumentNameL(aMessage);
   1.178 +		break;
   1.179 +	case EMMFMidiControllerCopyInstrumentName:
   1.180 +		complete = DoCopyInstrumentNameL(aMessage);
   1.181 +		break;
   1.182 +	case EMMFMidiControllerSetInstrument:
   1.183 +		complete = DoSetInstrumentL(aMessage);
   1.184 +		break;
   1.185 +	case EMMFMidiControllerLoadCustomInstrument:
   1.186 +		complete = DoLoadCustomInstrumentL(aMessage);
   1.187 +		break;
   1.188 +	case EMMFMidiControllerLoadCustomInstrumentData:
   1.189 +		complete = DoLoadCustomInstrumentDataL(aMessage);
   1.190 +		break;
   1.191 +	case EMMFMidiControllerUnloadCustomInstrument:
   1.192 +		complete = DoUnloadCustomInstrumentL(aMessage);
   1.193 +		break;
   1.194 +	case EMMFMidiControllerPercussionKeyName:
   1.195 +		complete = DoPercussionKeyNameL(aMessage);
   1.196 +		break;
   1.197 +	case EMMFMidiControllerCopyPercussionKeyName:
   1.198 +		complete = DoCopyPercussionKeyNameL(aMessage);
   1.199 +		break;
   1.200 +	case EMMFMidiControllerStopTime:
   1.201 +		complete = DoStopTimeL(aMessage);
   1.202 +		break;
   1.203 +	case EMMFMidiControllerSetStopTime:
   1.204 +		complete = DoSetStopTimeL(aMessage);
   1.205 +		break;
   1.206 +	case EMMFMidiControllerPolyphony:
   1.207 +		complete = DoPolyphonyL(aMessage);
   1.208 +		break;
   1.209 +	case EMMFMidiControllerChannelsSupported:
   1.210 +		complete = DoChannelsSupportedL(aMessage);
   1.211 +		break;
   1.212 +	case EMMFMidiControllerChannelVolume:
   1.213 +		complete = DoChannelVolumeL(aMessage);
   1.214 +		break;
   1.215 +	case EMMFMidiControllerMaxChannelVolume:
   1.216 +		complete = DoMaxChannelVolumeL(aMessage);
   1.217 +		break;
   1.218 +	case EMMFMidiControllerSetChannelVolume:
   1.219 +		complete = DoSetChannelVolumeL(aMessage);
   1.220 +		break;
   1.221 +	case EMMFMidiControllerSetChannelMute:
   1.222 +		complete = DoSetChannelMuteL(aMessage);
   1.223 +		break;
   1.224 +	case EMMFMidiControllerVolume:
   1.225 +		complete = DoVolumeL(aMessage);
   1.226 +		break;
   1.227 +	case EMMFMidiControllerMaxVolume:
   1.228 +		complete = DoMaxVolumeL(aMessage);
   1.229 +		break;
   1.230 +	case EMMFMidiControllerSetVolume:
   1.231 +		complete = DoSetVolumeL(aMessage);
   1.232 +		break;
   1.233 +	case EMMFMidiControllerSetVolumeRamp:
   1.234 +		complete = DoSetVolumeRampL(aMessage);
   1.235 +		break;
   1.236 +	case EMMFMidiControllerGetBalance:
   1.237 +		complete = DoGetBalanceL(aMessage);
   1.238 +		break;
   1.239 +	case EMMFMidiControllerSetBalance:
   1.240 +		complete = DoSetBalanceL(aMessage);
   1.241 +		break;
   1.242 +	case EMMFMidiControllerSetMaxPolyphony:
   1.243 +		complete = DoSetMaxPolyphonyL(aMessage);
   1.244 +		break;
   1.245 +	case EMMFMidiControllerGetRepeats:
   1.246 +		complete = DoGetRepeatsL(aMessage);
   1.247 +		break;
   1.248 +	case EMMFMidiControllerSetRepeats:
   1.249 +		complete = DoSetRepeatsL(aMessage);
   1.250 +		break;
   1.251 +	case EMMFMidiControllerSetBank:
   1.252 +		DoSetBankL(aMessage);
   1.253 +		break;
   1.254 +	case EMMFMidiControllerIsTrackMute:
   1.255 +		DoIsTrackMuteL(aMessage);
   1.256 +		break;
   1.257 +	case EMMFMidiControllerIsChannelMute:
   1.258 +		DoIsChannelMuteL(aMessage);
   1.259 +		break;
   1.260 +	case EMMFMidiControllerGetInstrument:
   1.261 +		DoGetInstrumentL(aMessage);
   1.262 +		break;
   1.263 +	case EMMFMidiControllerClose:
   1.264 +		complete = DoCloseL(aMessage);
   1.265 +		break;
   1.266 +	case EMMFMidiControllerStop:
   1.267 +		complete = DoStopL(aMessage);
   1.268 +		break;
   1.269 +	case EMMFMidiControllerReceiveEvents:
   1.270 +		complete = DoReceiveEventsL(aMessage);
   1.271 +		break;
   1.272 +	case EMMFMidiControllerRetrieveEvent:
   1.273 +		complete = DoRetrieveEventL(aMessage);
   1.274 +		break;
   1.275 +	case EMMFMidiControllerCancelReceiveEvents:
   1.276 +		complete = DoCancelReceiveEventsL(aMessage);
   1.277 +		break;
   1.278 +	case EMMFMidiControllerMaxPolyphony:
   1.279 +		complete = DoMaxPolyphonyL(aMessage);
   1.280 +		break;
   1.281 +	default:
   1.282 +		User::Leave(KErrNotSupported);
   1.283 +		break;
   1.284 +		}
   1.285 +	if (complete)
   1.286 +		aMessage.Complete(KErrNone);
   1.287 +	}
   1.288 +
   1.289 +TBool CMidiCustomCommandParser::DoSetPositionMicroBeatsL(TMMFMessage& aMessage)
   1.290 +	{
   1.291 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.292 +	aMessage.ReadData1FromClientL(pckg);
   1.293 +	iImplementor.MmcSetPositionMicroBeatsL(pckg().iPositionMicroBeats);
   1.294 +	return ETrue;
   1.295 +	}
   1.296 +
   1.297 +TBool CMidiCustomCommandParser::DoPositionMicroBeatsL(TMMFMessage& aMessage)
   1.298 +	{
   1.299 +	TInt64 microBeats = 0;
   1.300 +	iImplementor.MmcPositionMicroBeatsL(microBeats);
   1.301 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.302 +	pckg().iPositionMicroBeats = microBeats;
   1.303 +	aMessage.WriteDataToClientL(pckg);
   1.304 +	return ETrue;
   1.305 +	}
   1.306 +
   1.307 +TBool CMidiCustomCommandParser::DoPlayNoteL(TMMFMessage& aMessage)
   1.308 +	{
   1.309 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.310 +	aMessage.ReadData1FromClientL(pckg);
   1.311 +	iImplementor.MmcPlayNoteL(pckg().iChannel, pckg().iNote, pckg().iDurationMicroSeconds, pckg().iNoteOnVelocity, pckg().iNoteOffVelocity);
   1.312 +	return ETrue;
   1.313 +	}
   1.314 +
   1.315 +TBool CMidiCustomCommandParser::DoPlayNoteWithStartTimeL(TMMFMessage& aMessage)
   1.316 +	{
   1.317 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.318 +	aMessage.ReadData1FromClientL(pckg);
   1.319 +	iImplementor.MmcPlayNoteL(pckg().iChannel, pckg().iNote, pckg().iStartTime, pckg().iDurationMicroSeconds, pckg().iNoteOnVelocity, pckg().iNoteOffVelocity);
   1.320 +	return ETrue;
   1.321 +	}
   1.322 +
   1.323 +TBool CMidiCustomCommandParser::DoStopNotesL(TMMFMessage& aMessage)
   1.324 +	{
   1.325 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.326 +	aMessage.ReadData1FromClientL(pckg);
   1.327 +	iImplementor.MmcStopNotesL(pckg().iChannel);
   1.328 +	return ETrue;
   1.329 +	}
   1.330 +
   1.331 +TBool CMidiCustomCommandParser::DoNoteOnL(TMMFMessage& aMessage)
   1.332 +	{
   1.333 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.334 +	aMessage.ReadData1FromClientL(pckg);
   1.335 +	iImplementor.MmcNoteOnL(pckg().iChannel, pckg().iNote, pckg().iNoteOnVelocity);
   1.336 +	return ETrue;
   1.337 +	}
   1.338 +
   1.339 +TBool CMidiCustomCommandParser::DoNoteOffL(TMMFMessage& aMessage)
   1.340 +	{
   1.341 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.342 +	aMessage.ReadData1FromClientL(pckg);
   1.343 +	iImplementor.MmcNoteOffL(pckg().iChannel, pckg().iNote, pckg().iNoteOffVelocity);
   1.344 +	return ETrue;
   1.345 +	}
   1.346 +
   1.347 +TBool CMidiCustomCommandParser::DoPlaybackRateL(TMMFMessage& aMessage)
   1.348 +	{
   1.349 +	TInt playBackRate;
   1.350 +	iImplementor.MmcPlaybackRateL(playBackRate);
   1.351 +	TPckgBuf<TMMFMidiConfig3> pckg;
   1.352 +	pckg().iPlayBackRate = playBackRate;
   1.353 +	aMessage.WriteDataToClientL(pckg);
   1.354 +	return ETrue;
   1.355 +	}
   1.356 +
   1.357 +TBool CMidiCustomCommandParser::DoSetPlaybackRateL(TMMFMessage& aMessage)
   1.358 +	{
   1.359 +	TPckgBuf<TMMFMidiConfig3> pckg;
   1.360 +	aMessage.ReadData1FromClientL(pckg);
   1.361 +	iImplementor.MmcSetPlaybackRateL(pckg().iPlayBackRate);
   1.362 +	return ETrue;
   1.363 +	}
   1.364 +
   1.365 +TBool CMidiCustomCommandParser::DoMaxPlaybackRateL(TMMFMessage& aMessage)
   1.366 +	{
   1.367 +	TInt maxRate;
   1.368 +	iImplementor.MmcMaxPlaybackRateL(maxRate);
   1.369 +	TPckgBuf<TMMFMidiConfig3> pckg;
   1.370 +	pckg().iPlayBackMaxRate = maxRate;
   1.371 +	aMessage.WriteDataToClientL(pckg);
   1.372 +	return ETrue;
   1.373 +	}
   1.374 +
   1.375 +TBool CMidiCustomCommandParser::DoMinPlaybackRateL(TMMFMessage& aMessage)
   1.376 +	{
   1.377 +	TInt minRate;
   1.378 +	iImplementor.MmcMinPlaybackRateL(minRate);
   1.379 +	TPckgBuf<TMMFMidiConfig3> pckg;
   1.380 +	pckg().iPlayBackMinRate = minRate;
   1.381 +	aMessage.WriteDataToClientL(pckg);
   1.382 +	return ETrue;
   1.383 +	}
   1.384 +
   1.385 +TBool CMidiCustomCommandParser::DoTempoMicroBeatsPerMinuteL(TMMFMessage& aMessage)
   1.386 +	{
   1.387 +	TInt microBeatsPerMinute;
   1.388 +	iImplementor.MmcTempoMicroBeatsPerMinuteL(microBeatsPerMinute);
   1.389 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.390 +	pckg().iTempo = microBeatsPerMinute;
   1.391 +	aMessage.WriteDataToClientL(pckg);
   1.392 +	return ETrue;
   1.393 +	}
   1.394 +
   1.395 +TBool CMidiCustomCommandParser::DoSetTempoL(TMMFMessage& aMessage)
   1.396 +	{
   1.397 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.398 +	aMessage.ReadData1FromClientL(pckg);
   1.399 +	iImplementor.MmcSetTempoL(pckg().iTempo);
   1.400 +	return ETrue;
   1.401 +	}
   1.402 +
   1.403 +TBool CMidiCustomCommandParser::DoPitchTranspositionCentsL(TMMFMessage& aMessage)
   1.404 +	{
   1.405 +	TInt pitch;
   1.406 +	iImplementor.MmcPitchTranspositionCentsL(pitch);
   1.407 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.408 +	pckg().iPitch = pitch;
   1.409 +	aMessage.WriteDataToClientL(pckg);
   1.410 +	return ETrue;
   1.411 +	}
   1.412 +
   1.413 +TBool CMidiCustomCommandParser::DoSetPitchTranspositionL(TMMFMessage& aMessage)
   1.414 +	{
   1.415 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.416 +	aMessage.ReadData1FromClientL(pckg);
   1.417 +	TInt centsApplied;
   1.418 +	iImplementor.MmcSetPitchTranspositionL(pckg().iPitch, centsApplied);
   1.419 +	pckg().iPitch = centsApplied;
   1.420 +	aMessage.WriteDataToClientL(pckg);
   1.421 +	return ETrue;
   1.422 +	}
   1.423 +
   1.424 +TBool CMidiCustomCommandParser::DoDurationMicroBeatsL(TMMFMessage& aMessage)
   1.425 +	{
   1.426 +	TInt64 duration;
   1.427 +	iImplementor.MmcDurationMicroBeatsL(duration);
   1.428 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.429 +	pckg().iDurationMicroBeats = duration;
   1.430 +	aMessage.WriteDataToClientL(pckg);
   1.431 +	return ETrue;
   1.432 +	}
   1.433 +
   1.434 +TBool CMidiCustomCommandParser::DoNumTracksL(TMMFMessage& aMessage)
   1.435 +	{
   1.436 +	TInt numTracks;
   1.437 +	iImplementor.MmcNumTracksL(numTracks);
   1.438 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.439 +	pckg().iNumTracks = numTracks;
   1.440 +	aMessage.WriteDataToClientL(pckg);
   1.441 +	return ETrue;
   1.442 +	}
   1.443 +
   1.444 +TBool CMidiCustomCommandParser::DoSetTrackMuteL(TMMFMessage& aMessage)
   1.445 +	{
   1.446 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.447 +	aMessage.ReadData1FromClientL(pckg);
   1.448 +	iImplementor.MmcSetTrackMuteL(pckg().iTrack, pckg().iMuted);
   1.449 +	return ETrue;
   1.450 +	}
   1.451 +
   1.452 +TBool CMidiCustomCommandParser::DoMimeTypeL(TMMFMessage& aMessage)
   1.453 +	{
   1.454 +	HBufC8* mimeType = HBufC8::NewL(KMimeTypeLength);
   1.455 +	TPtr8 des = mimeType->Des();
   1.456 +	CleanupStack::PushL(mimeType);
   1.457 +	iImplementor.MmcMimeTypeL(des);
   1.458 +	aMessage.WriteDataToClientL(des);
   1.459 +	CleanupStack::PopAndDestroy();//mimeType
   1.460 +	return ETrue;
   1.461 +	}
   1.462 +
   1.463 +TBool CMidiCustomCommandParser::DoSetSyncUpdateCallbackIntervalL(TMMFMessage& aMessage)
   1.464 +	{
   1.465 +	TPckgBuf<TMMFMidiConfig3> pckg;
   1.466 +	aMessage.ReadData1FromClientL(pckg);
   1.467 +	iImplementor.MmcSetSyncUpdateCallbackIntervalL(pckg().iCallbackIntervalMicroSeconds, pckg().iCallbackIntervalMicroBeats);
   1.468 +	return ETrue;
   1.469 +	}
   1.470 +
   1.471 +TBool CMidiCustomCommandParser::DoSendMessageL(TMMFMessage& aMessage)
   1.472 +	{
   1.473 +	TPckgBuf<TMMFMidiConfig3> pckg;
   1.474 +	aMessage.ReadData1FromClientL(pckg);
   1.475 +	TInt bytesProcessed;
   1.476 +	iImplementor.MmcSendMessageL(*(pckg().iMidiMessage), bytesProcessed);
   1.477 +	pckg().iBytesProcessed = bytesProcessed;
   1.478 +	aMessage.WriteDataToClientL(pckg);
   1.479 +	return ETrue;
   1.480 +	}
   1.481 +
   1.482 +TBool CMidiCustomCommandParser::DoSendMessageWithTimeStampL(TMMFMessage& aMessage)
   1.483 +	{
   1.484 +	TPckgBuf<TMMFMidiConfig3> pckg;
   1.485 +	aMessage.ReadData1FromClientL(pckg);
   1.486 +	TInt bytesProcessed;
   1.487 +	iImplementor.MmcSendMessageL(*(pckg().iMidiMessage), pckg().iTimeStamp, bytesProcessed);
   1.488 +	pckg().iBytesProcessed = bytesProcessed;
   1.489 +	aMessage.WriteDataToClientL(pckg);
   1.490 +	return ETrue;
   1.491 +	}
   1.492 +
   1.493 +TBool CMidiCustomCommandParser::DoSendMipMessageL(TMMFMessage& aMessage)
   1.494 +	{
   1.495 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.496 +	aMessage.ReadData1FromClientL(pckg);
   1.497 +	iImplementor.MmcSendMipMessageL(*(pckg().iMipMessage));
   1.498 +	return ETrue;
   1.499 +	}
   1.500 +
   1.501 +TBool CMidiCustomCommandParser::DoNumberOfBanksL(TMMFMessage& aMessage)
   1.502 +	{
   1.503 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.504 +	aMessage.ReadData1FromClientL(pckg);
   1.505 +	TInt numBanks;
   1.506 +	iImplementor.MmcNumberOfBanksL(pckg().iCustom, numBanks);
   1.507 +	pckg().iNumBanks = numBanks;
   1.508 +	aMessage.WriteDataToClientL(pckg);
   1.509 +	return ETrue;
   1.510 +	}
   1.511 +
   1.512 +TBool CMidiCustomCommandParser::DoGetBankIdL(TMMFMessage& aMessage)
   1.513 +	{
   1.514 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.515 +	aMessage.ReadData1FromClientL(pckg);
   1.516 +	TInt bankId;
   1.517 +	iImplementor.MmcGetBankIdL(pckg().iCustom, pckg().iBankIndex, bankId);
   1.518 +	pckg().iBankId = bankId;
   1.519 +	aMessage.WriteDataToClientL(pckg);
   1.520 +	return ETrue;
   1.521 +	}
   1.522 +
   1.523 +TBool CMidiCustomCommandParser::DoLoadCustomBankL(TMMFMessage& aMessage)
   1.524 +	{
   1.525 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.526 +	aMessage.ReadData1FromClientL(pckg);
   1.527 +	TInt bankId;
   1.528 +	iImplementor.MmcLoadCustomBankL(*(pckg().iFileName), bankId);
   1.529 +	pckg().iBankId = bankId;
   1.530 +	aMessage.WriteDataToClientL(pckg);
   1.531 +	return ETrue;
   1.532 +	}
   1.533 +
   1.534 +TBool CMidiCustomCommandParser::DoLoadCustomBankDataL(TMMFMessage& aMessage)
   1.535 +	{
   1.536 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.537 +	aMessage.ReadData1FromClientL(pckg);
   1.538 +	TInt bankId;
   1.539 +	iImplementor.MmcLoadCustomBankDataL(*(pckg().iBankData), bankId);
   1.540 +	pckg().iBankId = bankId;
   1.541 +	aMessage.WriteDataToClientL(pckg);
   1.542 +	return ETrue;
   1.543 +	}
   1.544 +
   1.545 +TBool CMidiCustomCommandParser::DoUnloadCustomBankL(TMMFMessage& aMessage)
   1.546 +	{
   1.547 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.548 +	aMessage.ReadData1FromClientL(pckg);
   1.549 +	iImplementor.MmcUnloadCustomBankL(pckg().iBankId);
   1.550 +	return ETrue;
   1.551 +	}
   1.552 +
   1.553 +TBool CMidiCustomCommandParser::DoCustomBankLoadedL(TMMFMessage& aMessage)
   1.554 +	{
   1.555 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.556 +	aMessage.ReadData1FromClientL(pckg);
   1.557 +	TBool bankLoaded;
   1.558 +	iImplementor.MmcCustomBankLoadedL(pckg().iBankId, bankLoaded);
   1.559 +	pckg().iBankLoaded = bankLoaded;
   1.560 +	aMessage.WriteDataToClientL(pckg);
   1.561 +	return ETrue;
   1.562 +	}
   1.563 +
   1.564 +TBool CMidiCustomCommandParser::DoUnloadAllCustomBanksL(TMMFMessage& /*aMessage*/)
   1.565 +	{
   1.566 +	iImplementor.MmcUnloadAllCustomBanksL();
   1.567 +	return ETrue;
   1.568 +	}
   1.569 +
   1.570 +TBool CMidiCustomCommandParser::DoNumberOfInstrumentsL(TMMFMessage& aMessage)
   1.571 +	{
   1.572 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.573 +	aMessage.ReadData1FromClientL(pckg);
   1.574 +	TInt numInstruments;
   1.575 +	iImplementor.MmcNumberOfInstrumentsL(pckg().iBankId, pckg().iCustom, numInstruments);	
   1.576 +	pckg().iNumInstruments = numInstruments;
   1.577 +	aMessage.WriteDataToClientL(pckg);
   1.578 +	return ETrue;
   1.579 +	}
   1.580 +
   1.581 +TBool CMidiCustomCommandParser::DoGetInstrumentIdL(TMMFMessage& aMessage)
   1.582 +	{
   1.583 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.584 +	aMessage.ReadData1FromClientL(pckg);
   1.585 +	TInt instrumentId;
   1.586 +	iImplementor.MmcGetInstrumentIdL(pckg().iBankId, pckg().iCustom, pckg().iInstrumentIndex, instrumentId);
   1.587 +	pckg().iInstrumentId = instrumentId;
   1.588 +	aMessage.WriteDataToClientL(pckg);
   1.589 +	return ETrue;
   1.590 +	}
   1.591 +
   1.592 +TBool CMidiCustomCommandParser::DoInstrumentNameL(TMMFMessage& aMessage)
   1.593 +	{
   1.594 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.595 +	aMessage.ReadData1FromClientL(pckg);
   1.596 +
   1.597 +	// Prevent memory leaks by deleting old instrument name - something must have gone wrong in the client
   1.598 +	// if it already exists
   1.599 +	delete iInstrumentName;
   1.600 +	iInstrumentName = NULL;
   1.601 +
   1.602 +	// Get the instrument name from the controller
   1.603 +	const TDesC& instrumentName = iImplementor.MmcInstrumentNameL(pckg().iBankId, pckg().iCustom, pckg().iInstrumentId);
   1.604 +
   1.605 +	iInstrumentName = CBufFlat::NewL(32);
   1.606 +	RBufWriteStream stream;
   1.607 +	stream.Open(*iInstrumentName);
   1.608 +	CleanupClosePushL(stream);
   1.609 +	stream << instrumentName;
   1.610 +	CleanupStack::PopAndDestroy();//s
   1.611 +
   1.612 +	// Write the size of the descriptor back to the client
   1.613 +	TPckgBuf<TInt> descriptorSizePckg(iInstrumentName->Ptr(0).Length());	
   1.614 +	aMessage.WriteDataToClientL(descriptorSizePckg);
   1.615 +
   1.616 +	return ETrue;
   1.617 +	}
   1.618 +
   1.619 +TBool CMidiCustomCommandParser::DoCopyInstrumentNameL(TMMFMessage& aMessage)
   1.620 +	{
   1.621 +	if (!iInstrumentName)
   1.622 +		User::Leave(KErrNotReady);
   1.623 +
   1.624 +	// Copy the instrument name back to the client
   1.625 +	aMessage.WriteDataToClientL(iInstrumentName->Ptr(0));
   1.626 +	delete iInstrumentName;
   1.627 +	iInstrumentName = NULL;
   1.628 +	return ETrue;
   1.629 +	}
   1.630 +
   1.631 +TBool CMidiCustomCommandParser::DoSetInstrumentL(TMMFMessage& aMessage)
   1.632 +	{
   1.633 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.634 +	aMessage.ReadData1FromClientL(pckg);
   1.635 +	iImplementor.MmcSetInstrumentL(pckg().iChannel, pckg().iBankId, pckg().iInstrumentId);
   1.636 +	return ETrue;
   1.637 +	}
   1.638 +
   1.639 +TBool CMidiCustomCommandParser::DoLoadCustomInstrumentL(TMMFMessage& aMessage)
   1.640 +	{
   1.641 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.642 +	aMessage.ReadData1FromClientL(pckg);
   1.643 +	iImplementor.MmcLoadCustomInstrumentL(*(pckg().iFileName), pckg().iBankId, pckg().iInstrumentId, pckg().iMemoryBankId,  pckg().iMemoryInstrumentId);
   1.644 +	return ETrue;
   1.645 +	}
   1.646 +
   1.647 +TBool CMidiCustomCommandParser::DoLoadCustomInstrumentDataL(TMMFMessage& aMessage)
   1.648 +	{
   1.649 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.650 +	aMessage.ReadData1FromClientL(pckg);
   1.651 +	iImplementor.MmcLoadCustomInstrumentDataL(*(pckg().iInstrumentData), pckg().iBankId, pckg().iInstrumentId, pckg().iMemoryBankId,  pckg().iMemoryInstrumentId);
   1.652 +	return ETrue;
   1.653 +	}
   1.654 +
   1.655 +TBool CMidiCustomCommandParser::DoUnloadCustomInstrumentL(TMMFMessage& aMessage)
   1.656 +	{
   1.657 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.658 +	aMessage.ReadData1FromClientL(pckg);
   1.659 +	iImplementor.MmcUnloadCustomInstrumentL(pckg().iBankId, pckg().iInstrumentId);
   1.660 +	return ETrue;
   1.661 +	}
   1.662 +
   1.663 +TBool CMidiCustomCommandParser::DoPercussionKeyNameL(TMMFMessage& aMessage)
   1.664 +	{
   1.665 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.666 +	aMessage.ReadData1FromClientL(pckg);
   1.667 +
   1.668 +	// Prevent memory leaks by deleting old key name - something must have gone wrong in the client
   1.669 +	// if it already exists
   1.670 +	delete iPercussionKeyName;
   1.671 +	iPercussionKeyName = NULL;
   1.672 +
   1.673 +	const TDesC& percussionKeyName = iImplementor.MmcPercussionKeyNameL(pckg().iNote, pckg().iBankId, pckg().iCustom, pckg().iInstrumentId);
   1.674 +
   1.675 +	iPercussionKeyName = CBufFlat::NewL(32);
   1.676 +	RBufWriteStream stream;
   1.677 +	stream.Open(*iPercussionKeyName);
   1.678 +	CleanupClosePushL(stream);
   1.679 +	stream << percussionKeyName;
   1.680 +	CleanupStack::PopAndDestroy();//s
   1.681 +
   1.682 +	// Write the size of the descriptor back to the client
   1.683 +	TPckgBuf<TInt> descriptorSizePckg(iPercussionKeyName->Ptr(0).Length());	
   1.684 +	aMessage.WriteDataToClientL(descriptorSizePckg);	
   1.685 +	
   1.686 +	return ETrue;
   1.687 +	}
   1.688 +
   1.689 +
   1.690 +TBool CMidiCustomCommandParser::DoCopyPercussionKeyNameL(TMMFMessage& aMessage)
   1.691 +	{
   1.692 +	if (!iPercussionKeyName)
   1.693 +		User::Leave(KErrNotReady);
   1.694 +
   1.695 +	// Copy the instrument name back to the client
   1.696 +	aMessage.WriteDataToClientL(iPercussionKeyName->Ptr(0));
   1.697 +	delete iPercussionKeyName;
   1.698 +	iPercussionKeyName = NULL;
   1.699 +	return ETrue;
   1.700 +	}
   1.701 +
   1.702 +
   1.703 +TBool CMidiCustomCommandParser::DoStopTimeL(TMMFMessage& aMessage)
   1.704 +	{
   1.705 +	TTimeIntervalMicroSeconds stopTime;
   1.706 +	iImplementor.MmcStopTimeL(stopTime);
   1.707 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.708 +	pckg().iStopTime = stopTime;
   1.709 +	aMessage.WriteDataToClientL(pckg);
   1.710 +	return ETrue;
   1.711 +	}
   1.712 +
   1.713 +TBool CMidiCustomCommandParser::DoSetStopTimeL(TMMFMessage& aMessage)
   1.714 +	{
   1.715 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.716 +	aMessage.ReadData1FromClientL(pckg);
   1.717 +	iImplementor.MmcSetStopTimeL(pckg().iStopTime);
   1.718 +	return ETrue;
   1.719 +	}
   1.720 +
   1.721 +TBool CMidiCustomCommandParser::DoPolyphonyL(TMMFMessage& aMessage)
   1.722 +	{
   1.723 +	TInt numNotes;
   1.724 +	iImplementor.MmcPolyphonyL(numNotes);
   1.725 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.726 +	pckg().iNumNotes = numNotes;
   1.727 +	aMessage.WriteDataToClientL(pckg);
   1.728 +	return ETrue;
   1.729 +	}
   1.730 +
   1.731 +TBool CMidiCustomCommandParser::DoMaxPolyphonyL(TMMFMessage& aMessage)
   1.732 +	{
   1.733 +	TInt maxNotes;
   1.734 +	iImplementor.MmcMaxPolyphonyL(maxNotes);
   1.735 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.736 +	pckg().iMaxNotes = maxNotes;
   1.737 +	aMessage.WriteDataToClientL(pckg);
   1.738 +	return ETrue;
   1.739 +	}
   1.740 +
   1.741 +TBool CMidiCustomCommandParser::DoChannelsSupportedL(TMMFMessage& aMessage)
   1.742 +	{
   1.743 +	TInt channels;
   1.744 +	iImplementor.MmcChannelsSupportedL(channels);
   1.745 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.746 +	pckg().iChannel = channels;
   1.747 +	aMessage.WriteDataToClientL(pckg);
   1.748 +	return ETrue;
   1.749 +	}
   1.750 +
   1.751 +TBool CMidiCustomCommandParser::DoChannelVolumeL(TMMFMessage& aMessage)
   1.752 +	{
   1.753 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.754 +	aMessage.ReadData1FromClientL(pckg);
   1.755 +	TReal32 channelVol;
   1.756 +	iImplementor.MmcChannelVolumeL(pckg().iChannel, channelVol);
   1.757 +	pckg().iChannelVol = channelVol;
   1.758 +	aMessage.WriteDataToClientL(pckg);
   1.759 +	return ETrue;
   1.760 +	}
   1.761 +
   1.762 +TBool CMidiCustomCommandParser::DoMaxChannelVolumeL(TMMFMessage& aMessage)
   1.763 +	{
   1.764 +	TReal32 maxVol;
   1.765 +	iImplementor.MmcMaxChannelVolumeL(maxVol);
   1.766 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.767 +	pckg().iMaxChannelVol = maxVol;
   1.768 +	aMessage.WriteDataToClientL(pckg);
   1.769 +	return ETrue;
   1.770 +	}
   1.771 +
   1.772 +TBool CMidiCustomCommandParser::DoSetChannelVolumeL(TMMFMessage& aMessage)
   1.773 +	{
   1.774 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.775 +	aMessage.ReadData1FromClientL(pckg);
   1.776 +	iImplementor.MmcSetChannelVolumeL(pckg().iChannel, pckg().iChannelVol);
   1.777 +	return ETrue;
   1.778 +	}
   1.779 +
   1.780 +TBool CMidiCustomCommandParser::DoSetChannelMuteL(TMMFMessage& aMessage)
   1.781 +	{
   1.782 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.783 +	aMessage.ReadData1FromClientL(pckg);
   1.784 +	iImplementor.MmcSetChannelMuteL(pckg().iChannel, pckg().iMuted);
   1.785 +	return ETrue;
   1.786 +	}
   1.787 +
   1.788 +TBool CMidiCustomCommandParser::DoVolumeL(TMMFMessage& aMessage)
   1.789 +	{
   1.790 +	TInt vol;  
   1.791 +	iImplementor.MmcVolumeL(vol);
   1.792 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.793 +	pckg().iVolume = vol;
   1.794 +	aMessage.WriteDataToClientL(pckg);
   1.795 +	return ETrue;
   1.796 +	}
   1.797 +
   1.798 +TBool CMidiCustomCommandParser::DoMaxVolumeL(TMMFMessage& aMessage)
   1.799 +	{
   1.800 +	TInt maxVol;
   1.801 +	iImplementor.MmcMaxVolumeL(maxVol);
   1.802 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.803 +	pckg().iMaxVolume = maxVol;
   1.804 +	aMessage.WriteDataToClientL(pckg);
   1.805 +	return ETrue;
   1.806 +	}
   1.807 +
   1.808 +TBool CMidiCustomCommandParser::DoSetVolumeL(TMMFMessage& aMessage)
   1.809 +	{
   1.810 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.811 +	aMessage.ReadData1FromClientL(pckg);
   1.812 +	iImplementor.MmcSetVolumeL(pckg().iVolume);
   1.813 +	return ETrue;
   1.814 +	}
   1.815 +
   1.816 +TBool CMidiCustomCommandParser::DoSetVolumeRampL(TMMFMessage& aMessage)
   1.817 +	{
   1.818 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.819 +	aMessage.ReadData1FromClientL(pckg);
   1.820 +	iImplementor.MmcSetVolumeRampL(pckg().iRampDuration);
   1.821 +	return ETrue;
   1.822 +	}
   1.823 +
   1.824 +TBool CMidiCustomCommandParser::DoGetBalanceL(TMMFMessage& aMessage)
   1.825 +	{
   1.826 +	TInt balance;
   1.827 +	iImplementor.MmcGetBalanceL(balance);
   1.828 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.829 +	pckg().iBalance = balance;
   1.830 +	aMessage.WriteDataToClientL(pckg);
   1.831 +	return ETrue;
   1.832 +	}
   1.833 +
   1.834 +TBool CMidiCustomCommandParser::DoSetBalanceL(TMMFMessage& aMessage)
   1.835 +	{
   1.836 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.837 +	aMessage.ReadData1FromClientL(pckg);
   1.838 +	iImplementor.MmcSetBalanceL(pckg().iBalance);
   1.839 +	return ETrue;
   1.840 +	}
   1.841 +
   1.842 +TBool CMidiCustomCommandParser::DoSetMaxPolyphonyL(TMMFMessage& aMessage)
   1.843 +	{
   1.844 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.845 +	aMessage.ReadData1FromClientL(pckg);
   1.846 +	iImplementor.MmcSetMaxPolyphonyL(pckg().iMaxNotes);
   1.847 +	return ETrue;
   1.848 +	}
   1.849 +
   1.850 +TBool CMidiCustomCommandParser::DoGetRepeatsL(TMMFMessage& aMessage)
   1.851 +	{
   1.852 +	TInt numRepeats;
   1.853 +	iImplementor.MmcGetRepeatsL(numRepeats);
   1.854 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.855 +	pckg().iNumRepeats = numRepeats;
   1.856 +	aMessage.WriteDataToClientL(pckg);
   1.857 +	return ETrue;
   1.858 +	}
   1.859 +
   1.860 +TBool CMidiCustomCommandParser::DoSetRepeatsL(TMMFMessage& aMessage)
   1.861 +	{
   1.862 +	TPckgBuf<TMMFMidiConfig3> pckg;
   1.863 +	aMessage.ReadData1FromClientL(pckg);
   1.864 +	iImplementor.MmcSetRepeatsL(pckg().iRepeatNumberOfTimes, pckg().iTrailingSilence);
   1.865 +	return ETrue;
   1.866 +	}
   1.867 +
   1.868 +TBool CMidiCustomCommandParser::DoSetBankL(TMMFMessage& aMessage)
   1.869 +	{
   1.870 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.871 +	aMessage.ReadData1FromClientL(pckg);
   1.872 +	iImplementor.MmcSetBankL(pckg().iCustom);
   1.873 +	return ETrue;
   1.874 +	}
   1.875 +
   1.876 +TBool CMidiCustomCommandParser::DoIsTrackMuteL(TMMFMessage& aMessage)
   1.877 +	{
   1.878 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.879 +	aMessage.ReadData1FromClientL(pckg);
   1.880 +	TBool mute;
   1.881 +	iImplementor.MmcIsTrackMuteL(pckg().iTrack, mute);
   1.882 +	pckg().iMuted = mute;
   1.883 +	aMessage.WriteDataToClientL(pckg);
   1.884 +	return ETrue;
   1.885 +	}
   1.886 +
   1.887 +TBool CMidiCustomCommandParser::DoIsChannelMuteL(TMMFMessage& aMessage)
   1.888 +	{
   1.889 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.890 +	aMessage.ReadData1FromClientL(pckg);
   1.891 +	TBool mute;
   1.892 +	iImplementor.MmcIsChannelMuteL(pckg().iChannel, mute);
   1.893 +	pckg().iMuted = mute;
   1.894 +	aMessage.WriteDataToClientL(pckg);
   1.895 +	return ETrue;
   1.896 +	}
   1.897 +
   1.898 +TBool CMidiCustomCommandParser::DoGetInstrumentL(TMMFMessage& aMessage)
   1.899 +	{
   1.900 +	TPckgBuf<TMMFMidiConfig2> pckg;
   1.901 +	aMessage.ReadData1FromClientL(pckg);
   1.902 +	TInt instrumentId;
   1.903 +	TInt bankId;
   1.904 +	iImplementor.MmcGetInstrumentL(pckg().iChannel, instrumentId, bankId);
   1.905 +	pckg().iInstrumentId = instrumentId;
   1.906 +	pckg().iBankId = bankId;
   1.907 +	aMessage.WriteDataToClientL(pckg);
   1.908 +	return ETrue;
   1.909 +	}
   1.910 +
   1.911 +TBool CMidiCustomCommandParser::DoCloseL(TMMFMessage& /*aMessage*/)
   1.912 +	{
   1.913 +	iImplementor.MmcCloseL();
   1.914 +	return ETrue;
   1.915 +	}
   1.916 +
   1.917 +TBool CMidiCustomCommandParser::DoStopL(TMMFMessage& aMessage)
   1.918 +	{
   1.919 +	TPckgBuf<TMMFMidiConfig1> pckg;
   1.920 +	aMessage.ReadData1FromClientL(pckg);
   1.921 +	iImplementor.MmcStopL(pckg().iFadeOutDuration);
   1.922 +	return ETrue;
   1.923 +	}
   1.924 +
   1.925 +TBool CMidiCustomCommandParser::DoReceiveEventsL(TMMFMessage& aMessage)
   1.926 +	{
   1.927 +	if (iMidiEventReceiver)
   1.928 +		{
   1.929 +		if (iMidiEventReceiver->IsWaitingToSendEvent())
   1.930 +			{
   1.931 +			//Something must have gone wrong in the client
   1.932 +			// - we're waiting to get a RetrieveEvent() call, but it didn't come.
   1.933 +			// So, delete the existing event receiver
   1.934 +			delete iMidiEventReceiver;
   1.935 +			iMidiEventReceiver = NULL;
   1.936 +			}
   1.937 +		else
   1.938 +			{
   1.939 +			User::Leave(KErrAlreadyExists);
   1.940 +			}
   1.941 +		}
   1.942 +	ASSERT(!iMidiEventReceiver);
   1.943 +	iMidiEventReceiver = CMidiEventReceiver::NewL(aMessage);
   1.944 +	//send the next cached event (if any) to the client
   1.945 +	if (iMidiEvents.Count() > 0)
   1.946 +		{
   1.947 +		CMMFMidiEvent* midiEvent = iMidiEvents[0];
   1.948 +		iMidiEventReceiver->PrepareEventL(*midiEvent);
   1.949 +		iMidiEvents.Remove(0);
   1.950 +		delete midiEvent;
   1.951 +		}
   1.952 +	return EFalse;
   1.953 +	}
   1.954 +
   1.955 +TBool CMidiCustomCommandParser::DoRetrieveEventL(TMMFMessage& aMessage)
   1.956 +	{
   1.957 +	if (iMidiEventReceiver)
   1.958 +		{
   1.959 +		iMidiEventReceiver->SendEventL(aMessage);
   1.960 +		delete iMidiEventReceiver;
   1.961 +		iMidiEventReceiver = NULL;
   1.962 +		}
   1.963 +	else
   1.964 +		{
   1.965 +		User::Leave(KErrNotReady);
   1.966 +		}
   1.967 +
   1.968 +	return ETrue;
   1.969 +	}
   1.970 +
   1.971 +/**
   1.972 +Sent a MIDI event back to the client.
   1.973 +
   1.974 +@param aEvent MIDI event to be sent to the client.
   1.975 +@return One of the system-wide error codes.
   1.976 +*/
   1.977 +TInt CMidiCustomCommandParser::SendMidiEventToClient(const CMMFMidiEvent& aEvent)
   1.978 +	{
   1.979 +	TInt error = KErrNone;
   1.980 +	if (iMidiEventReceiver && !iMidiEventReceiver->IsWaitingToSendEvent())
   1.981 +		{
   1.982 +		//prepare to send event to client
   1.983 +		TRAP(error, iMidiEventReceiver->PrepareEventL(aEvent));
   1.984 +		}
   1.985 +	else
   1.986 +		{
   1.987 +		//queue the request for later
   1.988 +		CMMFMidiEvent* midiEvent = new CMMFMidiEvent();
   1.989 +		if (!midiEvent)
   1.990 +			return KErrNoMemory;
   1.991 +
   1.992 +		// coverity[leave_without_push]
   1.993 +		TRAP(error, midiEvent->CopyL(aEvent));
   1.994 +		//if we've exceeded the max number of cached messages, delete the first and append this one to the end
   1.995 +		if (!error)
   1.996 +			{
   1.997 +			error = iMidiEvents.Append(midiEvent);
   1.998 +			}
   1.999 +
  1.1000 +		if(error != KErrNone)
  1.1001 +			delete midiEvent;
  1.1002 +		}
  1.1003 +	return error;
  1.1004 +	}
  1.1005 +
  1.1006 +
  1.1007 +TBool CMidiCustomCommandParser::DoCancelReceiveEventsL(TMMFMessage& /*aMessage*/)
  1.1008 +	{
  1.1009 +	delete iMidiEventReceiver;
  1.1010 +	iMidiEventReceiver = NULL;
  1.1011 +	return ETrue;
  1.1012 +	}