examples/sfexamples/MidiPlaying/src/MidiPlayer.cpp

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:
00015 // 
00016 
00017 // INCLUDE FILES
00018 #include <eikenv.h>
00019 #include "MidiPlayer.h"
00020 
00021 // CONSTANTS
00022 const TInt KVolumeDenominator = 2;
00023 
00024 // METHODS DEFINITION
00025 
00026 CMidiPlayer::CMidiPlayer()
00027         {
00028         }
00029 
00030 CMidiPlayer::~CMidiPlayer()
00031         {
00032         delete iMidiUtility;
00033         }
00034 
00035 CMidiPlayer* CMidiPlayer::NewLC()
00036         {
00037         CMidiPlayer* self = new (ELeave) CMidiPlayer();
00038         CleanupStack::PushL(self);
00039         self->ConstructL();
00040         return self;
00041         }
00042 
00043 CMidiPlayer* CMidiPlayer::NewL()
00044         {
00045         CMidiPlayer* self = CMidiPlayer::NewLC();
00046         CleanupStack::Pop(self);
00047         return self;
00048         }
00049 
00050 void CMidiPlayer::ConstructL()
00051         {
00052         iMidiUtility = CMidiClientUtility::NewL(*this);
00053         }
00054 
00055 void CMidiPlayer::Play(const TDesC& aFileName)
00056         {
00057         iMidiUtility->Close();
00058         iMidiUtility->OpenFile(aFileName);
00059         }
00060 
00061 void CMidiPlayer::Stop()
00062         {
00063         iMidiUtility->Stop(TTimeIntervalMicroSeconds(0));
00064         iMidiUtility->Close();
00065         }
00066 
00067 void CMidiPlayer::MmcuoStateChanged(TMidiState aOldState, TMidiState aNewState,
00068                         const TTimeIntervalMicroSeconds& /*aTime*/, TInt aError)
00069         {
00070         if (KErrNone == aError)
00071                 {               
00072             if (EMidiStateOpenDisengaged == aNewState)
00073                         {
00074                         // Set the volume to half of the maximum volume.
00075                         TRAP_IGNORE(iMidiUtility->SetVolumeL(
00076                                         iMidiUtility->MaxVolumeL() / KVolumeDenominator));
00077                         
00078                         // Play the MIDI file.
00079                         iMidiUtility->Play();
00080                         }
00081                 }
00082         else
00083                 {
00084                 DisplayErrorMessage(aError);
00085                 }
00086         }
00087 
00088 void CMidiPlayer::MmcuoTempoChanged(TInt /*aMicroBeatsPerMinute*/)
00089         {
00090         }
00091 
00092 void CMidiPlayer::MmcuoVolumeChanged(TInt /*aChannel*/,
00093                 TReal32 /*aVolumeInDecibels*/)
00094         {
00095         }
00096 
00097 void CMidiPlayer::MmcuoMuteChanged(TInt /*aChannel*/, TBool /*aMuted*/)
00098         {
00099         }
00100 
00101 void CMidiPlayer::MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& /*aMicroSeconds*/,
00102                         TInt64 /*aMicroBeats*/)
00103         {
00104         }
00105 
00106 void CMidiPlayer::MmcuoMetaDataEntryFound(const TInt /*aMetaDataEntryId*/,
00107                         const TTimeIntervalMicroSeconds& /*aPosition*/)
00108         {
00109         }
00110 
00111 void CMidiPlayer::MmcuoMipMessageReceived(
00112                 const RArray<TMipMessageEntry>& /*aMessage*/)
00113         {
00114         }
00115 
00116 void CMidiPlayer::MmcuoPolyphonyChanged(TInt /*aNewPolyphony*/)
00117         {
00118         }
00119 
00120 void CMidiPlayer::MmcuoInstrumentChanged(TInt /*aChannel*/, TInt /*aBankId*/,
00121                         TInt /*aInstrumentId*/)
00122         {
00123         }
00124 
00125 void CMidiPlayer::DisplayErrorMessage(TInt aError)
00126         {
00127         const TInt KMaxBuffer = 15;
00128         _LIT(KErrorMessage, "Error: %d");
00129         TBuf<KMaxBuffer> buffer;
00130         buffer.AppendFormat(KErrorMessage, aError);
00131         TRAP_IGNORE(CEikonEnv::Static()->InfoWinL(KNullDesC, buffer));
00132         }
00133 
00134 // End of File

Generated by  doxygen 1.6.2