javauis/amms_qt/ammscontrol/audioeffect/src/cammsequalizercontrolgroup.cpp
branchRCL_3
changeset 24 0fd27995241b
equal deleted inserted replaced
20:f9bb0fca356a 24:0fd27995241b
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Group for equalizer controls
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <AudioEqualizerUtility.h>
       
    21 #include <AudioEqualizerUtilityData.h>
       
    22 #include <logger.h>
       
    23 
       
    24 #include "cammsequalizercontrolgroup.h"
       
    25 #include "cammsbaseequalizercontrol.h"
       
    26 
       
    27 // CONSTANTS
       
    28 namespace
       
    29 {
       
    30 const TInt KAMMSDefaultEqualizerLevel = 0;
       
    31 const TInt KAMMSDefaultEqualizerMaxLevel = 1200;
       
    32 const TInt KAMMSDefaultEqualizerMinLevel = -1200;
       
    33 const TInt KAMMSDefaultEqualizerTrebleAndBassLevel = 50;
       
    34 const TInt KAMMSUndefinedTrebleOrBass = -1004;
       
    35 const TInt KAMMSKilo = 1000;  // e.g. 1Hz = 1000 mHz
       
    36 }
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CAMMSEqualizerControlGroup::NewLC
       
    42 // Two-phased constructor.
       
    43 // -----------------------------------------------------------------------------
       
    44 CAMMSEqualizerControlGroup* CAMMSEqualizerControlGroup::NewLC()
       
    45 {
       
    46     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::NewLC +");
       
    47 
       
    48     CAMMSEqualizerControlGroup* self =
       
    49         new(ELeave) CAMMSEqualizerControlGroup;
       
    50 
       
    51     CleanupStack::PushL(self);
       
    52     self->ConstructL();
       
    53 
       
    54     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::NewLC -");
       
    55 
       
    56     return self;
       
    57 }
       
    58 
       
    59 // Destructor
       
    60 CAMMSEqualizerControlGroup::~CAMMSEqualizerControlGroup()
       
    61 {
       
    62     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::~ +");
       
    63 
       
    64     delete iEmptyAudioEqualizerUtility;
       
    65 
       
    66     iBands.Close();
       
    67 
       
    68     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::~ -");
       
    69 }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CAMMSEqualizerControlGroup::Band
       
    73 // Gets the band that has the most effect on the given frequency
       
    74 // (other items were commented in a header).
       
    75 // -----------------------------------------------------------------------------
       
    76 TInt CAMMSEqualizerControlGroup::Band(TInt aFrequency)
       
    77 {
       
    78     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::Band +");
       
    79 
       
    80     // Check whether bands have effect on the given frequency.
       
    81     if ((aFrequency <= 0) ||
       
    82             (aFrequency > KAMMSHalfOfSamplingFrequency))    // 24000000 milliHertz
       
    83     {
       
    84         return -1;  // no effect on the frequency. Frequency 0 goes here too.
       
    85     }
       
    86 
       
    87     TInt bandCount = iBands.Count();
       
    88     if (bandCount == 0)
       
    89     {
       
    90         return 0;  // if the number of the bands is zero, return band zero.
       
    91     }
       
    92 
       
    93     // Effect API uses hertzes whereas AMMS uses millihertzes.
       
    94     TInt frequencyInHertzes = aFrequency / KAMMSKilo;
       
    95 
       
    96     // Find the first band whose cross-over frequency is greater than the
       
    97     // given frequency (the band has effect on the given frequency).
       
    98     TInt i = 0;
       
    99     for (i = 0; i < bandCount; i++)
       
   100     {
       
   101         if (iBands[ i ].iCrossoverFrequency >= frequencyInHertzes)
       
   102         {
       
   103             return i;
       
   104         }
       
   105     }
       
   106 
       
   107     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::Band -");
       
   108 
       
   109     // If the given frequency if bigger than any cross-over frequency,
       
   110     // return the last band.
       
   111     return (bandCount - 1);
       
   112 }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CAMMSEqualizerControlGroup::GetBandLevelL
       
   116 // Gets the gain set for the given equalizer band.
       
   117 // (other items were commented in a header).
       
   118 // -----------------------------------------------------------------------------
       
   119 void CAMMSEqualizerControlGroup::GetBandLevelL(TInt aBand, TInt& aBandLevel)
       
   120 {
       
   121     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::GetBandLevelL +");
       
   122 
       
   123     CheckBandIndexL(aBand);
       
   124 
       
   125     aBandLevel = iBands[ aBand ].iBandLevel;  // CSI: 2 Index checked above #
       
   126 
       
   127     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::GetBandLevelL -");
       
   128 }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CAMMSEqualizerControlGroup::Bass
       
   132 // Gets the bass level.
       
   133 // (other items were commented in a header).
       
   134 // -----------------------------------------------------------------------------
       
   135 TInt CAMMSEqualizerControlGroup::Bass()
       
   136 {
       
   137     return iBass;
       
   138 }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CAMMSEqualizerControlGroup::GetCenterFreqL
       
   142 // Gets the center frequency of the given band
       
   143 // (other items were commented in a header).
       
   144 // -----------------------------------------------------------------------------
       
   145 void CAMMSEqualizerControlGroup::GetCenterFreqL(TInt aBand, TInt& aCenterFreq)
       
   146 {
       
   147     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::GetCenterFreqL +");
       
   148 
       
   149     CheckBandIndexL(aBand);
       
   150 
       
   151     // Effect API uses hertzes whereas AMMS uses millihertzes.
       
   152     aCenterFreq = iBands[ aBand ].iCenterFrequency * KAMMSKilo; // CSI: 2 Index checked above #
       
   153 
       
   154     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::GetCenterFreqL -");
       
   155 }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CAMMSEqualizerControlGroup::MaxBandLevel
       
   159 // Returns the maximum band level supported
       
   160 // (other items were commented in a header).
       
   161 // -----------------------------------------------------------------------------
       
   162 TInt CAMMSEqualizerControlGroup::MaxBandLevel()
       
   163 {
       
   164     return iMaxBandLevel;
       
   165 }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CAMMSEqualizerControlGroup::MinBandLevel
       
   169 // Returns the minimum band level supported.
       
   170 // (other items were commented in a header).
       
   171 // -----------------------------------------------------------------------------
       
   172 TInt CAMMSEqualizerControlGroup::MinBandLevel()
       
   173 {
       
   174     return iMinBandLevel;
       
   175 }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CAMMSEqualizerControlGroup::NumberOfBands
       
   179 // Gets the number of frequency bands that the equalizer supports.
       
   180 // (other items were commented in a header).
       
   181 // -----------------------------------------------------------------------------
       
   182 TInt CAMMSEqualizerControlGroup::NumberOfBands()
       
   183 {
       
   184     return iBands.Count();
       
   185 }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CAMMSEqualizerControlGroup::Treble
       
   189 // Gets the treble level.
       
   190 // (other items were commented in a header).
       
   191 // -----------------------------------------------------------------------------
       
   192 TInt CAMMSEqualizerControlGroup::Treble()
       
   193 {
       
   194     return iTreble;
       
   195 }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CAMMSEqualizerControlGroup::SetBandLevelL
       
   199 // Sets the given equalizer band to the given gain value.
       
   200 // (other items were commented in a header).
       
   201 // -----------------------------------------------------------------------------
       
   202 void CAMMSEqualizerControlGroup::SetBandLevelL(TInt aLevel, TInt aBand)
       
   203 {
       
   204     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::SetBandLevelL +");
       
   205 
       
   206     // check given parameters
       
   207     CheckBandIndexL(aBand);
       
   208 
       
   209     if (aLevel < iMinBandLevel || aLevel > iMaxBandLevel)
       
   210     {
       
   211         User::Leave(KErrArgument);
       
   212     }
       
   213 
       
   214     // Set new level to controls.
       
   215     TInt count = ControlCount();
       
   216     for (TInt i = 0; i < count; i++)
       
   217     {
       
   218         TypeSafeControl(i)->SetBandLevelL(aLevel, aBand);
       
   219     }
       
   220 
       
   221     iBands[ aBand ].iBandLevel = aLevel;  // CSI: 2 Index checked above #
       
   222 
       
   223     // remove current preset since it is not valid any more
       
   224     iPresetIndex = -1;
       
   225 
       
   226     iTreble = KAMMSUndefinedTrebleOrBass;
       
   227     iBass = KAMMSUndefinedTrebleOrBass;
       
   228 
       
   229     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::SetBandLevelL -");
       
   230 }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CAMMSEqualizerControlGroup::SetBassL
       
   234 // Sets the bass level
       
   235 // (other items were commented in a header).
       
   236 // -----------------------------------------------------------------------------
       
   237 void CAMMSEqualizerControlGroup::SetBassL(TInt aLevel, TInt& aSetLevel)
       
   238 {
       
   239     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::SetBassL +");
       
   240 
       
   241     __ASSERT_DEBUG((aLevel >= iMinBandLevel) &&
       
   242                    (aLevel <= iMaxBandLevel), User::Invariant());
       
   243 
       
   244     // Set the bass band (first band) to the given percentage of the valid range
       
   245     // between MinBandLevel and MaxBandLevel.
       
   246     TInt newBandLevel = iMinBandLevel + aLevel *
       
   247                         (iMaxBandLevel - iMinBandLevel) / 100;   // CSI: 47 Value 100 means 100% here #
       
   248 
       
   249     // Set new value to bass band (band 0) if band count > 0
       
   250     if (iBands.Count() > 0)
       
   251     {
       
   252         // Set new bass (band 0) to controls.
       
   253         TInt count = ControlCount();
       
   254         for (TInt i = 0; i < count; i++)
       
   255         {
       
   256             TypeSafeControl(i)->SetBandLevelL(newBandLevel, 0);
       
   257         }
       
   258 
       
   259         iBands[ 0 ].iBandLevel = newBandLevel;
       
   260     }
       
   261 
       
   262     // remove the current preset since it is not valid any more
       
   263     iPresetIndex = -1;
       
   264 
       
   265     iBass = aLevel;
       
   266 
       
   267     aSetLevel = iBass;
       
   268 
       
   269     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::SetBassL -");
       
   270 }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CAMMSEqualizerControlGroup::SetTrebleL
       
   274 // Sets the treble level
       
   275 // (other items were commented in a header).
       
   276 // -----------------------------------------------------------------------------
       
   277 void CAMMSEqualizerControlGroup::SetTrebleL(TInt aLevel, TInt& aSetLevel)
       
   278 {
       
   279     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::SetTrebleL +");
       
   280 
       
   281     __ASSERT_DEBUG((aLevel >= iMinBandLevel) &&
       
   282                    (aLevel <= iMaxBandLevel), User::Invariant());
       
   283 
       
   284     TInt bands = iBands.Count();
       
   285     // Set new values to treble bands if there is at least two bands.
       
   286     if (bands > 1)
       
   287     {
       
   288         // Treble affects to two bands.
       
   289         TInt trebleIndex1 = bands - 1;  // CSI: 47 Last band #
       
   290         TInt trebleIndex2 = bands - 2;  // CSI: 47 Second last band #
       
   291 
       
   292         // Set the highest band with 100% weight of the given percentage
       
   293         // of the valid range between MinBandLevel and MaxBandLevel.
       
   294         TInt newBandLevel1 = iMinBandLevel +
       
   295                              aLevel * (iMaxBandLevel - iMinBandLevel) / 100;   // CSI: 47 Value 100 means 100% #
       
   296 
       
   297         // The treble affects 50% to the next highest band.
       
   298         TInt newBandLevel2 = KAMMSDefaultEqualizerLevel +
       
   299                              (newBandLevel1 - KAMMSDefaultEqualizerLevel) / 2;   // CSI: 47 Divided by 2 is the same as 50% #
       
   300 
       
   301         // Set new treble level to controls.
       
   302         TInt count = ControlCount();
       
   303         for (TInt i = 0; i < count; i++)
       
   304         {
       
   305             TypeSafeControl(i)->SetBandLevelL(newBandLevel1, trebleIndex1);
       
   306             TypeSafeControl(i)->SetBandLevelL(newBandLevel2, trebleIndex2);
       
   307         }
       
   308 
       
   309         iBands[ trebleIndex1 ].iBandLevel = newBandLevel1;
       
   310         iBands[ trebleIndex2 ].iBandLevel = newBandLevel2;
       
   311     }
       
   312 
       
   313     // remove the current preset since it is not valid any more
       
   314     iPresetIndex = -1;
       
   315 
       
   316     iTreble = aLevel;
       
   317 
       
   318     aSetLevel = iTreble;
       
   319 
       
   320     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::SetTrebleL -");
       
   321 }
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CAMMSEqualizerControlGroup::TypeSafeControl
       
   325 // Gets control. Ownership is not tranferred.
       
   326 // (other items were commented in a header).
       
   327 // -----------------------------------------------------------------------------
       
   328 CAMMSBaseEqualizerControl*
       
   329 CAMMSEqualizerControlGroup::TypeSafeControl(TInt aIndex) const
       
   330 {
       
   331     return static_cast<CAMMSBaseEqualizerControl*>(Control(aIndex));
       
   332 }
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // CAMMSEqualizerControlGroup::CheckBandIndexL
       
   336 // Checks whether the band index is between 0 and number of bands -1.
       
   337 // (other items were commented in a header).
       
   338 // -----------------------------------------------------------------------------
       
   339 void CAMMSEqualizerControlGroup::CheckBandIndexL(TInt aBand) const
       
   340 {
       
   341     if (aBand < 0 || aBand >= iBands.Count())
       
   342     {
       
   343         User::Leave(KErrArgument);
       
   344     }
       
   345 }
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // CAMMSEqualizerControlGroup::GetPresetBandsL
       
   349 // Gets bands corresponding to the given preset index.
       
   350 // (other items were commented in a header).
       
   351 // -----------------------------------------------------------------------------
       
   352 void CAMMSEqualizerControlGroup::GetPresetBandsL(TUint /*aPresetIndex*/,
       
   353         RArray< TEfAudioEqualizerBand >& aBands)
       
   354 {
       
   355     aBands.Reset();
       
   356 
       
   357     TInt count = ControlCount();
       
   358 
       
   359     LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::GetPresetBandsL, controls=%d",
       
   360               count);
       
   361 
       
   362     // Get data of each band from a control. If there is no controls in the
       
   363     // group, get the data from the empty group utility.
       
   364     if (count > 0)
       
   365     {
       
   366         CAMMSBaseEqualizerControl* control =
       
   367             CAMMSEqualizerControlGroup::TypeSafeControl(0);
       
   368 
       
   369         TInt bands = control->NumberOfBands();
       
   370 
       
   371         for (TInt i = 0; i < bands; i++)
       
   372         {
       
   373             TEfAudioEqualizerBand band;
       
   374 
       
   375             band.iBandLevel = control->BandLevelL(i);
       
   376             band.iBandWidth = control->BandWidth(i);
       
   377             band.iCenterFrequency = control->CenterFrequency(i);
       
   378             band.iCrossoverFrequency = control->CrossoverFrequency(i);
       
   379 
       
   380             aBands.AppendL(band);
       
   381         }
       
   382     }
       
   383     else
       
   384     {
       
   385         // Create empty group utilities for getting preset data.
       
   386         PrepareEmptyGroupUtilitiesL();
       
   387 
       
   388         CAudioEqualizer& audioEffect = iEmptyAudioEqualizerUtility->Equalizer();
       
   389         TInt bands = audioEffect.NumberOfBands();
       
   390 
       
   391         for (TInt i = 0; i < bands; i++)
       
   392         {
       
   393             TEfAudioEqualizerBand band;
       
   394 
       
   395             // Band 0 in JSR-234 equals Band 1 in Effect API
       
   396             TUint8 bandId = (TUint8)(i + KAMMSBandOffset);
       
   397 
       
   398             band.iBandLevel = audioEffect.BandLevel(bandId);
       
   399             band.iBandWidth = audioEffect.BandWidth(bandId);
       
   400             band.iCenterFrequency = audioEffect.CenterFrequency(bandId);
       
   401             band.iCrossoverFrequency = audioEffect.CrossoverFrequency(bandId);
       
   402 
       
   403             aBands.AppendL(band);
       
   404         }
       
   405 
       
   406         // Delete empty group utilities in order to save memory.
       
   407         DeleteEmptyGroupUtilities();
       
   408     }
       
   409 
       
   410     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::GetPresetBandsL -");
       
   411 }
       
   412 
       
   413 // -----------------------------------------------------------------------------
       
   414 // CAMMSEqualizerControlGroup::ClassName
       
   415 // Returns class name that identifies this control group.
       
   416 // (other items were commented in a header).
       
   417 // -----------------------------------------------------------------------------
       
   418 const TDesC16& CAMMSEqualizerControlGroup::ClassName()
       
   419 {
       
   420     return KAMMSEqualizerControlClassName;
       
   421 }
       
   422 
       
   423 // -----------------------------------------------------------------------------
       
   424 // CAMMSEqualizerControlGroup::NotifyPlayerAddedL
       
   425 // Called by when a new player is added
       
   426 // (other items were commented in a header).
       
   427 // -----------------------------------------------------------------------------
       
   428 void CAMMSEqualizerControlGroup::NotifyPlayerAddedL(
       
   429     CMMAPlayer *aPlayer,
       
   430     CMMAControl* aControl)
       
   431 {
       
   432     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::NotifyPlayerAddedL +");
       
   433 
       
   434     CAMMSEffectControlGroup::NotifyPlayerAddedL(aPlayer, aControl);
       
   435 
       
   436     CAMMSBaseEqualizerControl* control =
       
   437         static_cast<CAMMSBaseEqualizerControl*>(aControl);
       
   438 
       
   439     // if preset was not set into the new control by the main class,
       
   440     // set bands, treble, and bass manually
       
   441     if (iPresetIndex < 0)
       
   442     {
       
   443         TInt bands = iBands.Count();
       
   444 
       
   445         // set current band levels
       
   446         for (TInt i = 0; i < bands; i++)
       
   447         {
       
   448             control->SetBandLevelL(iBands[ i ].iBandLevel, i);
       
   449         }
       
   450     }
       
   451 
       
   452     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::NotifyPlayerAddedL -");
       
   453 }
       
   454 
       
   455 // -----------------------------------------------------------------------------
       
   456 // CAMMSEqualizerControlGroup::PresetChangedL
       
   457 // Called when the current preset changes
       
   458 // (other items were commented in a header).
       
   459 // -----------------------------------------------------------------------------
       
   460 void CAMMSEqualizerControlGroup::PresetChangedL()
       
   461 {
       
   462     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::PresetChangedL +");
       
   463 
       
   464     // Invalidate bass and treble levels
       
   465     iBass = KAMMSUndefinedTrebleOrBass;
       
   466     iTreble = KAMMSUndefinedTrebleOrBass;
       
   467 
       
   468     // Get band data from controls (or from empty group utility, if the
       
   469     // group has no controls).
       
   470     GetPresetBandsL(iPresetIndex, iBands);   // index limits already checked
       
   471 
       
   472     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::PresetChangedL -");
       
   473 }
       
   474 
       
   475 // -----------------------------------------------------------------------------
       
   476 // CAMMSEqualizerControlGroup::InitializeL
       
   477 // Finish initialization (after the 1st player is added)
       
   478 // (other items were commented in a header).
       
   479 // -----------------------------------------------------------------------------
       
   480 void CAMMSEqualizerControlGroup::InitializeL()
       
   481 {
       
   482     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::InitializeL +");
       
   483 
       
   484     CAMMSBaseEqualizerControl* control = TypeSafeControl(0);
       
   485 
       
   486     iMaxBandLevel = control->MaxBandLevel();
       
   487     iMinBandLevel = control->MinBandLevel();
       
   488 
       
   489     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::InitializeL -");
       
   490 }
       
   491 
       
   492 // -----------------------------------------------------------------------------
       
   493 // CAMMSEqualizerControlGroup::PrepareEmptyGroupUtilitiesL
       
   494 // Creates utilities that can be used to obtain preset names and preset data.
       
   495 // (other items were commented in a header).
       
   496 // -----------------------------------------------------------------------------
       
   497 void CAMMSEqualizerControlGroup::PrepareEmptyGroupUtilitiesL()
       
   498 {
       
   499     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::PrepareEmptyGroupUtilitiesL +");
       
   500 
       
   501     if (!iEmptyAudioEqualizerUtility)
       
   502     {
       
   503         CAMMSEffectControlGroup::PrepareEmptyGroupUtilitiesL();
       
   504 
       
   505         iEmptyAudioEqualizerUtility =
       
   506             CAudioEqualizerUtility::NewL(*iEmptyPlayerUtility);
       
   507     }
       
   508 
       
   509     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::PrepareEmptyGroupUtilitiesL -");
       
   510 }
       
   511 
       
   512 // -----------------------------------------------------------------------------
       
   513 // CAMMSEqualizerControlGroup::DeleteEmptyGroupUtilities
       
   514 // Deletes utilities that are used to obtain preset names and preset data.
       
   515 // (other items were commented in a header).
       
   516 // -----------------------------------------------------------------------------
       
   517 void CAMMSEqualizerControlGroup::DeleteEmptyGroupUtilities()
       
   518 {
       
   519     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::DeleteEmptyGroupUtilities +");
       
   520 
       
   521     if (iEmptyPlayerUtility)
       
   522     {
       
   523         delete iEmptyAudioEqualizerUtility;
       
   524         iEmptyAudioEqualizerUtility = NULL;
       
   525 
       
   526         CAMMSEffectControlGroup::DeleteEmptyGroupUtilities();
       
   527     }
       
   528 
       
   529     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::DeleteEmptyGroupUtilities -");
       
   530 }
       
   531 
       
   532 // -----------------------------------------------------------------------------
       
   533 // CAMMSEqualizerControlGroup::GetPresetNamesL
       
   534 // Gets list of preset names available.
       
   535 // (other items were commented in a header).
       
   536 // -----------------------------------------------------------------------------
       
   537 void CAMMSEqualizerControlGroup::GetPresetNamesL(
       
   538     CDesCArray& aPresetNames)
       
   539 {
       
   540     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::GetPresetNamesL +");
       
   541 
       
   542     // Create empty group utilities for getting preset names.
       
   543     PrepareEmptyGroupUtilitiesL();
       
   544 
       
   545     TArray< TEfAudioEqualizerUtilityPreset > presetNames =
       
   546         iEmptyAudioEqualizerUtility->Presets();
       
   547 
       
   548 
       
   549     TInt presetCount = presetNames.Count();
       
   550 
       
   551     for (TInt i = 0; i < presetCount; i++)
       
   552     {
       
   553         aPresetNames.AppendL(presetNames[ i ].iPresetName);
       
   554     }
       
   555 
       
   556     // Delete empty group utilities in order to save memory.
       
   557     DeleteEmptyGroupUtilities();
       
   558 
       
   559     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::GetPresetNamesL -");
       
   560 }
       
   561 
       
   562 // -----------------------------------------------------------------------------
       
   563 // CAMMSEqualizerControlGroup::CAMMSEqualizerControlGroup
       
   564 // C++ default constructor can NOT contain any code, that might leave.
       
   565 // -----------------------------------------------------------------------------
       
   566 CAMMSEqualizerControlGroup::CAMMSEqualizerControlGroup()
       
   567         : CAMMSEffectControlGroup(KAMMSBaseEqualizerControl)
       
   568 {
       
   569     iMaxBandLevel = KAMMSDefaultEqualizerMaxLevel;
       
   570     iMinBandLevel = KAMMSDefaultEqualizerMinLevel;
       
   571 }
       
   572 
       
   573 // -----------------------------------------------------------------------------
       
   574 // CAMMSEqualizerControlGroup::ConstructL
       
   575 // Symbian 2nd phase constructor can leave.
       
   576 // -----------------------------------------------------------------------------
       
   577 void CAMMSEqualizerControlGroup::ConstructL()
       
   578 {
       
   579     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::ConstructL +");
       
   580 
       
   581     CAMMSEffectControlGroup::BaseConstructL();
       
   582 
       
   583     // Get band data from empty group utility.
       
   584     // If the Effect API implementation does not support the effect,
       
   585     // the function leaves with KErrNotSupported. The leaving can be ignored
       
   586     // in this case, the result is that the list of supported presets
       
   587     // remain empty.
       
   588     TRAPD(err, GetPresetBandsL(0, iBands));
       
   589 
       
   590     ELOG1( EJavaAMMS, "AMMS::CAMMSEqualizerControlGroup::ConstructL, err %d", err);
       
   591 
       
   592     // In case of an error, delete possible utilities to save memory.
       
   593     if (err != KErrNone)
       
   594     {
       
   595         DeleteEmptyGroupUtilities();
       
   596     }
       
   597 
       
   598     // Ignore the error so that using MMA and AMMS is possible.
       
   599     // Only successfully read bands are visible for the user.
       
   600 
       
   601 
       
   602     TInt bands = iBands.Count();
       
   603 
       
   604     // Set default band levels.
       
   605     for (TInt i = 0; i < bands; i++)
       
   606     {
       
   607         iBands[ i ].iBandLevel = KAMMSDefaultEqualizerLevel;
       
   608     }
       
   609 
       
   610     // Set default values for Bass and Treble. Value 50 means flat equalization.
       
   611     iBass = KAMMSDefaultEqualizerTrebleAndBassLevel;
       
   612     iTreble = KAMMSDefaultEqualizerTrebleAndBassLevel;
       
   613 
       
   614     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControlGroup::ConstructL -");
       
   615 }
       
   616 
       
   617 //  End of File