javauis/mmapi_qt/baseline/src/cmmamiditempocontrol.cpp
changeset 23 98ccebc37403
child 26 dc7c549001d5
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
       
     1 /*
       
     2 * Copyright (c) 2002 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:  This class is a TempoControl.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include <logger.h>
       
    21 #include <e32base.h>
       
    22 
       
    23 #include "cmmamiditempocontrol.h"
       
    24 #include "cmmamidiplayer.h"
       
    25 
       
    26 static const TInt KMicroBeatsInMiliBeat = 1000;
       
    27 static const TInt KMMAMIDIMinimumTempo = 10000;
       
    28 static const TInt KMMAMIDIMaximumTempo = 300000;
       
    29 static const TInt KMMAMIDIDefaultTempoInMicroBeats = 120000000;
       
    30 _LIT(KMMAMidiTempoStateChangedError, "Tempo error in state change");
       
    31 
       
    32 CMMAMIDITempoControl* CMMAMIDITempoControl::NewL(CMMAMIDIPlayer* aPlayer)
       
    33 {
       
    34     CMMAMIDITempoControl* self = new(ELeave) CMMAMIDITempoControl(aPlayer);
       
    35     CleanupStack::PushL(self);
       
    36     self->ConstructL();
       
    37     CleanupStack::Pop();
       
    38     return self;
       
    39 }
       
    40 
       
    41 CMMAMIDITempoControl::CMMAMIDITempoControl(CMMAMIDIPlayer* aPlayer)
       
    42 {
       
    43     iPlayer = aPlayer;
       
    44     iTempo = KMMAMIDIDefaultTempoInMicroBeats;
       
    45 
       
    46     LOG( EJavaMMAPI, EInfo, "MMA:CMMAMIDITempoControl::CMMAMIDITempoControl");
       
    47 }
       
    48 
       
    49 CMMAMIDITempoControl::~CMMAMIDITempoControl()
       
    50 {
       
    51     LOG( EJavaMMAPI, EInfo, "MMA:CMMAMIDITempoControl::~CMMAMIDITempoControl");
       
    52 }
       
    53 
       
    54 inline void CMMAMIDITempoControl::ConstructL()
       
    55 {
       
    56     LOG( EJavaMMAPI, EInfo, "MMA:CMMAMIDITempoControl::ConstructL");
       
    57 
       
    58     iPlayer->addObserverL(this);
       
    59     iPlayer->AddStateListenerL(this);
       
    60 }
       
    61 
       
    62 const TDesC& CMMAMIDITempoControl::ClassName() const
       
    63 {
       
    64     LOG( EJavaMMAPI, EInfo, "MMA:CMMAMIDITempoControl::ClassName");
       
    65     return KMIDITempoControlName;
       
    66 }
       
    67 
       
    68 
       
    69 TInt CMMAMIDITempoControl::TempoL()
       
    70 {
       
    71     LOG( EJavaMMAPI, EInfo, "MMA: CMMAMIDITempoControl: TempoL");
       
    72 
       
    73     return iTempo / KMicroBeatsInMiliBeat;
       
    74 }
       
    75 
       
    76 TInt CMMAMIDITempoControl::SetTempoL(TInt aTempo)
       
    77 {
       
    78     LOG( EJavaMMAPI, EInfo, "MMA: CMMAMIDITempoControl: SetTempoL");
       
    79     TInt tempo = aTempo;
       
    80     if (tempo < KMMAMIDIMinimumTempo)
       
    81     {
       
    82         tempo = KMMAMIDIMinimumTempo;
       
    83     }
       
    84     if (tempo > KMMAMIDIMaximumTempo)
       
    85     {
       
    86         tempo = KMMAMIDIMaximumTempo;
       
    87     }
       
    88 
       
    89     LOG1( EJavaMMAPI, EInfo, "MMA: CMMAMIDITempoControl: SetTempoL: setting tempo %d",
       
    90               tempo);
       
    91 
       
    92     // Convert tempo to micro-beats.
       
    93     tempo *= KMicroBeatsInMiliBeat;
       
    94 
       
    95     // Set the tempo to the midi client if the player state is not REALIZED.
       
    96     // (Tempo cannot be set to the midi client if the player
       
    97     // has not been prefetched).
       
    98     if (iPlayer->State() != CMMAPlayer::ERealized)
       
    99     {
       
   100         CMidiClientUtility* midi = iPlayer->MidiClient();
       
   101         midi->SetTempoL(tempo);
       
   102         tempo = iPlayer->MidiClient()->TempoMicroBeatsPerMinuteL();
       
   103     }
       
   104 
       
   105     iTempo = tempo;
       
   106 
       
   107     LOG1( EJavaMMAPI, EInfo, "MMA: CMMAMIDITempoControl: SetTempoL: Tempo set: %d",
       
   108               tempo / KMicroBeatsInMiliBeat);
       
   109 
       
   110     return tempo / KMicroBeatsInMiliBeat;
       
   111 }
       
   112 
       
   113 TInt CMMAMIDITempoControl::SetRateL(TInt aRate)
       
   114 {
       
   115     TInt rate = aRate;
       
   116     TInt maxRate = MaxRateL();
       
   117     TInt minRate = MinRateL();
       
   118 
       
   119     if (rate > maxRate)
       
   120     {
       
   121         rate = maxRate;
       
   122     }
       
   123     else if (rate < minRate)
       
   124     {
       
   125         rate = minRate;
       
   126     }
       
   127     iPlayer->MidiClient()->SetPlaybackRateL(rate);
       
   128     return RateL();         // return the actual tempo
       
   129 }
       
   130 
       
   131 TInt CMMAMIDITempoControl::RateL()
       
   132 {
       
   133     return iPlayer->MidiClient()->PlaybackRateL();
       
   134 }
       
   135 
       
   136 TInt CMMAMIDITempoControl::MaxRateL()
       
   137 {
       
   138     return iPlayer->MidiClient()->MaxPlaybackRateL();
       
   139 }
       
   140 
       
   141 TInt CMMAMIDITempoControl::MinRateL()
       
   142 {
       
   143     return iPlayer->MidiClient()->MinPlaybackRateL();
       
   144 }
       
   145 
       
   146 void CMMAMIDITempoControl::StateChanged(TInt aState)
       
   147 {
       
   148     LOG1( EJavaMMAPI, EInfo, "CMMAMIDITempoControl:: StateChanged, state = %d", aState);
       
   149 
       
   150     // If tempo was set when the player was in REALIZED state, set the tempo
       
   151     // now when the player has been prefetched.
       
   152     if ((aState == CMMAPlayer::EPrefetched) &&
       
   153             (iTempo != KMMAMIDIDefaultTempoInMicroBeats))
       
   154     {
       
   155         CMidiClientUtility* midi = iPlayer->MidiClient();
       
   156         TRAPD(err, midi->SetTempoL(iTempo));
       
   157 
       
   158         ELOG1( EJavaMMAPI, "CMMAMIDITempoControl:: StateChanged, err = %d", err);
       
   159 
       
   160         if (err != KErrNone)
       
   161         {
       
   162             iPlayer->PostStringEvent(CMMAPlayerEvent::EError,
       
   163                                      KMMAMidiTempoStateChangedError);
       
   164         }
       
   165     }
       
   166     else if (aState == CMMAPlayer::ERealized)
       
   167     {
       
   168         // If the player was deallocated, set the tempo to the default value.
       
   169         iTempo = KMMAMIDIDefaultTempoInMicroBeats;
       
   170     }
       
   171 }
       
   172 void CMMAMIDITempoControl::MmcuoStateChanged(TMidiState /*aOldState*/,
       
   173         TMidiState /*aNewState*/,
       
   174         const TTimeIntervalMicroSeconds& /*aTime*/,
       
   175         TInt /*aError*/)
       
   176 {
       
   177 }
       
   178 
       
   179 void CMMAMIDITempoControl::MmcuoTempoChanged(TInt aMicroBeatsPerMinute)
       
   180 {
       
   181     LOG( EJavaMMAPI, EInfo, "CMMAMIDITempoControl:: MmcuoTempoChanged");
       
   182 
       
   183     iTempo = aMicroBeatsPerMinute;
       
   184 }
       
   185 
       
   186 void CMMAMIDITempoControl::MmcuoVolumeChanged(TInt /*aChannel*/,TReal32 /*aVolumeInDecibels*/)
       
   187 {
       
   188 }
       
   189 
       
   190 void CMMAMIDITempoControl::MmcuoMuteChanged(TInt /*aChannel*/,TBool /*aMuted*/)
       
   191 {
       
   192 }
       
   193 
       
   194 void CMMAMIDITempoControl::MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& /*aMicroSeconds*/,TInt64 /*aMicroBeats*/)
       
   195 {
       
   196 }
       
   197 
       
   198 void CMMAMIDITempoControl::MmcuoMetaDataEntryFound(const TInt /*aMetaDataEntryId*/,const TTimeIntervalMicroSeconds& /*aPosition*/)
       
   199 {
       
   200 }
       
   201 
       
   202 void CMMAMIDITempoControl::MmcuoMipMessageReceived(const RArray<TMipMessageEntry>& /*aMessage*/)
       
   203 {
       
   204 }
       
   205 
       
   206 void CMMAMIDITempoControl::MmcuoPolyphonyChanged(TInt /*aNewPolyphony*/)
       
   207 {
       
   208 }
       
   209 
       
   210 void CMMAMIDITempoControl::MmcuoInstrumentChanged(TInt /*aChannel*/,TInt /*aBankId*/,TInt /*aInstrumentId*/)
       
   211 {
       
   212 }
       
   213 //  END OF FILE