javauis/amms_qt/ammscontrol/audio3D/src/cammsdopplercontrolgroup.cpp
branchRCL_3
changeset 24 0fd27995241b
equal deleted inserted replaced
20:f9bb0fca356a 24:0fd27995241b
       
     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:  Group for Doppler controls
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "cammsdopplercontrolgroup.h"
       
    22 #include "cammsdopplercontrol.h"
       
    23 #include "ammsutil.h"
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CAMMSDopplerControlGroup::NewLC
       
    29 // Two-phased constructor.
       
    30 // -----------------------------------------------------------------------------
       
    31 CAMMSDopplerControlGroup* CAMMSDopplerControlGroup::NewLC(
       
    32     TAMMSControlTypes aControlType)
       
    33 {
       
    34     CAMMSDopplerControlGroup* self = new(ELeave) CAMMSDopplerControlGroup(
       
    35         aControlType);
       
    36 
       
    37     CleanupStack::PushL(self);
       
    38     self->ConstructL();
       
    39 
       
    40     return self;
       
    41 }
       
    42 
       
    43 // Destructor
       
    44 CAMMSDopplerControlGroup::~CAMMSDopplerControlGroup()
       
    45 {
       
    46 }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CAMMSDopplerControlGroup::VelocityCartesianL
       
    50 // Returns the current velocity, used in calculations for the Doppler effect
       
    51 // (other items were commented in a header).
       
    52 // -----------------------------------------------------------------------------
       
    53 void CAMMSDopplerControlGroup::VelocityCartesianL(
       
    54     TInt aVelocity[ KAMMSVectorComponents ])
       
    55 {
       
    56     for (TInt i = 0; i < KAMMSVectorComponents; i++)
       
    57     {
       
    58         aVelocity[ i ] = iCommited.iVelocity[ i ];
       
    59     }
       
    60 }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CAMMSDopplerControlGroup::Enabled
       
    64 // Returns whether this Doppler effect is currently active.
       
    65 // (other items were commented in a header).
       
    66 // -----------------------------------------------------------------------------
       
    67 TBool CAMMSDopplerControlGroup::Enabled()
       
    68 {
       
    69     return iCommited.iEnabled;
       
    70 }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CAMMSDopplerControlGroup::SetEnabledL
       
    74 // Specifies if this Doppler effect is active or ignored.
       
    75 // (other items were commented in a header).
       
    76 // -----------------------------------------------------------------------------
       
    77 void CAMMSDopplerControlGroup::SetEnabledL(TBool aEnabled)
       
    78 {
       
    79     // If the DopplerControl was fetched from the Spectator,
       
    80     // this method has no effect. So only disable the value for SoundSource3D.
       
    81     if (aEnabled ||
       
    82             (!aEnabled && iControlType == EAMMSSoundSource3DControl))
       
    83     {
       
    84         iUncommited.iEnabled = aEnabled;
       
    85         UpdateL(EEnabled);
       
    86     }
       
    87 }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CAMMSDopplerControlGroup::SetVelocityCartesianL
       
    91 // Sets the velocity, used in calculations for the Doppler effect.
       
    92 // (other items were commented in a header).
       
    93 // -----------------------------------------------------------------------------
       
    94 void CAMMSDopplerControlGroup::SetVelocityCartesianL(
       
    95     TInt aX,
       
    96     TInt aY,
       
    97     TInt aZ)
       
    98 {
       
    99     iUncommited.iVelocity[ EComponentX ] = aX;
       
   100     iUncommited.iVelocity[ EComponentY ] = aY;
       
   101     iUncommited.iVelocity[ EComponentZ ] = aZ;
       
   102 
       
   103     UpdateL(EVelocity);
       
   104 }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CAMMSDopplerControlGroup::SetVelocitySphericalL
       
   108 // Sets the velocity, used in calculations for the Doppler effect.
       
   109 // (other items were commented in a header).
       
   110 // -----------------------------------------------------------------------------
       
   111 void CAMMSDopplerControlGroup::SetVelocitySphericalL(
       
   112     TInt aAzimuth,
       
   113     TInt aElevation,
       
   114     TInt aRadius)
       
   115 {
       
   116     TInt sphericalVector[] = { aAzimuth, aElevation, aRadius };
       
   117 
       
   118     // Convert to cartesian.
       
   119     AMMSUtil::FromSphericalToCartesianL(sphericalVector,
       
   120                                         iUncommited.iVelocity);
       
   121 
       
   122     UpdateL(EVelocity);
       
   123 }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CAMMSDopplerControlGroup::TypeSafeControl
       
   127 // Gets control. Ownership is not tranferred.
       
   128 // (other items were commented in a header).
       
   129 // -----------------------------------------------------------------------------
       
   130 CAMMSDopplerControl*
       
   131 CAMMSDopplerControlGroup::TypeSafeControl(TInt aIndex) const
       
   132 {
       
   133     return static_cast<CAMMSDopplerControl*>(Control(aIndex));
       
   134 }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CAMMSDopplerControlGroup::ClassName
       
   138 // Returns class name that identifies this control group.
       
   139 // (other items were commented in a header).
       
   140 // -----------------------------------------------------------------------------
       
   141 const TDesC16& CAMMSDopplerControlGroup::ClassName()
       
   142 {
       
   143     return KAMMSDopplerControlClassName;
       
   144 }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CAMMSDopplerControlGroup::CommitL
       
   148 // Transfers all the pending parameters to the audio processing system.
       
   149 // (other items were commented in a header).
       
   150 // -----------------------------------------------------------------------------
       
   151 void CAMMSDopplerControlGroup::CommitL(TInt aCommit)
       
   152 {
       
   153     TInt controls = ControlCount();
       
   154 
       
   155     // first commit enabled state
       
   156     if (aCommit & EEnabled)
       
   157     {
       
   158         for (TInt i = 0; i < controls; i++)
       
   159         {
       
   160             CAMMSDopplerControl* control = TypeSafeControl(i);
       
   161             control->SetEnabledL(iUncommited.iEnabled);
       
   162         }
       
   163         iCommited.iEnabled = iUncommited.iEnabled;
       
   164     }
       
   165 
       
   166     // then commit velocity
       
   167     if (aCommit & EVelocity)
       
   168     {
       
   169         for (TInt i = 0; i < controls; i++)
       
   170         {
       
   171             CAMMSDopplerControl* control = TypeSafeControl(i);
       
   172 
       
   173             control->SetVelocityCartesianL(
       
   174                 iUncommited.iVelocity[ EComponentX ],
       
   175                 iUncommited.iVelocity[ EComponentY ],
       
   176                 iUncommited.iVelocity[ EComponentZ ]);
       
   177         }
       
   178 
       
   179         // Change uncommited velocity to commited
       
   180         for (TInt i = 0; i < KAMMSVectorComponents; i++)
       
   181         {
       
   182             iCommited.iVelocity[ i ] = iUncommited.iVelocity[ i ];
       
   183         }
       
   184     }
       
   185 }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CAMMSDopplerControlGroup::NotifyPlayerAddedL
       
   189 // Called by when a new player is added
       
   190 // (other items were commented in a header).
       
   191 // -----------------------------------------------------------------------------
       
   192 void CAMMSDopplerControlGroup::NotifyPlayerAddedL(
       
   193     CMMAPlayer* aPlayer,
       
   194     CMMAControl* aControl)
       
   195 {
       
   196     CAMMSAudio3DControlGroup::NotifyPlayerAddedL(aPlayer, aControl);
       
   197 
       
   198     CAMMSDopplerControl* control =
       
   199         static_cast<CAMMSDopplerControl*>(aControl);
       
   200 
       
   201     // set the current parameters
       
   202 
       
   203     control->SetVelocityCartesianL(
       
   204         iCommited.iVelocity[ EComponentX ],
       
   205         iCommited.iVelocity[ EComponentY ],
       
   206         iCommited.iVelocity[ EComponentZ ]);
       
   207 
       
   208     control->SetEnabledL(iCommited.iEnabled);
       
   209 }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CAMMSDopplerControlGroup::CAMMSDopplerControlGroup
       
   213 // C++ default constructor can NOT contain any code, that might leave.
       
   214 // -----------------------------------------------------------------------------
       
   215 CAMMSDopplerControlGroup::CAMMSDopplerControlGroup(
       
   216     TAMMSControlTypes aControlType):
       
   217         CAMMSAudio3DControlGroup(KAMMSDopplerControl, aControlType)
       
   218 {
       
   219 }
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // CAMMSDopplerControlGroup::ConstructL
       
   223 // Symbian 2nd phase constructor can leave.
       
   224 // -----------------------------------------------------------------------------
       
   225 inline void CAMMSDopplerControlGroup::ConstructL()
       
   226 {
       
   227     CAMMSAudio3DControlGroup::ConstructL();
       
   228 
       
   229     // The default value for Spectator's DopplerControl is true
       
   230     // (the default value for SoundSource3D's DopplerControl is false)
       
   231     if (iControlType == EAMMSSpectatorControl)
       
   232     {
       
   233         SetEnabledL(ETrue);
       
   234     }
       
   235 }
       
   236 
       
   237 //  End of File