12 #include <dmusici.h> |
14 #include <dmusici.h> |
13 #include <dmusicc.h> |
15 #include <dmusicc.h> |
14 #include <dmusicf.h> |
16 #include <dmusicf.h> |
15 |
17 |
16 |
18 |
17 // the performance object controls manipulation of the segments |
19 /** the performance object controls manipulation of the segments */ |
18 static IDirectMusicPerformance* performance = NULL; |
20 static IDirectMusicPerformance* performance = NULL; |
19 |
21 |
20 // the loader object can load many types of DMusic related files |
22 /** the loader object can load many types of DMusic related files */ |
21 static IDirectMusicLoader* loader = NULL; |
23 static IDirectMusicLoader* loader = NULL; |
22 |
24 |
23 // the segment object is where the MIDI data is stored for playback |
25 /** the segment object is where the MIDI data is stored for playback */ |
24 static IDirectMusicSegment* segment = NULL; |
26 static IDirectMusicSegment* segment = NULL; |
25 |
27 |
26 static bool seeking = false; |
28 static bool seeking = false; |
27 |
29 |
28 |
30 |
52 if (proc.CoCreateInstance == NULL) { |
54 if (proc.CoCreateInstance == NULL) { |
53 if (!LoadLibraryList((Function*)&proc, ole_files)) |
55 if (!LoadLibraryList((Function*)&proc, ole_files)) |
54 return "ole32.dll load failed"; |
56 return "ole32.dll load failed"; |
55 } |
57 } |
56 |
58 |
57 // Initialize COM |
59 /* Initialize COM */ |
58 if (FAILED(proc.CoInitialize(NULL))) { |
60 if (FAILED(proc.CoInitialize(NULL))) { |
59 return "COM initialization failed"; |
61 return "COM initialization failed"; |
60 } |
62 } |
61 |
63 |
62 // create the performance object |
64 /* create the performance object */ |
63 if (FAILED(proc.CoCreateInstance( |
65 if (FAILED(proc.CoCreateInstance( |
64 CLSID_DirectMusicPerformance, |
66 CLSID_DirectMusicPerformance, |
65 NULL, |
67 NULL, |
66 CLSCTX_INPROC, |
68 CLSCTX_INPROC, |
67 IID_IDirectMusicPerformance, |
69 IID_IDirectMusicPerformance, |
69 ))) { |
71 ))) { |
70 proc.CoUninitialize(); |
72 proc.CoUninitialize(); |
71 return "Failed to create the performance object"; |
73 return "Failed to create the performance object"; |
72 } |
74 } |
73 |
75 |
74 // initialize it |
76 /* initialize it */ |
75 if (FAILED(performance->Init(NULL, NULL, NULL))) { |
77 if (FAILED(performance->Init(NULL, NULL, NULL))) { |
76 performance->Release(); |
78 performance->Release(); |
77 performance = NULL; |
79 performance = NULL; |
78 proc.CoUninitialize(); |
80 proc.CoUninitialize(); |
79 return "Failed to initialize performance object"; |
81 return "Failed to initialize performance object"; |
80 } |
82 } |
81 |
83 |
82 // choose default Windows synth |
84 /* choose default Windows synth */ |
83 if (FAILED(performance->AddPort(NULL))) { |
85 if (FAILED(performance->AddPort(NULL))) { |
84 performance->CloseDown(); |
86 performance->CloseDown(); |
85 performance->Release(); |
87 performance->Release(); |
86 performance = NULL; |
88 performance = NULL; |
87 proc.CoUninitialize(); |
89 proc.CoUninitialize(); |
88 return "AddPort failed"; |
90 return "AddPort failed"; |
89 } |
91 } |
90 |
92 |
91 // create the loader object; this will be used to load the MIDI file |
93 /* create the loader object; this will be used to load the MIDI file */ |
92 if (FAILED(proc.CoCreateInstance( |
94 if (FAILED(proc.CoCreateInstance( |
93 CLSID_DirectMusicLoader, |
95 CLSID_DirectMusicLoader, |
94 NULL, |
96 NULL, |
95 CLSCTX_INPROC, |
97 CLSCTX_INPROC, |
96 IID_IDirectMusicLoader, |
98 IID_IDirectMusicLoader, |
134 } |
136 } |
135 |
137 |
136 |
138 |
137 static void DMusicMidiPlaySong(const char* filename) |
139 static void DMusicMidiPlaySong(const char* filename) |
138 { |
140 { |
139 // set up the loader object info |
141 /* set up the loader object info */ |
140 DMUS_OBJECTDESC obj_desc; |
142 DMUS_OBJECTDESC obj_desc; |
141 ZeroMemory(&obj_desc, sizeof(obj_desc)); |
143 ZeroMemory(&obj_desc, sizeof(obj_desc)); |
142 obj_desc.dwSize = sizeof(obj_desc); |
144 obj_desc.dwSize = sizeof(obj_desc); |
143 obj_desc.guidClass = CLSID_DirectMusicSegment; |
145 obj_desc.guidClass = CLSID_DirectMusicSegment; |
144 obj_desc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH; |
146 obj_desc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH; |
146 CP_ACP, MB_PRECOMPOSED, |
148 CP_ACP, MB_PRECOMPOSED, |
147 filename, -1, |
149 filename, -1, |
148 obj_desc.wszFileName, lengthof(obj_desc.wszFileName) |
150 obj_desc.wszFileName, lengthof(obj_desc.wszFileName) |
149 ); |
151 ); |
150 |
152 |
151 // release the existing segment if we have any |
153 /* release the existing segment if we have any */ |
152 if (segment != NULL) { |
154 if (segment != NULL) { |
153 segment->Release(); |
155 segment->Release(); |
154 segment = NULL; |
156 segment = NULL; |
155 } |
157 } |
156 |
158 |
157 // make a new segment |
159 /* make a new segment */ |
158 if (FAILED(loader->GetObject( |
160 if (FAILED(loader->GetObject( |
159 &obj_desc, IID_IDirectMusicSegment, (LPVOID*)&segment |
161 &obj_desc, IID_IDirectMusicSegment, (LPVOID*)&segment |
160 ))) { |
162 ))) { |
161 DEBUG(driver, 0, "DirectMusic: GetObject failed"); |
163 DEBUG(driver, 0, "DirectMusic: GetObject failed"); |
162 return; |
164 return; |
163 } |
165 } |
164 |
166 |
165 // tell the segment what kind of data it contains |
167 /* tell the segment what kind of data it contains */ |
166 if (FAILED(segment->SetParam( |
168 if (FAILED(segment->SetParam( |
167 GUID_StandardMIDIFile, 0xFFFFFFFF, 0, 0, performance |
169 GUID_StandardMIDIFile, 0xFFFFFFFF, 0, 0, performance |
168 ))) { |
170 ))) { |
169 DEBUG(driver, 0, "DirectMusic: SetParam (MIDI file) failed"); |
171 DEBUG(driver, 0, "DirectMusic: SetParam (MIDI file) failed"); |
170 return; |
172 return; |
171 } |
173 } |
172 |
174 |
173 // tell the segment to 'download' the instruments |
175 /* tell the segment to 'download' the instruments */ |
174 if (FAILED(segment->SetParam(GUID_Download, 0xFFFFFFFF, 0, 0, performance))) { |
176 if (FAILED(segment->SetParam(GUID_Download, 0xFFFFFFFF, 0, 0, performance))) { |
175 DEBUG(driver, 0, "DirectMusic: failed to download instruments"); |
177 DEBUG(driver, 0, "DirectMusic: failed to download instruments"); |
176 return; |
178 return; |
177 } |
179 } |
178 |
180 |
179 // start playing the MIDI file |
181 /* start playing the MIDI file */ |
180 if (FAILED(performance->PlaySegment(segment, 0, 0, NULL))) { |
182 if (FAILED(performance->PlaySegment(segment, 0, 0, NULL))) { |
181 DEBUG(driver, 0, "DirectMusic: PlaySegment failed"); |
183 DEBUG(driver, 0, "DirectMusic: PlaySegment failed"); |
182 return; |
184 return; |
183 } |
185 } |
184 |
186 |