javauis/amms_qt/mmacontrol/src.mmf/cammspancontrol.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 panning of a Player in the stereo output mix.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <logger.h>
       
    22 #include <CMMAAudioPlayer.h>
       
    23 #include <CMMAMidiPlayer.h>
       
    24 #include "CAMMSPanControl.h"
       
    25 
       
    26 
       
    27 #ifdef _DEBUG
       
    28 // CONSTANTS
       
    29 const TInt KAMMSMaxPanning = 100;
       
    30 const TInt KAMMSMinPanning = -100;
       
    31 #endif // _DEBUG
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CAMMSPanControl::NewLC
       
    37 // Two-phased constructor.
       
    38 // -----------------------------------------------------------------------------
       
    39 CAMMSPanControl* CAMMSPanControl::NewLC(CMMAPlayer* aPlayer)
       
    40 {
       
    41     CAMMSPanControl* self = new(ELeave) CAMMSPanControl(aPlayer);
       
    42 
       
    43     CleanupStack::PushL(self);
       
    44 
       
    45     self->ConstructL();
       
    46 
       
    47     return self;
       
    48 }
       
    49 
       
    50 // Destructor
       
    51 CAMMSPanControl::~CAMMSPanControl()
       
    52 {
       
    53     delete iRMMFAudioPlayDeviceCustomCommands;
       
    54 }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CAMMSPanControl::PanL
       
    58 // Gets the current panning set.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 TInt CAMMSPanControl::PanL()
       
    62 {
       
    63     TInt balance = KMMFBalanceCenter;
       
    64 
       
    65     // In case of MIDIPlayer, use CMidiClientUtility, otherwise RMMFController.
       
    66     if (iMidiClientUtility)
       
    67     {
       
    68         // Get the current stereo balance value.
       
    69 
       
    70         balance = iMidiClientUtility->GetBalanceL();
       
    71     }
       
    72     else
       
    73     {
       
    74         // Gets the balance between the left and right stereo audio channels.
       
    75 
       
    76         User::LeaveIfError(
       
    77             iRMMFAudioPlayDeviceCustomCommands->GetBalance(balance));
       
    78     }
       
    79     LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSPanControl::PanL called, native GetBalance = %d",
       
    80               balance);
       
    81 
       
    82     return balance;
       
    83 }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CAMMSPanControl::SetPanL
       
    87 // Sets the panning using a linear point scale (-100 - +100).
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 TInt CAMMSPanControl::SetPanL(TInt aPan)
       
    91 {
       
    92     LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSPanControl::SetPanL: Pan = %d", aPan);
       
    93 
       
    94     // Check in debug build that aPan is within valid range.
       
    95     __ASSERT_DEBUG(
       
    96         (aPan <= KAMMSMaxPanning) &&
       
    97         (aPan >= KAMMSMinPanning),
       
    98         User::Invariant());
       
    99 
       
   100     // In case of MIDIPlayer, use CMidiClientUtility, otherwise RMMFController.
       
   101     if (iMidiClientUtility)
       
   102     {
       
   103         // Set the current stereo balance value.
       
   104         // Defaults to KMMFBalanceCenter to restore equal left-right balance.
       
   105 
       
   106         iMidiClientUtility->SetBalanceL(aPan);
       
   107     }
       
   108     else
       
   109     {
       
   110         // Sets the balance between the left and right stereo audio channels
       
   111         // Use a value between KMMFBalanceMaxLeft and KMMFBalanceMaxRight.
       
   112         // Centre balance can be restored by using KMMFBalanceCenter.
       
   113 
       
   114         User::LeaveIfError(
       
   115             iRMMFAudioPlayDeviceCustomCommands->SetBalance(aPan));
       
   116     }
       
   117 
       
   118     return PanL();
       
   119 }
       
   120 
       
   121 
       
   122 const TDesC& CAMMSPanControl::ClassName() const
       
   123 {
       
   124     return KAMMSPanControl;
       
   125 }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CAMMSPanControl::ConstructL
       
   129 // Symbian 2nd phase constructor can leave.
       
   130 // -----------------------------------------------------------------------------
       
   131 void CAMMSPanControl::ConstructL()
       
   132 {
       
   133     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSPanControl::ConstructL");
       
   134 
       
   135     if (iPlayer->Type() == KMMAMIDIPlayer)
       
   136     {
       
   137         // In case of CMMAMIDIPlayer use CMidiClientUtility
       
   138         CMMAMIDIPlayer* mmaMIDIPlayer =
       
   139             reinterpret_cast< CMMAMIDIPlayer* >(iPlayer);
       
   140 
       
   141         iMidiClientUtility = mmaMIDIPlayer->MidiClient();
       
   142     }
       
   143     else
       
   144     {
       
   145         CMMAAudioPlayer* mmaAudioPlayer =
       
   146             reinterpret_cast< CMMAAudioPlayer* >(iPlayer);
       
   147 
       
   148         RMMFController& mmfController = mmaAudioPlayer->Controller();
       
   149 
       
   150         iRMMFAudioPlayDeviceCustomCommands =
       
   151             new(ELeave) RMMFAudioPlayDeviceCustomCommands(mmfController);
       
   152     }
       
   153 }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CAMMSPanControl::CAMMSPanControl
       
   157 // C++ default constructor can NOT contain any code, that
       
   158 // might leave.
       
   159 // -----------------------------------------------------------------------------
       
   160 CAMMSPanControl::CAMMSPanControl(CMMAPlayer* aPlayer)
       
   161         : CAMMSControl(aPlayer)
       
   162 {
       
   163 }
       
   164 //  End of File