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: #ifndef __MIDICLIENTUTILITY_H__ sl@0: #define __MIDICLIENTUTILITY_H__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: sl@0: /** sl@0: General utility class to hold instrument information. sl@0: sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: class TInstrumentInfo sl@0: { sl@0: public: sl@0: /** sl@0: *Identifier of sound bank to reference. sl@0: */ sl@0: TInt iBankId; sl@0: sl@0: /** sl@0: * Specifies whether to reference a custom or standard sound bank. sl@0: */ sl@0: TBool iCustom; sl@0: sl@0: /** sl@0: * Identifier of specified instrument. sl@0: */ sl@0: TInt iInstrumentId; sl@0: }; sl@0: sl@0: /** sl@0: Defines the state of the MIDI client utility with regard to the MIDI resource. sl@0: sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: enum TMidiState sl@0: { sl@0: /** sl@0: * No MIDI resource is currently open. sl@0: * The MIDI engine is not processing midi events. sl@0: */ sl@0: EMidiStateClosedDisengaged, sl@0: sl@0: sl@0: /** sl@0: * A MIDI resource is open and primed but not playing. sl@0: * The MIDI engine is not processing midi events. sl@0: */ sl@0: EMidiStateOpenDisengaged, sl@0: sl@0: /** sl@0: * A MIDI resource is open and currently playing. sl@0: * The MIDI engine is currently processing midi events. sl@0: */ sl@0: EMidiStateOpenPlaying, sl@0: sl@0: /** sl@0: * Not able to play full SP-MIDI or DLS content, but attempting best-effort playback. sl@0: */ sl@0: EMidiStatePlaybackIncompatible, sl@0: sl@0: /** sl@0: * Due to system resource constraints and SP-MIDI content constraints, sl@0: * there is no audible MIDI content during playback currently. sl@0: * The situation may change if resources are freed later. sl@0: */ sl@0: EMidiStatePlaybackSilent, sl@0: sl@0: /** sl@0: * No MIDI resource is currently open. sl@0: * The MIDI engine is currently processing midi events. sl@0: */ sl@0: EMidiStateClosedEngaged, sl@0: sl@0: /** sl@0: * A MIDI resource is open and primed but not playing. sl@0: * The MIDI engine is currently processing MIDI events. sl@0: * The transition to this state is only possible from EMidiStateOpenPlaying state, sl@0: * when the 'playback head' reaches the end of media data or the playback sl@0: * stops due to stop time set. sl@0: */ sl@0: EMidiStateOpenEngaged, sl@0: }; sl@0: sl@0: /** sl@0: Active object utility class to allow MIDI events to be signalled asynchronously. sl@0: @see CMidiClientUtility::NewL(). sl@0: sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: class MMidiClientUtilityObserver sl@0: { sl@0: public: sl@0: /** sl@0: A state change has occurred in the MIDI client utility. sl@0: sl@0: @param aOldState sl@0: Old state. sl@0: @param aNewState sl@0: New state. sl@0: @param aTime sl@0: The time in microseconds at which playback stopped relative to the start of the MIDI resource. sl@0: @param aError sl@0: Error code. sl@0: */ sl@0: virtual void MmcuoStateChanged(TMidiState aOldState,TMidiState aNewState,const TTimeIntervalMicroSeconds& aTime,TInt aError) = 0; sl@0: /** sl@0: The MIDI resource has encountered a tempo change message in the MIDI data stream. sl@0: sl@0: @param aMicroBeatsPerMinute sl@0: New tempo value in micro beats per minute (BPM*1000000). sl@0: */ sl@0: virtual void MmcuoTempoChanged(TInt aMicroBeatsPerMinute) = 0; sl@0: /** sl@0: The MIDI resource has encountered a volume change message in the MIDI data stream. sl@0: sl@0: @param aChannel sl@0: Logical channel to which the message applies. 0 <= aChannel < ChannelsSupportedL(). sl@0: @param aVolumeInDecibels sl@0: New volume setting being used. sl@0: */ sl@0: virtual void MmcuoVolumeChanged(TInt aChannel,TReal32 aVolumeInDecibels) = 0; sl@0: /** sl@0: The MIDI resource has encountered a mute message in the MIDI data stream. sl@0: sl@0: @param aChannel sl@0: Logical channel to which the message applies. 0 <= aChannel < ChannelsSupportedL(). sl@0: @param aMuted sl@0: New muting state of the channel - ETrue is muted, EFalse is unmuted. sl@0: */ sl@0: virtual void MmcuoMuteChanged(TInt aChannel,TBool aMuted) = 0; sl@0: /** sl@0: Callback in response to a call to CMIDIClientUtility::SetSyncUpdateCallbackIntervalL(). sl@0: By default there are no callbacks. Otherwise the callback is called at an interval set by the client. sl@0: sl@0: @param aMicroSeconds sl@0: Position in microseconds relative to the start of the resource - only set if sl@0: the sync update set function was called with the microseconds parameter set. sl@0: @param aMicroBeats sl@0: Position in microbeats relative to the start of the resource - only set if sl@0: the sync update set function was called with the microbeats parameter set and sl@0: the microseconds parameter set to 0. sl@0: */ sl@0: virtual void MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& aMicroSeconds,TInt64 aMicroBeats) = 0; sl@0: /** sl@0: A timed meta data entry has been found in the MIDI data stream, eg a timed song lyric in an SMF file. sl@0: sl@0: @param aMetaDataEntryId sl@0: Index of the meta data entry - if this entry has not been encountere before, sl@0: it will be added to the list of meta data entries. Previously encountered timed sl@0: entries still generate this callback. sl@0: @param aPosition sl@0: Position in microseconds relative to the start of the MIDI resource that the MIDI sl@0: meta data entry was found at. sl@0: */ sl@0: virtual void MmcuoMetaDataEntryFound(const TInt aMetaDataEntryId,const TTimeIntervalMicroSeconds& aPosition) = 0; sl@0: /** sl@0: A MIP message has been found in the MIDI data stream. sl@0: sl@0: @param aMessage sl@0: Reference to an array of MIP message entries (logical {channel, MIP} value pairs) sl@0: contained in the message. sl@0: */ sl@0: virtual void MmcuoMipMessageReceived(const RArray& aMessage) = 0; sl@0: /** sl@0: The polyphony of the MIDI engine has changed. sl@0: sl@0: @param aNewPolyphony sl@0: The new polyphony value. sl@0: */ sl@0: virtual void MmcuoPolyphonyChanged(TInt aNewPolyphony) = 0; sl@0: /** sl@0: An instrument has been changed on a channel. sl@0: sl@0: @param aChannel sl@0: Channel where the change of instrument occurred. 0 <= aChannel < ChannelsSupportedL(). sl@0: @param aBankId sl@0: Identifier of the bank that the instrument belongs to, occupying no more than 14 bits. sl@0: The bank ID is a concatenation of MIDI bank MSB and LSB values. sl@0: @param aInstrumentId sl@0: Identifier of the instrument that has been changed. 0 <= aInstrumentId <= 127. sl@0: */ sl@0: virtual void MmcuoInstrumentChanged(TInt aChannel,TInt aBankId,TInt aInstrumentId) = 0; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: Utility class to provide a standard client interface to a MIDI controller. sl@0: sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: class CMidiClientUtility : public CBase sl@0: { sl@0: class CBody; sl@0: public: sl@0: IMPORT_C static CMidiClientUtility* NewL(MMidiClientUtilityObserver& aObserver, sl@0: TInt aPriority = EMdaPriorityNormal, sl@0: TInt aPref = EMdaPriorityPreferenceTimeAndQuality); sl@0: sl@0: // alternative NewL for selecting shared/separate controller heap(s) sl@0: IMPORT_C static CMidiClientUtility* NewL(MMidiClientUtilityObserver& aObserver, sl@0: TInt aPriority, sl@0: TInt aPref, sl@0: TBool aUseSharedHeap); sl@0: sl@0: /** Destructor */ sl@0: virtual ~CMidiClientUtility(); sl@0: IMPORT_C TMidiState State() const; sl@0: IMPORT_C void OpenFile(const TDesC& aFileName); sl@0: IMPORT_C void OpenFile(const RFile& aFile); sl@0: sl@0: IMPORT_C void OpenFile(const TMMSource& aSource); sl@0: sl@0: IMPORT_C void OpenDes(const TDesC8& aDescriptor); sl@0: IMPORT_C void OpenUrl(const TDesC& aUrl,TInt aIapId = KUseDefaultIap,const TDesC8& aMimeType=KNullDesC8); sl@0: IMPORT_C void Close(); sl@0: IMPORT_C void Play(); sl@0: IMPORT_C void Stop(const TTimeIntervalMicroSeconds& aFadeOutDuration); sl@0: IMPORT_C void PlayNoteL(TInt aChannel,TInt aNote,const TTimeIntervalMicroSeconds& aDuration,TInt aNoteOnVelocity,TInt aNoteOffVelocity); sl@0: IMPORT_C void PlayNoteL(TInt aChannel,TInt aNote,const TTimeIntervalMicroSeconds& aStartTime,const TTimeIntervalMicroSeconds& aDuration,TInt aNoteOnVelocity,TInt aNoteOffVelocity); sl@0: IMPORT_C void StopNotes(TInt aChannel); sl@0: IMPORT_C void NoteOnL(TInt aChannel,TInt aNote,TInt aVelocity); sl@0: IMPORT_C void NoteOffL(TInt aChannel,TInt aNote,TInt aVelocity); sl@0: IMPORT_C TInt PlaybackRateL() const; sl@0: IMPORT_C void SetPlaybackRateL(TInt aRate); sl@0: IMPORT_C TInt MaxPlaybackRateL() const; sl@0: IMPORT_C TInt MinPlaybackRateL() const; sl@0: IMPORT_C TInt TempoMicroBeatsPerMinuteL() const; sl@0: IMPORT_C void SetTempoL(TInt aMicroBeatsPerMinute); sl@0: IMPORT_C TInt PitchTranspositionCentsL() const; sl@0: IMPORT_C TInt SetPitchTranspositionL(TInt aCents); sl@0: IMPORT_C TTimeIntervalMicroSeconds DurationMicroSecondsL() const; sl@0: IMPORT_C TInt64 DurationMicroBeatsL() const; sl@0: IMPORT_C TInt NumTracksL() const; sl@0: IMPORT_C void SetTrackMuteL(TInt aTrack,TBool aMuted) const; sl@0: IMPORT_C const TDesC8& MimeTypeL(); sl@0: IMPORT_C TTimeIntervalMicroSeconds PositionMicroSecondsL() const; sl@0: IMPORT_C void SetPositionMicroSecondsL(const TTimeIntervalMicroSeconds& aPosition); sl@0: IMPORT_C TInt64 PositionMicroBeatsL() const; sl@0: IMPORT_C void SetPositionMicroBeatsL(TInt64 aMicroBeats); sl@0: IMPORT_C void SetSyncUpdateCallbackIntervalL(const TTimeIntervalMicroSeconds& aMicroSeconds, TInt64 aMicroBeats=0); sl@0: IMPORT_C TInt SendMessageL(const TDesC8& aMidiMessage); sl@0: IMPORT_C TInt SendMessageL(const TDesC8& aMidiMessage,const TTimeIntervalMicroSeconds& aTime); sl@0: IMPORT_C void SendMipMessageL(const RArray& aEntry); sl@0: IMPORT_C TInt NumberOfBanksL(TBool aCustom) const; sl@0: IMPORT_C TInt GetBankIdL(TBool aCustom,TInt aBankIndex) const; sl@0: IMPORT_C void LoadCustomBankL(const TDesC& aFileName,TInt& aBankCollectionIndex); sl@0: IMPORT_C void LoadCustomBankDataL(const TDesC8& aBankData,TInt& aBankCollectionIndex); sl@0: IMPORT_C void UnloadCustomBankL(TInt aBankCollectionIndex); sl@0: IMPORT_C TBool CustomBankLoadedL(TInt aBankCollectionIndex) const; sl@0: IMPORT_C void UnloadAllCustomBanksL(); sl@0: IMPORT_C TInt NumberOfInstrumentsL(TInt aBankId,TBool aCustom) const; sl@0: IMPORT_C TInt GetInstrumentIdL(TInt aBankId,TBool aCustom,TInt aInstrumentIndex) const; sl@0: IMPORT_C HBufC* InstrumentNameL(TInt aBankId, TBool aCustom, TInt aInstrumentId) const; sl@0: IMPORT_C void GetInstrumentL(TInt aChannel, TInt& aInstrumentId, TInt& aBankId); sl@0: IMPORT_C void SetInstrumentL(TInt aChannel,TInt aBankId,TInt aInstrumentId); sl@0: IMPORT_C void LoadCustomInstrumentL(const TDesC& aFileName,TInt aFileBankId,TInt aFileInstrumentId,TInt aMemoryBankId,TInt aMemoryInstrumentId); sl@0: IMPORT_C void LoadCustomInstrumentDataL(const TDesC8& aInstrumentData, TInt aBankDataId, TInt aInstrumentDataId, TInt aMemoryBankId, TInt aMemoryInstrumentId); sl@0: IMPORT_C void UnloadCustomInstrumentL(TInt aCustomBankId,TInt aInstrumentId); sl@0: IMPORT_C HBufC* PercussionKeyNameL(TInt aNote, TInt aBankId, TBool aCustom, TInt aInstrumentId) const; sl@0: IMPORT_C void StopTimeL(TTimeIntervalMicroSeconds& aStopTime) const; sl@0: IMPORT_C void SetStopTimeL(const TTimeIntervalMicroSeconds& aStopTime); sl@0: IMPORT_C void SetRepeatsL(TInt aRepeatNumberOfTimes, const TTimeIntervalMicroSeconds& aTrailingSilence); sl@0: IMPORT_C TInt GetRepeats() const; sl@0: IMPORT_C TInt PolyphonyL() const; sl@0: IMPORT_C void SetMaxPolyphonyL(TInt aMaxNotes); sl@0: IMPORT_C TInt ChannelsSupportedL() const; sl@0: IMPORT_C TReal32 ChannelVolumeL(TInt aChannel) const; sl@0: IMPORT_C TReal32 MaxChannelVolumeL() const; sl@0: IMPORT_C void SetChannelVolumeL(TInt aChannel,TReal32 aVolumeInDecibels); sl@0: IMPORT_C void SetChannelMuteL(TInt aChannel,TBool aMuted); sl@0: IMPORT_C TInt VolumeL() const; sl@0: IMPORT_C TInt MaxVolumeL() const; sl@0: IMPORT_C void SetVolumeL(TInt aVolume); sl@0: IMPORT_C void SetVolumeRampL(const TTimeIntervalMicroSeconds& aRampDuration); sl@0: IMPORT_C TInt GetBalanceL() const; sl@0: IMPORT_C void SetBalanceL(TInt aBalance = KMMFBalanceCenter); sl@0: IMPORT_C void SetPriorityL(TInt aPriority, TInt aPref); sl@0: IMPORT_C TInt NumberOfMetaDataEntriesL() const; sl@0: IMPORT_C CMMFMetaDataEntry* GetMetaDataEntryL(TInt aMetaDataIndex) const; sl@0: /** sl@0: * @deprecated SetBankL is deprecated due to Mobile XMF specification requirement that user instruments (custom instruments) override standard instruments. sl@0: */ sl@0: IMPORT_C void SetBankL(TBool aCustom); sl@0: IMPORT_C TBool IsTrackMuteL(TInt aTrack) const; sl@0: IMPORT_C TBool IsChannelMuteL(TInt aChannel) const; sl@0: IMPORT_C void CustomCommandSyncL(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom); sl@0: IMPORT_C void CustomCommandSyncL(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2); sl@0: IMPORT_C void CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TDes8& aDataFrom, TRequestStatus& aStatus); sl@0: IMPORT_C void CustomCommandAsync(const TMMFMessageDestinationPckg& aDestination, TInt aFunction, const TDesC8& aDataTo1, const TDesC8& aDataTo2, TRequestStatus& aStatus); sl@0: IMPORT_C TInt MaxPolyphonyL() const; sl@0: sl@0: IMPORT_C MMMFDRMCustomCommand* GetDRMCustomCommand(); sl@0: sl@0: private: sl@0: /** sl@0: * a pointer to the implementation. sl@0: */ sl@0: CBody* iBody; sl@0: friend class CBody; sl@0: }; sl@0: sl@0: #endif