os/mm/mmlibs/mmfw/MIDI/src/midicustomcommandparser.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <mmf/common/midistandardcustomcommands.h>
    17 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    18 #include <mmf/common/midieventreceiver.h>
    19 #include <mmf/common/mmfmidiconfig.h>
    20 #endif
    21 const TInt KMimeTypeLength = 256;
    22 
    23 
    24 /**
    25 Creates a new MIDI custom command parser capable of handling MIDI controller commands.
    26 
    27 @param	aImplementor A reference to the controller plugin that owns this new object.
    28 @leave	This function may leave with one of the system-wide error codes.
    29 */
    30 EXPORT_C CMidiCustomCommandParser* CMidiCustomCommandParser::NewL(MMidiCustomCommandImplementor& aImplementor)
    31 	{
    32 	return new(ELeave) CMidiCustomCommandParser(aImplementor);
    33 	}
    34 
    35 CMidiCustomCommandParser::CMidiCustomCommandParser(MMidiCustomCommandImplementor& aImplementor) :
    36 	CMMFCustomCommandParserBase(KUidInterfaceMidi),
    37 	iImplementor(aImplementor)
    38 	{
    39 	}
    40 
    41 /**
    42 Destructor.
    43 */
    44 EXPORT_C CMidiCustomCommandParser::~CMidiCustomCommandParser()
    45 	{
    46 	delete iMidiEventReceiver;
    47 	delete iInstrumentName;
    48 	delete iPercussionKeyName;
    49 	iMidiEvents.ResetAndDestroy();
    50 	iMidiEvents.Close();
    51 	}
    52 
    53 /**
    54 Handles a request from the client. Called by the controller framework.
    55 
    56 @param aMessage The message to be handled.
    57 */
    58 void CMidiCustomCommandParser::HandleRequest(TMMFMessage& aMessage)
    59 	{
    60 	if (aMessage.Destination().InterfaceId() == KUidInterfaceMidi)
    61 		{
    62 		TRAPD(error, DoHandleRequestL(aMessage));
    63 		if (error)
    64 			aMessage.Complete(error);
    65 		}
    66 	else
    67 		{
    68 		aMessage.Complete(KErrNotSupported);
    69 		}
    70 	}
    71 
    72 void CMidiCustomCommandParser::DoHandleRequestL(TMMFMessage& aMessage)
    73 	{
    74 	TBool complete = ETrue;
    75 	switch (aMessage.Function())
    76 		{
    77 	case EMMFMidiControllerSetPositionMicroBeats:
    78 		complete = DoSetPositionMicroBeatsL(aMessage);
    79 		break;
    80 	case EMMFMidiControllerPositionMicroBeats:
    81 		complete = DoPositionMicroBeatsL(aMessage);
    82 		break;
    83 	case EMMFMidiControllerPlayNote:
    84 		complete = DoPlayNoteL(aMessage);
    85 		break;
    86 	case EMMFMidiControllerPlayNoteWithStartTime:
    87 		complete = DoPlayNoteWithStartTimeL(aMessage);
    88 		break;
    89 	case EMMFMidiControllerStopNotes:
    90 		complete = DoStopNotesL(aMessage);
    91 		break;
    92 	case EMMFMidiControllerNoteOn:
    93 		complete = DoNoteOnL(aMessage);
    94 		break;
    95 	case EMMFMidiControllerNoteOff:
    96 		complete = DoNoteOffL(aMessage);
    97 		break;
    98 	case EMMFMidiControllerPlaybackRate:
    99 		complete = DoPlaybackRateL(aMessage);
   100 		break;
   101 	case EMMFMidiControllerSetPlaybackRate:
   102 		complete = DoSetPlaybackRateL(aMessage);
   103 		break;
   104 	case EMMFMidiControllerMaxPlaybackRate:
   105 		complete = DoMaxPlaybackRateL(aMessage);
   106 		break;
   107 	case EMMFMidiControllerMinPlaybackRate:
   108 		complete = DoMinPlaybackRateL(aMessage);
   109 		break;
   110 	case EMMFMidiControllerTempo:
   111 		complete = DoTempoMicroBeatsPerMinuteL(aMessage);
   112 		break;
   113 	case EMMFMidiControllerSetTempo:
   114 		complete = DoSetTempoL(aMessage);
   115 		break;
   116 	case EMMFMidiControllerPitch:
   117 		complete = DoPitchTranspositionCentsL(aMessage);
   118 		break;
   119 	case EMMFMidiControllerSetPitch:
   120 		complete = DoSetPitchTranspositionL(aMessage);
   121 		break;
   122 	case EMMFMidiControllerDurationMicroBeats:
   123 		complete = DoDurationMicroBeatsL(aMessage);
   124 		break;
   125 	case EMMFMidiControllerNumTracks:
   126 		complete = DoNumTracksL(aMessage);
   127 		break;
   128 	case EMMFMidiControllerSetTrackMute:
   129 		complete = DoSetTrackMuteL(aMessage);
   130 		break;
   131 	case EMMFMidiControllerMimeType:
   132 		complete = DoMimeTypeL(aMessage);
   133 		break;
   134 	case EMMFMidiControllerSetSyncUpdateCallbackInterval:
   135 		complete = DoSetSyncUpdateCallbackIntervalL(aMessage);
   136 		break;
   137 	case EMMFMidiControllerSendMessage:
   138 		complete = DoSendMessageL(aMessage);
   139 		break;
   140 	case EMMFMidiControllerSendMessageWithTimeStamp:
   141 		complete = DoSendMessageWithTimeStampL(aMessage);
   142 		break;
   143 	case EMMFMidiControllerSendMipMessage:
   144 		complete = DoSendMipMessageL(aMessage);
   145 		break;
   146 	case EMMFMidiControllerNumberOfBanks:
   147 		complete = DoNumberOfBanksL(aMessage);
   148 		break;
   149 	case EMMFMidiControllerGetBankId:
   150 		complete = DoGetBankIdL(aMessage);
   151 		break;
   152 	case EMMFMidiControllerLoadCustomBank:
   153 		complete = DoLoadCustomBankL(aMessage);
   154 		break;
   155 	case EMMFMidiControllerLoadCustomBankData:
   156 		complete = DoLoadCustomBankDataL(aMessage);
   157 		break;
   158 	case EMMFMidiControllerUnloadCustomBank:
   159 		complete = DoUnloadCustomBankL(aMessage);
   160 		break;
   161 	case EMMFMidiControllerCustomBankLoaded:
   162 		complete = DoCustomBankLoadedL(aMessage);
   163 		break;
   164 	case EMMFMidiControllerUnloadAllCustomBanks:
   165 		complete = DoUnloadAllCustomBanksL(aMessage);
   166 		break;
   167 	case EMMFMidiControllerNumberOfInstruments:
   168 		complete = DoNumberOfInstrumentsL(aMessage);
   169 		break;
   170 	case EMMFMidiControllerGetInstrumentId:
   171 		complete = DoGetInstrumentIdL(aMessage);
   172 		break;
   173 	case EMMFMidiControllerInstrumentName:
   174 		complete = DoInstrumentNameL(aMessage);
   175 		break;
   176 	case EMMFMidiControllerCopyInstrumentName:
   177 		complete = DoCopyInstrumentNameL(aMessage);
   178 		break;
   179 	case EMMFMidiControllerSetInstrument:
   180 		complete = DoSetInstrumentL(aMessage);
   181 		break;
   182 	case EMMFMidiControllerLoadCustomInstrument:
   183 		complete = DoLoadCustomInstrumentL(aMessage);
   184 		break;
   185 	case EMMFMidiControllerLoadCustomInstrumentData:
   186 		complete = DoLoadCustomInstrumentDataL(aMessage);
   187 		break;
   188 	case EMMFMidiControllerUnloadCustomInstrument:
   189 		complete = DoUnloadCustomInstrumentL(aMessage);
   190 		break;
   191 	case EMMFMidiControllerPercussionKeyName:
   192 		complete = DoPercussionKeyNameL(aMessage);
   193 		break;
   194 	case EMMFMidiControllerCopyPercussionKeyName:
   195 		complete = DoCopyPercussionKeyNameL(aMessage);
   196 		break;
   197 	case EMMFMidiControllerStopTime:
   198 		complete = DoStopTimeL(aMessage);
   199 		break;
   200 	case EMMFMidiControllerSetStopTime:
   201 		complete = DoSetStopTimeL(aMessage);
   202 		break;
   203 	case EMMFMidiControllerPolyphony:
   204 		complete = DoPolyphonyL(aMessage);
   205 		break;
   206 	case EMMFMidiControllerChannelsSupported:
   207 		complete = DoChannelsSupportedL(aMessage);
   208 		break;
   209 	case EMMFMidiControllerChannelVolume:
   210 		complete = DoChannelVolumeL(aMessage);
   211 		break;
   212 	case EMMFMidiControllerMaxChannelVolume:
   213 		complete = DoMaxChannelVolumeL(aMessage);
   214 		break;
   215 	case EMMFMidiControllerSetChannelVolume:
   216 		complete = DoSetChannelVolumeL(aMessage);
   217 		break;
   218 	case EMMFMidiControllerSetChannelMute:
   219 		complete = DoSetChannelMuteL(aMessage);
   220 		break;
   221 	case EMMFMidiControllerVolume:
   222 		complete = DoVolumeL(aMessage);
   223 		break;
   224 	case EMMFMidiControllerMaxVolume:
   225 		complete = DoMaxVolumeL(aMessage);
   226 		break;
   227 	case EMMFMidiControllerSetVolume:
   228 		complete = DoSetVolumeL(aMessage);
   229 		break;
   230 	case EMMFMidiControllerSetVolumeRamp:
   231 		complete = DoSetVolumeRampL(aMessage);
   232 		break;
   233 	case EMMFMidiControllerGetBalance:
   234 		complete = DoGetBalanceL(aMessage);
   235 		break;
   236 	case EMMFMidiControllerSetBalance:
   237 		complete = DoSetBalanceL(aMessage);
   238 		break;
   239 	case EMMFMidiControllerSetMaxPolyphony:
   240 		complete = DoSetMaxPolyphonyL(aMessage);
   241 		break;
   242 	case EMMFMidiControllerGetRepeats:
   243 		complete = DoGetRepeatsL(aMessage);
   244 		break;
   245 	case EMMFMidiControllerSetRepeats:
   246 		complete = DoSetRepeatsL(aMessage);
   247 		break;
   248 	case EMMFMidiControllerSetBank:
   249 		DoSetBankL(aMessage);
   250 		break;
   251 	case EMMFMidiControllerIsTrackMute:
   252 		DoIsTrackMuteL(aMessage);
   253 		break;
   254 	case EMMFMidiControllerIsChannelMute:
   255 		DoIsChannelMuteL(aMessage);
   256 		break;
   257 	case EMMFMidiControllerGetInstrument:
   258 		DoGetInstrumentL(aMessage);
   259 		break;
   260 	case EMMFMidiControllerClose:
   261 		complete = DoCloseL(aMessage);
   262 		break;
   263 	case EMMFMidiControllerStop:
   264 		complete = DoStopL(aMessage);
   265 		break;
   266 	case EMMFMidiControllerReceiveEvents:
   267 		complete = DoReceiveEventsL(aMessage);
   268 		break;
   269 	case EMMFMidiControllerRetrieveEvent:
   270 		complete = DoRetrieveEventL(aMessage);
   271 		break;
   272 	case EMMFMidiControllerCancelReceiveEvents:
   273 		complete = DoCancelReceiveEventsL(aMessage);
   274 		break;
   275 	case EMMFMidiControllerMaxPolyphony:
   276 		complete = DoMaxPolyphonyL(aMessage);
   277 		break;
   278 	default:
   279 		User::Leave(KErrNotSupported);
   280 		break;
   281 		}
   282 	if (complete)
   283 		aMessage.Complete(KErrNone);
   284 	}
   285 
   286 TBool CMidiCustomCommandParser::DoSetPositionMicroBeatsL(TMMFMessage& aMessage)
   287 	{
   288 	TPckgBuf<TMMFMidiConfig2> pckg;
   289 	aMessage.ReadData1FromClientL(pckg);
   290 	iImplementor.MmcSetPositionMicroBeatsL(pckg().iPositionMicroBeats);
   291 	return ETrue;
   292 	}
   293 
   294 TBool CMidiCustomCommandParser::DoPositionMicroBeatsL(TMMFMessage& aMessage)
   295 	{
   296 	TInt64 microBeats = 0;
   297 	iImplementor.MmcPositionMicroBeatsL(microBeats);
   298 	TPckgBuf<TMMFMidiConfig2> pckg;
   299 	pckg().iPositionMicroBeats = microBeats;
   300 	aMessage.WriteDataToClientL(pckg);
   301 	return ETrue;
   302 	}
   303 
   304 TBool CMidiCustomCommandParser::DoPlayNoteL(TMMFMessage& aMessage)
   305 	{
   306 	TPckgBuf<TMMFMidiConfig2> pckg;
   307 	aMessage.ReadData1FromClientL(pckg);
   308 	iImplementor.MmcPlayNoteL(pckg().iChannel, pckg().iNote, pckg().iDurationMicroSeconds, pckg().iNoteOnVelocity, pckg().iNoteOffVelocity);
   309 	return ETrue;
   310 	}
   311 
   312 TBool CMidiCustomCommandParser::DoPlayNoteWithStartTimeL(TMMFMessage& aMessage)
   313 	{
   314 	TPckgBuf<TMMFMidiConfig2> pckg;
   315 	aMessage.ReadData1FromClientL(pckg);
   316 	iImplementor.MmcPlayNoteL(pckg().iChannel, pckg().iNote, pckg().iStartTime, pckg().iDurationMicroSeconds, pckg().iNoteOnVelocity, pckg().iNoteOffVelocity);
   317 	return ETrue;
   318 	}
   319 
   320 TBool CMidiCustomCommandParser::DoStopNotesL(TMMFMessage& aMessage)
   321 	{
   322 	TPckgBuf<TMMFMidiConfig2> pckg;
   323 	aMessage.ReadData1FromClientL(pckg);
   324 	iImplementor.MmcStopNotesL(pckg().iChannel);
   325 	return ETrue;
   326 	}
   327 
   328 TBool CMidiCustomCommandParser::DoNoteOnL(TMMFMessage& aMessage)
   329 	{
   330 	TPckgBuf<TMMFMidiConfig2> pckg;
   331 	aMessage.ReadData1FromClientL(pckg);
   332 	iImplementor.MmcNoteOnL(pckg().iChannel, pckg().iNote, pckg().iNoteOnVelocity);
   333 	return ETrue;
   334 	}
   335 
   336 TBool CMidiCustomCommandParser::DoNoteOffL(TMMFMessage& aMessage)
   337 	{
   338 	TPckgBuf<TMMFMidiConfig2> pckg;
   339 	aMessage.ReadData1FromClientL(pckg);
   340 	iImplementor.MmcNoteOffL(pckg().iChannel, pckg().iNote, pckg().iNoteOffVelocity);
   341 	return ETrue;
   342 	}
   343 
   344 TBool CMidiCustomCommandParser::DoPlaybackRateL(TMMFMessage& aMessage)
   345 	{
   346 	TInt playBackRate;
   347 	iImplementor.MmcPlaybackRateL(playBackRate);
   348 	TPckgBuf<TMMFMidiConfig3> pckg;
   349 	pckg().iPlayBackRate = playBackRate;
   350 	aMessage.WriteDataToClientL(pckg);
   351 	return ETrue;
   352 	}
   353 
   354 TBool CMidiCustomCommandParser::DoSetPlaybackRateL(TMMFMessage& aMessage)
   355 	{
   356 	TPckgBuf<TMMFMidiConfig3> pckg;
   357 	aMessage.ReadData1FromClientL(pckg);
   358 	iImplementor.MmcSetPlaybackRateL(pckg().iPlayBackRate);
   359 	return ETrue;
   360 	}
   361 
   362 TBool CMidiCustomCommandParser::DoMaxPlaybackRateL(TMMFMessage& aMessage)
   363 	{
   364 	TInt maxRate;
   365 	iImplementor.MmcMaxPlaybackRateL(maxRate);
   366 	TPckgBuf<TMMFMidiConfig3> pckg;
   367 	pckg().iPlayBackMaxRate = maxRate;
   368 	aMessage.WriteDataToClientL(pckg);
   369 	return ETrue;
   370 	}
   371 
   372 TBool CMidiCustomCommandParser::DoMinPlaybackRateL(TMMFMessage& aMessage)
   373 	{
   374 	TInt minRate;
   375 	iImplementor.MmcMinPlaybackRateL(minRate);
   376 	TPckgBuf<TMMFMidiConfig3> pckg;
   377 	pckg().iPlayBackMinRate = minRate;
   378 	aMessage.WriteDataToClientL(pckg);
   379 	return ETrue;
   380 	}
   381 
   382 TBool CMidiCustomCommandParser::DoTempoMicroBeatsPerMinuteL(TMMFMessage& aMessage)
   383 	{
   384 	TInt microBeatsPerMinute;
   385 	iImplementor.MmcTempoMicroBeatsPerMinuteL(microBeatsPerMinute);
   386 	TPckgBuf<TMMFMidiConfig1> pckg;
   387 	pckg().iTempo = microBeatsPerMinute;
   388 	aMessage.WriteDataToClientL(pckg);
   389 	return ETrue;
   390 	}
   391 
   392 TBool CMidiCustomCommandParser::DoSetTempoL(TMMFMessage& aMessage)
   393 	{
   394 	TPckgBuf<TMMFMidiConfig1> pckg;
   395 	aMessage.ReadData1FromClientL(pckg);
   396 	iImplementor.MmcSetTempoL(pckg().iTempo);
   397 	return ETrue;
   398 	}
   399 
   400 TBool CMidiCustomCommandParser::DoPitchTranspositionCentsL(TMMFMessage& aMessage)
   401 	{
   402 	TInt pitch;
   403 	iImplementor.MmcPitchTranspositionCentsL(pitch);
   404 	TPckgBuf<TMMFMidiConfig1> pckg;
   405 	pckg().iPitch = pitch;
   406 	aMessage.WriteDataToClientL(pckg);
   407 	return ETrue;
   408 	}
   409 
   410 TBool CMidiCustomCommandParser::DoSetPitchTranspositionL(TMMFMessage& aMessage)
   411 	{
   412 	TPckgBuf<TMMFMidiConfig1> pckg;
   413 	aMessage.ReadData1FromClientL(pckg);
   414 	TInt centsApplied;
   415 	iImplementor.MmcSetPitchTranspositionL(pckg().iPitch, centsApplied);
   416 	pckg().iPitch = centsApplied;
   417 	aMessage.WriteDataToClientL(pckg);
   418 	return ETrue;
   419 	}
   420 
   421 TBool CMidiCustomCommandParser::DoDurationMicroBeatsL(TMMFMessage& aMessage)
   422 	{
   423 	TInt64 duration;
   424 	iImplementor.MmcDurationMicroBeatsL(duration);
   425 	TPckgBuf<TMMFMidiConfig2> pckg;
   426 	pckg().iDurationMicroBeats = duration;
   427 	aMessage.WriteDataToClientL(pckg);
   428 	return ETrue;
   429 	}
   430 
   431 TBool CMidiCustomCommandParser::DoNumTracksL(TMMFMessage& aMessage)
   432 	{
   433 	TInt numTracks;
   434 	iImplementor.MmcNumTracksL(numTracks);
   435 	TPckgBuf<TMMFMidiConfig1> pckg;
   436 	pckg().iNumTracks = numTracks;
   437 	aMessage.WriteDataToClientL(pckg);
   438 	return ETrue;
   439 	}
   440 
   441 TBool CMidiCustomCommandParser::DoSetTrackMuteL(TMMFMessage& aMessage)
   442 	{
   443 	TPckgBuf<TMMFMidiConfig2> pckg;
   444 	aMessage.ReadData1FromClientL(pckg);
   445 	iImplementor.MmcSetTrackMuteL(pckg().iTrack, pckg().iMuted);
   446 	return ETrue;
   447 	}
   448 
   449 TBool CMidiCustomCommandParser::DoMimeTypeL(TMMFMessage& aMessage)
   450 	{
   451 	HBufC8* mimeType = HBufC8::NewL(KMimeTypeLength);
   452 	TPtr8 des = mimeType->Des();
   453 	CleanupStack::PushL(mimeType);
   454 	iImplementor.MmcMimeTypeL(des);
   455 	aMessage.WriteDataToClientL(des);
   456 	CleanupStack::PopAndDestroy();//mimeType
   457 	return ETrue;
   458 	}
   459 
   460 TBool CMidiCustomCommandParser::DoSetSyncUpdateCallbackIntervalL(TMMFMessage& aMessage)
   461 	{
   462 	TPckgBuf<TMMFMidiConfig3> pckg;
   463 	aMessage.ReadData1FromClientL(pckg);
   464 	iImplementor.MmcSetSyncUpdateCallbackIntervalL(pckg().iCallbackIntervalMicroSeconds, pckg().iCallbackIntervalMicroBeats);
   465 	return ETrue;
   466 	}
   467 
   468 TBool CMidiCustomCommandParser::DoSendMessageL(TMMFMessage& aMessage)
   469 	{
   470 	TPckgBuf<TMMFMidiConfig3> pckg;
   471 	aMessage.ReadData1FromClientL(pckg);
   472 	TInt bytesProcessed;
   473 	iImplementor.MmcSendMessageL(*(pckg().iMidiMessage), bytesProcessed);
   474 	pckg().iBytesProcessed = bytesProcessed;
   475 	aMessage.WriteDataToClientL(pckg);
   476 	return ETrue;
   477 	}
   478 
   479 TBool CMidiCustomCommandParser::DoSendMessageWithTimeStampL(TMMFMessage& aMessage)
   480 	{
   481 	TPckgBuf<TMMFMidiConfig3> pckg;
   482 	aMessage.ReadData1FromClientL(pckg);
   483 	TInt bytesProcessed;
   484 	iImplementor.MmcSendMessageL(*(pckg().iMidiMessage), pckg().iTimeStamp, bytesProcessed);
   485 	pckg().iBytesProcessed = bytesProcessed;
   486 	aMessage.WriteDataToClientL(pckg);
   487 	return ETrue;
   488 	}
   489 
   490 TBool CMidiCustomCommandParser::DoSendMipMessageL(TMMFMessage& aMessage)
   491 	{
   492 	TPckgBuf<TMMFMidiConfig1> pckg;
   493 	aMessage.ReadData1FromClientL(pckg);
   494 	iImplementor.MmcSendMipMessageL(*(pckg().iMipMessage));
   495 	return ETrue;
   496 	}
   497 
   498 TBool CMidiCustomCommandParser::DoNumberOfBanksL(TMMFMessage& aMessage)
   499 	{
   500 	TPckgBuf<TMMFMidiConfig2> pckg;
   501 	aMessage.ReadData1FromClientL(pckg);
   502 	TInt numBanks;
   503 	iImplementor.MmcNumberOfBanksL(pckg().iCustom, numBanks);
   504 	pckg().iNumBanks = numBanks;
   505 	aMessage.WriteDataToClientL(pckg);
   506 	return ETrue;
   507 	}
   508 
   509 TBool CMidiCustomCommandParser::DoGetBankIdL(TMMFMessage& aMessage)
   510 	{
   511 	TPckgBuf<TMMFMidiConfig2> pckg;
   512 	aMessage.ReadData1FromClientL(pckg);
   513 	TInt bankId;
   514 	iImplementor.MmcGetBankIdL(pckg().iCustom, pckg().iBankIndex, bankId);
   515 	pckg().iBankId = bankId;
   516 	aMessage.WriteDataToClientL(pckg);
   517 	return ETrue;
   518 	}
   519 
   520 TBool CMidiCustomCommandParser::DoLoadCustomBankL(TMMFMessage& aMessage)
   521 	{
   522 	TPckgBuf<TMMFMidiConfig2> pckg;
   523 	aMessage.ReadData1FromClientL(pckg);
   524 	TInt bankId;
   525 	iImplementor.MmcLoadCustomBankL(*(pckg().iFileName), bankId);
   526 	pckg().iBankId = bankId;
   527 	aMessage.WriteDataToClientL(pckg);
   528 	return ETrue;
   529 	}
   530 
   531 TBool CMidiCustomCommandParser::DoLoadCustomBankDataL(TMMFMessage& aMessage)
   532 	{
   533 	TPckgBuf<TMMFMidiConfig2> pckg;
   534 	aMessage.ReadData1FromClientL(pckg);
   535 	TInt bankId;
   536 	iImplementor.MmcLoadCustomBankDataL(*(pckg().iBankData), bankId);
   537 	pckg().iBankId = bankId;
   538 	aMessage.WriteDataToClientL(pckg);
   539 	return ETrue;
   540 	}
   541 
   542 TBool CMidiCustomCommandParser::DoUnloadCustomBankL(TMMFMessage& aMessage)
   543 	{
   544 	TPckgBuf<TMMFMidiConfig2> pckg;
   545 	aMessage.ReadData1FromClientL(pckg);
   546 	iImplementor.MmcUnloadCustomBankL(pckg().iBankId);
   547 	return ETrue;
   548 	}
   549 
   550 TBool CMidiCustomCommandParser::DoCustomBankLoadedL(TMMFMessage& aMessage)
   551 	{
   552 	TPckgBuf<TMMFMidiConfig2> pckg;
   553 	aMessage.ReadData1FromClientL(pckg);
   554 	TBool bankLoaded;
   555 	iImplementor.MmcCustomBankLoadedL(pckg().iBankId, bankLoaded);
   556 	pckg().iBankLoaded = bankLoaded;
   557 	aMessage.WriteDataToClientL(pckg);
   558 	return ETrue;
   559 	}
   560 
   561 TBool CMidiCustomCommandParser::DoUnloadAllCustomBanksL(TMMFMessage& /*aMessage*/)
   562 	{
   563 	iImplementor.MmcUnloadAllCustomBanksL();
   564 	return ETrue;
   565 	}
   566 
   567 TBool CMidiCustomCommandParser::DoNumberOfInstrumentsL(TMMFMessage& aMessage)
   568 	{
   569 	TPckgBuf<TMMFMidiConfig2> pckg;
   570 	aMessage.ReadData1FromClientL(pckg);
   571 	TInt numInstruments;
   572 	iImplementor.MmcNumberOfInstrumentsL(pckg().iBankId, pckg().iCustom, numInstruments);	
   573 	pckg().iNumInstruments = numInstruments;
   574 	aMessage.WriteDataToClientL(pckg);
   575 	return ETrue;
   576 	}
   577 
   578 TBool CMidiCustomCommandParser::DoGetInstrumentIdL(TMMFMessage& aMessage)
   579 	{
   580 	TPckgBuf<TMMFMidiConfig2> pckg;
   581 	aMessage.ReadData1FromClientL(pckg);
   582 	TInt instrumentId;
   583 	iImplementor.MmcGetInstrumentIdL(pckg().iBankId, pckg().iCustom, pckg().iInstrumentIndex, instrumentId);
   584 	pckg().iInstrumentId = instrumentId;
   585 	aMessage.WriteDataToClientL(pckg);
   586 	return ETrue;
   587 	}
   588 
   589 TBool CMidiCustomCommandParser::DoInstrumentNameL(TMMFMessage& aMessage)
   590 	{
   591 	TPckgBuf<TMMFMidiConfig2> pckg;
   592 	aMessage.ReadData1FromClientL(pckg);
   593 
   594 	// Prevent memory leaks by deleting old instrument name - something must have gone wrong in the client
   595 	// if it already exists
   596 	delete iInstrumentName;
   597 	iInstrumentName = NULL;
   598 
   599 	// Get the instrument name from the controller
   600 	const TDesC& instrumentName = iImplementor.MmcInstrumentNameL(pckg().iBankId, pckg().iCustom, pckg().iInstrumentId);
   601 
   602 	iInstrumentName = CBufFlat::NewL(32);
   603 	RBufWriteStream stream;
   604 	stream.Open(*iInstrumentName);
   605 	CleanupClosePushL(stream);
   606 	stream << instrumentName;
   607 	CleanupStack::PopAndDestroy();//s
   608 
   609 	// Write the size of the descriptor back to the client
   610 	TPckgBuf<TInt> descriptorSizePckg(iInstrumentName->Ptr(0).Length());	
   611 	aMessage.WriteDataToClientL(descriptorSizePckg);
   612 
   613 	return ETrue;
   614 	}
   615 
   616 TBool CMidiCustomCommandParser::DoCopyInstrumentNameL(TMMFMessage& aMessage)
   617 	{
   618 	if (!iInstrumentName)
   619 		User::Leave(KErrNotReady);
   620 
   621 	// Copy the instrument name back to the client
   622 	aMessage.WriteDataToClientL(iInstrumentName->Ptr(0));
   623 	delete iInstrumentName;
   624 	iInstrumentName = NULL;
   625 	return ETrue;
   626 	}
   627 
   628 TBool CMidiCustomCommandParser::DoSetInstrumentL(TMMFMessage& aMessage)
   629 	{
   630 	TPckgBuf<TMMFMidiConfig2> pckg;
   631 	aMessage.ReadData1FromClientL(pckg);
   632 	iImplementor.MmcSetInstrumentL(pckg().iChannel, pckg().iBankId, pckg().iInstrumentId);
   633 	return ETrue;
   634 	}
   635 
   636 TBool CMidiCustomCommandParser::DoLoadCustomInstrumentL(TMMFMessage& aMessage)
   637 	{
   638 	TPckgBuf<TMMFMidiConfig2> pckg;
   639 	aMessage.ReadData1FromClientL(pckg);
   640 	iImplementor.MmcLoadCustomInstrumentL(*(pckg().iFileName), pckg().iBankId, pckg().iInstrumentId, pckg().iMemoryBankId,  pckg().iMemoryInstrumentId);
   641 	return ETrue;
   642 	}
   643 
   644 TBool CMidiCustomCommandParser::DoLoadCustomInstrumentDataL(TMMFMessage& aMessage)
   645 	{
   646 	TPckgBuf<TMMFMidiConfig2> pckg;
   647 	aMessage.ReadData1FromClientL(pckg);
   648 	iImplementor.MmcLoadCustomInstrumentDataL(*(pckg().iInstrumentData), pckg().iBankId, pckg().iInstrumentId, pckg().iMemoryBankId,  pckg().iMemoryInstrumentId);
   649 	return ETrue;
   650 	}
   651 
   652 TBool CMidiCustomCommandParser::DoUnloadCustomInstrumentL(TMMFMessage& aMessage)
   653 	{
   654 	TPckgBuf<TMMFMidiConfig2> pckg;
   655 	aMessage.ReadData1FromClientL(pckg);
   656 	iImplementor.MmcUnloadCustomInstrumentL(pckg().iBankId, pckg().iInstrumentId);
   657 	return ETrue;
   658 	}
   659 
   660 TBool CMidiCustomCommandParser::DoPercussionKeyNameL(TMMFMessage& aMessage)
   661 	{
   662 	TPckgBuf<TMMFMidiConfig2> pckg;
   663 	aMessage.ReadData1FromClientL(pckg);
   664 
   665 	// Prevent memory leaks by deleting old key name - something must have gone wrong in the client
   666 	// if it already exists
   667 	delete iPercussionKeyName;
   668 	iPercussionKeyName = NULL;
   669 
   670 	const TDesC& percussionKeyName = iImplementor.MmcPercussionKeyNameL(pckg().iNote, pckg().iBankId, pckg().iCustom, pckg().iInstrumentId);
   671 
   672 	iPercussionKeyName = CBufFlat::NewL(32);
   673 	RBufWriteStream stream;
   674 	stream.Open(*iPercussionKeyName);
   675 	CleanupClosePushL(stream);
   676 	stream << percussionKeyName;
   677 	CleanupStack::PopAndDestroy();//s
   678 
   679 	// Write the size of the descriptor back to the client
   680 	TPckgBuf<TInt> descriptorSizePckg(iPercussionKeyName->Ptr(0).Length());	
   681 	aMessage.WriteDataToClientL(descriptorSizePckg);	
   682 	
   683 	return ETrue;
   684 	}
   685 
   686 
   687 TBool CMidiCustomCommandParser::DoCopyPercussionKeyNameL(TMMFMessage& aMessage)
   688 	{
   689 	if (!iPercussionKeyName)
   690 		User::Leave(KErrNotReady);
   691 
   692 	// Copy the instrument name back to the client
   693 	aMessage.WriteDataToClientL(iPercussionKeyName->Ptr(0));
   694 	delete iPercussionKeyName;
   695 	iPercussionKeyName = NULL;
   696 	return ETrue;
   697 	}
   698 
   699 
   700 TBool CMidiCustomCommandParser::DoStopTimeL(TMMFMessage& aMessage)
   701 	{
   702 	TTimeIntervalMicroSeconds stopTime;
   703 	iImplementor.MmcStopTimeL(stopTime);
   704 	TPckgBuf<TMMFMidiConfig2> pckg;
   705 	pckg().iStopTime = stopTime;
   706 	aMessage.WriteDataToClientL(pckg);
   707 	return ETrue;
   708 	}
   709 
   710 TBool CMidiCustomCommandParser::DoSetStopTimeL(TMMFMessage& aMessage)
   711 	{
   712 	TPckgBuf<TMMFMidiConfig2> pckg;
   713 	aMessage.ReadData1FromClientL(pckg);
   714 	iImplementor.MmcSetStopTimeL(pckg().iStopTime);
   715 	return ETrue;
   716 	}
   717 
   718 TBool CMidiCustomCommandParser::DoPolyphonyL(TMMFMessage& aMessage)
   719 	{
   720 	TInt numNotes;
   721 	iImplementor.MmcPolyphonyL(numNotes);
   722 	TPckgBuf<TMMFMidiConfig1> pckg;
   723 	pckg().iNumNotes = numNotes;
   724 	aMessage.WriteDataToClientL(pckg);
   725 	return ETrue;
   726 	}
   727 
   728 TBool CMidiCustomCommandParser::DoMaxPolyphonyL(TMMFMessage& aMessage)
   729 	{
   730 	TInt maxNotes;
   731 	iImplementor.MmcMaxPolyphonyL(maxNotes);
   732 	TPckgBuf<TMMFMidiConfig1> pckg;
   733 	pckg().iMaxNotes = maxNotes;
   734 	aMessage.WriteDataToClientL(pckg);
   735 	return ETrue;
   736 	}
   737 
   738 TBool CMidiCustomCommandParser::DoChannelsSupportedL(TMMFMessage& aMessage)
   739 	{
   740 	TInt channels;
   741 	iImplementor.MmcChannelsSupportedL(channels);
   742 	TPckgBuf<TMMFMidiConfig2> pckg;
   743 	pckg().iChannel = channels;
   744 	aMessage.WriteDataToClientL(pckg);
   745 	return ETrue;
   746 	}
   747 
   748 TBool CMidiCustomCommandParser::DoChannelVolumeL(TMMFMessage& aMessage)
   749 	{
   750 	TPckgBuf<TMMFMidiConfig2> pckg;
   751 	aMessage.ReadData1FromClientL(pckg);
   752 	TReal32 channelVol;
   753 	iImplementor.MmcChannelVolumeL(pckg().iChannel, channelVol);
   754 	pckg().iChannelVol = channelVol;
   755 	aMessage.WriteDataToClientL(pckg);
   756 	return ETrue;
   757 	}
   758 
   759 TBool CMidiCustomCommandParser::DoMaxChannelVolumeL(TMMFMessage& aMessage)
   760 	{
   761 	TReal32 maxVol;
   762 	iImplementor.MmcMaxChannelVolumeL(maxVol);
   763 	TPckgBuf<TMMFMidiConfig2> pckg;
   764 	pckg().iMaxChannelVol = maxVol;
   765 	aMessage.WriteDataToClientL(pckg);
   766 	return ETrue;
   767 	}
   768 
   769 TBool CMidiCustomCommandParser::DoSetChannelVolumeL(TMMFMessage& aMessage)
   770 	{
   771 	TPckgBuf<TMMFMidiConfig2> pckg;
   772 	aMessage.ReadData1FromClientL(pckg);
   773 	iImplementor.MmcSetChannelVolumeL(pckg().iChannel, pckg().iChannelVol);
   774 	return ETrue;
   775 	}
   776 
   777 TBool CMidiCustomCommandParser::DoSetChannelMuteL(TMMFMessage& aMessage)
   778 	{
   779 	TPckgBuf<TMMFMidiConfig2> pckg;
   780 	aMessage.ReadData1FromClientL(pckg);
   781 	iImplementor.MmcSetChannelMuteL(pckg().iChannel, pckg().iMuted);
   782 	return ETrue;
   783 	}
   784 
   785 TBool CMidiCustomCommandParser::DoVolumeL(TMMFMessage& aMessage)
   786 	{
   787 	TInt vol;  
   788 	iImplementor.MmcVolumeL(vol);
   789 	TPckgBuf<TMMFMidiConfig1> pckg;
   790 	pckg().iVolume = vol;
   791 	aMessage.WriteDataToClientL(pckg);
   792 	return ETrue;
   793 	}
   794 
   795 TBool CMidiCustomCommandParser::DoMaxVolumeL(TMMFMessage& aMessage)
   796 	{
   797 	TInt maxVol;
   798 	iImplementor.MmcMaxVolumeL(maxVol);
   799 	TPckgBuf<TMMFMidiConfig1> pckg;
   800 	pckg().iMaxVolume = maxVol;
   801 	aMessage.WriteDataToClientL(pckg);
   802 	return ETrue;
   803 	}
   804 
   805 TBool CMidiCustomCommandParser::DoSetVolumeL(TMMFMessage& aMessage)
   806 	{
   807 	TPckgBuf<TMMFMidiConfig1> pckg;
   808 	aMessage.ReadData1FromClientL(pckg);
   809 	iImplementor.MmcSetVolumeL(pckg().iVolume);
   810 	return ETrue;
   811 	}
   812 
   813 TBool CMidiCustomCommandParser::DoSetVolumeRampL(TMMFMessage& aMessage)
   814 	{
   815 	TPckgBuf<TMMFMidiConfig1> pckg;
   816 	aMessage.ReadData1FromClientL(pckg);
   817 	iImplementor.MmcSetVolumeRampL(pckg().iRampDuration);
   818 	return ETrue;
   819 	}
   820 
   821 TBool CMidiCustomCommandParser::DoGetBalanceL(TMMFMessage& aMessage)
   822 	{
   823 	TInt balance;
   824 	iImplementor.MmcGetBalanceL(balance);
   825 	TPckgBuf<TMMFMidiConfig1> pckg;
   826 	pckg().iBalance = balance;
   827 	aMessage.WriteDataToClientL(pckg);
   828 	return ETrue;
   829 	}
   830 
   831 TBool CMidiCustomCommandParser::DoSetBalanceL(TMMFMessage& aMessage)
   832 	{
   833 	TPckgBuf<TMMFMidiConfig1> pckg;
   834 	aMessage.ReadData1FromClientL(pckg);
   835 	iImplementor.MmcSetBalanceL(pckg().iBalance);
   836 	return ETrue;
   837 	}
   838 
   839 TBool CMidiCustomCommandParser::DoSetMaxPolyphonyL(TMMFMessage& aMessage)
   840 	{
   841 	TPckgBuf<TMMFMidiConfig1> pckg;
   842 	aMessage.ReadData1FromClientL(pckg);
   843 	iImplementor.MmcSetMaxPolyphonyL(pckg().iMaxNotes);
   844 	return ETrue;
   845 	}
   846 
   847 TBool CMidiCustomCommandParser::DoGetRepeatsL(TMMFMessage& aMessage)
   848 	{
   849 	TInt numRepeats;
   850 	iImplementor.MmcGetRepeatsL(numRepeats);
   851 	TPckgBuf<TMMFMidiConfig1> pckg;
   852 	pckg().iNumRepeats = numRepeats;
   853 	aMessage.WriteDataToClientL(pckg);
   854 	return ETrue;
   855 	}
   856 
   857 TBool CMidiCustomCommandParser::DoSetRepeatsL(TMMFMessage& aMessage)
   858 	{
   859 	TPckgBuf<TMMFMidiConfig3> pckg;
   860 	aMessage.ReadData1FromClientL(pckg);
   861 	iImplementor.MmcSetRepeatsL(pckg().iRepeatNumberOfTimes, pckg().iTrailingSilence);
   862 	return ETrue;
   863 	}
   864 
   865 TBool CMidiCustomCommandParser::DoSetBankL(TMMFMessage& aMessage)
   866 	{
   867 	TPckgBuf<TMMFMidiConfig2> pckg;
   868 	aMessage.ReadData1FromClientL(pckg);
   869 	iImplementor.MmcSetBankL(pckg().iCustom);
   870 	return ETrue;
   871 	}
   872 
   873 TBool CMidiCustomCommandParser::DoIsTrackMuteL(TMMFMessage& aMessage)
   874 	{
   875 	TPckgBuf<TMMFMidiConfig2> pckg;
   876 	aMessage.ReadData1FromClientL(pckg);
   877 	TBool mute;
   878 	iImplementor.MmcIsTrackMuteL(pckg().iTrack, mute);
   879 	pckg().iMuted = mute;
   880 	aMessage.WriteDataToClientL(pckg);
   881 	return ETrue;
   882 	}
   883 
   884 TBool CMidiCustomCommandParser::DoIsChannelMuteL(TMMFMessage& aMessage)
   885 	{
   886 	TPckgBuf<TMMFMidiConfig2> pckg;
   887 	aMessage.ReadData1FromClientL(pckg);
   888 	TBool mute;
   889 	iImplementor.MmcIsChannelMuteL(pckg().iChannel, mute);
   890 	pckg().iMuted = mute;
   891 	aMessage.WriteDataToClientL(pckg);
   892 	return ETrue;
   893 	}
   894 
   895 TBool CMidiCustomCommandParser::DoGetInstrumentL(TMMFMessage& aMessage)
   896 	{
   897 	TPckgBuf<TMMFMidiConfig2> pckg;
   898 	aMessage.ReadData1FromClientL(pckg);
   899 	TInt instrumentId;
   900 	TInt bankId;
   901 	iImplementor.MmcGetInstrumentL(pckg().iChannel, instrumentId, bankId);
   902 	pckg().iInstrumentId = instrumentId;
   903 	pckg().iBankId = bankId;
   904 	aMessage.WriteDataToClientL(pckg);
   905 	return ETrue;
   906 	}
   907 
   908 TBool CMidiCustomCommandParser::DoCloseL(TMMFMessage& /*aMessage*/)
   909 	{
   910 	iImplementor.MmcCloseL();
   911 	return ETrue;
   912 	}
   913 
   914 TBool CMidiCustomCommandParser::DoStopL(TMMFMessage& aMessage)
   915 	{
   916 	TPckgBuf<TMMFMidiConfig1> pckg;
   917 	aMessage.ReadData1FromClientL(pckg);
   918 	iImplementor.MmcStopL(pckg().iFadeOutDuration);
   919 	return ETrue;
   920 	}
   921 
   922 TBool CMidiCustomCommandParser::DoReceiveEventsL(TMMFMessage& aMessage)
   923 	{
   924 	if (iMidiEventReceiver)
   925 		{
   926 		if (iMidiEventReceiver->IsWaitingToSendEvent())
   927 			{
   928 			//Something must have gone wrong in the client
   929 			// - we're waiting to get a RetrieveEvent() call, but it didn't come.
   930 			// So, delete the existing event receiver
   931 			delete iMidiEventReceiver;
   932 			iMidiEventReceiver = NULL;
   933 			}
   934 		else
   935 			{
   936 			User::Leave(KErrAlreadyExists);
   937 			}
   938 		}
   939 	ASSERT(!iMidiEventReceiver);
   940 	iMidiEventReceiver = CMidiEventReceiver::NewL(aMessage);
   941 	//send the next cached event (if any) to the client
   942 	if (iMidiEvents.Count() > 0)
   943 		{
   944 		CMMFMidiEvent* midiEvent = iMidiEvents[0];
   945 		iMidiEventReceiver->PrepareEventL(*midiEvent);
   946 		iMidiEvents.Remove(0);
   947 		delete midiEvent;
   948 		}
   949 	return EFalse;
   950 	}
   951 
   952 TBool CMidiCustomCommandParser::DoRetrieveEventL(TMMFMessage& aMessage)
   953 	{
   954 	if (iMidiEventReceiver)
   955 		{
   956 		iMidiEventReceiver->SendEventL(aMessage);
   957 		delete iMidiEventReceiver;
   958 		iMidiEventReceiver = NULL;
   959 		}
   960 	else
   961 		{
   962 		User::Leave(KErrNotReady);
   963 		}
   964 
   965 	return ETrue;
   966 	}
   967 
   968 /**
   969 Sent a MIDI event back to the client.
   970 
   971 @param aEvent MIDI event to be sent to the client.
   972 @return One of the system-wide error codes.
   973 */
   974 TInt CMidiCustomCommandParser::SendMidiEventToClient(const CMMFMidiEvent& aEvent)
   975 	{
   976 	TInt error = KErrNone;
   977 	if (iMidiEventReceiver && !iMidiEventReceiver->IsWaitingToSendEvent())
   978 		{
   979 		//prepare to send event to client
   980 		TRAP(error, iMidiEventReceiver->PrepareEventL(aEvent));
   981 		}
   982 	else
   983 		{
   984 		//queue the request for later
   985 		CMMFMidiEvent* midiEvent = new CMMFMidiEvent();
   986 		if (!midiEvent)
   987 			return KErrNoMemory;
   988 
   989 		// coverity[leave_without_push]
   990 		TRAP(error, midiEvent->CopyL(aEvent));
   991 		//if we've exceeded the max number of cached messages, delete the first and append this one to the end
   992 		if (!error)
   993 			{
   994 			error = iMidiEvents.Append(midiEvent);
   995 			}
   996 
   997 		if(error != KErrNone)
   998 			delete midiEvent;
   999 		}
  1000 	return error;
  1001 	}
  1002 
  1003 
  1004 TBool CMidiCustomCommandParser::DoCancelReceiveEventsL(TMMFMessage& /*aMessage*/)
  1005 	{
  1006 	delete iMidiEventReceiver;
  1007 	iMidiEventReceiver = NULL;
  1008 	return ETrue;
  1009 	}