javauis/amms_qt/mmacontrol/src.emc/cammsemcspectatordopplercontrol.cpp
branchRCL_3
changeset 24 0fd27995241b
equal deleted inserted replaced
20:f9bb0fca356a 24:0fd27995241b
       
     1 /*
       
     2 * Copyright (c) 2005 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 doppler effect of the spectator.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <logger.h>
       
    22 #include <e32math.h>
       
    23 #include "cammsemcspectatordopplercontrol.h"
       
    24 
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ===============================
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CAMMSEMCSpectatorDopplerControl::NewLC
       
    30 // Two-phased constructor.
       
    31 // -----------------------------------------------------------------------------
       
    32 CAMMSEMCSpectatorDopplerControl* CAMMSEMCSpectatorDopplerControl::NewLC(
       
    33     CMMAPlayer* aPlayer)
       
    34 {
       
    35     CAMMSEMCSpectatorDopplerControl* self =
       
    36         new(ELeave)CAMMSEMCSpectatorDopplerControl(aPlayer);
       
    37 
       
    38     CleanupStack::PushL(self);
       
    39 
       
    40     return self;
       
    41 }
       
    42 
       
    43 // Destructor
       
    44 CAMMSEMCSpectatorDopplerControl::~CAMMSEMCSpectatorDopplerControl()
       
    45 {
       
    46     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCSpectatorDopplerControl::~CAMMSEMCSpectatorDopplerControl");
       
    47 
       
    48     // Perform DeallocateControl, if the state change has not yet performed it.
       
    49     DeallocateControl();
       
    50 }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CAMMSEMCSpectatorDopplerControl::PrepareControlL
       
    54 // Function which is called after the correct state is set in Player.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void CAMMSEMCSpectatorDopplerControl::PrepareControlL()
       
    58 {
       
    59     // Perform the action only for the first time, skip if called afterwards
       
    60     if (!iMListenerDopplerControl)
       
    61     {
       
    62         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCSpectatorDopplerControl::PrepareControlL");
       
    63         iStreamControl = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->StreamControl();
       
    64         iFactory = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->MMFactory();
       
    65         MEffectControl* temp(NULL);
       
    66         User::LeaveIfError(iFactory->CreateEffectControl(KListenerDopplerEffectControl, temp));
       
    67         iMListenerDopplerControl  = static_cast<MListenerDopplerControl*>(temp);
       
    68         User::LeaveIfError(iStreamControl->AddEffect(*iMListenerDopplerControl));
       
    69         TInt err = iMListenerDopplerControl->Enable();
       
    70         ELOG1( EJavaAMMS, "AMMS::CAMMSEMCSpectatorDopplerControl::PrepareControlL: EnableErr = %d", err);
       
    71     }
       
    72 }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CAMMSEMCSpectatorDopplerControl::DeallocateControl
       
    76 // Function which is called after the correct state is set in Player.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CAMMSEMCSpectatorDopplerControl::DeallocateControl()
       
    80 {
       
    81     if (iMListenerDopplerControl)
       
    82     {
       
    83         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCSpectatorDopplerControl::DeallocateControl");
       
    84 
       
    85         // Doppler for Spectator is always enabled (JSR-234 mandates it)
       
    86         // so the disabling is needed here
       
    87         iMListenerDopplerControl->Disable();
       
    88         //return the control to factory
       
    89         MEffectControl* temp = iMListenerDopplerControl;
       
    90         iStreamControl->RemoveEffect(*temp);
       
    91         // Delete the Effect
       
    92         MEffectControl* tempCtrl = iMListenerDopplerControl;
       
    93         iFactory->DeleteEffectControl(tempCtrl);
       
    94         iMListenerDopplerControl = NULL;
       
    95     }
       
    96 }
       
    97 
       
    98 const TDesC& CAMMSEMCSpectatorDopplerControl::ClassName() const
       
    99 {
       
   100     return KAMMSEMCListenerDopplerControl;
       
   101 }
       
   102 
       
   103 
       
   104 void CAMMSEMCSpectatorDopplerControl::SetEnabledL(TBool aDopplerEnabled)
       
   105 {
       
   106     if (aDopplerEnabled)
       
   107     {
       
   108         TInt err = iMListenerDopplerControl->Enable();
       
   109         ELOG1( EJavaAMMS, "AMMS::CAMMSEMCSpectatorDopplerControl::SetEnabledL: Enable err = %d", err);
       
   110     }
       
   111     else
       
   112     {
       
   113         TInt err = iMListenerDopplerControl->Disable();
       
   114         ELOG1( EJavaAMMS, "AMMS::CAMMSEMCSpectatorDopplerControl::SetEnabledL: Disable err = %d", err);
       
   115     }
       
   116 }
       
   117 
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CAMMSEMCSpectatorDopplerControl::Enabled
       
   121 // Returns whether this Doppler effect is currently active.
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 TBool CAMMSEMCSpectatorDopplerControl::Enabled()
       
   125 {
       
   126     TBool temp;
       
   127     TInt err = iMListenerDopplerControl->IsEnabled(temp);
       
   128     LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSEMCSpectatorDopplerControl::Enabled: err = %d", err);
       
   129     return temp;
       
   130 }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CAMMSEMCSpectatorDopplerControl::SetVelocityCartesianL
       
   134 // Sets the velocity, used in calculations for the Doppler effect.
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CAMMSEMCSpectatorDopplerControl::SetVelocityCartesianL(
       
   138     TInt aX,
       
   139     TInt aY,
       
   140     TInt aZ)
       
   141 {
       
   142     LOG3( EJavaAMMS, EInfo, "AMMS::CAMMSEMCSpectatorDopplerControl::SetVelocityCartesianL: X=%d, Y=%d, Z=%d",
       
   143                aX, aY, aZ);
       
   144     TInt err = iMListenerDopplerControl->SetCartesianVelocity(aX, aY, aZ);
       
   145 
       
   146     ELOG1( EJavaAMMS, "AMMS::CAMMSEMCSpectatorDopplerControl::SetVelocityCartesianL: err = %d", err);
       
   147     // Apply updated settings
       
   148     iMListenerDopplerControl->Apply();
       
   149 
       
   150 }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CAMMSEMCSpectatorDopplerControl::VelocityCartesian
       
   154 // Returns the current velocity, used in calculations for the Doppler effect.
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 void CAMMSEMCSpectatorDopplerControl::VelocityCartesian(
       
   158     TInt& aX, TInt& aY, TInt& aZ)
       
   159 {
       
   160     // Get the velocity's cartesian settings
       
   161     // aX, aY and aZ are velocities in format mm/s
       
   162 
       
   163     TInt err = iMListenerDopplerControl->CartesianVelocity(aX,aY,aZ);
       
   164     ELOG1( EJavaAMMS, "AMMS::CAMMSEMCSpectatorDopplerControl::VelocityCartesian: err = %d", err);
       
   165 }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CAMMSEMCSpectatorDopplerControl::SetVelocitySphericalL
       
   169 // Sets the velocity, used in calculations for the Doppler effect.
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CAMMSEMCSpectatorDopplerControl::SetVelocitySphericalL(
       
   173     TInt aAzimuth,
       
   174     TInt aElevation,
       
   175     TInt aRadius)
       
   176 {
       
   177     // Parameters are thousandths of radians
       
   178 
       
   179     LOG3( EJavaAMMS, EInfo, "AMMS::CAMMSEMCSpectatorDopplerControl::SetVelocitySphericalL %d, %d, %d",
       
   180                aAzimuth, aElevation, aRadius);
       
   181 
       
   182     TInt32 convertedAzimuth = (TInt32)(aAzimuth * KDegToRad *
       
   183                                        1000);   // CSI: 47 Effect API uses thousands of radians #
       
   184 
       
   185     TInt32 convertedElevation = (TInt32)(aElevation * KDegToRad *
       
   186                                          1000);   // CSI: 47 Effect API uses thousands of radians #
       
   187 
       
   188     LOG2( EJavaAMMS, EInfo, "AMMS::CAMMSEMCSpectatorDopplerControl::SetVelocitySphericalL %d, %d",
       
   189                convertedAzimuth, convertedElevation);
       
   190 
       
   191     TInt err = iMListenerDopplerControl->SetSphericalVelocity(
       
   192                    convertedAzimuth, convertedElevation, aRadius);
       
   193     ELOG1( EJavaAMMS, "AMMS::CAMMSEMCSpectatorDopplerControl::SetVelocitySphericalL: err = %d", err);
       
   194     // Apply updated settings to EMC API.
       
   195     iMListenerDopplerControl->Apply();
       
   196 }
       
   197 
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CAMMSEMCSpectatorDopplerControl::CAMMSEMCSpectatorDopplerControl
       
   201 // C++ default constructor can NOT contain any code, that
       
   202 // might leave.
       
   203 // -----------------------------------------------------------------------------
       
   204 CAMMSEMCSpectatorDopplerControl::CAMMSEMCSpectatorDopplerControl(
       
   205     CMMAPlayer* aPlayer)
       
   206         : CAMMSDopplerControl(aPlayer)
       
   207 {
       
   208     iMMAPlayer = aPlayer;
       
   209 }
       
   210 
       
   211 
       
   212 //  End of File