00001
00002 #pragma hdrstop
00003
00004 #include "clanmidi.h"
00005
00006
00007 #pragma package(smart_init)
00008
00009
00010
00011
00012
00013
00014
00015
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