Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

clanmidi.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 #pragma hdrstop
00003 
00004 #include "clanmidi.h"
00005 
00006 //---------------------------------------------------------------------------
00007 #pragma package(smart_init)
00008 
00009 //Okay this is the first draft of a WIN32 CLANLIB MIDI PLAYER
00010 //It compiles on my system C++ Borland Builder 3
00011 //Things to do : Look a little clanlibish and add headers
00012 // Some cleanup MUST BE MADE for non Borland users (Read nearly all of you)
00013 // This ONLY works with DX7
00014 //I am not even sure that this code can actually play some music right now
00015 //I need to have a look at those damn string function for unicode first
00016 
00017 ClanMidi::ClanMidi()
00018 {
00019     if (SUCCEEDED(CoInitialize(NULL)))
00020     {
00021         CL_MIDIPerformance = CreatePerformance();
00022         if (CL_MIDIPerformance != NULL)
00023         {
00024             if (SUCCEEDED(CL_MIDIPerformance->Init(NULL, NULL, NULL)))
00025             {
00026                 if (FAILED(CL_MIDIPerformance->AddPort(NULL)))
00027                 {
00028                     CL_MIDIPerformance->CloseDown();
00029                     CL_MIDIPerformance->Release();
00030                 };
00031             };
00032         };
00033         CL_MIDILoader = CreateLoader();
00034         CL_MIDISegment = NULL;
00035         CL_MIDISegmentState = NULL;
00036     };
00037 };
00038 
00039 ClanMidi::~ClanMidi()
00040 {
00041     CL_MIDIPerformance->CloseDown();
00042     CL_MIDIPerformance->Release();
00043     CL_MIDILoader->Release();
00044     CL_MIDISegment = NULL;
00045     CL_MIDISegmentState = NULL;
00046     CoUninitialize();
00047 };
00048 
00049 IDirectMusicPerformance* ClanMidi::CreatePerformance()
00050 {
00051     IDirectMusicPerformance* pPerf;
00052 
00053     if (FAILED(CoCreateInstance(
00054             CLSID_DirectMusicPerformance,
00055             NULL,
00056             CLSCTX_INPROC,
00057             IID_IDirectMusicPerformance2,
00058             (void**)&pPerf
00059         )))
00060     {
00061         pPerf = NULL;
00062     }
00063     return pPerf;
00064 };
00065 
00066 IDirectMusicLoader* ClanMidi::CreateLoader()
00067 {
00068     IDirectMusicLoader* pLoader;
00069 
00070     if (FAILED(CoCreateInstance(
00071             CLSID_DirectMusicLoader,
00072             NULL,
00073             CLSCTX_INPROC,
00074             IID_IDirectMusicLoader,
00075             (void**)&pLoader
00076         )))
00077     {
00078         pLoader = NULL;
00079     }
00080     return pLoader;
00081 };
00082 
00083 bool ClanMidi::StartPlaying()
00084 {
00085     if (FAILED(CL_MIDIPerformance->PlaySegment(CL_MIDISegment, 0, 0,
00086                 &CL_MIDISegmentState)))
00087         return false;
00088     return true;
00089 };
00090 
00091 bool ClanMidi::StopPlaying()
00092 {
00093     if (FAILED(CL_MIDIPerformance->Stop( NULL, NULL, 0, 0 )))
00094         return false;
00095     return true;
00096 };
00097 
00098 bool ClanMidi::LoadMIDIFile(wchar_t* MIDIFilename)
00099 {
00100 
00101     DMUS_OBJECTDESC ObjDesc;
00102 
00103     ObjDesc.guidClass = CLSID_DirectMusicSegment;
00104     ObjDesc.dwSize = sizeof(DMUS_OBJECTDESC);
00105     wcscpy( ObjDesc.wszFileName, MIDIFilename );    
00106     ObjDesc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME;
00107 
00108     CL_MIDILoader->GetObject(&ObjDesc,
00109             IID_IDirectMusicSegment2, (void**) &CL_MIDISegment);
00110     CL_MIDISegment->SetParam(GUID_StandardMIDIFile,
00111             -1, 0, 0, (void*)CL_MIDIPerformance);
00112     CL_MIDISegment->SetParam(GUID_Download, -1, 0, 0, (void*)CL_MIDIPerformance);
00113 
00114     return true;
00115 };                                        
00116 

Generated at Wed Apr 4 19:53:59 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001