|
1 /* |
|
2 * Copyright (c) 2009 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: Wrapper for equalizer utility - private implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <qDebug> |
|
20 #include <QStringList> |
|
21 #include <audioequalizerutility.h> |
|
22 #include <EqualizerConstants.h> |
|
23 #include <mpxplaybackutility.h> |
|
24 |
|
25 // User includes |
|
26 #include "mpequalizerwrapper.h" |
|
27 #include "mpequalizerwrapper_p.h" |
|
28 #include "mpsettingsmanager.h" |
|
29 #include "mpcommondefs.h" |
|
30 #include "mptrace.h" |
|
31 |
|
32 // CONSTANTS |
|
33 _LIT( KMPXNullSoundPath, "\\nullsound.mp3" ); |
|
34 const TInt KEqualizerID = 0x101FFC76; |
|
35 |
|
36 /*! |
|
37 \class MpEqualizerWrapperPrivate |
|
38 \ingroup musicplayer |
|
39 \brief Wrapper for equalizer utility - private implementation. |
|
40 |
|
41 This is a private implementation of the audio eqalizer wrapper |
|
42 utilties interface. |
|
43 |
|
44 */ |
|
45 |
|
46 /*! |
|
47 Constructs a new MpEqualizerWrapper with \a parent and initializes its |
|
48 private imaplementation. |
|
49 */ |
|
50 MpEqualizerWrapperPrivate::MpEqualizerWrapperPrivate( |
|
51 MpEqualizerWrapper *wrapper ): q_ptr( wrapper ), |
|
52 iEqualizerUtility (NULL), iCurrentPresetIndex(KEqualizerPresetNone) |
|
53 { |
|
54 TX_LOG |
|
55 } |
|
56 |
|
57 /*! |
|
58 Destructs the class. |
|
59 */ |
|
60 MpEqualizerWrapperPrivate::~MpEqualizerWrapperPrivate() |
|
61 { |
|
62 TX_ENTRY |
|
63 |
|
64 delete iEqualizerUtility; |
|
65 |
|
66 if ( iMdaPlayUtility ) |
|
67 { |
|
68 iMdaPlayUtility->Close(); |
|
69 } |
|
70 delete iMdaPlayUtility; |
|
71 |
|
72 if ( iMpxPlaybackUtility ) |
|
73 { |
|
74 iMpxPlaybackUtility->Close(); |
|
75 } |
|
76 |
|
77 TX_EXIT |
|
78 } |
|
79 |
|
80 /*! |
|
81 Calls the DoInit to initialize Symbian based components. |
|
82 |
|
83 \sa DoInitL() |
|
84 */ |
|
85 void MpEqualizerWrapperPrivate::init() |
|
86 { |
|
87 TX_ENTRY |
|
88 |
|
89 TRAPD(err, DoInitL()); |
|
90 if ( err != KErrNone ) |
|
91 { |
|
92 TX_LOG_ARGS("MpEqualizerWrapperPrivate::init err = " << err); |
|
93 } |
|
94 |
|
95 TX_EXIT |
|
96 } |
|
97 |
|
98 /*! |
|
99 Apply the preset by giving preset index. The index is subtracted by 1 because |
|
100 index 0 represent "Off" at UI level. |
|
101 |
|
102 */ |
|
103 void MpEqualizerWrapperPrivate::applyPreset( int preset ) |
|
104 { |
|
105 TX_ENTRY_ARGS( "preset=" << preset ); |
|
106 |
|
107 if ( iEqualizerUtility ) |
|
108 { |
|
109 TInt presetKey(KErrNotFound); |
|
110 TRAPD(err, presetKey = GetEngineIndexL( preset - 1 )); |
|
111 if ( err != KErrNone ) |
|
112 { |
|
113 TX_LOG_ARGS("GetEngineIndexL Error = " << err); |
|
114 return; |
|
115 } |
|
116 TX_LOG_ARGS( "Preset key in engine =" << presetKey ); |
|
117 HandlePresetActivation( presetKey ); |
|
118 iCurrentPresetIndex = preset; |
|
119 } |
|
120 else |
|
121 { |
|
122 TX_LOG_ARGS( "Equalizer not ready." ); |
|
123 } |
|
124 |
|
125 TX_EXIT |
|
126 } |
|
127 |
|
128 /*! |
|
129 Return current preset index (UI) |
|
130 |
|
131 */ |
|
132 int MpEqualizerWrapperPrivate::activePreset() |
|
133 { |
|
134 TX_LOG_ARGS("iCurrentPresetIndex = " << iCurrentPresetIndex ); |
|
135 |
|
136 return iCurrentPresetIndex; |
|
137 } |
|
138 |
|
139 /*! |
|
140 Disabling equalizer by setting the preset to -1 and apply it to |
|
141 disable current preset. |
|
142 |
|
143 */ |
|
144 void MpEqualizerWrapperPrivate::disableEqualizer() |
|
145 { |
|
146 TX_ENTRY |
|
147 |
|
148 TInt nullPreset( KErrNotFound ); |
|
149 iCurrentPresetIndex = KEqualizerPresetNone; |
|
150 HandlePresetActivation( nullPreset ); |
|
151 |
|
152 TX_EXIT |
|
153 } |
|
154 |
|
155 /*! |
|
156 Returning the list of availale preset names. |
|
157 |
|
158 \sa CAudioEqualizerUtility |
|
159 */ |
|
160 QStringList MpEqualizerWrapperPrivate::presetNames() |
|
161 { |
|
162 TX_ENTRY |
|
163 |
|
164 QStringList presetList; |
|
165 |
|
166 if ( iEqualizerUtility == NULL ) |
|
167 { |
|
168 TX_LOG_ARGS( "Equalizer not ready." ); |
|
169 return presetList; |
|
170 } |
|
171 |
|
172 TArray<TEfAudioEqualizerUtilityPreset> presetArray = iEqualizerUtility->Presets(); |
|
173 for (TInt i=0; i<presetArray.Count(); i++) |
|
174 { |
|
175 TPresetName selectedItem = presetArray[i].iPresetName; |
|
176 presetList << QString::fromUtf16( selectedItem.Ptr(), selectedItem.Length() ); |
|
177 } |
|
178 |
|
179 TX_EXIT |
|
180 |
|
181 return presetList; |
|
182 } |
|
183 |
|
184 /*! |
|
185 \internal |
|
186 */ |
|
187 void MpEqualizerWrapperPrivate::DoInitL() |
|
188 { |
|
189 TX_ENTRY |
|
190 |
|
191 if (!iMpxPlaybackUtility) |
|
192 { |
|
193 iMpxPlaybackUtility = MMPXPlaybackUtility::UtilityL( TUid::Uid( MpCommon::KMusicPlayerUid ) ); |
|
194 } |
|
195 |
|
196 if (iMdaPlayUtility) |
|
197 { |
|
198 iMdaPlayUtility->Close(); |
|
199 delete iMdaPlayUtility; |
|
200 iMdaPlayUtility = NULL; |
|
201 } |
|
202 |
|
203 iMdaPlayUtility = ( CMdaAudioPlayerUtility* )User::LeaveIfNull( |
|
204 CMdaAudioPlayerUtility::NewL( |
|
205 *this, |
|
206 EMdaPriorityMin, |
|
207 EMdaPriorityPreferenceNone )); |
|
208 |
|
209 TX_LOG_ARGS("Loading null sound"); |
|
210 TFileName nullSoundPath( KMPXNullSoundPath ); |
|
211 User::LeaveIfError( MPXUser::CompleteWithDllPath( nullSoundPath ) ); |
|
212 TX_LOG_ARGS("Loading null sound done!"); |
|
213 iMdaPlayUtility->OpenFileL( nullSoundPath ); |
|
214 |
|
215 TX_EXIT |
|
216 } |
|
217 |
|
218 |
|
219 /*! |
|
220 \internal |
|
221 */ |
|
222 void MpEqualizerWrapperPrivate::HandlePresetActivation( TInt aActivatedPreset ) |
|
223 { |
|
224 TX_ENTRY_ARGS( "aActivatedPreset=" << aActivatedPreset ); |
|
225 |
|
226 // Store in CenRep file |
|
227 MpSettingsManager::setPreset( aActivatedPreset ); |
|
228 |
|
229 // Notify playback framework of the change. |
|
230 TRAPD(error, |
|
231 { |
|
232 iMpxPlaybackUtility->CommandL( EPbApplyEffect, KEqualizerID ); |
|
233 }); |
|
234 |
|
235 if (error != KErrNone) |
|
236 { |
|
237 TX_ENTRY_ARGS( "Equalizer error:" << error ); |
|
238 } |
|
239 |
|
240 TX_EXIT |
|
241 } |
|
242 |
|
243 |
|
244 /*! |
|
245 \internal |
|
246 */ |
|
247 void MpEqualizerWrapperPrivate::GetPresetId( TInt& aPresetId ) |
|
248 { |
|
249 TX_ENTRY |
|
250 |
|
251 // Get preset id from cenrep |
|
252 TInt presetId( MpSettingsManager::preset() ); |
|
253 |
|
254 TBool found( EFalse ); |
|
255 if ( iEqualizerUtility && presetId != KEqualizerPresetNone ) |
|
256 { |
|
257 TArray<TEfAudioEqualizerUtilityPreset> presetArray = iEqualizerUtility->Presets(); |
|
258 for ( TInt i = 0; i < presetArray.Count() && found == EFalse; i++ ) { |
|
259 TX_LOG_ARGS("presetArray[" << i << "].iPresetNameKey (" |
|
260 << presetArray[i].iPresetNameKey << ") vs presetId (" <<presetId << ")"); |
|
261 if ( presetArray[i].iPresetNameKey == static_cast<TUint32>( presetId ) ) { |
|
262 found = ETrue; |
|
263 iCurrentPresetIndex = aPresetId = i + 1; |
|
264 break; |
|
265 } |
|
266 } |
|
267 } |
|
268 |
|
269 if ( found == EFalse ) |
|
270 { |
|
271 iCurrentPresetIndex = aPresetId = KEqualizerPresetNone; |
|
272 } |
|
273 |
|
274 TX_EXIT |
|
275 } |
|
276 |
|
277 |
|
278 /*! |
|
279 \internal |
|
280 */ |
|
281 TInt MpEqualizerWrapperPrivate::GetEngineIndexL( const TInt preset ) const |
|
282 { |
|
283 TX_ENTRY_ARGS( "preset=" << preset ); |
|
284 |
|
285 TInt engineIndex = KErrNotFound; |
|
286 |
|
287 TPresetName presetName = iEqualizerUtility->GetPresetL( preset ); |
|
288 |
|
289 TArray<TEfAudioEqualizerUtilityPreset> presets = iEqualizerUtility->Presets(); |
|
290 for (TInt count = 0; count < presets.Count(); count++) |
|
291 { |
|
292 TPresetName selectedItem = presets[count].iPresetName; |
|
293 TX_LOG_ARGS(" Comparing..." << presets[count].iPresetNameKey ); |
|
294 if ( selectedItem == presetName ) { |
|
295 engineIndex = presets[count].iPresetNameKey; |
|
296 TX_LOG_ARGS(" Comparing mached engineIndex = " << engineIndex ); |
|
297 break; |
|
298 } |
|
299 } |
|
300 |
|
301 TX_EXIT |
|
302 |
|
303 return engineIndex; |
|
304 } |
|
305 |
|
306 /*! |
|
307 \internal |
|
308 */ |
|
309 void MpEqualizerWrapperPrivate::MapcInitComplete( |
|
310 TInt aError, |
|
311 const TTimeIntervalMicroSeconds& /* aDuration */ ) |
|
312 { |
|
313 TX_ENTRY_ARGS( "aError=" << aError ); |
|
314 |
|
315 if ( !aError ) |
|
316 { |
|
317 TRAPD(err, iEqualizerUtility = CAudioEqualizerUtility::NewL( *iMdaPlayUtility ) ); |
|
318 if ( err == KErrNone ) { |
|
319 TInt preset(KEqualizerPresetNone); |
|
320 GetPresetId( preset ); |
|
321 emit q_ptr->equalizerReady(); |
|
322 } |
|
323 else |
|
324 { |
|
325 TX_ENTRY_ARGS( "CAudioEquqlizerUtility error=" << err ); |
|
326 } |
|
327 } |
|
328 else |
|
329 { |
|
330 TX_ENTRY_ARGS( "MapcInitComplete error=" << aError ); |
|
331 } |
|
332 |
|
333 TX_EXIT |
|
334 } |
|
335 |
|
336 /*! |
|
337 \internal |
|
338 */ |
|
339 void MpEqualizerWrapperPrivate::MapcPlayComplete( |
|
340 TInt /* aError */ ) |
|
341 { |
|
342 TX_LOG |
|
343 // Do nothing |
|
344 } |
|
345 |
|
346 //End of File |