javauis/amms_qt/mmacontrol/src/cammsreverbsourcecontrol.cpp
branchRCL_3
changeset 25 ae942d28ec0e
parent 17 0fd27995241b
equal deleted inserted replaced
24:6c158198356e 25:ae942d28ec0e
       
     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 settings of an audio effect reverb source.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <logger.h>
       
    21 #include "cammsreverbsourcecontrol.h"
       
    22 #include "cammsbasereverbcontrol.h"
       
    23 
       
    24 // CONSTANTS
       
    25 const TInt KAMMSDisconnectReverbSource = 2147483647; // From JSR-234
       
    26 
       
    27 
       
    28 #ifdef _DEBUG
       
    29 const TInt KAMMSMaxRoomLevel = 0;
       
    30 #endif // _DEBUG
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CAMMSReverbSourceControl::NewLC
       
    36 // Two-phased constructor.
       
    37 // -----------------------------------------------------------------------------
       
    38 CAMMSReverbSourceControl* CAMMSReverbSourceControl::NewLC(
       
    39     CMMAPlayer* aPlayer,
       
    40     CAMMSBaseReverbControl* aReverbControl)
       
    41 {
       
    42     CAMMSReverbSourceControl* self =
       
    43         new(ELeave)CAMMSReverbSourceControl(aPlayer, aReverbControl);
       
    44 
       
    45     CleanupStack::PushL(self);
       
    46 
       
    47     return self;
       
    48 }
       
    49 
       
    50 // Destructor
       
    51 CAMMSReverbSourceControl::~CAMMSReverbSourceControl()
       
    52 {
       
    53     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbSourceControl::~CAMMSReverbSourceControl");
       
    54 
       
    55     // Perform DeallocateControl, if the state change has not yet performed it.
       
    56     DeallocateControl();
       
    57     delete iReverbSource;
       
    58 }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CAMMSReverbSourceControl::SetRoomLevelL
       
    62 // Sets the object specific level for the reverberant sound.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 void CAMMSReverbSourceControl::SetRoomLevelL(TInt aLevel)
       
    66 {
       
    67     LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSReverbSourceControl::SetRoomLevelL +: %d", aLevel);
       
    68 
       
    69     // Check in debug build that aLevel is within valid range.
       
    70     __ASSERT_DEBUG(
       
    71         (aLevel <= KAMMSMaxRoomLevel) ||
       
    72         (aLevel == KAMMSDisconnectReverbSource),
       
    73         User::Invariant());
       
    74 
       
    75     // With the JSR-234 value Integer.MIN_VALUE, the reflected sound for the
       
    76     // given object can be disabled.
       
    77     if (aLevel == KMinTInt)
       
    78     {
       
    79         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbSourceControl::SetRoomLevelL(Integer.MIN_VALUE)");
       
    80         aLevel = 0;
       
    81     }
       
    82 
       
    83     // Check the allowed boundaries for room level.
       
    84     TInt32 minLevel = 0;
       
    85     TInt32 maxLevel = 0;
       
    86     iReverbSource->LevelRange(minLevel, maxLevel);
       
    87     LOG2( EJavaAMMS, EInfo, "AMMS::CAMMSReverbSourceControl::SetRoomLevelL boundaries %d, %d",
       
    88                minLevel, maxLevel);
       
    89 
       
    90     // Check the state of the effect. If it is in disabled state, enable it.
       
    91     if (!iReverbSource->IsEnabled())
       
    92     {
       
    93         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbSourceControl::SetRoomLevelL calling EnableL");
       
    94         iReverbSource->EnableL();
       
    95     }
       
    96 
       
    97     // With the JSR-234 value DISCONNECT, the object can be disconnected
       
    98     // from the reverb.
       
    99     if (aLevel == KAMMSDisconnectReverbSource)
       
   100     {
       
   101         // Do not call iReverbSource->DisableL(), instead set the room level to
       
   102         // _minimum_ value (= smallest negative gain -> maximum attenuation).
       
   103         // The CRoomLevel must also be kept enabled.
       
   104         aLevel = minLevel;
       
   105 
       
   106         LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSReverbSourceControl::SetRoomLevelL(DISCONNECT) %d",
       
   107                   minLevel);
       
   108     }
       
   109     else
       
   110     {
       
   111         // Set the room level within allowed boundaries from Effect API
       
   112         aLevel = Min(aLevel, maxLevel);
       
   113         aLevel = Max(aLevel, minLevel);
       
   114         LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSReverbSourceControl::SetRoomLevelL setting value: %d", aLevel);
       
   115     }
       
   116 
       
   117     // Sets the RoomLevel level, it will leave if aRoomLevel is not within range
       
   118     // of Min and Max
       
   119     iReverbSource->SetRoomLevelL((TInt32)aLevel);
       
   120 
       
   121     // Apply updated settings to Effect API.
       
   122     iReverbSource->ApplyL();
       
   123 
       
   124     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbSourceControl::SetRoomLevelL -");
       
   125 }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CAMMSReverbSourceControl::PrepareControlL
       
   129 // Function which is called after the correct state is set in Player.
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CAMMSReverbSourceControl::PrepareControlL()
       
   133 {
       
   134     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbSourceControl::PrepareControlL");
       
   135 
       
   136     // Perform the action only for the first time, skip if called afterwards
       
   137     if (!iReverbSource)
       
   138     {
       
   139         CEnvironmentalReverbUtility* reverbUtility = NULL;
       
   140         iReverbControl->GetEnvironmentalReverbUtilityL(&reverbUtility);
       
   141         // Reverb utility must exist, otherwise room level creation will fail.
       
   142         __ASSERT_DEBUG(reverbUtility, User::Invariant());
       
   143 
       
   144         CEnvironmentalReverb* reverb =
       
   145             &(reverbUtility->EnvironmentalReverb());
       
   146 
       
   147         CCustomCommandUtility* customCommandUtility =
       
   148             CreateCustomCommandUtilityL();
       
   149 
       
   150         // Effect API takes the ownership of customCommandUtility.
       
   151         iReverbSource = CRoomLevel::NewL(customCommandUtility, *reverb);
       
   152     }
       
   153 }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CAMMSReverbSourceControl::DeallocateControl
       
   157 // Function which is called after the correct state is set in Player.
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void CAMMSReverbSourceControl::DeallocateControl()
       
   161 {
       
   162     if (iReverbSource)
       
   163     {
       
   164         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbSourceControl::DeallocateControl");
       
   165 
       
   166         // Disable the Effect API Control
       
   167         TRAPD(err, iReverbSource->DisableL());
       
   168         if (err != KErrNone)
       
   169         {
       
   170             // The only even theoritically possible error code here would be
       
   171             // KErrAccessDenied which is a result from Effect API calling ApplyL
       
   172             // method without having update rights, but since the Effect
       
   173             // is already created, that situation can be discarded here.
       
   174         }
       
   175 
       
   176         // Delete the Effect API class (it deletes CustomCommandUtility)
       
   177         delete iReverbSource;
       
   178         iReverbSource = NULL;
       
   179     }
       
   180 }
       
   181 
       
   182 const TDesC& CAMMSReverbSourceControl::ClassName() const
       
   183 {
       
   184     return KAMMSReverbSourceControl;
       
   185 }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CAMMSReverbSourceControl::CAMMSReverbSourceControl
       
   189 // C++ default constructor can NOT contain any code, that
       
   190 // might leave.
       
   191 // -----------------------------------------------------------------------------
       
   192 CAMMSReverbSourceControl::CAMMSReverbSourceControl(
       
   193     CMMAPlayer* aPlayer,
       
   194     CAMMSBaseReverbControl* aReverbControl)
       
   195         : CAMMSBaseReverbSourceControl(aPlayer), iReverbControl(aReverbControl)
       
   196 {
       
   197 }
       
   198 
       
   199 //  End of File