javauis/mmapi_akn/baseline/src/cmmamidiplayerfactory.cpp
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     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 used for creating MIDI player.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include <jdebug.h>
       
    21 
       
    22 #include "cmmamidiplayerfactory.h"
       
    23 #include "cmmamidiplayer.h"
       
    24 #include "cmmamidivolumecontrol.h"
       
    25 #include "cmmamidistoptimecontrol.h"
       
    26 #include "cmmamidicontrol.h"
       
    27 #include "cmmamiditempocontrol.h"
       
    28 #include "cmmamidipitchcontrol.h"
       
    29 #include "cmmammfresolver.h"
       
    30 #include "cmmamidimetadatacontrol.h"
       
    31 
       
    32 
       
    33 _LIT(KMMAMidi, "midi");
       
    34 _LIT(KDeviceMidiContentType, "audio/midi");
       
    35 
       
    36 CMMAMIDIPlayerFactory* CMMAMIDIPlayerFactory::NewLC()
       
    37 {
       
    38     CMMAMIDIPlayerFactory* pFactory =
       
    39         new(ELeave) CMMAMIDIPlayerFactory();
       
    40     CleanupStack::PushL(pFactory);
       
    41     return pFactory;
       
    42 }
       
    43 
       
    44 CMMAMIDIPlayerFactory::CMMAMIDIPlayerFactory()
       
    45 {
       
    46 }
       
    47 
       
    48 
       
    49 CMMAMIDIPlayerFactory::~CMMAMIDIPlayerFactory()
       
    50 {
       
    51 }
       
    52 
       
    53 CMMAPlayer* CMMAMIDIPlayerFactory::CreatePlayerL(
       
    54     CMMAMMFResolver* aResolver)
       
    55 {
       
    56     // if we get this far then MIDI is supported
       
    57     HBufC* contentType = aResolver->ContentType();
       
    58     HBufC* tmpFileName = aResolver->FileNameOwnership();
       
    59     TFileName fileName;
       
    60     if (tmpFileName)
       
    61     {
       
    62         fileName.Copy(tmpFileName->Des());
       
    63     }
       
    64     else
       
    65     {
       
    66         fileName = KNullDesC;
       
    67     }
       
    68     delete tmpFileName;
       
    69     CMMAPlayer* player = CreateMidiFilePlayerL(*contentType, fileName);
       
    70     return player;
       
    71 }
       
    72 
       
    73 
       
    74 void CMMAMIDIPlayerFactory::MediaIdsL(RArray<TUid>& aMediaIds)
       
    75 {
       
    76     CleanupClosePushL(aMediaIds);
       
    77     User::LeaveIfError(aMediaIds.Append(KUidMediaTypeMidi));
       
    78     CleanupStack::Pop();
       
    79 }
       
    80 
       
    81 CMMAPlayer* CMMAMIDIPlayerFactory::CreatePlayerL(
       
    82     const TDesC& aProtocol,
       
    83     const TDesC& aMiddlePart,
       
    84     const TDesC& aProperties)
       
    85 {
       
    86     CMMAPlayer* player = NULL;
       
    87     if ((aProtocol == KMMADeviceProtocol) &&
       
    88             (aMiddlePart == KMMAMidi))
       
    89     {
       
    90         // locator was device://midi
       
    91         player = CreateMidiSynthPlayerL(KDeviceMidiContentType);
       
    92     }
       
    93     else
       
    94     {
       
    95         // other locator, if it is midi file CMMAMMFPlayerFactory
       
    96         // calls CreatePlayerL( CMMAMMFResolver* aResolver ) method.
       
    97         player = CMMAMMFPlayerFactory::CreatePlayerL(aProtocol,
       
    98                  aMiddlePart,
       
    99                  aProperties);
       
   100     }
       
   101     return player;
       
   102 }
       
   103 
       
   104 void CMMAMIDIPlayerFactory::GetSupportedProtocolsL(
       
   105     const TDesC& aContentType,
       
   106     CDesC16Array& aProtocolArray)
       
   107 {
       
   108     if (IsSupportedContentTypeL(aContentType))
       
   109     {
       
   110         aProtocolArray.AppendL(KMMADeviceProtocol);
       
   111     }
       
   112 }
       
   113 
       
   114 CMMAPlayer* CMMAMIDIPlayerFactory::CreateMidiFilePlayerL(const TDesC& aContentType,
       
   115         TFileName aFileName)
       
   116 {
       
   117     CMMAMIDIPlayer* player = CMMAMIDIPlayer::NewLC(aContentType, aFileName);
       
   118 
       
   119     CMMAMIDIVolumeControl* volumeControl = CMMAMIDIVolumeControl::NewL(player);
       
   120     CleanupStack::PushL(volumeControl);
       
   121     player->AddControlL(volumeControl);
       
   122     CleanupStack::Pop(volumeControl);
       
   123 
       
   124     CMMAMIDIStopTimeControl* stopTimeControl = CMMAMIDIStopTimeControl::NewL(player);
       
   125     CleanupStack::PushL(stopTimeControl);
       
   126     player->AddControlL(stopTimeControl);
       
   127     CleanupStack::Pop(stopTimeControl);
       
   128 
       
   129     CMMAMIDIControl* midiControl = CMMAMIDIControl::NewL(player);
       
   130     CleanupStack::PushL(midiControl);
       
   131     player->AddControlL(midiControl);
       
   132     CleanupStack::Pop(midiControl);
       
   133 
       
   134     CMMAMIDITempoControl* tempoControl = CMMAMIDITempoControl::NewL(player);
       
   135     CleanupStack::PushL(tempoControl);
       
   136     player->AddControlL(tempoControl);
       
   137     CleanupStack::Pop(tempoControl);
       
   138 
       
   139     CMMAMIDIPitchControl* pitchControl = CMMAMIDIPitchControl::NewL(player);
       
   140     CleanupStack::PushL(pitchControl);
       
   141     player->AddControlL(pitchControl);
       
   142     CleanupStack::Pop(pitchControl);
       
   143 
       
   144     CMMAMIDIMetaDataControl* metaDataControl =
       
   145         new(ELeave) CMMAMIDIMetaDataControl(player);
       
   146     CleanupStack::PushL(metaDataControl);
       
   147     player->AddControlL(metaDataControl);
       
   148     CleanupStack::Pop(metaDataControl);
       
   149 
       
   150     CleanupStack::Pop(player);
       
   151     return player;
       
   152 }
       
   153 
       
   154 CMMAPlayer* CMMAMIDIPlayerFactory::CreateMidiSynthPlayerL(const TDesC& aContentType)
       
   155 {
       
   156     CMMAMIDIPlayer* player = CMMAMIDIPlayer::NewLC(aContentType, KNullDesC());
       
   157 
       
   158     CMMAMIDIVolumeControl* volumeControl = CMMAMIDIVolumeControl::NewL(player);
       
   159     CleanupStack::PushL(volumeControl);
       
   160     player->AddControlL(volumeControl);
       
   161     CleanupStack::Pop(volumeControl);
       
   162 
       
   163     CMMAMIDIControl* midiControl = CMMAMIDIControl::NewL(player);
       
   164     CleanupStack::PushL(midiControl);
       
   165     player->AddControlL(midiControl);
       
   166     CleanupStack::Pop(midiControl);
       
   167 
       
   168     CMMAMIDIPitchControl* pitchControl = CMMAMIDIPitchControl::NewL(player);
       
   169     CleanupStack::PushL(pitchControl);
       
   170     player->AddControlL(pitchControl);
       
   171     CleanupStack::Pop(pitchControl);
       
   172 
       
   173     CleanupStack::Pop(player);
       
   174     return player;
       
   175 }
       
   176 
       
   177 //  END OF FILE
       
   178