|
1 /* |
|
2 * Copyright (c) 2005-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: Manipulates the panning of a Player in the stereo output mix. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <logger.h> |
|
22 #include <cmmaaudioplayer.h> |
|
23 #include <cmmamidiplayer.h> |
|
24 #include <cmmaemcaudioplayer.h> |
|
25 #include "cammspancontrol.h" |
|
26 |
|
27 #ifdef _DEBUG |
|
28 // CONSTANTS |
|
29 const TInt KAMMSMaxPanning = 100; |
|
30 const TInt KAMMSMinPanning = -100; |
|
31 #endif // _DEBUG |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CAMMSPanControl::NewLC |
|
37 // Two-phased constructor. |
|
38 // ----------------------------------------------------------------------------- |
|
39 CAMMSPanControl* CAMMSPanControl::NewLC(CMMAPlayer* aPlayer) |
|
40 { |
|
41 CAMMSPanControl* self = new(ELeave) CAMMSPanControl(aPlayer); |
|
42 |
|
43 CleanupStack::PushL(self); |
|
44 |
|
45 self->ConstructL(); |
|
46 |
|
47 return self; |
|
48 } |
|
49 |
|
50 // Destructor |
|
51 CAMMSPanControl::~CAMMSPanControl() |
|
52 { |
|
53 if (iRMMFAudioPlayDeviceCustomCommands) |
|
54 { |
|
55 delete iRMMFAudioPlayDeviceCustomCommands; |
|
56 iRMMFAudioPlayDeviceCustomCommands = NULL; |
|
57 } |
|
58 |
|
59 // Remove the EMC Pan Control Effect from Stream Control |
|
60 // Deleted the effect |
|
61 if (iMBalanceControl) |
|
62 { |
|
63 //return the control to factory |
|
64 MEffectControl* temp = iMBalanceControl; |
|
65 if (iStreamControl) |
|
66 iStreamControl->RemoveEffect(*temp); |
|
67 // Delete the Effect |
|
68 MEffectControl* tempCtrl = iMBalanceControl; |
|
69 if (iFactory) |
|
70 iFactory->DeleteEffectControl(tempCtrl); |
|
71 iMBalanceControl = NULL; |
|
72 } |
|
73 |
|
74 |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CAMMSPanControl::PanL |
|
79 // Gets the current panning set. |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 TInt CAMMSPanControl::PanL() |
|
83 { |
|
84 TInt balance = KMMFBalanceCenter; |
|
85 |
|
86 // In case of MIDIPlayer, use CMidiClientUtility, otherwise RMMFController. |
|
87 if (iMidiClientUtility) |
|
88 { |
|
89 // Get the current stereo balance value. |
|
90 |
|
91 balance = iMidiClientUtility->GetBalanceL(); |
|
92 } |
|
93 else if (iRMMFAudioPlayDeviceCustomCommands) |
|
94 { |
|
95 // Gets the balance between the left and right stereo audio channels. |
|
96 |
|
97 User::LeaveIfError( |
|
98 iRMMFAudioPlayDeviceCustomCommands->GetBalance(balance)); |
|
99 } |
|
100 else // if EMC Pan Control |
|
101 { |
|
102 // Get the balance and set it to balance var. |
|
103 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSPanControl::PanL is called for EMC implemented palyer"); |
|
104 User::LeaveIfError(iMBalanceControl->GetBalance(balance)); |
|
105 } |
|
106 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSPanControl::PanL called, native GetBalance = %d", |
|
107 balance); |
|
108 |
|
109 return balance; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CAMMSPanControl::SetPanL |
|
114 // Sets the panning using a linear point scale (-100 - +100). |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 TInt CAMMSPanControl::SetPanL(TInt aPan) |
|
118 { |
|
119 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSPanControl::SetPanL: Pan = %d", aPan); |
|
120 |
|
121 // Check in debug build that aPan is within valid range. |
|
122 __ASSERT_DEBUG( |
|
123 (aPan <= KAMMSMaxPanning) && |
|
124 (aPan >= KAMMSMinPanning), |
|
125 User::Invariant()); |
|
126 |
|
127 // In case of MIDIPlayer, use CMidiClientUtility, otherwise RMMFController. |
|
128 if (iMidiClientUtility) |
|
129 { |
|
130 // Set the current stereo balance value. |
|
131 // Defaults to KMMFBalanceCenter to restore equal left-right balance. |
|
132 |
|
133 iMidiClientUtility->SetBalanceL(aPan); |
|
134 } |
|
135 else if (iRMMFAudioPlayDeviceCustomCommands) |
|
136 { |
|
137 // Sets the balance between the left and right stereo audio channels |
|
138 // Use a value between KMMFBalanceMaxLeft and KMMFBalanceMaxRight. |
|
139 // Centre balance can be restored by using KMMFBalanceCenter. |
|
140 |
|
141 User::LeaveIfError( |
|
142 iRMMFAudioPlayDeviceCustomCommands->SetBalance(aPan)); |
|
143 } |
|
144 else // EMC Pan Control |
|
145 { |
|
146 // Set the Balance using the Pan Control |
|
147 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSPanControl::SetPanL: SetBalance()-- EMC "); |
|
148 User::LeaveIfError(iMBalanceControl->SetBalance(aPan)); |
|
149 User::LeaveIfError(iMBalanceControl->Apply()); |
|
150 } |
|
151 |
|
152 return PanL(); |
|
153 } |
|
154 |
|
155 |
|
156 const TDesC& CAMMSPanControl::ClassName() const |
|
157 { |
|
158 return KAMMSPanControl; |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CAMMSPanControl::ConstructL |
|
163 // Symbian 2nd phase constructor can leave. |
|
164 // ----------------------------------------------------------------------------- |
|
165 void CAMMSPanControl::ConstructL() |
|
166 { |
|
167 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSPanControl::ConstructL"); |
|
168 |
|
169 if (iPlayer->Type() == KMMAMIDIPlayer) |
|
170 { |
|
171 // In case of CMMAMIDIPlayer use CMidiClientUtility |
|
172 CMMAMIDIPlayer* mmaMIDIPlayer = |
|
173 reinterpret_cast< CMMAMIDIPlayer* >(iPlayer); |
|
174 |
|
175 iMidiClientUtility = mmaMIDIPlayer->MidiClient(); |
|
176 } |
|
177 else if (iPlayer->Type() == KMMAEMCAudioPlayer) |
|
178 { |
|
179 //Get MMFactory and StreamControl from the player |
|
180 //Create Pan Control using EMC API. |
|
181 //Add the control to Stream Control |
|
182 //Create Balance Control |
|
183 iStreamControl = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->StreamControl(); |
|
184 iFactory = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->MMFactory(); |
|
185 |
|
186 MEffectControl* temp(NULL); |
|
187 User::LeaveIfError(iFactory->CreateEffectControl(KBalanceEffectControl, temp)); |
|
188 iMBalanceControl = static_cast<MBalanceControl*>(temp); |
|
189 User::LeaveIfError(iStreamControl->AddEffect(*iMBalanceControl)); |
|
190 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSPanControl::ConstructL is called for EMC implemented Player"); |
|
191 } |
|
192 else |
|
193 { |
|
194 CMMAAudioPlayer* mmaAudioPlayer = |
|
195 reinterpret_cast< CMMAAudioPlayer* >(iPlayer); |
|
196 |
|
197 RMMFController& mmfController = mmaAudioPlayer->Controller(); |
|
198 |
|
199 iRMMFAudioPlayDeviceCustomCommands = |
|
200 new(ELeave) RMMFAudioPlayDeviceCustomCommands(mmfController); |
|
201 } |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CAMMSPanControl::CAMMSPanControl |
|
206 // C++ default constructor can NOT contain any code, that |
|
207 // might leave. |
|
208 // ----------------------------------------------------------------------------- |
|
209 CAMMSPanControl::CAMMSPanControl(CMMAPlayer* aPlayer) |
|
210 : CAMMSControl(aPlayer) |
|
211 { |
|
212 iMMAPlayer = aPlayer; |
|
213 } |
|
214 // End of File |