1 /* |
|
2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This class is a MIDIControl. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CMMAMIDICONTROL_H |
|
20 #define CMMAMIDICONTROL_H |
|
21 |
|
22 // EXTERNAL INCLUDES |
|
23 |
|
24 // INTERNAL INCLUDES |
|
25 #include "cmmacontrol.h" // base class |
|
26 #include "mmmaplayerstatelistener.h" |
|
27 #include <midiclientutility.h> // MMidiClientUtilityObserver |
|
28 #include <TimeOutTimer.h> |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 // Constant for control name. Name is used in Java side to instantiate |
|
33 // Java Class which uses CMMAMIDIControl. |
|
34 _LIT(KMIDIControlName, "MIDIControl"); |
|
35 |
|
36 class CMMAMIDIPlayer; |
|
37 |
|
38 // Maximum volume defined in the Java API. |
|
39 // It is used to convert volume values between native and java values. |
|
40 static const TInt KMAXVolume = 127; |
|
41 |
|
42 |
|
43 |
|
44 // CLASS DECLARATION |
|
45 /** |
|
46 * This class implements MIDIControl interface. |
|
47 * |
|
48 * |
|
49 */ |
|
50 NONSHARABLE_CLASS(CMMAMIDIControl): public CMMAControl, |
|
51 public MMidiClientUtilityObserver |
|
52 { |
|
53 private: |
|
54 |
|
55 class CChannelVolumeEventWait : public CBase, |
|
56 public MTimeOutNotify |
|
57 { |
|
58 public: // Constructor and destructor |
|
59 |
|
60 static CChannelVolumeEventWait* NewL(); |
|
61 |
|
62 ~CChannelVolumeEventWait(); |
|
63 |
|
64 public: // Methods from base classes |
|
65 |
|
66 /** |
|
67 * From MTimeOutNotify Timer expiration call back method |
|
68 */ |
|
69 void TimerExpired(); |
|
70 |
|
71 public: // New methods |
|
72 |
|
73 void StartWait(TInt aChannel); |
|
74 |
|
75 void StopWait(); |
|
76 |
|
77 void HandleVolumeChangedEvent(TInt aChannel); |
|
78 |
|
79 private: // Constructor |
|
80 |
|
81 CChannelVolumeEventWait(); |
|
82 |
|
83 void ConstructL(); |
|
84 |
|
85 private: // Data |
|
86 |
|
87 // Own. For waiting the correct volume changed event |
|
88 CActiveSchedulerWait* iWait; |
|
89 |
|
90 // Own. Time-out for waiting volume changed event |
|
91 CTimeOutTimer* iTimer; |
|
92 |
|
93 // Expected channel for volume event |
|
94 TInt iChannel; |
|
95 |
|
96 }; |
|
97 |
|
98 public: |
|
99 /** |
|
100 * Creates new CMMAMIDIControl. |
|
101 * |
|
102 * @param aPlayer Player that plays the MIDI. |
|
103 */ |
|
104 static CMMAMIDIControl* NewL(CMMAMIDIPlayer* aPlayer); |
|
105 |
|
106 /** |
|
107 * Destructor. |
|
108 */ |
|
109 ~CMMAMIDIControl(); |
|
110 protected: |
|
111 /** |
|
112 * Constructor. |
|
113 * @param aPlayer Player that plays the MIDI. |
|
114 */ |
|
115 CMMAMIDIControl(CMMAMIDIPlayer* aPlayer); |
|
116 |
|
117 /** |
|
118 * Initializes this control. |
|
119 */ |
|
120 void ConstructL(); |
|
121 |
|
122 public: // From CMMAControl |
|
123 const TDesC& ClassName() const; |
|
124 |
|
125 public: // From MMMAPlayerStateListener |
|
126 void StateChanged(TInt aState); |
|
127 |
|
128 public: // Static new methods |
|
129 |
|
130 /** |
|
131 * Get volume for the given channel. The return value is |
|
132 * independent of the player's volume. |
|
133 * |
|
134 * @param aChannel 0-15 |
|
135 */ |
|
136 TInt ChannelVolumeL(TInt aChannel); |
|
137 |
|
138 /** |
|
139 * Set volume for given channel. |
|
140 * |
|
141 * @param aChannel 0-15 |
|
142 * @param aVolume 0-127 |
|
143 */ |
|
144 void SetChannelVolumeL(TInt aChannel, TInt aVolume); |
|
145 |
|
146 /** |
|
147 * Set program of a channel. |
|
148 * |
|
149 * @param aChannel 0-15 |
|
150 * @param aBank 0-16383, or -1 for default bank |
|
151 * @param aProgram 0-127 |
|
152 */ |
|
153 void SetProgramL(TInt aChannel, |
|
154 TInt aBank, |
|
155 TInt aProgram); |
|
156 |
|
157 /** |
|
158 * Sends a long MIDI event to the device. |
|
159 * This method passes the data directly to the receiving device. |
|
160 * The data array's contents are not checked for validity. |
|
161 * |
|
162 * @param aData array of the bytes to send |
|
163 * @return the number of bytes actually sent to the device |
|
164 */ |
|
165 TInt SendMIDIEventL(const TDesC8* aData); |
|
166 |
|
167 /** |
|
168 * Reinitializes native midi engine with new sequence data. |
|
169 * First closes midi engine and then opens it again with new |
|
170 * data. The data array's contents are not checked for validity. |
|
171 * |
|
172 * @param aData midi sequence data for initialization |
|
173 * @return KErrNone (return value is present only for |
|
174 * method footprint) |
|
175 */ |
|
176 TInt ReInitializeMidiL(const TDesC8* aData); |
|
177 |
|
178 public: // from MMidiClientUtilityObserver |
|
179 void MmcuoStateChanged(TMidiState aOldState,TMidiState aNewState,const TTimeIntervalMicroSeconds& aTime,TInt aError); |
|
180 void MmcuoTempoChanged(TInt aMicroBeatsPerMinute); |
|
181 void MmcuoVolumeChanged(TInt aChannel,TReal32 aVolumeInDecibels); |
|
182 void MmcuoMuteChanged(TInt aChannel,TBool aMuted); |
|
183 void MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& aMicroSeconds,TInt64 aMicroBeats); |
|
184 void MmcuoMetaDataEntryFound(const TInt aMetaDataEntryId,const TTimeIntervalMicroSeconds& aPosition); |
|
185 void MmcuoMipMessageReceived(const RArray<TMipMessageEntry>& aMessage); |
|
186 void MmcuoPolyphonyChanged(TInt aNewPolyphony); |
|
187 void MmcuoInstrumentChanged(TInt aChannel,TInt aBankId,TInt aInstrumentId); |
|
188 |
|
189 private: // Data |
|
190 /** |
|
191 * Used to control MIDI events. |
|
192 */ |
|
193 CMMAMIDIPlayer* iPlayer; |
|
194 |
|
195 /** |
|
196 * Own. Utility for waiting for channel volume events |
|
197 */ |
|
198 CChannelVolumeEventWait* iVolumeEventWait; |
|
199 |
|
200 }; |
|
201 |
|
202 |
|
203 #endif // CMMAMIDICONTROL_H |
|