javauis/amms_qt/mmacontrol/src.emc/cammsemcreverbsourcecontrol.cpp
changeset 23 98ccebc37403
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
       
     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 "cammsemcreverbsourcecontrol.h"
       
    22 #include "cammsbasereverbcontrol.h"
       
    23 #include "cammsemcreverbcontrol.h"
       
    24 
       
    25 // CONSTANTS
       
    26 const TInt KAMMSDisconnectReverbSource = 2147483647; // From JSR-234
       
    27 
       
    28 #ifdef _DEBUG
       
    29 const TInt KAMMSMaxRoomLevel = 0;
       
    30 #endif // _DEBUG
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CAMMSEMCReverbSourceControl::NewLC
       
    36 // Two-phased constructor.
       
    37 // -----------------------------------------------------------------------------
       
    38 CAMMSEMCReverbSourceControl* CAMMSEMCReverbSourceControl::NewLC(
       
    39     CMMAPlayer* aPlayer,
       
    40     CAMMSBaseReverbControl* aBaseReverbControl)
       
    41 {
       
    42     CAMMSEMCReverbSourceControl* self =
       
    43         new(ELeave)CAMMSEMCReverbSourceControl(aPlayer, aBaseReverbControl);
       
    44 
       
    45     CleanupStack::PushL(self);
       
    46 
       
    47     return self;
       
    48 }
       
    49 
       
    50 // Destructor
       
    51 CAMMSEMCReverbSourceControl::~CAMMSEMCReverbSourceControl()
       
    52 {
       
    53     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbSourceControl::~CAMMSEMCReverbSourceControl");
       
    54 
       
    55     // Perform DeallocateControl, if the state change has not yet performed it.
       
    56     DeallocateControl();
       
    57 
       
    58 }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CAMMSEMCReverbSourceControl::SetRoomLevelL
       
    62 // Sets the object specific level for the reverberant sound.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 void CAMMSEMCReverbSourceControl::SetRoomLevelL(TInt aLevel)
       
    66 {
       
    67     LOG1( EJavaAMMS, EInfo, "AMMS:: CAMMSEMCReverbSourceControl::SetRoomLevelL +: %d", aLevel);
       
    68 // Check in debug build that aLevel is within valid range.
       
    69     __ASSERT_DEBUG(
       
    70         (aLevel <= KAMMSMaxRoomLevel) ||
       
    71         (aLevel == KAMMSDisconnectReverbSource),
       
    72         User::Invariant());
       
    73 
       
    74     // With the JSR-234 value Integer.MIN_VALUE, the reflected sound for the
       
    75     // given object can be disabled.
       
    76     if (aLevel == KMinTInt)
       
    77     {
       
    78         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbSourceControl::SetRoomLevelL(Integer.MIN_VALUE)");
       
    79         aLevel = 0;
       
    80     }
       
    81 
       
    82     // Check the allowed boundaries for room level.
       
    83     TInt minLevel = 0;
       
    84     TInt maxLevel = 0;
       
    85     iRoomLevelControl->LevelRange(minLevel, maxLevel);
       
    86     LOG2( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbSourceControl::SetRoomLevelL boundaries %d, %d",
       
    87                minLevel, maxLevel);
       
    88 
       
    89     // Check the state of the effect. If it is in disabled state, enable it.
       
    90     TBool enabled;
       
    91     iRoomLevelControl->IsEnabled(enabled);
       
    92     if (!enabled)
       
    93     {
       
    94         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbSourceControl::SetRoomLevelL calling EnableL");
       
    95         iRoomLevelControl->Enable();
       
    96     }
       
    97 
       
    98     // With the JSR-234 value DISCONNECT, the object can be disconnected
       
    99     // from the reverb.
       
   100     if (aLevel == KAMMSDisconnectReverbSource)
       
   101     {
       
   102         // Do not call iReverbSource->DisableL(), instead set the room level to
       
   103         // _minimum_ value (= smallest negative gain -> maximum attenuation).
       
   104         // The CRoomLevel must also be kept enabled.
       
   105         aLevel = minLevel;
       
   106 
       
   107         LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbSourceControl::SetRoomLevelL(DISCONNECT) %d",
       
   108                   minLevel);
       
   109     }
       
   110     else
       
   111     {
       
   112         // Set the room level within allowed boundaries from EMC API
       
   113         aLevel = Min(aLevel, maxLevel);
       
   114         aLevel = Max(aLevel, minLevel);
       
   115         LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbSourceControl::SetRoomLevelL setting value: %d", aLevel);
       
   116     }
       
   117 
       
   118     // Sets the RoomLevel level, it will leave if aRoomLevel is not within range
       
   119     // of Min and Max
       
   120     iRoomLevelControl->SetRoomLevel(aLevel);
       
   121 
       
   122     // Apply updated settings to EMC API.
       
   123     iRoomLevelControl->Apply();
       
   124 
       
   125     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbSourceControl::SetRoomLevelL -");
       
   126 }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CAMMSEMCReverbSourceControl::PrepareControlL
       
   130 // Function which is called after the correct state is set in Player.
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CAMMSEMCReverbSourceControl::PrepareControlL()
       
   134 {
       
   135     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbSourceControl::PrepareControlL");
       
   136 
       
   137     if (!iRoomLevelControl)
       
   138     {
       
   139         //Create RoomLevel Effect Control
       
   140         iStreamControl = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->StreamControl();
       
   141         iFactory = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->MMFactory();
       
   142 
       
   143         MEffectControl* temp(NULL);
       
   144         User::LeaveIfError(iFactory->CreateEffectControl(KRoomLevelEffectControl, temp));
       
   145         iRoomLevelControl  = static_cast<MRoomLevelControl*>(temp);
       
   146 
       
   147 
       
   148         //Attach EMC Reverb Control to RoomLevelControl
       
   149         MReverbControl* reverbControl = iBaseReverbControl->GetReverbControlL();
       
   150         iRoomLevelControl->AttachReverb(*reverbControl);
       
   151 
       
   152         //Add Effect to Stream Control
       
   153         User::LeaveIfError(iStreamControl->AddEffect(*iRoomLevelControl));
       
   154     }
       
   155 
       
   156 
       
   157 }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CAMMSEMCReverbSourceControl::DeallocateControl
       
   161 // Function which is called after the correct state is set in Player.
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 void CAMMSEMCReverbSourceControl::DeallocateControl()
       
   165 {
       
   166     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbSourceControl::DeallocateControl");
       
   167     if (iRoomLevelControl)
       
   168     {
       
   169         /*
       
   170         //idealy reverbControl should be checked for its existance and if it is there ,should be detached from RoomLevelControl.
       
   171         //But in this case reverbControl is deleted till this position,so need not to do it.
       
   172         if(reverbControl)
       
   173             {
       
   174             iRoomLevelControl->DetachReverb(*reverbControl);
       
   175             }
       
   176         */
       
   177         iStreamControl->RemoveEffect(*iRoomLevelControl);
       
   178         MEffectControl* objPtr2 = iRoomLevelControl;
       
   179         iFactory->DeleteEffectControl(objPtr2);
       
   180         iRoomLevelControl = NULL;
       
   181     }
       
   182 
       
   183 
       
   184 
       
   185 
       
   186 }
       
   187 
       
   188 const TDesC& CAMMSEMCReverbSourceControl::ClassName() const
       
   189 {
       
   190     return KAMMSEMCReverbSourceControl;
       
   191 }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CAMMSEMCReverbSourceControl::CAMMSEMCReverbSourceControl
       
   195 // C++ default constructor can NOT contain any code, that
       
   196 // might leave.
       
   197 // -----------------------------------------------------------------------------
       
   198 CAMMSEMCReverbSourceControl::CAMMSEMCReverbSourceControl(
       
   199     CMMAPlayer* aPlayer,
       
   200     CAMMSBaseReverbControl* aBaseReverbControl)
       
   201         : CAMMSBaseReverbSourceControl(aPlayer), iBaseReverbControl(aBaseReverbControl)
       
   202 {
       
   203 
       
   204     iMMAPlayer = aPlayer;
       
   205 
       
   206 }
       
   207 
       
   208 //  End of File