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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include <mmf/common/midistandardcustomcommands.h>
17 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
18 #include <mmf/common/midieventreceiver.h>
19 #include <mmf/common/mmfmidiconfig.h>
21 const TInt KMimeTypeLength = 256;
25 Creates a new MIDI custom command parser capable of handling MIDI controller commands.
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.
30 EXPORT_C CMidiCustomCommandParser* CMidiCustomCommandParser::NewL(MMidiCustomCommandImplementor& aImplementor)
32 return new(ELeave) CMidiCustomCommandParser(aImplementor);
35 CMidiCustomCommandParser::CMidiCustomCommandParser(MMidiCustomCommandImplementor& aImplementor) :
36 CMMFCustomCommandParserBase(KUidInterfaceMidi),
37 iImplementor(aImplementor)
44 EXPORT_C CMidiCustomCommandParser::~CMidiCustomCommandParser()
46 delete iMidiEventReceiver;
47 delete iInstrumentName;
48 delete iPercussionKeyName;
49 iMidiEvents.ResetAndDestroy();
54 Handles a request from the client. Called by the controller framework.
56 @param aMessage The message to be handled.
58 void CMidiCustomCommandParser::HandleRequest(TMMFMessage& aMessage)
60 if (aMessage.Destination().InterfaceId() == KUidInterfaceMidi)
62 TRAPD(error, DoHandleRequestL(aMessage));
64 aMessage.Complete(error);
68 aMessage.Complete(KErrNotSupported);
72 void CMidiCustomCommandParser::DoHandleRequestL(TMMFMessage& aMessage)
74 TBool complete = ETrue;
75 switch (aMessage.Function())
77 case EMMFMidiControllerSetPositionMicroBeats:
78 complete = DoSetPositionMicroBeatsL(aMessage);
80 case EMMFMidiControllerPositionMicroBeats:
81 complete = DoPositionMicroBeatsL(aMessage);
83 case EMMFMidiControllerPlayNote:
84 complete = DoPlayNoteL(aMessage);
86 case EMMFMidiControllerPlayNoteWithStartTime:
87 complete = DoPlayNoteWithStartTimeL(aMessage);
89 case EMMFMidiControllerStopNotes:
90 complete = DoStopNotesL(aMessage);
92 case EMMFMidiControllerNoteOn:
93 complete = DoNoteOnL(aMessage);
95 case EMMFMidiControllerNoteOff:
96 complete = DoNoteOffL(aMessage);
98 case EMMFMidiControllerPlaybackRate:
99 complete = DoPlaybackRateL(aMessage);
101 case EMMFMidiControllerSetPlaybackRate:
102 complete = DoSetPlaybackRateL(aMessage);
104 case EMMFMidiControllerMaxPlaybackRate:
105 complete = DoMaxPlaybackRateL(aMessage);
107 case EMMFMidiControllerMinPlaybackRate:
108 complete = DoMinPlaybackRateL(aMessage);
110 case EMMFMidiControllerTempo:
111 complete = DoTempoMicroBeatsPerMinuteL(aMessage);
113 case EMMFMidiControllerSetTempo:
114 complete = DoSetTempoL(aMessage);
116 case EMMFMidiControllerPitch:
117 complete = DoPitchTranspositionCentsL(aMessage);
119 case EMMFMidiControllerSetPitch:
120 complete = DoSetPitchTranspositionL(aMessage);
122 case EMMFMidiControllerDurationMicroBeats:
123 complete = DoDurationMicroBeatsL(aMessage);
125 case EMMFMidiControllerNumTracks:
126 complete = DoNumTracksL(aMessage);
128 case EMMFMidiControllerSetTrackMute:
129 complete = DoSetTrackMuteL(aMessage);
131 case EMMFMidiControllerMimeType:
132 complete = DoMimeTypeL(aMessage);
134 case EMMFMidiControllerSetSyncUpdateCallbackInterval:
135 complete = DoSetSyncUpdateCallbackIntervalL(aMessage);
137 case EMMFMidiControllerSendMessage:
138 complete = DoSendMessageL(aMessage);
140 case EMMFMidiControllerSendMessageWithTimeStamp:
141 complete = DoSendMessageWithTimeStampL(aMessage);
143 case EMMFMidiControllerSendMipMessage:
144 complete = DoSendMipMessageL(aMessage);
146 case EMMFMidiControllerNumberOfBanks:
147 complete = DoNumberOfBanksL(aMessage);
149 case EMMFMidiControllerGetBankId:
150 complete = DoGetBankIdL(aMessage);
152 case EMMFMidiControllerLoadCustomBank:
153 complete = DoLoadCustomBankL(aMessage);
155 case EMMFMidiControllerLoadCustomBankData:
156 complete = DoLoadCustomBankDataL(aMessage);
158 case EMMFMidiControllerUnloadCustomBank:
159 complete = DoUnloadCustomBankL(aMessage);
161 case EMMFMidiControllerCustomBankLoaded:
162 complete = DoCustomBankLoadedL(aMessage);
164 case EMMFMidiControllerUnloadAllCustomBanks:
165 complete = DoUnloadAllCustomBanksL(aMessage);
167 case EMMFMidiControllerNumberOfInstruments:
168 complete = DoNumberOfInstrumentsL(aMessage);
170 case EMMFMidiControllerGetInstrumentId:
171 complete = DoGetInstrumentIdL(aMessage);
173 case EMMFMidiControllerInstrumentName:
174 complete = DoInstrumentNameL(aMessage);
176 case EMMFMidiControllerCopyInstrumentName:
177 complete = DoCopyInstrumentNameL(aMessage);
179 case EMMFMidiControllerSetInstrument:
180 complete = DoSetInstrumentL(aMessage);
182 case EMMFMidiControllerLoadCustomInstrument:
183 complete = DoLoadCustomInstrumentL(aMessage);
185 case EMMFMidiControllerLoadCustomInstrumentData:
186 complete = DoLoadCustomInstrumentDataL(aMessage);
188 case EMMFMidiControllerUnloadCustomInstrument:
189 complete = DoUnloadCustomInstrumentL(aMessage);
191 case EMMFMidiControllerPercussionKeyName:
192 complete = DoPercussionKeyNameL(aMessage);
194 case EMMFMidiControllerCopyPercussionKeyName:
195 complete = DoCopyPercussionKeyNameL(aMessage);
197 case EMMFMidiControllerStopTime:
198 complete = DoStopTimeL(aMessage);
200 case EMMFMidiControllerSetStopTime:
201 complete = DoSetStopTimeL(aMessage);
203 case EMMFMidiControllerPolyphony:
204 complete = DoPolyphonyL(aMessage);
206 case EMMFMidiControllerChannelsSupported:
207 complete = DoChannelsSupportedL(aMessage);
209 case EMMFMidiControllerChannelVolume:
210 complete = DoChannelVolumeL(aMessage);
212 case EMMFMidiControllerMaxChannelVolume:
213 complete = DoMaxChannelVolumeL(aMessage);
215 case EMMFMidiControllerSetChannelVolume:
216 complete = DoSetChannelVolumeL(aMessage);
218 case EMMFMidiControllerSetChannelMute:
219 complete = DoSetChannelMuteL(aMessage);
221 case EMMFMidiControllerVolume:
222 complete = DoVolumeL(aMessage);
224 case EMMFMidiControllerMaxVolume:
225 complete = DoMaxVolumeL(aMessage);
227 case EMMFMidiControllerSetVolume:
228 complete = DoSetVolumeL(aMessage);
230 case EMMFMidiControllerSetVolumeRamp:
231 complete = DoSetVolumeRampL(aMessage);
233 case EMMFMidiControllerGetBalance:
234 complete = DoGetBalanceL(aMessage);
236 case EMMFMidiControllerSetBalance:
237 complete = DoSetBalanceL(aMessage);
239 case EMMFMidiControllerSetMaxPolyphony:
240 complete = DoSetMaxPolyphonyL(aMessage);
242 case EMMFMidiControllerGetRepeats:
243 complete = DoGetRepeatsL(aMessage);
245 case EMMFMidiControllerSetRepeats:
246 complete = DoSetRepeatsL(aMessage);
248 case EMMFMidiControllerSetBank:
249 DoSetBankL(aMessage);
251 case EMMFMidiControllerIsTrackMute:
252 DoIsTrackMuteL(aMessage);
254 case EMMFMidiControllerIsChannelMute:
255 DoIsChannelMuteL(aMessage);
257 case EMMFMidiControllerGetInstrument:
258 DoGetInstrumentL(aMessage);
260 case EMMFMidiControllerClose:
261 complete = DoCloseL(aMessage);
263 case EMMFMidiControllerStop:
264 complete = DoStopL(aMessage);
266 case EMMFMidiControllerReceiveEvents:
267 complete = DoReceiveEventsL(aMessage);
269 case EMMFMidiControllerRetrieveEvent:
270 complete = DoRetrieveEventL(aMessage);
272 case EMMFMidiControllerCancelReceiveEvents:
273 complete = DoCancelReceiveEventsL(aMessage);
275 case EMMFMidiControllerMaxPolyphony:
276 complete = DoMaxPolyphonyL(aMessage);
279 User::Leave(KErrNotSupported);
283 aMessage.Complete(KErrNone);
286 TBool CMidiCustomCommandParser::DoSetPositionMicroBeatsL(TMMFMessage& aMessage)
288 TPckgBuf<TMMFMidiConfig2> pckg;
289 aMessage.ReadData1FromClientL(pckg);
290 iImplementor.MmcSetPositionMicroBeatsL(pckg().iPositionMicroBeats);
294 TBool CMidiCustomCommandParser::DoPositionMicroBeatsL(TMMFMessage& aMessage)
296 TInt64 microBeats = 0;
297 iImplementor.MmcPositionMicroBeatsL(microBeats);
298 TPckgBuf<TMMFMidiConfig2> pckg;
299 pckg().iPositionMicroBeats = microBeats;
300 aMessage.WriteDataToClientL(pckg);
304 TBool CMidiCustomCommandParser::DoPlayNoteL(TMMFMessage& aMessage)
306 TPckgBuf<TMMFMidiConfig2> pckg;
307 aMessage.ReadData1FromClientL(pckg);
308 iImplementor.MmcPlayNoteL(pckg().iChannel, pckg().iNote, pckg().iDurationMicroSeconds, pckg().iNoteOnVelocity, pckg().iNoteOffVelocity);
312 TBool CMidiCustomCommandParser::DoPlayNoteWithStartTimeL(TMMFMessage& aMessage)
314 TPckgBuf<TMMFMidiConfig2> pckg;
315 aMessage.ReadData1FromClientL(pckg);
316 iImplementor.MmcPlayNoteL(pckg().iChannel, pckg().iNote, pckg().iStartTime, pckg().iDurationMicroSeconds, pckg().iNoteOnVelocity, pckg().iNoteOffVelocity);
320 TBool CMidiCustomCommandParser::DoStopNotesL(TMMFMessage& aMessage)
322 TPckgBuf<TMMFMidiConfig2> pckg;
323 aMessage.ReadData1FromClientL(pckg);
324 iImplementor.MmcStopNotesL(pckg().iChannel);
328 TBool CMidiCustomCommandParser::DoNoteOnL(TMMFMessage& aMessage)
330 TPckgBuf<TMMFMidiConfig2> pckg;
331 aMessage.ReadData1FromClientL(pckg);
332 iImplementor.MmcNoteOnL(pckg().iChannel, pckg().iNote, pckg().iNoteOnVelocity);
336 TBool CMidiCustomCommandParser::DoNoteOffL(TMMFMessage& aMessage)
338 TPckgBuf<TMMFMidiConfig2> pckg;
339 aMessage.ReadData1FromClientL(pckg);
340 iImplementor.MmcNoteOffL(pckg().iChannel, pckg().iNote, pckg().iNoteOffVelocity);
344 TBool CMidiCustomCommandParser::DoPlaybackRateL(TMMFMessage& aMessage)
347 iImplementor.MmcPlaybackRateL(playBackRate);
348 TPckgBuf<TMMFMidiConfig3> pckg;
349 pckg().iPlayBackRate = playBackRate;
350 aMessage.WriteDataToClientL(pckg);
354 TBool CMidiCustomCommandParser::DoSetPlaybackRateL(TMMFMessage& aMessage)
356 TPckgBuf<TMMFMidiConfig3> pckg;
357 aMessage.ReadData1FromClientL(pckg);
358 iImplementor.MmcSetPlaybackRateL(pckg().iPlayBackRate);
362 TBool CMidiCustomCommandParser::DoMaxPlaybackRateL(TMMFMessage& aMessage)
365 iImplementor.MmcMaxPlaybackRateL(maxRate);
366 TPckgBuf<TMMFMidiConfig3> pckg;
367 pckg().iPlayBackMaxRate = maxRate;
368 aMessage.WriteDataToClientL(pckg);
372 TBool CMidiCustomCommandParser::DoMinPlaybackRateL(TMMFMessage& aMessage)
375 iImplementor.MmcMinPlaybackRateL(minRate);
376 TPckgBuf<TMMFMidiConfig3> pckg;
377 pckg().iPlayBackMinRate = minRate;
378 aMessage.WriteDataToClientL(pckg);
382 TBool CMidiCustomCommandParser::DoTempoMicroBeatsPerMinuteL(TMMFMessage& aMessage)
384 TInt microBeatsPerMinute;
385 iImplementor.MmcTempoMicroBeatsPerMinuteL(microBeatsPerMinute);
386 TPckgBuf<TMMFMidiConfig1> pckg;
387 pckg().iTempo = microBeatsPerMinute;
388 aMessage.WriteDataToClientL(pckg);
392 TBool CMidiCustomCommandParser::DoSetTempoL(TMMFMessage& aMessage)
394 TPckgBuf<TMMFMidiConfig1> pckg;
395 aMessage.ReadData1FromClientL(pckg);
396 iImplementor.MmcSetTempoL(pckg().iTempo);
400 TBool CMidiCustomCommandParser::DoPitchTranspositionCentsL(TMMFMessage& aMessage)
403 iImplementor.MmcPitchTranspositionCentsL(pitch);
404 TPckgBuf<TMMFMidiConfig1> pckg;
405 pckg().iPitch = pitch;
406 aMessage.WriteDataToClientL(pckg);
410 TBool CMidiCustomCommandParser::DoSetPitchTranspositionL(TMMFMessage& aMessage)
412 TPckgBuf<TMMFMidiConfig1> pckg;
413 aMessage.ReadData1FromClientL(pckg);
415 iImplementor.MmcSetPitchTranspositionL(pckg().iPitch, centsApplied);
416 pckg().iPitch = centsApplied;
417 aMessage.WriteDataToClientL(pckg);
421 TBool CMidiCustomCommandParser::DoDurationMicroBeatsL(TMMFMessage& aMessage)
424 iImplementor.MmcDurationMicroBeatsL(duration);
425 TPckgBuf<TMMFMidiConfig2> pckg;
426 pckg().iDurationMicroBeats = duration;
427 aMessage.WriteDataToClientL(pckg);
431 TBool CMidiCustomCommandParser::DoNumTracksL(TMMFMessage& aMessage)
434 iImplementor.MmcNumTracksL(numTracks);
435 TPckgBuf<TMMFMidiConfig1> pckg;
436 pckg().iNumTracks = numTracks;
437 aMessage.WriteDataToClientL(pckg);
441 TBool CMidiCustomCommandParser::DoSetTrackMuteL(TMMFMessage& aMessage)
443 TPckgBuf<TMMFMidiConfig2> pckg;
444 aMessage.ReadData1FromClientL(pckg);
445 iImplementor.MmcSetTrackMuteL(pckg().iTrack, pckg().iMuted);
449 TBool CMidiCustomCommandParser::DoMimeTypeL(TMMFMessage& aMessage)
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
460 TBool CMidiCustomCommandParser::DoSetSyncUpdateCallbackIntervalL(TMMFMessage& aMessage)
462 TPckgBuf<TMMFMidiConfig3> pckg;
463 aMessage.ReadData1FromClientL(pckg);
464 iImplementor.MmcSetSyncUpdateCallbackIntervalL(pckg().iCallbackIntervalMicroSeconds, pckg().iCallbackIntervalMicroBeats);
468 TBool CMidiCustomCommandParser::DoSendMessageL(TMMFMessage& aMessage)
470 TPckgBuf<TMMFMidiConfig3> pckg;
471 aMessage.ReadData1FromClientL(pckg);
473 iImplementor.MmcSendMessageL(*(pckg().iMidiMessage), bytesProcessed);
474 pckg().iBytesProcessed = bytesProcessed;
475 aMessage.WriteDataToClientL(pckg);
479 TBool CMidiCustomCommandParser::DoSendMessageWithTimeStampL(TMMFMessage& aMessage)
481 TPckgBuf<TMMFMidiConfig3> pckg;
482 aMessage.ReadData1FromClientL(pckg);
484 iImplementor.MmcSendMessageL(*(pckg().iMidiMessage), pckg().iTimeStamp, bytesProcessed);
485 pckg().iBytesProcessed = bytesProcessed;
486 aMessage.WriteDataToClientL(pckg);
490 TBool CMidiCustomCommandParser::DoSendMipMessageL(TMMFMessage& aMessage)
492 TPckgBuf<TMMFMidiConfig1> pckg;
493 aMessage.ReadData1FromClientL(pckg);
494 iImplementor.MmcSendMipMessageL(*(pckg().iMipMessage));
498 TBool CMidiCustomCommandParser::DoNumberOfBanksL(TMMFMessage& aMessage)
500 TPckgBuf<TMMFMidiConfig2> pckg;
501 aMessage.ReadData1FromClientL(pckg);
503 iImplementor.MmcNumberOfBanksL(pckg().iCustom, numBanks);
504 pckg().iNumBanks = numBanks;
505 aMessage.WriteDataToClientL(pckg);
509 TBool CMidiCustomCommandParser::DoGetBankIdL(TMMFMessage& aMessage)
511 TPckgBuf<TMMFMidiConfig2> pckg;
512 aMessage.ReadData1FromClientL(pckg);
514 iImplementor.MmcGetBankIdL(pckg().iCustom, pckg().iBankIndex, bankId);
515 pckg().iBankId = bankId;
516 aMessage.WriteDataToClientL(pckg);
520 TBool CMidiCustomCommandParser::DoLoadCustomBankL(TMMFMessage& aMessage)
522 TPckgBuf<TMMFMidiConfig2> pckg;
523 aMessage.ReadData1FromClientL(pckg);
525 iImplementor.MmcLoadCustomBankL(*(pckg().iFileName), bankId);
526 pckg().iBankId = bankId;
527 aMessage.WriteDataToClientL(pckg);
531 TBool CMidiCustomCommandParser::DoLoadCustomBankDataL(TMMFMessage& aMessage)
533 TPckgBuf<TMMFMidiConfig2> pckg;
534 aMessage.ReadData1FromClientL(pckg);
536 iImplementor.MmcLoadCustomBankDataL(*(pckg().iBankData), bankId);
537 pckg().iBankId = bankId;
538 aMessage.WriteDataToClientL(pckg);
542 TBool CMidiCustomCommandParser::DoUnloadCustomBankL(TMMFMessage& aMessage)
544 TPckgBuf<TMMFMidiConfig2> pckg;
545 aMessage.ReadData1FromClientL(pckg);
546 iImplementor.MmcUnloadCustomBankL(pckg().iBankId);
550 TBool CMidiCustomCommandParser::DoCustomBankLoadedL(TMMFMessage& aMessage)
552 TPckgBuf<TMMFMidiConfig2> pckg;
553 aMessage.ReadData1FromClientL(pckg);
555 iImplementor.MmcCustomBankLoadedL(pckg().iBankId, bankLoaded);
556 pckg().iBankLoaded = bankLoaded;
557 aMessage.WriteDataToClientL(pckg);
561 TBool CMidiCustomCommandParser::DoUnloadAllCustomBanksL(TMMFMessage& /*aMessage*/)
563 iImplementor.MmcUnloadAllCustomBanksL();
567 TBool CMidiCustomCommandParser::DoNumberOfInstrumentsL(TMMFMessage& aMessage)
569 TPckgBuf<TMMFMidiConfig2> pckg;
570 aMessage.ReadData1FromClientL(pckg);
572 iImplementor.MmcNumberOfInstrumentsL(pckg().iBankId, pckg().iCustom, numInstruments);
573 pckg().iNumInstruments = numInstruments;
574 aMessage.WriteDataToClientL(pckg);
578 TBool CMidiCustomCommandParser::DoGetInstrumentIdL(TMMFMessage& aMessage)
580 TPckgBuf<TMMFMidiConfig2> pckg;
581 aMessage.ReadData1FromClientL(pckg);
583 iImplementor.MmcGetInstrumentIdL(pckg().iBankId, pckg().iCustom, pckg().iInstrumentIndex, instrumentId);
584 pckg().iInstrumentId = instrumentId;
585 aMessage.WriteDataToClientL(pckg);
589 TBool CMidiCustomCommandParser::DoInstrumentNameL(TMMFMessage& aMessage)
591 TPckgBuf<TMMFMidiConfig2> pckg;
592 aMessage.ReadData1FromClientL(pckg);
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;
599 // Get the instrument name from the controller
600 const TDesC& instrumentName = iImplementor.MmcInstrumentNameL(pckg().iBankId, pckg().iCustom, pckg().iInstrumentId);
602 iInstrumentName = CBufFlat::NewL(32);
603 RBufWriteStream stream;
604 stream.Open(*iInstrumentName);
605 CleanupClosePushL(stream);
606 stream << instrumentName;
607 CleanupStack::PopAndDestroy();//s
609 // Write the size of the descriptor back to the client
610 TPckgBuf<TInt> descriptorSizePckg(iInstrumentName->Ptr(0).Length());
611 aMessage.WriteDataToClientL(descriptorSizePckg);
616 TBool CMidiCustomCommandParser::DoCopyInstrumentNameL(TMMFMessage& aMessage)
618 if (!iInstrumentName)
619 User::Leave(KErrNotReady);
621 // Copy the instrument name back to the client
622 aMessage.WriteDataToClientL(iInstrumentName->Ptr(0));
623 delete iInstrumentName;
624 iInstrumentName = NULL;
628 TBool CMidiCustomCommandParser::DoSetInstrumentL(TMMFMessage& aMessage)
630 TPckgBuf<TMMFMidiConfig2> pckg;
631 aMessage.ReadData1FromClientL(pckg);
632 iImplementor.MmcSetInstrumentL(pckg().iChannel, pckg().iBankId, pckg().iInstrumentId);
636 TBool CMidiCustomCommandParser::DoLoadCustomInstrumentL(TMMFMessage& aMessage)
638 TPckgBuf<TMMFMidiConfig2> pckg;
639 aMessage.ReadData1FromClientL(pckg);
640 iImplementor.MmcLoadCustomInstrumentL(*(pckg().iFileName), pckg().iBankId, pckg().iInstrumentId, pckg().iMemoryBankId, pckg().iMemoryInstrumentId);
644 TBool CMidiCustomCommandParser::DoLoadCustomInstrumentDataL(TMMFMessage& aMessage)
646 TPckgBuf<TMMFMidiConfig2> pckg;
647 aMessage.ReadData1FromClientL(pckg);
648 iImplementor.MmcLoadCustomInstrumentDataL(*(pckg().iInstrumentData), pckg().iBankId, pckg().iInstrumentId, pckg().iMemoryBankId, pckg().iMemoryInstrumentId);
652 TBool CMidiCustomCommandParser::DoUnloadCustomInstrumentL(TMMFMessage& aMessage)
654 TPckgBuf<TMMFMidiConfig2> pckg;
655 aMessage.ReadData1FromClientL(pckg);
656 iImplementor.MmcUnloadCustomInstrumentL(pckg().iBankId, pckg().iInstrumentId);
660 TBool CMidiCustomCommandParser::DoPercussionKeyNameL(TMMFMessage& aMessage)
662 TPckgBuf<TMMFMidiConfig2> pckg;
663 aMessage.ReadData1FromClientL(pckg);
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;
670 const TDesC& percussionKeyName = iImplementor.MmcPercussionKeyNameL(pckg().iNote, pckg().iBankId, pckg().iCustom, pckg().iInstrumentId);
672 iPercussionKeyName = CBufFlat::NewL(32);
673 RBufWriteStream stream;
674 stream.Open(*iPercussionKeyName);
675 CleanupClosePushL(stream);
676 stream << percussionKeyName;
677 CleanupStack::PopAndDestroy();//s
679 // Write the size of the descriptor back to the client
680 TPckgBuf<TInt> descriptorSizePckg(iPercussionKeyName->Ptr(0).Length());
681 aMessage.WriteDataToClientL(descriptorSizePckg);
687 TBool CMidiCustomCommandParser::DoCopyPercussionKeyNameL(TMMFMessage& aMessage)
689 if (!iPercussionKeyName)
690 User::Leave(KErrNotReady);
692 // Copy the instrument name back to the client
693 aMessage.WriteDataToClientL(iPercussionKeyName->Ptr(0));
694 delete iPercussionKeyName;
695 iPercussionKeyName = NULL;
700 TBool CMidiCustomCommandParser::DoStopTimeL(TMMFMessage& aMessage)
702 TTimeIntervalMicroSeconds stopTime;
703 iImplementor.MmcStopTimeL(stopTime);
704 TPckgBuf<TMMFMidiConfig2> pckg;
705 pckg().iStopTime = stopTime;
706 aMessage.WriteDataToClientL(pckg);
710 TBool CMidiCustomCommandParser::DoSetStopTimeL(TMMFMessage& aMessage)
712 TPckgBuf<TMMFMidiConfig2> pckg;
713 aMessage.ReadData1FromClientL(pckg);
714 iImplementor.MmcSetStopTimeL(pckg().iStopTime);
718 TBool CMidiCustomCommandParser::DoPolyphonyL(TMMFMessage& aMessage)
721 iImplementor.MmcPolyphonyL(numNotes);
722 TPckgBuf<TMMFMidiConfig1> pckg;
723 pckg().iNumNotes = numNotes;
724 aMessage.WriteDataToClientL(pckg);
728 TBool CMidiCustomCommandParser::DoMaxPolyphonyL(TMMFMessage& aMessage)
731 iImplementor.MmcMaxPolyphonyL(maxNotes);
732 TPckgBuf<TMMFMidiConfig1> pckg;
733 pckg().iMaxNotes = maxNotes;
734 aMessage.WriteDataToClientL(pckg);
738 TBool CMidiCustomCommandParser::DoChannelsSupportedL(TMMFMessage& aMessage)
741 iImplementor.MmcChannelsSupportedL(channels);
742 TPckgBuf<TMMFMidiConfig2> pckg;
743 pckg().iChannel = channels;
744 aMessage.WriteDataToClientL(pckg);
748 TBool CMidiCustomCommandParser::DoChannelVolumeL(TMMFMessage& aMessage)
750 TPckgBuf<TMMFMidiConfig2> pckg;
751 aMessage.ReadData1FromClientL(pckg);
753 iImplementor.MmcChannelVolumeL(pckg().iChannel, channelVol);
754 pckg().iChannelVol = channelVol;
755 aMessage.WriteDataToClientL(pckg);
759 TBool CMidiCustomCommandParser::DoMaxChannelVolumeL(TMMFMessage& aMessage)
762 iImplementor.MmcMaxChannelVolumeL(maxVol);
763 TPckgBuf<TMMFMidiConfig2> pckg;
764 pckg().iMaxChannelVol = maxVol;
765 aMessage.WriteDataToClientL(pckg);
769 TBool CMidiCustomCommandParser::DoSetChannelVolumeL(TMMFMessage& aMessage)
771 TPckgBuf<TMMFMidiConfig2> pckg;
772 aMessage.ReadData1FromClientL(pckg);
773 iImplementor.MmcSetChannelVolumeL(pckg().iChannel, pckg().iChannelVol);
777 TBool CMidiCustomCommandParser::DoSetChannelMuteL(TMMFMessage& aMessage)
779 TPckgBuf<TMMFMidiConfig2> pckg;
780 aMessage.ReadData1FromClientL(pckg);
781 iImplementor.MmcSetChannelMuteL(pckg().iChannel, pckg().iMuted);
785 TBool CMidiCustomCommandParser::DoVolumeL(TMMFMessage& aMessage)
788 iImplementor.MmcVolumeL(vol);
789 TPckgBuf<TMMFMidiConfig1> pckg;
790 pckg().iVolume = vol;
791 aMessage.WriteDataToClientL(pckg);
795 TBool CMidiCustomCommandParser::DoMaxVolumeL(TMMFMessage& aMessage)
798 iImplementor.MmcMaxVolumeL(maxVol);
799 TPckgBuf<TMMFMidiConfig1> pckg;
800 pckg().iMaxVolume = maxVol;
801 aMessage.WriteDataToClientL(pckg);
805 TBool CMidiCustomCommandParser::DoSetVolumeL(TMMFMessage& aMessage)
807 TPckgBuf<TMMFMidiConfig1> pckg;
808 aMessage.ReadData1FromClientL(pckg);
809 iImplementor.MmcSetVolumeL(pckg().iVolume);
813 TBool CMidiCustomCommandParser::DoSetVolumeRampL(TMMFMessage& aMessage)
815 TPckgBuf<TMMFMidiConfig1> pckg;
816 aMessage.ReadData1FromClientL(pckg);
817 iImplementor.MmcSetVolumeRampL(pckg().iRampDuration);
821 TBool CMidiCustomCommandParser::DoGetBalanceL(TMMFMessage& aMessage)
824 iImplementor.MmcGetBalanceL(balance);
825 TPckgBuf<TMMFMidiConfig1> pckg;
826 pckg().iBalance = balance;
827 aMessage.WriteDataToClientL(pckg);
831 TBool CMidiCustomCommandParser::DoSetBalanceL(TMMFMessage& aMessage)
833 TPckgBuf<TMMFMidiConfig1> pckg;
834 aMessage.ReadData1FromClientL(pckg);
835 iImplementor.MmcSetBalanceL(pckg().iBalance);
839 TBool CMidiCustomCommandParser::DoSetMaxPolyphonyL(TMMFMessage& aMessage)
841 TPckgBuf<TMMFMidiConfig1> pckg;
842 aMessage.ReadData1FromClientL(pckg);
843 iImplementor.MmcSetMaxPolyphonyL(pckg().iMaxNotes);
847 TBool CMidiCustomCommandParser::DoGetRepeatsL(TMMFMessage& aMessage)
850 iImplementor.MmcGetRepeatsL(numRepeats);
851 TPckgBuf<TMMFMidiConfig1> pckg;
852 pckg().iNumRepeats = numRepeats;
853 aMessage.WriteDataToClientL(pckg);
857 TBool CMidiCustomCommandParser::DoSetRepeatsL(TMMFMessage& aMessage)
859 TPckgBuf<TMMFMidiConfig3> pckg;
860 aMessage.ReadData1FromClientL(pckg);
861 iImplementor.MmcSetRepeatsL(pckg().iRepeatNumberOfTimes, pckg().iTrailingSilence);
865 TBool CMidiCustomCommandParser::DoSetBankL(TMMFMessage& aMessage)
867 TPckgBuf<TMMFMidiConfig2> pckg;
868 aMessage.ReadData1FromClientL(pckg);
869 iImplementor.MmcSetBankL(pckg().iCustom);
873 TBool CMidiCustomCommandParser::DoIsTrackMuteL(TMMFMessage& aMessage)
875 TPckgBuf<TMMFMidiConfig2> pckg;
876 aMessage.ReadData1FromClientL(pckg);
878 iImplementor.MmcIsTrackMuteL(pckg().iTrack, mute);
879 pckg().iMuted = mute;
880 aMessage.WriteDataToClientL(pckg);
884 TBool CMidiCustomCommandParser::DoIsChannelMuteL(TMMFMessage& aMessage)
886 TPckgBuf<TMMFMidiConfig2> pckg;
887 aMessage.ReadData1FromClientL(pckg);
889 iImplementor.MmcIsChannelMuteL(pckg().iChannel, mute);
890 pckg().iMuted = mute;
891 aMessage.WriteDataToClientL(pckg);
895 TBool CMidiCustomCommandParser::DoGetInstrumentL(TMMFMessage& aMessage)
897 TPckgBuf<TMMFMidiConfig2> pckg;
898 aMessage.ReadData1FromClientL(pckg);
901 iImplementor.MmcGetInstrumentL(pckg().iChannel, instrumentId, bankId);
902 pckg().iInstrumentId = instrumentId;
903 pckg().iBankId = bankId;
904 aMessage.WriteDataToClientL(pckg);
908 TBool CMidiCustomCommandParser::DoCloseL(TMMFMessage& /*aMessage*/)
910 iImplementor.MmcCloseL();
914 TBool CMidiCustomCommandParser::DoStopL(TMMFMessage& aMessage)
916 TPckgBuf<TMMFMidiConfig1> pckg;
917 aMessage.ReadData1FromClientL(pckg);
918 iImplementor.MmcStopL(pckg().iFadeOutDuration);
922 TBool CMidiCustomCommandParser::DoReceiveEventsL(TMMFMessage& aMessage)
924 if (iMidiEventReceiver)
926 if (iMidiEventReceiver->IsWaitingToSendEvent())
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;
936 User::Leave(KErrAlreadyExists);
939 ASSERT(!iMidiEventReceiver);
940 iMidiEventReceiver = CMidiEventReceiver::NewL(aMessage);
941 //send the next cached event (if any) to the client
942 if (iMidiEvents.Count() > 0)
944 CMMFMidiEvent* midiEvent = iMidiEvents[0];
945 iMidiEventReceiver->PrepareEventL(*midiEvent);
946 iMidiEvents.Remove(0);
952 TBool CMidiCustomCommandParser::DoRetrieveEventL(TMMFMessage& aMessage)
954 if (iMidiEventReceiver)
956 iMidiEventReceiver->SendEventL(aMessage);
957 delete iMidiEventReceiver;
958 iMidiEventReceiver = NULL;
962 User::Leave(KErrNotReady);
969 Sent a MIDI event back to the client.
971 @param aEvent MIDI event to be sent to the client.
972 @return One of the system-wide error codes.
974 TInt CMidiCustomCommandParser::SendMidiEventToClient(const CMMFMidiEvent& aEvent)
976 TInt error = KErrNone;
977 if (iMidiEventReceiver && !iMidiEventReceiver->IsWaitingToSendEvent())
979 //prepare to send event to client
980 TRAP(error, iMidiEventReceiver->PrepareEventL(aEvent));
984 //queue the request for later
985 CMMFMidiEvent* midiEvent = new CMMFMidiEvent();
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
994 error = iMidiEvents.Append(midiEvent);
997 if(error != KErrNone)
1004 TBool CMidiCustomCommandParser::DoCancelReceiveEventsL(TMMFMessage& /*aMessage*/)
1006 delete iMidiEventReceiver;
1007 iMidiEventReceiver = NULL;