sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS sl@0: #include sl@0: #include sl@0: #endif sl@0: const TInt KMimeTypeLength = 256; sl@0: sl@0: sl@0: /** sl@0: Creates a new MIDI custom command parser capable of handling MIDI controller commands. sl@0: sl@0: @param aImplementor A reference to the controller plugin that owns this new object. sl@0: @leave This function may leave with one of the system-wide error codes. sl@0: */ sl@0: EXPORT_C CMidiCustomCommandParser* CMidiCustomCommandParser::NewL(MMidiCustomCommandImplementor& aImplementor) sl@0: { sl@0: return new(ELeave) CMidiCustomCommandParser(aImplementor); sl@0: } sl@0: sl@0: CMidiCustomCommandParser::CMidiCustomCommandParser(MMidiCustomCommandImplementor& aImplementor) : sl@0: CMMFCustomCommandParserBase(KUidInterfaceMidi), sl@0: iImplementor(aImplementor) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Destructor. sl@0: */ sl@0: EXPORT_C CMidiCustomCommandParser::~CMidiCustomCommandParser() sl@0: { sl@0: delete iMidiEventReceiver; sl@0: delete iInstrumentName; sl@0: delete iPercussionKeyName; sl@0: iMidiEvents.ResetAndDestroy(); sl@0: iMidiEvents.Close(); sl@0: } sl@0: sl@0: /** sl@0: Handles a request from the client. Called by the controller framework. sl@0: sl@0: @param aMessage The message to be handled. sl@0: */ sl@0: void CMidiCustomCommandParser::HandleRequest(TMMFMessage& aMessage) sl@0: { sl@0: if (aMessage.Destination().InterfaceId() == KUidInterfaceMidi) sl@0: { sl@0: TRAPD(error, DoHandleRequestL(aMessage)); sl@0: if (error) sl@0: aMessage.Complete(error); sl@0: } sl@0: else sl@0: { sl@0: aMessage.Complete(KErrNotSupported); sl@0: } sl@0: } sl@0: sl@0: void CMidiCustomCommandParser::DoHandleRequestL(TMMFMessage& aMessage) sl@0: { sl@0: TBool complete = ETrue; sl@0: switch (aMessage.Function()) sl@0: { sl@0: case EMMFMidiControllerSetPositionMicroBeats: sl@0: complete = DoSetPositionMicroBeatsL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerPositionMicroBeats: sl@0: complete = DoPositionMicroBeatsL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerPlayNote: sl@0: complete = DoPlayNoteL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerPlayNoteWithStartTime: sl@0: complete = DoPlayNoteWithStartTimeL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerStopNotes: sl@0: complete = DoStopNotesL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerNoteOn: sl@0: complete = DoNoteOnL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerNoteOff: sl@0: complete = DoNoteOffL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerPlaybackRate: sl@0: complete = DoPlaybackRateL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSetPlaybackRate: sl@0: complete = DoSetPlaybackRateL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerMaxPlaybackRate: sl@0: complete = DoMaxPlaybackRateL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerMinPlaybackRate: sl@0: complete = DoMinPlaybackRateL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerTempo: sl@0: complete = DoTempoMicroBeatsPerMinuteL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSetTempo: sl@0: complete = DoSetTempoL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerPitch: sl@0: complete = DoPitchTranspositionCentsL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSetPitch: sl@0: complete = DoSetPitchTranspositionL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerDurationMicroBeats: sl@0: complete = DoDurationMicroBeatsL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerNumTracks: sl@0: complete = DoNumTracksL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSetTrackMute: sl@0: complete = DoSetTrackMuteL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerMimeType: sl@0: complete = DoMimeTypeL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSetSyncUpdateCallbackInterval: sl@0: complete = DoSetSyncUpdateCallbackIntervalL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSendMessage: sl@0: complete = DoSendMessageL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSendMessageWithTimeStamp: sl@0: complete = DoSendMessageWithTimeStampL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSendMipMessage: sl@0: complete = DoSendMipMessageL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerNumberOfBanks: sl@0: complete = DoNumberOfBanksL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerGetBankId: sl@0: complete = DoGetBankIdL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerLoadCustomBank: sl@0: complete = DoLoadCustomBankL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerLoadCustomBankData: sl@0: complete = DoLoadCustomBankDataL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerUnloadCustomBank: sl@0: complete = DoUnloadCustomBankL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerCustomBankLoaded: sl@0: complete = DoCustomBankLoadedL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerUnloadAllCustomBanks: sl@0: complete = DoUnloadAllCustomBanksL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerNumberOfInstruments: sl@0: complete = DoNumberOfInstrumentsL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerGetInstrumentId: sl@0: complete = DoGetInstrumentIdL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerInstrumentName: sl@0: complete = DoInstrumentNameL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerCopyInstrumentName: sl@0: complete = DoCopyInstrumentNameL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSetInstrument: sl@0: complete = DoSetInstrumentL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerLoadCustomInstrument: sl@0: complete = DoLoadCustomInstrumentL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerLoadCustomInstrumentData: sl@0: complete = DoLoadCustomInstrumentDataL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerUnloadCustomInstrument: sl@0: complete = DoUnloadCustomInstrumentL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerPercussionKeyName: sl@0: complete = DoPercussionKeyNameL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerCopyPercussionKeyName: sl@0: complete = DoCopyPercussionKeyNameL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerStopTime: sl@0: complete = DoStopTimeL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSetStopTime: sl@0: complete = DoSetStopTimeL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerPolyphony: sl@0: complete = DoPolyphonyL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerChannelsSupported: sl@0: complete = DoChannelsSupportedL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerChannelVolume: sl@0: complete = DoChannelVolumeL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerMaxChannelVolume: sl@0: complete = DoMaxChannelVolumeL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSetChannelVolume: sl@0: complete = DoSetChannelVolumeL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSetChannelMute: sl@0: complete = DoSetChannelMuteL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerVolume: sl@0: complete = DoVolumeL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerMaxVolume: sl@0: complete = DoMaxVolumeL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSetVolume: sl@0: complete = DoSetVolumeL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSetVolumeRamp: sl@0: complete = DoSetVolumeRampL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerGetBalance: sl@0: complete = DoGetBalanceL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSetBalance: sl@0: complete = DoSetBalanceL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSetMaxPolyphony: sl@0: complete = DoSetMaxPolyphonyL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerGetRepeats: sl@0: complete = DoGetRepeatsL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSetRepeats: sl@0: complete = DoSetRepeatsL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerSetBank: sl@0: DoSetBankL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerIsTrackMute: sl@0: DoIsTrackMuteL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerIsChannelMute: sl@0: DoIsChannelMuteL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerGetInstrument: sl@0: DoGetInstrumentL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerClose: sl@0: complete = DoCloseL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerStop: sl@0: complete = DoStopL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerReceiveEvents: sl@0: complete = DoReceiveEventsL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerRetrieveEvent: sl@0: complete = DoRetrieveEventL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerCancelReceiveEvents: sl@0: complete = DoCancelReceiveEventsL(aMessage); sl@0: break; sl@0: case EMMFMidiControllerMaxPolyphony: sl@0: complete = DoMaxPolyphonyL(aMessage); sl@0: break; sl@0: default: sl@0: User::Leave(KErrNotSupported); sl@0: break; sl@0: } sl@0: if (complete) sl@0: aMessage.Complete(KErrNone); sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetPositionMicroBeatsL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSetPositionMicroBeatsL(pckg().iPositionMicroBeats); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoPositionMicroBeatsL(TMMFMessage& aMessage) sl@0: { sl@0: TInt64 microBeats = 0; sl@0: iImplementor.MmcPositionMicroBeatsL(microBeats); sl@0: TPckgBuf pckg; sl@0: pckg().iPositionMicroBeats = microBeats; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoPlayNoteL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcPlayNoteL(pckg().iChannel, pckg().iNote, pckg().iDurationMicroSeconds, pckg().iNoteOnVelocity, pckg().iNoteOffVelocity); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoPlayNoteWithStartTimeL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcPlayNoteL(pckg().iChannel, pckg().iNote, pckg().iStartTime, pckg().iDurationMicroSeconds, pckg().iNoteOnVelocity, pckg().iNoteOffVelocity); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoStopNotesL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcStopNotesL(pckg().iChannel); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoNoteOnL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcNoteOnL(pckg().iChannel, pckg().iNote, pckg().iNoteOnVelocity); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoNoteOffL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcNoteOffL(pckg().iChannel, pckg().iNote, pckg().iNoteOffVelocity); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoPlaybackRateL(TMMFMessage& aMessage) sl@0: { sl@0: TInt playBackRate; sl@0: iImplementor.MmcPlaybackRateL(playBackRate); sl@0: TPckgBuf pckg; sl@0: pckg().iPlayBackRate = playBackRate; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetPlaybackRateL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSetPlaybackRateL(pckg().iPlayBackRate); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoMaxPlaybackRateL(TMMFMessage& aMessage) sl@0: { sl@0: TInt maxRate; sl@0: iImplementor.MmcMaxPlaybackRateL(maxRate); sl@0: TPckgBuf pckg; sl@0: pckg().iPlayBackMaxRate = maxRate; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoMinPlaybackRateL(TMMFMessage& aMessage) sl@0: { sl@0: TInt minRate; sl@0: iImplementor.MmcMinPlaybackRateL(minRate); sl@0: TPckgBuf pckg; sl@0: pckg().iPlayBackMinRate = minRate; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoTempoMicroBeatsPerMinuteL(TMMFMessage& aMessage) sl@0: { sl@0: TInt microBeatsPerMinute; sl@0: iImplementor.MmcTempoMicroBeatsPerMinuteL(microBeatsPerMinute); sl@0: TPckgBuf pckg; sl@0: pckg().iTempo = microBeatsPerMinute; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetTempoL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSetTempoL(pckg().iTempo); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoPitchTranspositionCentsL(TMMFMessage& aMessage) sl@0: { sl@0: TInt pitch; sl@0: iImplementor.MmcPitchTranspositionCentsL(pitch); sl@0: TPckgBuf pckg; sl@0: pckg().iPitch = pitch; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetPitchTranspositionL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: TInt centsApplied; sl@0: iImplementor.MmcSetPitchTranspositionL(pckg().iPitch, centsApplied); sl@0: pckg().iPitch = centsApplied; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoDurationMicroBeatsL(TMMFMessage& aMessage) sl@0: { sl@0: TInt64 duration; sl@0: iImplementor.MmcDurationMicroBeatsL(duration); sl@0: TPckgBuf pckg; sl@0: pckg().iDurationMicroBeats = duration; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoNumTracksL(TMMFMessage& aMessage) sl@0: { sl@0: TInt numTracks; sl@0: iImplementor.MmcNumTracksL(numTracks); sl@0: TPckgBuf pckg; sl@0: pckg().iNumTracks = numTracks; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetTrackMuteL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSetTrackMuteL(pckg().iTrack, pckg().iMuted); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoMimeTypeL(TMMFMessage& aMessage) sl@0: { sl@0: HBufC8* mimeType = HBufC8::NewL(KMimeTypeLength); sl@0: TPtr8 des = mimeType->Des(); sl@0: CleanupStack::PushL(mimeType); sl@0: iImplementor.MmcMimeTypeL(des); sl@0: aMessage.WriteDataToClientL(des); sl@0: CleanupStack::PopAndDestroy();//mimeType sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetSyncUpdateCallbackIntervalL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSetSyncUpdateCallbackIntervalL(pckg().iCallbackIntervalMicroSeconds, pckg().iCallbackIntervalMicroBeats); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSendMessageL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: TInt bytesProcessed; sl@0: iImplementor.MmcSendMessageL(*(pckg().iMidiMessage), bytesProcessed); sl@0: pckg().iBytesProcessed = bytesProcessed; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSendMessageWithTimeStampL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: TInt bytesProcessed; sl@0: iImplementor.MmcSendMessageL(*(pckg().iMidiMessage), pckg().iTimeStamp, bytesProcessed); sl@0: pckg().iBytesProcessed = bytesProcessed; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSendMipMessageL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSendMipMessageL(*(pckg().iMipMessage)); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoNumberOfBanksL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: TInt numBanks; sl@0: iImplementor.MmcNumberOfBanksL(pckg().iCustom, numBanks); sl@0: pckg().iNumBanks = numBanks; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoGetBankIdL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: TInt bankId; sl@0: iImplementor.MmcGetBankIdL(pckg().iCustom, pckg().iBankIndex, bankId); sl@0: pckg().iBankId = bankId; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoLoadCustomBankL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: TInt bankId; sl@0: iImplementor.MmcLoadCustomBankL(*(pckg().iFileName), bankId); sl@0: pckg().iBankId = bankId; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoLoadCustomBankDataL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: TInt bankId; sl@0: iImplementor.MmcLoadCustomBankDataL(*(pckg().iBankData), bankId); sl@0: pckg().iBankId = bankId; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoUnloadCustomBankL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcUnloadCustomBankL(pckg().iBankId); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoCustomBankLoadedL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: TBool bankLoaded; sl@0: iImplementor.MmcCustomBankLoadedL(pckg().iBankId, bankLoaded); sl@0: pckg().iBankLoaded = bankLoaded; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoUnloadAllCustomBanksL(TMMFMessage& /*aMessage*/) sl@0: { sl@0: iImplementor.MmcUnloadAllCustomBanksL(); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoNumberOfInstrumentsL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: TInt numInstruments; sl@0: iImplementor.MmcNumberOfInstrumentsL(pckg().iBankId, pckg().iCustom, numInstruments); sl@0: pckg().iNumInstruments = numInstruments; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoGetInstrumentIdL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: TInt instrumentId; sl@0: iImplementor.MmcGetInstrumentIdL(pckg().iBankId, pckg().iCustom, pckg().iInstrumentIndex, instrumentId); sl@0: pckg().iInstrumentId = instrumentId; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoInstrumentNameL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: sl@0: // Prevent memory leaks by deleting old instrument name - something must have gone wrong in the client sl@0: // if it already exists sl@0: delete iInstrumentName; sl@0: iInstrumentName = NULL; sl@0: sl@0: // Get the instrument name from the controller sl@0: const TDesC& instrumentName = iImplementor.MmcInstrumentNameL(pckg().iBankId, pckg().iCustom, pckg().iInstrumentId); sl@0: sl@0: iInstrumentName = CBufFlat::NewL(32); sl@0: RBufWriteStream stream; sl@0: stream.Open(*iInstrumentName); sl@0: CleanupClosePushL(stream); sl@0: stream << instrumentName; sl@0: CleanupStack::PopAndDestroy();//s sl@0: sl@0: // Write the size of the descriptor back to the client sl@0: TPckgBuf descriptorSizePckg(iInstrumentName->Ptr(0).Length()); sl@0: aMessage.WriteDataToClientL(descriptorSizePckg); sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoCopyInstrumentNameL(TMMFMessage& aMessage) sl@0: { sl@0: if (!iInstrumentName) sl@0: User::Leave(KErrNotReady); sl@0: sl@0: // Copy the instrument name back to the client sl@0: aMessage.WriteDataToClientL(iInstrumentName->Ptr(0)); sl@0: delete iInstrumentName; sl@0: iInstrumentName = NULL; sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetInstrumentL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSetInstrumentL(pckg().iChannel, pckg().iBankId, pckg().iInstrumentId); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoLoadCustomInstrumentL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcLoadCustomInstrumentL(*(pckg().iFileName), pckg().iBankId, pckg().iInstrumentId, pckg().iMemoryBankId, pckg().iMemoryInstrumentId); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoLoadCustomInstrumentDataL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcLoadCustomInstrumentDataL(*(pckg().iInstrumentData), pckg().iBankId, pckg().iInstrumentId, pckg().iMemoryBankId, pckg().iMemoryInstrumentId); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoUnloadCustomInstrumentL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcUnloadCustomInstrumentL(pckg().iBankId, pckg().iInstrumentId); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoPercussionKeyNameL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: sl@0: // Prevent memory leaks by deleting old key name - something must have gone wrong in the client sl@0: // if it already exists sl@0: delete iPercussionKeyName; sl@0: iPercussionKeyName = NULL; sl@0: sl@0: const TDesC& percussionKeyName = iImplementor.MmcPercussionKeyNameL(pckg().iNote, pckg().iBankId, pckg().iCustom, pckg().iInstrumentId); sl@0: sl@0: iPercussionKeyName = CBufFlat::NewL(32); sl@0: RBufWriteStream stream; sl@0: stream.Open(*iPercussionKeyName); sl@0: CleanupClosePushL(stream); sl@0: stream << percussionKeyName; sl@0: CleanupStack::PopAndDestroy();//s sl@0: sl@0: // Write the size of the descriptor back to the client sl@0: TPckgBuf descriptorSizePckg(iPercussionKeyName->Ptr(0).Length()); sl@0: aMessage.WriteDataToClientL(descriptorSizePckg); sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: sl@0: TBool CMidiCustomCommandParser::DoCopyPercussionKeyNameL(TMMFMessage& aMessage) sl@0: { sl@0: if (!iPercussionKeyName) sl@0: User::Leave(KErrNotReady); sl@0: sl@0: // Copy the instrument name back to the client sl@0: aMessage.WriteDataToClientL(iPercussionKeyName->Ptr(0)); sl@0: delete iPercussionKeyName; sl@0: iPercussionKeyName = NULL; sl@0: return ETrue; sl@0: } sl@0: sl@0: sl@0: TBool CMidiCustomCommandParser::DoStopTimeL(TMMFMessage& aMessage) sl@0: { sl@0: TTimeIntervalMicroSeconds stopTime; sl@0: iImplementor.MmcStopTimeL(stopTime); sl@0: TPckgBuf pckg; sl@0: pckg().iStopTime = stopTime; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetStopTimeL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSetStopTimeL(pckg().iStopTime); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoPolyphonyL(TMMFMessage& aMessage) sl@0: { sl@0: TInt numNotes; sl@0: iImplementor.MmcPolyphonyL(numNotes); sl@0: TPckgBuf pckg; sl@0: pckg().iNumNotes = numNotes; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoMaxPolyphonyL(TMMFMessage& aMessage) sl@0: { sl@0: TInt maxNotes; sl@0: iImplementor.MmcMaxPolyphonyL(maxNotes); sl@0: TPckgBuf pckg; sl@0: pckg().iMaxNotes = maxNotes; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoChannelsSupportedL(TMMFMessage& aMessage) sl@0: { sl@0: TInt channels; sl@0: iImplementor.MmcChannelsSupportedL(channels); sl@0: TPckgBuf pckg; sl@0: pckg().iChannel = channels; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoChannelVolumeL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: TReal32 channelVol; sl@0: iImplementor.MmcChannelVolumeL(pckg().iChannel, channelVol); sl@0: pckg().iChannelVol = channelVol; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoMaxChannelVolumeL(TMMFMessage& aMessage) sl@0: { sl@0: TReal32 maxVol; sl@0: iImplementor.MmcMaxChannelVolumeL(maxVol); sl@0: TPckgBuf pckg; sl@0: pckg().iMaxChannelVol = maxVol; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetChannelVolumeL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSetChannelVolumeL(pckg().iChannel, pckg().iChannelVol); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetChannelMuteL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSetChannelMuteL(pckg().iChannel, pckg().iMuted); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoVolumeL(TMMFMessage& aMessage) sl@0: { sl@0: TInt vol; sl@0: iImplementor.MmcVolumeL(vol); sl@0: TPckgBuf pckg; sl@0: pckg().iVolume = vol; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoMaxVolumeL(TMMFMessage& aMessage) sl@0: { sl@0: TInt maxVol; sl@0: iImplementor.MmcMaxVolumeL(maxVol); sl@0: TPckgBuf pckg; sl@0: pckg().iMaxVolume = maxVol; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetVolumeL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSetVolumeL(pckg().iVolume); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetVolumeRampL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSetVolumeRampL(pckg().iRampDuration); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoGetBalanceL(TMMFMessage& aMessage) sl@0: { sl@0: TInt balance; sl@0: iImplementor.MmcGetBalanceL(balance); sl@0: TPckgBuf pckg; sl@0: pckg().iBalance = balance; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetBalanceL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSetBalanceL(pckg().iBalance); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetMaxPolyphonyL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSetMaxPolyphonyL(pckg().iMaxNotes); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoGetRepeatsL(TMMFMessage& aMessage) sl@0: { sl@0: TInt numRepeats; sl@0: iImplementor.MmcGetRepeatsL(numRepeats); sl@0: TPckgBuf pckg; sl@0: pckg().iNumRepeats = numRepeats; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetRepeatsL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSetRepeatsL(pckg().iRepeatNumberOfTimes, pckg().iTrailingSilence); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoSetBankL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcSetBankL(pckg().iCustom); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoIsTrackMuteL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: TBool mute; sl@0: iImplementor.MmcIsTrackMuteL(pckg().iTrack, mute); sl@0: pckg().iMuted = mute; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoIsChannelMuteL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: TBool mute; sl@0: iImplementor.MmcIsChannelMuteL(pckg().iChannel, mute); sl@0: pckg().iMuted = mute; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoGetInstrumentL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: TInt instrumentId; sl@0: TInt bankId; sl@0: iImplementor.MmcGetInstrumentL(pckg().iChannel, instrumentId, bankId); sl@0: pckg().iInstrumentId = instrumentId; sl@0: pckg().iBankId = bankId; sl@0: aMessage.WriteDataToClientL(pckg); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoCloseL(TMMFMessage& /*aMessage*/) sl@0: { sl@0: iImplementor.MmcCloseL(); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoStopL(TMMFMessage& aMessage) sl@0: { sl@0: TPckgBuf pckg; sl@0: aMessage.ReadData1FromClientL(pckg); sl@0: iImplementor.MmcStopL(pckg().iFadeOutDuration); sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoReceiveEventsL(TMMFMessage& aMessage) sl@0: { sl@0: if (iMidiEventReceiver) sl@0: { sl@0: if (iMidiEventReceiver->IsWaitingToSendEvent()) sl@0: { sl@0: //Something must have gone wrong in the client sl@0: // - we're waiting to get a RetrieveEvent() call, but it didn't come. sl@0: // So, delete the existing event receiver sl@0: delete iMidiEventReceiver; sl@0: iMidiEventReceiver = NULL; sl@0: } sl@0: else sl@0: { sl@0: User::Leave(KErrAlreadyExists); sl@0: } sl@0: } sl@0: ASSERT(!iMidiEventReceiver); sl@0: iMidiEventReceiver = CMidiEventReceiver::NewL(aMessage); sl@0: //send the next cached event (if any) to the client sl@0: if (iMidiEvents.Count() > 0) sl@0: { sl@0: CMMFMidiEvent* midiEvent = iMidiEvents[0]; sl@0: iMidiEventReceiver->PrepareEventL(*midiEvent); sl@0: iMidiEvents.Remove(0); sl@0: delete midiEvent; sl@0: } sl@0: return EFalse; sl@0: } sl@0: sl@0: TBool CMidiCustomCommandParser::DoRetrieveEventL(TMMFMessage& aMessage) sl@0: { sl@0: if (iMidiEventReceiver) sl@0: { sl@0: iMidiEventReceiver->SendEventL(aMessage); sl@0: delete iMidiEventReceiver; sl@0: iMidiEventReceiver = NULL; sl@0: } sl@0: else sl@0: { sl@0: User::Leave(KErrNotReady); sl@0: } sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Sent a MIDI event back to the client. sl@0: sl@0: @param aEvent MIDI event to be sent to the client. sl@0: @return One of the system-wide error codes. sl@0: */ sl@0: TInt CMidiCustomCommandParser::SendMidiEventToClient(const CMMFMidiEvent& aEvent) sl@0: { sl@0: TInt error = KErrNone; sl@0: if (iMidiEventReceiver && !iMidiEventReceiver->IsWaitingToSendEvent()) sl@0: { sl@0: //prepare to send event to client sl@0: TRAP(error, iMidiEventReceiver->PrepareEventL(aEvent)); sl@0: } sl@0: else sl@0: { sl@0: //queue the request for later sl@0: CMMFMidiEvent* midiEvent = new CMMFMidiEvent(); sl@0: if (!midiEvent) sl@0: return KErrNoMemory; sl@0: sl@0: // coverity[leave_without_push] sl@0: TRAP(error, midiEvent->CopyL(aEvent)); sl@0: //if we've exceeded the max number of cached messages, delete the first and append this one to the end sl@0: if (!error) sl@0: { sl@0: error = iMidiEvents.Append(midiEvent); sl@0: } sl@0: sl@0: if(error != KErrNone) sl@0: delete midiEvent; sl@0: } sl@0: return error; sl@0: } sl@0: sl@0: sl@0: TBool CMidiCustomCommandParser::DoCancelReceiveEventsL(TMMFMessage& /*aMessage*/) sl@0: { sl@0: delete iMidiEventReceiver; sl@0: iMidiEventReceiver = NULL; sl@0: return ETrue; sl@0: }