1 /* Debug and Helper Functions
3 * Copyright (C) 2004 Rok Mandeljc
4 * Copyright (C) 2004 Raphael Junqueira
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(dmfile
);
48 HRESULT
IDirectMusicUtils_IPersistStream_ParseDescGeneric (DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
, LPDMUS_OBJECTDESC pDesc
) {
50 switch (pChunk
->fccID
) {
51 case DMUS_FOURCC_GUID_CHUNK
: {
52 TRACE(": GUID chunk\n");
53 pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
54 IStream_Read (pStm
, &pDesc
->guidObject
, pChunk
->dwSize
, NULL
);
57 case DMUS_FOURCC_DATE_CHUNK
: {
58 TRACE(": file date chunk\n");
59 pDesc
->dwValidData
|= DMUS_OBJ_DATE
;
60 IStream_Read (pStm
, &pDesc
->ftDate
, pChunk
->dwSize
, NULL
);
63 case DMUS_FOURCC_NAME_CHUNK
: {
64 TRACE(": name chunk\n");
65 pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
66 IStream_Read (pStm
, pDesc
->wszName
, pChunk
->dwSize
, NULL
);
69 case DMUS_FOURCC_FILE_CHUNK
: {
70 TRACE(": file name chunk\n");
71 pDesc
->dwValidData
|= DMUS_OBJ_FILENAME
;
72 IStream_Read (pStm
, pDesc
->wszFileName
, pChunk
->dwSize
, NULL
);
75 case DMUS_FOURCC_VERSION_CHUNK
: {
76 TRACE(": version chunk\n");
77 pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
78 IStream_Read (pStm
, &pDesc
->vVersion
, pChunk
->dwSize
, NULL
);
81 case DMUS_FOURCC_CATEGORY_CHUNK
: {
82 TRACE(": category chunk\n");
83 pDesc
->dwValidData
|= DMUS_OBJ_CATEGORY
;
84 IStream_Read (pStm
, pDesc
->wszCategory
, pChunk
->dwSize
, NULL
);
95 HRESULT
IDirectMusicUtils_IPersistStream_ParseUNFOGeneric (DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
, LPDMUS_OBJECTDESC pDesc
) {
97 LARGE_INTEGER liMove
; /* used when skipping chunks */
100 * don't ask me why, but M$ puts INFO elements in UNFO list sometimes
101 * (though strings seem to be valid unicode)
103 switch (pChunk
->fccID
) {
105 case mmioFOURCC('I','N','A','M'):
106 case DMUS_FOURCC_UNAM_CHUNK
: {
107 TRACE(": name chunk\n");
108 pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
109 IStream_Read (pStm
, pDesc
->wszName
, pChunk
->dwSize
, NULL
);
110 TRACE(" - wszName: %s\n", debugstr_w(pDesc
->wszName
));
114 case mmioFOURCC('I','A','R','T'):
115 case DMUS_FOURCC_UART_CHUNK
: {
116 TRACE(": artist chunk (ignored)\n");
117 liMove
.QuadPart
= pChunk
->dwSize
;
118 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
121 case mmioFOURCC('I','C','O','P'):
122 case DMUS_FOURCC_UCOP_CHUNK
: {
123 TRACE(": copyright chunk (ignored)\n");
124 liMove
.QuadPart
= pChunk
->dwSize
;
125 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
128 case mmioFOURCC('I','S','B','J'):
129 case DMUS_FOURCC_USBJ_CHUNK
: {
130 TRACE(": subject chunk (ignored)\n");
131 liMove
.QuadPart
= pChunk
->dwSize
;
132 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
135 case mmioFOURCC('I','C','M','T'):
136 case DMUS_FOURCC_UCMT_CHUNK
: {
137 TRACE(": comment chunk (ignored)\n");
138 liMove
.QuadPart
= pChunk
->dwSize
;
139 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
150 HRESULT
IDirectMusicUtils_IPersistStream_ParseReference (LPPERSISTSTREAM iface
, DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
, IDirectMusicObject
** ppObject
) {
151 DMUS_PRIVATE_CHUNK Chunk
;
152 DWORD ListSize
[3], ListCount
[3];
153 LARGE_INTEGER liMove
; /* used when skipping chunks */
156 DMUS_IO_REFERENCE ref
;
157 DMUS_OBJECTDESC ref_desc
;
159 memset(&ref
, 0, sizeof(ref
));
160 memset(&ref_desc
, 0, sizeof(ref_desc
));
162 if (pChunk
->fccID
!= DMUS_FOURCC_REF_LIST
) {
163 ERR(": %s chunk should be a REF list\n", debugstr_fourcc (pChunk
->fccID
));
167 ListSize
[0] = pChunk
->dwSize
- sizeof(FOURCC
);
171 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
172 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
173 TRACE(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
175 hr
= IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk
, pStm
, &ref_desc
);
176 if (FAILED(hr
)) return hr
;
179 switch (Chunk
.fccID
) {
180 case DMUS_FOURCC_REF_CHUNK
: {
181 TRACE(": Reference chunk\n");
182 if (Chunk
.dwSize
!= sizeof(DMUS_IO_REFERENCE
)) return E_FAIL
;
183 IStream_Read (pStm
, &ref
, sizeof(DMUS_IO_REFERENCE
), NULL
);
184 TRACE(" - guidClassID: %s\n", debugstr_dmguid(&ref
.guidClassID
));
185 TRACE(" - dwValidData: %u\n", ref
.dwValidData
);
189 TRACE(": unknown chunk (irrelevant & skipping)\n");
190 liMove
.QuadPart
= Chunk
.dwSize
;
191 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
196 TRACE(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
197 } while (ListCount
[0] < ListSize
[0]);
199 ref_desc
.dwValidData
|= DMUS_OBJ_CLASS
;
200 ref_desc
.guidClass
= ref
.guidClassID
;
202 TRACE("** DM Reference Begin of Load ***\n");
203 TRACE("With Desc:\n");
204 debugstr_DMUS_OBJECTDESC(&ref_desc
);
207 LPDIRECTMUSICGETLOADER pGetLoader
= NULL
;
208 LPDIRECTMUSICLOADER pLoader
= NULL
;
210 IStream_QueryInterface (pStm
, &IID_IDirectMusicGetLoader
, (LPVOID
*)&pGetLoader
);
211 IDirectMusicGetLoader_GetLoader (pGetLoader
, &pLoader
);
212 IDirectMusicGetLoader_Release (pGetLoader
);
214 hr
= IDirectMusicLoader_GetObject (pLoader
, &ref_desc
, &IID_IDirectMusicObject
, (LPVOID
*)ppObject
);
215 IDirectMusicLoader_Release (pLoader
); /* release loader */
217 TRACE("** DM Reference End of Load ***\n");
222 /* FOURCC to string conversion for debug messages */
223 const char *debugstr_fourcc (DWORD fourcc
) {
224 if (!fourcc
) return "'null'";
225 return wine_dbg_sprintf ("\'%c%c%c%c\'",
226 (char)(fourcc
), (char)(fourcc
>> 8),
227 (char)(fourcc
>> 16), (char)(fourcc
>> 24));
230 /* DMUS_VERSION struct to string conversion for debug messages */
231 static const char *debugstr_dmversion (const DMUS_VERSION
*version
) {
232 if (!version
) return "'null'";
233 return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
234 HIWORD(version
->dwVersionMS
),LOWORD(version
->dwVersionMS
),
235 HIWORD(version
->dwVersionLS
), LOWORD(version
->dwVersionLS
));
238 /* month number into month name (for debugstr_filetime) */
239 static const char *debugstr_month (DWORD dwMonth
) {
241 case 1: return "January";
242 case 2: return "February";
243 case 3: return "March";
244 case 4: return "April";
245 case 5: return "May";
246 case 6: return "June";
247 case 7: return "July";
248 case 8: return "August";
249 case 9: return "September";
250 case 10: return "October";
251 case 11: return "November";
252 case 12: return "December";
253 default: return "Invalid";
257 /* FILETIME struct to string conversion for debug messages */
258 static const char *debugstr_filetime (const FILETIME
*time
) {
261 if (!time
) return "'null'";
263 FileTimeToSystemTime (time
, &sysTime
);
265 return wine_dbg_sprintf ("\'%02i. %s %04i %02i:%02i:%02i\'",
266 sysTime
.wDay
, debugstr_month(sysTime
.wMonth
), sysTime
.wYear
,
267 sysTime
.wHour
, sysTime
.wMinute
, sysTime
.wSecond
);
270 /* returns name of given GUID */
271 const char *debugstr_dmguid (const GUID
*id
) {
272 static const guid_info guids
[] = {
274 GE(CLSID_AudioVBScript
),
275 GE(CLSID_DirectMusic
),
276 GE(CLSID_DirectMusicAudioPath
),
277 GE(CLSID_DirectMusicAudioPathConfig
),
278 GE(CLSID_DirectMusicAuditionTrack
),
279 GE(CLSID_DirectMusicBand
),
280 GE(CLSID_DirectMusicBandTrack
),
281 GE(CLSID_DirectMusicChordMapTrack
),
282 GE(CLSID_DirectMusicChordMap
),
283 GE(CLSID_DirectMusicChordTrack
),
284 GE(CLSID_DirectMusicCollection
),
285 GE(CLSID_DirectMusicCommandTrack
),
286 GE(CLSID_DirectMusicComposer
),
287 GE(CLSID_DirectMusicContainer
),
288 GE(CLSID_DirectMusicGraph
),
289 GE(CLSID_DirectMusicLoader
),
290 GE(CLSID_DirectMusicLyricsTrack
),
291 GE(CLSID_DirectMusicMarkerTrack
),
292 GE(CLSID_DirectMusicMelodyFormulationTrack
),
293 GE(CLSID_DirectMusicMotifTrack
),
294 GE(CLSID_DirectMusicMuteTrack
),
295 GE(CLSID_DirectMusicParamControlTrack
),
296 GE(CLSID_DirectMusicPatternTrack
),
297 GE(CLSID_DirectMusicPerformance
),
298 GE(CLSID_DirectMusicScript
),
299 GE(CLSID_DirectMusicScriptAutoImpSegment
),
300 GE(CLSID_DirectMusicScriptAutoImpPerformance
),
301 GE(CLSID_DirectMusicScriptAutoImpSegmentState
),
302 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig
),
303 GE(CLSID_DirectMusicScriptAutoImpAudioPath
),
304 GE(CLSID_DirectMusicScriptAutoImpSong
),
305 GE(CLSID_DirectMusicScriptSourceCodeLoader
),
306 GE(CLSID_DirectMusicScriptTrack
),
307 GE(CLSID_DirectMusicSection
),
308 GE(CLSID_DirectMusicSegment
),
309 GE(CLSID_DirectMusicSegmentState
),
310 GE(CLSID_DirectMusicSegmentTriggerTrack
),
311 GE(CLSID_DirectMusicSegTriggerTrack
),
312 GE(CLSID_DirectMusicSeqTrack
),
313 GE(CLSID_DirectMusicSignPostTrack
),
314 GE(CLSID_DirectMusicSong
),
315 GE(CLSID_DirectMusicStyle
),
316 GE(CLSID_DirectMusicStyleTrack
),
317 GE(CLSID_DirectMusicSynth
),
318 GE(CLSID_DirectMusicSynthSink
),
319 GE(CLSID_DirectMusicSysExTrack
),
320 GE(CLSID_DirectMusicTemplate
),
321 GE(CLSID_DirectMusicTempoTrack
),
322 GE(CLSID_DirectMusicTimeSigTrack
),
323 GE(CLSID_DirectMusicWaveTrack
),
324 GE(CLSID_DirectSoundWave
),
326 GE(IID_IDirectMusic
),
327 GE(IID_IDirectMusic2
),
328 GE(IID_IDirectMusic8
),
329 GE(IID_IDirectMusicAudioPath
),
330 GE(IID_IDirectMusicBand
),
331 GE(IID_IDirectMusicBuffer
),
332 GE(IID_IDirectMusicChordMap
),
333 GE(IID_IDirectMusicCollection
),
334 GE(IID_IDirectMusicComposer
),
335 GE(IID_IDirectMusicContainer
),
336 GE(IID_IDirectMusicDownload
),
337 GE(IID_IDirectMusicDownloadedInstrument
),
338 GE(IID_IDirectMusicGetLoader
),
339 GE(IID_IDirectMusicGraph
),
340 GE(IID_IDirectMusicInstrument
),
341 GE(IID_IDirectMusicLoader
),
342 GE(IID_IDirectMusicLoader8
),
343 GE(IID_IDirectMusicObject
),
344 GE(IID_IDirectMusicPatternTrack
),
345 GE(IID_IDirectMusicPerformance
),
346 GE(IID_IDirectMusicPerformance2
),
347 GE(IID_IDirectMusicPerformance8
),
348 GE(IID_IDirectMusicPort
),
349 GE(IID_IDirectMusicPortDownload
),
350 GE(IID_IDirectMusicScript
),
351 GE(IID_IDirectMusicSegment
),
352 GE(IID_IDirectMusicSegment2
),
353 GE(IID_IDirectMusicSegment8
),
354 GE(IID_IDirectMusicSegmentState
),
355 GE(IID_IDirectMusicSegmentState8
),
356 GE(IID_IDirectMusicStyle
),
357 GE(IID_IDirectMusicStyle8
),
358 GE(IID_IDirectMusicSynth
),
359 GE(IID_IDirectMusicSynth8
),
360 GE(IID_IDirectMusicSynthSink
),
361 GE(IID_IDirectMusicThru
),
362 GE(IID_IDirectMusicTool
),
363 GE(IID_IDirectMusicTool8
),
364 GE(IID_IDirectMusicTrack
),
365 GE(IID_IDirectMusicTrack8
),
367 GE(IID_IPersistStream
),
369 GE(IID_IClassFactory
),
371 GE(GUID_DirectMusicAllTypes
),
372 GE(GUID_NOTIFICATION_CHORD
),
373 GE(GUID_NOTIFICATION_COMMAND
),
374 GE(GUID_NOTIFICATION_MEASUREANDBEAT
),
375 GE(GUID_NOTIFICATION_PERFORMANCE
),
376 GE(GUID_NOTIFICATION_RECOMPOSE
),
377 GE(GUID_NOTIFICATION_SEGMENT
),
380 GE(GUID_CommandParam
),
381 GE(GUID_CommandParam2
),
382 GE(GUID_CommandParamNext
),
383 GE(GUID_IDirectMusicBand
),
384 GE(GUID_IDirectMusicChordMap
),
385 GE(GUID_IDirectMusicStyle
),
387 GE(GUID_Play_Marker
),
388 GE(GUID_RhythmParam
),
390 GE(GUID_TimeSignature
),
391 GE(GUID_Valid_Start_Time
),
392 GE(GUID_Clear_All_Bands
),
393 GE(GUID_ConnectToDLSCollection
),
394 GE(GUID_Disable_Auto_Download
),
395 GE(GUID_DisableTempo
),
396 GE(GUID_DisableTimeSig
),
398 GE(GUID_DownloadToAudioPath
),
399 GE(GUID_Enable_Auto_Download
),
400 GE(GUID_EnableTempo
),
401 GE(GUID_EnableTimeSig
),
402 GE(GUID_IgnoreBankSelectForGM
),
403 GE(GUID_SeedVariations
),
404 GE(GUID_StandardMIDIFile
),
406 GE(GUID_UnloadFromAudioPath
),
408 GE(GUID_PerfMasterTempo
),
409 GE(GUID_PerfMasterVolume
),
410 GE(GUID_PerfMasterGrooveLevel
),
411 GE(GUID_PerfAutoDownload
),
412 GE(GUID_DefaultGMCollection
),
413 GE(GUID_Synth_Default
),
414 GE(GUID_Buffer_Reverb
),
415 GE(GUID_Buffer_EnvReverb
),
416 GE(GUID_Buffer_Stereo
),
417 GE(GUID_Buffer_3D_Dry
),
418 GE(GUID_Buffer_Mono
),
419 GE(GUID_DMUS_PROP_GM_Hardware
),
420 GE(GUID_DMUS_PROP_GS_Capable
),
421 GE(GUID_DMUS_PROP_GS_Hardware
),
422 GE(GUID_DMUS_PROP_DLS1
),
423 GE(GUID_DMUS_PROP_DLS2
),
424 GE(GUID_DMUS_PROP_Effects
),
425 GE(GUID_DMUS_PROP_INSTRUMENT2
),
426 GE(GUID_DMUS_PROP_LegacyCaps
),
427 GE(GUID_DMUS_PROP_MemorySize
),
428 GE(GUID_DMUS_PROP_SampleMemorySize
),
429 GE(GUID_DMUS_PROP_SamplePlaybackRate
),
430 GE(GUID_DMUS_PROP_SetSynthSink
),
431 GE(GUID_DMUS_PROP_SinkUsesDSound
),
432 GE(GUID_DMUS_PROP_SynthSink_DSOUND
),
433 GE(GUID_DMUS_PROP_SynthSink_WAVE
),
434 GE(GUID_DMUS_PROP_Volume
),
435 GE(GUID_DMUS_PROP_WavesReverb
),
436 GE(GUID_DMUS_PROP_WriteLatency
),
437 GE(GUID_DMUS_PROP_WritePeriod
),
438 GE(GUID_DMUS_PROP_XG_Capable
),
439 GE(GUID_DMUS_PROP_XG_Hardware
)
444 if (!id
) return "(null)";
445 for (i
= 0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++) {
446 if (IsEqualGUID(id
, guids
[i
].guid
))
447 return guids
[i
].name
;
450 /* if we didn't find it, act like standard debugstr_guid */
451 return debugstr_guid(id
);
454 /* generic flag-dumping function */
455 static const char* debugstr_flags (DWORD flags
, const flag_info
* names
, size_t num_names
){
456 static char buffer
[128] = "", *ptr
= &buffer
[0];
458 int size
= sizeof(buffer
);
460 for (i
=0; i
< num_names
; i
++) {
461 if ((flags
& names
[i
].val
)) {
462 int cnt
= snprintf(ptr
, size
, "%s ", names
[i
].name
);
463 if (cnt
< 0 || cnt
>= size
) break;
473 /* dump DMUS_OBJ flags */
474 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask
) {
475 static const flag_info flags
[] = {
479 FE(DMUS_OBJ_CATEGORY
),
480 FE(DMUS_OBJ_FILENAME
),
481 FE(DMUS_OBJ_FULLPATH
),
483 FE(DMUS_OBJ_VERSION
),
489 return debugstr_flags (flagmask
, flags
, sizeof(flags
)/sizeof(flags
[0]));
492 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc
) {
494 char buffer
[1024], *ptr
= buffer
;
496 ptr
+= sprintf(ptr
, "DMUS_OBJECTDESC (%p):\n", pDesc
);
497 ptr
+= sprintf(ptr
, " - dwSize = 0x%08X\n", pDesc
->dwSize
);
498 ptr
+= sprintf(ptr
, " - dwValidData = 0x%08X ( %s)\n", pDesc
->dwValidData
, debugstr_DMUS_OBJ_FLAGS (pDesc
->dwValidData
));
499 if (pDesc
->dwValidData
& DMUS_OBJ_CLASS
) ptr
+= sprintf(ptr
, " - guidClass = %s\n", debugstr_dmguid(&pDesc
->guidClass
));
500 if (pDesc
->dwValidData
& DMUS_OBJ_OBJECT
) ptr
+= sprintf(ptr
, " - guidObject = %s\n", debugstr_guid(&pDesc
->guidObject
));
501 if (pDesc
->dwValidData
& DMUS_OBJ_DATE
) ptr
+= sprintf(ptr
, " - ftDate = %s\n", debugstr_filetime (&pDesc
->ftDate
));
502 if (pDesc
->dwValidData
& DMUS_OBJ_VERSION
) ptr
+= sprintf(ptr
, " - vVersion = %s\n", debugstr_dmversion(&pDesc
->vVersion
));
503 if (pDesc
->dwValidData
& DMUS_OBJ_NAME
) ptr
+= sprintf(ptr
, " - wszName = %s\n", debugstr_w(pDesc
->wszName
));
504 if (pDesc
->dwValidData
& DMUS_OBJ_CATEGORY
) ptr
+= sprintf(ptr
, " - wszCategory = %s\n", debugstr_w(pDesc
->wszCategory
));
505 if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
) ptr
+= sprintf(ptr
, " - wszFileName = %s\n", debugstr_w(pDesc
->wszFileName
));
506 if (pDesc
->dwValidData
& DMUS_OBJ_MEMORY
) ptr
+= sprintf(ptr
, " - llMemLength = 0x%s\n - pbMemData = %p\n",
507 wine_dbgstr_longlong(pDesc
->llMemLength
), pDesc
->pbMemData
);
508 if (pDesc
->dwValidData
& DMUS_OBJ_STREAM
) ptr
+= sprintf(ptr
, " - pStream = %p\n", pDesc
->pStream
);
510 return wine_dbg_sprintf("%s", buffer
);
512 return wine_dbg_sprintf("(NULL)");