|
1 /* |
|
2 * Copyright (c) 2006 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: Helper class for managing equalizer utility instances. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <AudioEqualizerUtility.h> |
|
22 #include <mdaaudiosampleplayer.h> |
|
23 #include <centralrepository.h> |
|
24 #include <textresolver.h> |
|
25 #include <aknnotewrappers.h> |
|
26 #include <akntoolbar.h> |
|
27 #include <layoutmetadata.cdl.h> |
|
28 #include <mpxplaybackutility.h> |
|
29 #include <mpxplaybackmessage.h> |
|
30 #include <mpxprivatecrkeys.h> |
|
31 #include <mpxmessagegeneraldefs.h> |
|
32 #include <mpxuser.h> |
|
33 #include "mpxequalizerhelper.h" |
|
34 #include "mpxlog.h" |
|
35 #include <aknclearer.h> |
|
36 |
|
37 |
|
38 // CONSTANTS |
|
39 // Null file path |
|
40 _LIT( KMPXNullSoundPath, "\\system\\data\\nullsound.mp3" ); |
|
41 const TInt KEqualizerID = 0x101FFC76; |
|
42 // Music setting |
|
43 const TUid KCRUidMPXMPSettings = {0x101FFCDC}; |
|
44 const TUint32 KMPXMPEqPresetId = 0x00000001; |
|
45 |
|
46 const TUid KCRUidOldMPSettings = {0x101F880C}; |
|
47 const TUint32 KOldMPEqPresetId = 0x00000009; |
|
48 |
|
49 // ======== MEMBER FUNCTIONS ======== |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // C++ default constructor can NOT contain any code, that |
|
53 // might leave. |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CMPXEqualizerHelper::CMPXEqualizerHelper() |
|
57 { |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // Symbian 2nd phase constructor can leave. |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 void CMPXEqualizerHelper::ConstructL() |
|
65 { |
|
66 // Get the playback utility instance from engine. |
|
67 iPlaybackUtility = MMPXPlaybackUtility::UtilityL( KPbModeDefault ); |
|
68 iPlaybackUtility->AddObserverL( *this ); |
|
69 iWait = new( ELeave )CActiveSchedulerWait; |
|
70 InitializeBackupEqualizerUtilityL(); |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // Two-phased constructor. |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 CMPXEqualizerHelper* CMPXEqualizerHelper::NewL() |
|
78 { |
|
79 CMPXEqualizerHelper* self = |
|
80 new ( ELeave ) CMPXEqualizerHelper(); |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL(); |
|
83 CleanupStack::Pop( self ); |
|
84 return self; |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // Destructor |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 CMPXEqualizerHelper::~CMPXEqualizerHelper() |
|
92 { |
|
93 delete iAudioEqualizerUtility; |
|
94 delete iBackupEqualizerUtility; |
|
95 iEqualizerUtility = NULL; |
|
96 iEqDialog = NULL; |
|
97 |
|
98 if ( iPlayUtility ) |
|
99 { |
|
100 if ( iPlaybackUtility ) |
|
101 { |
|
102 TRAP_IGNORE( iPlaybackUtility->RemoveObserverL( *this ) ); |
|
103 } |
|
104 iPlayUtility->Close(); |
|
105 } |
|
106 delete iPlayUtility; |
|
107 |
|
108 if ( iPlaybackUtility ) |
|
109 { |
|
110 iPlaybackUtility->Close(); |
|
111 } |
|
112 delete iWait; |
|
113 iWait = NULL; |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // Initialize audio equalizer utility for current active playing track. |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 void CMPXEqualizerHelper::InitializeEqualizerUtilityL() |
|
121 { |
|
122 MPX_FUNC( "CMPXEqualizerHelper::InitializeEqualizerUtilityL" ); |
|
123 |
|
124 ReleaseEqualizerUtility(); |
|
125 |
|
126 //CCustomCommandUtility* customCmdUtility = |
|
127 // CMPXPlaybackCCustomCommandUtility::NewCustomCommandUtilityL( |
|
128 // *iPlaybackUtility ); |
|
129 //CleanupStack::PushL( customCmdUtility ); |
|
130 |
|
131 //iAudioEqualizerUtility = |
|
132 // CAudioEqualizerUtility::NewL( customCmdUtility ); |
|
133 //MPX_DEBUG2( "--> CAudioEqualizerUtility created ok (0x%08x)", |
|
134 // iAudioEqualizerUtility ); |
|
135 |
|
136 //CleanupStack::Pop( customCmdUtility ); // ownership is transferred |
|
137 |
|
138 SetupActiveEqualizerUtility(); |
|
139 |
|
140 TInt ignore( KEqualizerPresetNone ); |
|
141 TInt index = GetPresetId( ignore ); |
|
142 if ( KErrNotFound != index ) |
|
143 { |
|
144 iEqualizerUtility->ApplyPresetL( index ); |
|
145 } |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // Release audio equalizer utility. |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 void CMPXEqualizerHelper::ReleaseEqualizerUtility() |
|
153 { |
|
154 MPX_FUNC( "CMPXEqualizerHelper::ReleaseEqualizerUtility" ); |
|
155 |
|
156 if ( iEqDialog ) |
|
157 { |
|
158 // Recreate Backup Equalizer Utility to make sure it can get the |
|
159 // latest presets. |
|
160 if ( !iBackupEqualizerUtility ) |
|
161 { |
|
162 CreateBackupEqualizerUtility(); |
|
163 } |
|
164 |
|
165 MPX_DEBUG2( "--> iEqDialog->SetAudioEqualizerL(0x%08x)", |
|
166 iBackupEqualizerUtility ); |
|
167 |
|
168 TRAP_IGNORE( |
|
169 iEqDialog->SetAudioEqualizerL( iBackupEqualizerUtility ) ); |
|
170 } |
|
171 |
|
172 iEqualizerUtility = iBackupEqualizerUtility; |
|
173 |
|
174 if ( iAudioEqualizerUtility ) |
|
175 { |
|
176 delete iAudioEqualizerUtility; |
|
177 iAudioEqualizerUtility = NULL; |
|
178 } |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // Get current preset ID. |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 TInt CMPXEqualizerHelper::GetPresetId( TInt& aPresetId ) |
|
186 { |
|
187 MPX_FUNC( "CMPXEqualizerHelper::GetPresetId" ); |
|
188 |
|
189 // Get preset id from cenrep |
|
190 TInt presetId( KEqualizerPresetNone ); |
|
191 TRAP_IGNORE( |
|
192 { |
|
193 CRepository* repository = CRepository::NewL( KCRUidMPXMPSettings ); |
|
194 repository->Get( KMPXMPEqPresetId, presetId ); |
|
195 delete repository; |
|
196 repository = NULL; |
|
197 } ); |
|
198 |
|
199 TInt index( KErrNotFound ); |
|
200 if ( iEqualizerUtility && presetId != KEqualizerPresetNone ) |
|
201 { |
|
202 TArray<TEfAudioEqualizerUtilityPreset> presetArray = |
|
203 iEqualizerUtility->Presets(); |
|
204 |
|
205 TBool found( EFalse ); |
|
206 for ( TInt i = 0; i < presetArray.Count() && found == EFalse; i++ ) |
|
207 { |
|
208 if ( presetArray[i].iPresetNameKey == |
|
209 static_cast<TUint32>( presetId ) ) |
|
210 { |
|
211 found = ETrue; |
|
212 index = i; |
|
213 aPresetId = presetId; |
|
214 } |
|
215 } |
|
216 } |
|
217 else |
|
218 { |
|
219 aPresetId = KEqualizerPresetNone; |
|
220 } |
|
221 |
|
222 MPX_DEBUG2( "--> Preset id get: %d", presetId ); |
|
223 return index; |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // Initialize secondary audio equalizer utility for situations when the |
|
228 // engine cannot provide one. |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 void CMPXEqualizerHelper::InitializeBackupEqualizerUtilityL() |
|
232 { |
|
233 MPX_FUNC( "CMPXEqualizerHelper::InitializeBackupEqualizerUtilityL()" ); |
|
234 |
|
235 if ( iOpenInProgress ) |
|
236 { |
|
237 // OpenFileL already called |
|
238 return; |
|
239 } |
|
240 |
|
241 if ( !iPlayUtility ) |
|
242 { |
|
243 iPlayUtility = CMdaAudioPlayerUtility::NewL( |
|
244 *this, |
|
245 EMdaPriorityMin, |
|
246 EMdaPriorityPreferenceNone ); |
|
247 } |
|
248 |
|
249 TFileName nullSoundPath( KMPXNullSoundPath ); |
|
250 User::LeaveIfError( MPXUser::CompleteWithDllPath( nullSoundPath ) ); |
|
251 iPlayUtility->OpenFileL( nullSoundPath ); |
|
252 iOpenInProgress = ETrue; |
|
253 } |
|
254 |
|
255 // --------------------------------------------------------------------------- |
|
256 // Create secondary audio equalizer utility based on latest preset settings. |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 void CMPXEqualizerHelper::CreateBackupEqualizerUtility() |
|
260 { |
|
261 if ( iPlayUtility ) |
|
262 { |
|
263 delete iBackupEqualizerUtility; |
|
264 iBackupEqualizerUtility = NULL; |
|
265 TRAP_IGNORE( iBackupEqualizerUtility = |
|
266 CAudioEqualizerUtility::NewL( *iPlayUtility ) ); |
|
267 } |
|
268 } |
|
269 |
|
270 // --------------------------------------------------------------------------- |
|
271 // Setup active equalizer utility for equalizer dialog. |
|
272 // --------------------------------------------------------------------------- |
|
273 // |
|
274 void CMPXEqualizerHelper::SetupActiveEqualizerUtility() |
|
275 { |
|
276 CAudioEqualizerUtility* oldUtility( iEqualizerUtility ); |
|
277 |
|
278 // Try to use the real equalizer utility first |
|
279 if ( !iAudioEqualizerUtility && iBackupEqualizerUtility ) |
|
280 { |
|
281 iEqualizerUtility = iBackupEqualizerUtility; |
|
282 } |
|
283 else |
|
284 { |
|
285 iEqualizerUtility = iAudioEqualizerUtility; |
|
286 } |
|
287 |
|
288 if ( iEqDialog && oldUtility != iEqualizerUtility ) |
|
289 { |
|
290 MPX_DEBUG2( "--> iEqDialog->SetAudioEqualizerL(0x%08x)", iEqualizerUtility ); |
|
291 TRAP_IGNORE( iEqDialog->SetAudioEqualizerL( iEqualizerUtility ) ); |
|
292 } |
|
293 } |
|
294 |
|
295 // --------------------------------------------------------------------------- |
|
296 // Launch equalizer dialog. |
|
297 // --------------------------------------------------------------------------- |
|
298 // |
|
299 void CMPXEqualizerHelper::DoLaunchEqualizerDialogL() |
|
300 { |
|
301 MPX_FUNC( "CMPXEqualizerHelper::DoLaunchEqualizerDialogL()" ); |
|
302 |
|
303 __ASSERT_DEBUG( |
|
304 iEqualizerUtility, |
|
305 User::Panic( _L( "CMPXEqualizerHelper" ), KErrArgument ) ); |
|
306 |
|
307 TInt presetId( KEqualizerPresetNone ); |
|
308 GetPresetId( presetId ); |
|
309 |
|
310 CEqualizerPresetsDialog* dlg = CEqualizerPresetsDialog::NewL( |
|
311 iEqualizerUtility, presetId, *this ); |
|
312 iEqDialog = dlg; |
|
313 |
|
314 CAknToolbar* toolbar = |
|
315 static_cast< CAknAppUi* >(CEikonEnv::Static()->AppUi())->CurrentFixedToolbar(); |
|
316 |
|
317 TBool wasToolbarVisible = toolbar->IsVisible(); |
|
318 |
|
319 if ( toolbar ) |
|
320 { |
|
321 toolbar->HideItemsAndDrawOnlyBackground( ETrue ); |
|
322 } |
|
323 |
|
324 MPX_TRAPD( err, dlg->ExecuteLD() ); |
|
325 iEqDialog = NULL; |
|
326 |
|
327 if ( toolbar && wasToolbarVisible ) |
|
328 { |
|
329 toolbar->HideItemsAndDrawOnlyBackground( EFalse ); |
|
330 } |
|
331 |
|
332 if ( err ) |
|
333 { |
|
334 MPX_DEBUG2( "--> dlg->ExecuteLD() left with %d", err ); |
|
335 User::Leave( err ); |
|
336 } |
|
337 } |
|
338 |
|
339 // --------------------------------------------------------------------------- |
|
340 // Handle playback message. |
|
341 // --------------------------------------------------------------------------- |
|
342 // |
|
343 void CMPXEqualizerHelper::DoHandlePlaybackMessageL( |
|
344 const CMPXMessage& aMessage ) |
|
345 { |
|
346 MPX_FUNC( "CMPXEqualizerHelper::DoHandlePlaybackMessageL" ); |
|
347 TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) ); |
|
348 if ( KMPXMessageGeneral == id ) |
|
349 { |
|
350 switch ( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) ) |
|
351 { |
|
352 case TMPXPlaybackMessage::EStateChanged: |
|
353 { |
|
354 TMPXPlaybackState state( |
|
355 static_cast<TMPXPlaybackState>( |
|
356 aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) ) ); |
|
357 DoHandleStateChangedL( state ); |
|
358 break; |
|
359 } |
|
360 default: |
|
361 { |
|
362 // pass |
|
363 break; |
|
364 } |
|
365 } |
|
366 } |
|
367 } |
|
368 |
|
369 // --------------------------------------------------------------------------- |
|
370 // Handle playback state changed. |
|
371 // --------------------------------------------------------------------------- |
|
372 // |
|
373 void CMPXEqualizerHelper::DoHandleStateChangedL( |
|
374 TMPXPlaybackState aState ) |
|
375 { |
|
376 switch ( aState ) |
|
377 { |
|
378 case EPbStateNotInitialised: |
|
379 case EPbStateStopped: |
|
380 case EPbStatePaused: |
|
381 case EPbStateShuttingDown: |
|
382 { |
|
383 // Need to release Equalizer utility when audio is stopped. |
|
384 // It's because of the limitation in adaptation layer. |
|
385 ReleaseEqualizerUtility(); |
|
386 break; |
|
387 } |
|
388 case EPbStatePlaying: |
|
389 { |
|
390 // Need to initialize Equalizer utility when audio is started |
|
391 // playing. It's because of the limitation in adaptation layer. |
|
392 InitializeEqualizerUtilityL(); |
|
393 break; |
|
394 } |
|
395 default: |
|
396 { |
|
397 // pass |
|
398 break; |
|
399 } |
|
400 } |
|
401 } |
|
402 |
|
403 // --------------------------------------------------------------------------- |
|
404 // From CMPXEqualizerView |
|
405 // Launch equalizer dialog. |
|
406 // --------------------------------------------------------------------------- |
|
407 // |
|
408 void CMPXEqualizerHelper::LaunchEqualizerL() |
|
409 { |
|
410 MPX_FUNC( "CMPXEqualizerHelper::LaunchEqualizerL" ); |
|
411 |
|
412 if ( iLaunchEqualizerOnOpenComplete ) |
|
413 { |
|
414 // Waiting for open complete callback, cannot do anything now |
|
415 return; |
|
416 } |
|
417 |
|
418 if ( !iPlayUtility || !iBackupEqualizerUtility ) |
|
419 { |
|
420 // Backup equalizer does not exist, must initialize first |
|
421 iLaunchEqualizerOnOpenComplete = ETrue; |
|
422 InitializeBackupEqualizerUtilityL(); |
|
423 if( iWait ) |
|
424 { |
|
425 iWait->Start(); |
|
426 } |
|
427 } |
|
428 else |
|
429 { |
|
430 // Recreate Backup Equalizer Utility to make sure it can get the |
|
431 // latest presets. |
|
432 CreateBackupEqualizerUtility(); |
|
433 |
|
434 // Setup active equalizer utility and launch the dialog |
|
435 SetupActiveEqualizerUtility(); |
|
436 DoLaunchEqualizerDialogL(); |
|
437 } |
|
438 } |
|
439 |
|
440 // --------------------------------------------------------------------------- |
|
441 // From MMPXPlaybackObserver |
|
442 // Handle playback message. |
|
443 // --------------------------------------------------------------------------- |
|
444 // |
|
445 void CMPXEqualizerHelper::HandlePlaybackMessage( |
|
446 CMPXMessage* aMessage, TInt aError ) |
|
447 { |
|
448 if ( aError == KErrNone && aMessage ) |
|
449 { |
|
450 TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) ); |
|
451 } |
|
452 } |
|
453 |
|
454 // --------------------------------------------------------------------------- |
|
455 // From MEqualizerPresetActivationObserver |
|
456 // Handle preset id activation from Equalizer dialog. |
|
457 // --------------------------------------------------------------------------- |
|
458 // |
|
459 void CMPXEqualizerHelper::HandlePresetActivation( |
|
460 TInt aActivatedPreset ) |
|
461 { |
|
462 MPX_DEBUG2("CMPXEqualizerHelper::HandlePresetActivation %i", aActivatedPreset); |
|
463 MPX_FUNC( "CMPXEqualizerHelper::HandlePresetActivation" ); |
|
464 |
|
465 // Store in CenRep file |
|
466 TRAP_IGNORE( |
|
467 { |
|
468 CRepository* repository = CRepository::NewL( KCRUidMPXMPSettings ); |
|
469 TInt err = repository->Set( KMPXMPEqPresetId, aActivatedPreset ); |
|
470 delete repository; |
|
471 repository = NULL; |
|
472 |
|
473 repository = CRepository::NewL( KCRUidOldMPSettings ); |
|
474 err = repository->Set( KOldMPEqPresetId, aActivatedPreset ); |
|
475 delete repository; |
|
476 repository = NULL; |
|
477 |
|
478 } ); |
|
479 |
|
480 // Notify playback framework of the change. |
|
481 // |
|
482 TRAP_IGNORE( iPlaybackUtility->CommandL( EPbApplyEffect, KEqualizerID ) ); |
|
483 } |
|
484 |
|
485 // --------------------------------------------------------------------------- |
|
486 // From MMdaAudioPlayerCallback |
|
487 // Callback when an attempt to open and initialise an audio sample |
|
488 // has completed. |
|
489 // --------------------------------------------------------------------------- |
|
490 // |
|
491 void CMPXEqualizerHelper::MapcInitComplete( |
|
492 TInt aError, |
|
493 const TTimeIntervalMicroSeconds& /* aDuration */ ) |
|
494 { |
|
495 MPX_DEBUG3( "CMPXEqualizerHelper::MapcInitComplete(%d) -- iLaunchEqualizerOnOpenComplete=%d", aError, iLaunchEqualizerOnOpenComplete ); |
|
496 |
|
497 iOpenInProgress = EFalse; |
|
498 if ( !aError ) |
|
499 { |
|
500 // Recreate Backup Equalizer Utility to make sure it can get the |
|
501 // latest presets. |
|
502 CreateBackupEqualizerUtility(); |
|
503 |
|
504 if ( iBackupEqualizerUtility ) |
|
505 { |
|
506 MPX_DEBUG2( "--> iBackupEqualizerUtility=0x%08x, NewL ok", iBackupEqualizerUtility ); |
|
507 |
|
508 // Setup active equalizer utility |
|
509 SetupActiveEqualizerUtility(); |
|
510 |
|
511 if ( iLaunchEqualizerOnOpenComplete ) |
|
512 { |
|
513 TRAP_IGNORE( DoLaunchEqualizerDialogL() ); |
|
514 } |
|
515 } |
|
516 } |
|
517 else |
|
518 { |
|
519 TRAP_IGNORE( |
|
520 { |
|
521 // TextResolver instance for error resolving. |
|
522 CTextResolver* textresolver = CTextResolver::NewLC(); |
|
523 // Resolve the error text |
|
524 const TDesC& text = |
|
525 textresolver->ResolveErrorString( aError ); |
|
526 |
|
527 CAknErrorNote* dlg = new ( ELeave ) CAknErrorNote( ETrue ); |
|
528 dlg->ExecuteLD( text ); |
|
529 CleanupStack::PopAndDestroy( textresolver ); |
|
530 } ); |
|
531 } |
|
532 iLaunchEqualizerOnOpenComplete = EFalse; |
|
533 if( iWait && iWait->IsStarted() ) |
|
534 { |
|
535 iWait->AsyncStop(); |
|
536 } |
|
537 } |
|
538 |
|
539 // --------------------------------------------------------------------------- |
|
540 // From MMdaAudioPlayerCallback |
|
541 // Callback when an attempt to playback an audio sample has completed. |
|
542 // --------------------------------------------------------------------------- |
|
543 // |
|
544 void CMPXEqualizerHelper::MapcPlayComplete( |
|
545 TInt /* aError */ ) |
|
546 { |
|
547 // Do nothing |
|
548 } |
|
549 |
|
550 // End of File |