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
33 #include "wine/debug.h"
34 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(dmfile
);
45 HRESULT
IDirectMusicUtils_IPersistStream_ParseDescGeneric (DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
, LPDMUS_OBJECTDESC pDesc
) {
47 switch (pChunk
->fccID
) {
48 case DMUS_FOURCC_GUID_CHUNK
: {
49 TRACE(": GUID chunk\n");
50 pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
51 IStream_Read (pStm
, &pDesc
->guidObject
, pChunk
->dwSize
, NULL
);
54 case DMUS_FOURCC_DATE_CHUNK
: {
55 TRACE(": file date chunk\n");
56 pDesc
->dwValidData
|= DMUS_OBJ_DATE
;
57 IStream_Read (pStm
, &pDesc
->ftDate
, pChunk
->dwSize
, NULL
);
60 case DMUS_FOURCC_NAME_CHUNK
: {
61 TRACE(": name chunk\n");
62 pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
63 IStream_Read (pStm
, pDesc
->wszName
, pChunk
->dwSize
, NULL
);
66 case DMUS_FOURCC_FILE_CHUNK
: {
67 TRACE(": file name chunk\n");
68 pDesc
->dwValidData
|= DMUS_OBJ_FILENAME
;
69 IStream_Read (pStm
, pDesc
->wszFileName
, pChunk
->dwSize
, NULL
);
72 case DMUS_FOURCC_VERSION_CHUNK
: {
73 TRACE(": version chunk\n");
74 pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
75 IStream_Read (pStm
, &pDesc
->vVersion
, pChunk
->dwSize
, NULL
);
78 case DMUS_FOURCC_CATEGORY_CHUNK
: {
79 TRACE(": category chunk\n");
80 pDesc
->dwValidData
|= DMUS_OBJ_CATEGORY
;
81 IStream_Read (pStm
, pDesc
->wszCategory
, pChunk
->dwSize
, NULL
);
92 HRESULT
IDirectMusicUtils_IPersistStream_ParseUNFOGeneric (DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
, LPDMUS_OBJECTDESC pDesc
) {
94 LARGE_INTEGER liMove
; /* used when skipping chunks */
97 * don't ask me why, but M$ puts INFO elements in UNFO list sometimes
98 * (though strings seem to be valid unicode)
100 switch (pChunk
->fccID
) {
102 case mmioFOURCC('I','N','A','M'):
103 case DMUS_FOURCC_UNAM_CHUNK
: {
104 TRACE(": name chunk\n");
105 pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
106 IStream_Read (pStm
, pDesc
->wszName
, pChunk
->dwSize
, NULL
);
107 TRACE(" - wszName: %s\n", debugstr_w(pDesc
->wszName
));
111 case mmioFOURCC('I','A','R','T'):
112 case DMUS_FOURCC_UART_CHUNK
: {
113 TRACE(": artist chunk (ignored)\n");
114 liMove
.QuadPart
= pChunk
->dwSize
;
115 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
118 case mmioFOURCC('I','C','O','P'):
119 case DMUS_FOURCC_UCOP_CHUNK
: {
120 TRACE(": copyright chunk (ignored)\n");
121 liMove
.QuadPart
= pChunk
->dwSize
;
122 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
125 case mmioFOURCC('I','S','B','J'):
126 case DMUS_FOURCC_USBJ_CHUNK
: {
127 TRACE(": subject chunk (ignored)\n");
128 liMove
.QuadPart
= pChunk
->dwSize
;
129 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
132 case mmioFOURCC('I','C','M','T'):
133 case DMUS_FOURCC_UCMT_CHUNK
: {
134 TRACE(": comment chunk (ignored)\n");
135 liMove
.QuadPart
= pChunk
->dwSize
;
136 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
147 HRESULT
IDirectMusicUtils_IPersistStream_ParseReference (LPPERSISTSTREAM iface
, DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
, IDirectMusicObject
** ppObject
) {
148 DMUS_PRIVATE_CHUNK Chunk
;
149 DWORD ListSize
[3], ListCount
[3];
150 LARGE_INTEGER liMove
; /* used when skipping chunks */
153 DMUS_IO_REFERENCE ref
;
154 DMUS_OBJECTDESC ref_desc
;
156 memset(&ref
, 0, sizeof(ref
));
157 memset(&ref_desc
, 0, sizeof(ref_desc
));
159 if (pChunk
->fccID
!= DMUS_FOURCC_REF_LIST
) {
160 ERR(": %s chunk should be a REF list\n", debugstr_fourcc (pChunk
->fccID
));
164 ListSize
[0] = pChunk
->dwSize
- sizeof(FOURCC
);
168 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
169 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
170 TRACE(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
172 hr
= IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk
, pStm
, &ref_desc
);
173 if (FAILED(hr
)) return hr
;
176 switch (Chunk
.fccID
) {
177 case DMUS_FOURCC_REF_CHUNK
: {
178 TRACE(": Reference chunk\n");
179 if (Chunk
.dwSize
!= sizeof(DMUS_IO_REFERENCE
)) return E_FAIL
;
180 IStream_Read (pStm
, &ref
, sizeof(DMUS_IO_REFERENCE
), NULL
);
181 TRACE(" - guidClassID: %s\n", debugstr_dmguid(&ref
.guidClassID
));
182 TRACE(" - dwValidData: %u\n", ref
.dwValidData
);
186 TRACE(": unknown chunk (irrevelant & skipping)\n");
187 liMove
.QuadPart
= Chunk
.dwSize
;
188 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
193 TRACE(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
194 } while (ListCount
[0] < ListSize
[0]);
196 ref_desc
.dwValidData
|= DMUS_OBJ_CLASS
;
197 ref_desc
.guidClass
= ref
.guidClassID
;
199 TRACE("** DM Reference Begin of Load ***\n");
200 TRACE("With Desc:\n");
201 debugstr_DMUS_OBJECTDESC(&ref_desc
);
204 LPDIRECTMUSICGETLOADER pGetLoader
= NULL
;
205 LPDIRECTMUSICLOADER pLoader
= NULL
;
207 IStream_QueryInterface (pStm
, &IID_IDirectMusicGetLoader
, (LPVOID
*)&pGetLoader
);
208 IDirectMusicGetLoader_GetLoader (pGetLoader
, &pLoader
);
209 IDirectMusicGetLoader_Release (pGetLoader
);
211 hr
= IDirectMusicLoader_GetObject (pLoader
, &ref_desc
, &IID_IDirectMusicObject
, (LPVOID
*)ppObject
);
212 IDirectMusicLoader_Release (pLoader
); /* release loader */
214 TRACE("** DM Reference End of Load ***\n");
219 /* FOURCC to string conversion for debug messages */
220 const char *debugstr_fourcc (DWORD fourcc
) {
221 if (!fourcc
) return "'null'";
222 return wine_dbg_sprintf ("\'%c%c%c%c\'",
223 (char)(fourcc
), (char)(fourcc
>> 8),
224 (char)(fourcc
>> 16), (char)(fourcc
>> 24));
227 /* DMUS_VERSION struct to string conversion for debug messages */
228 static const char *debugstr_dmversion (const DMUS_VERSION
*version
) {
229 if (!version
) return "'null'";
230 return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
231 HIWORD(version
->dwVersionMS
),LOWORD(version
->dwVersionMS
),
232 HIWORD(version
->dwVersionLS
), LOWORD(version
->dwVersionLS
));
235 /* month number into month name (for debugstr_filetime) */
236 static const char *debugstr_month (DWORD dwMonth
) {
238 case 1: return "January";
239 case 2: return "February";
240 case 3: return "March";
241 case 4: return "April";
242 case 5: return "May";
243 case 6: return "June";
244 case 7: return "July";
245 case 8: return "August";
246 case 9: return "September";
247 case 10: return "October";
248 case 11: return "November";
249 case 12: return "December";
250 default: return "Invalid";
254 /* FILETIME struct to string conversion for debug messages */
255 static const char *debugstr_filetime (const FILETIME
*time
) {
258 if (!time
) return "'null'";
260 FileTimeToSystemTime (time
, &sysTime
);
262 return wine_dbg_sprintf ("\'%02i. %s %04i %02i:%02i:%02i\'",
263 sysTime
.wDay
, debugstr_month(sysTime
.wMonth
), sysTime
.wYear
,
264 sysTime
.wHour
, sysTime
.wMinute
, sysTime
.wSecond
);
267 /* returns name of given GUID */
268 const char *debugstr_dmguid (const GUID
*id
) {
269 static const guid_info guids
[] = {
271 GE(CLSID_AudioVBScript
),
272 GE(CLSID_DirectMusic
),
273 GE(CLSID_DirectMusicAudioPath
),
274 GE(CLSID_DirectMusicAudioPathConfig
),
275 GE(CLSID_DirectMusicAuditionTrack
),
276 GE(CLSID_DirectMusicBand
),
277 GE(CLSID_DirectMusicBandTrack
),
278 GE(CLSID_DirectMusicChordMapTrack
),
279 GE(CLSID_DirectMusicChordMap
),
280 GE(CLSID_DirectMusicChordTrack
),
281 GE(CLSID_DirectMusicCollection
),
282 GE(CLSID_DirectMusicCommandTrack
),
283 GE(CLSID_DirectMusicComposer
),
284 GE(CLSID_DirectMusicContainer
),
285 GE(CLSID_DirectMusicGraph
),
286 GE(CLSID_DirectMusicLoader
),
287 GE(CLSID_DirectMusicLyricsTrack
),
288 GE(CLSID_DirectMusicMarkerTrack
),
289 GE(CLSID_DirectMusicMelodyFormulationTrack
),
290 GE(CLSID_DirectMusicMotifTrack
),
291 GE(CLSID_DirectMusicMuteTrack
),
292 GE(CLSID_DirectMusicParamControlTrack
),
293 GE(CLSID_DirectMusicPatternTrack
),
294 GE(CLSID_DirectMusicPerformance
),
295 GE(CLSID_DirectMusicScript
),
296 GE(CLSID_DirectMusicScriptAutoImpSegment
),
297 GE(CLSID_DirectMusicScriptAutoImpPerformance
),
298 GE(CLSID_DirectMusicScriptAutoImpSegmentState
),
299 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig
),
300 GE(CLSID_DirectMusicScriptAutoImpAudioPath
),
301 GE(CLSID_DirectMusicScriptAutoImpSong
),
302 GE(CLSID_DirectMusicScriptSourceCodeLoader
),
303 GE(CLSID_DirectMusicScriptTrack
),
304 GE(CLSID_DirectMusicSection
),
305 GE(CLSID_DirectMusicSegment
),
306 GE(CLSID_DirectMusicSegmentState
),
307 GE(CLSID_DirectMusicSegmentTriggerTrack
),
308 GE(CLSID_DirectMusicSegTriggerTrack
),
309 GE(CLSID_DirectMusicSeqTrack
),
310 GE(CLSID_DirectMusicSignPostTrack
),
311 GE(CLSID_DirectMusicSong
),
312 GE(CLSID_DirectMusicStyle
),
313 GE(CLSID_DirectMusicStyleTrack
),
314 GE(CLSID_DirectMusicSynth
),
315 GE(CLSID_DirectMusicSynthSink
),
316 GE(CLSID_DirectMusicSysExTrack
),
317 GE(CLSID_DirectMusicTemplate
),
318 GE(CLSID_DirectMusicTempoTrack
),
319 GE(CLSID_DirectMusicTimeSigTrack
),
320 GE(CLSID_DirectMusicWaveTrack
),
321 GE(CLSID_DirectSoundWave
),
323 GE(IID_IDirectMusic
),
324 GE(IID_IDirectMusic2
),
325 GE(IID_IDirectMusic8
),
326 GE(IID_IDirectMusicAudioPath
),
327 GE(IID_IDirectMusicBand
),
328 GE(IID_IDirectMusicBuffer
),
329 GE(IID_IDirectMusicChordMap
),
330 GE(IID_IDirectMusicCollection
),
331 GE(IID_IDirectMusicComposer
),
332 GE(IID_IDirectMusicContainer
),
333 GE(IID_IDirectMusicDownload
),
334 GE(IID_IDirectMusicDownloadedInstrument
),
335 GE(IID_IDirectMusicGetLoader
),
336 GE(IID_IDirectMusicGraph
),
337 GE(IID_IDirectMusicInstrument
),
338 GE(IID_IDirectMusicLoader
),
339 GE(IID_IDirectMusicLoader8
),
340 GE(IID_IDirectMusicObject
),
341 GE(IID_IDirectMusicPatternTrack
),
342 GE(IID_IDirectMusicPerformance
),
343 GE(IID_IDirectMusicPerformance2
),
344 GE(IID_IDirectMusicPerformance8
),
345 GE(IID_IDirectMusicPort
),
346 GE(IID_IDirectMusicPortDownload
),
347 GE(IID_IDirectMusicScript
),
348 GE(IID_IDirectMusicSegment
),
349 GE(IID_IDirectMusicSegment2
),
350 GE(IID_IDirectMusicSegment8
),
351 GE(IID_IDirectMusicSegmentState
),
352 GE(IID_IDirectMusicSegmentState8
),
353 GE(IID_IDirectMusicStyle
),
354 GE(IID_IDirectMusicStyle8
),
355 GE(IID_IDirectMusicSynth
),
356 GE(IID_IDirectMusicSynth8
),
357 GE(IID_IDirectMusicSynthSink
),
358 GE(IID_IDirectMusicThru
),
359 GE(IID_IDirectMusicTool
),
360 GE(IID_IDirectMusicTool8
),
361 GE(IID_IDirectMusicTrack
),
362 GE(IID_IDirectMusicTrack8
),
364 GE(IID_IPersistStream
),
366 GE(IID_IClassFactory
),
368 GE(GUID_DirectMusicAllTypes
),
369 GE(GUID_NOTIFICATION_CHORD
),
370 GE(GUID_NOTIFICATION_COMMAND
),
371 GE(GUID_NOTIFICATION_MEASUREANDBEAT
),
372 GE(GUID_NOTIFICATION_PERFORMANCE
),
373 GE(GUID_NOTIFICATION_RECOMPOSE
),
374 GE(GUID_NOTIFICATION_SEGMENT
),
377 GE(GUID_CommandParam
),
378 GE(GUID_CommandParam2
),
379 GE(GUID_CommandParamNext
),
380 GE(GUID_IDirectMusicBand
),
381 GE(GUID_IDirectMusicChordMap
),
382 GE(GUID_IDirectMusicStyle
),
384 GE(GUID_Play_Marker
),
385 GE(GUID_RhythmParam
),
387 GE(GUID_TimeSignature
),
388 GE(GUID_Valid_Start_Time
),
389 GE(GUID_Clear_All_Bands
),
390 GE(GUID_ConnectToDLSCollection
),
391 GE(GUID_Disable_Auto_Download
),
392 GE(GUID_DisableTempo
),
393 GE(GUID_DisableTimeSig
),
395 GE(GUID_DownloadToAudioPath
),
396 GE(GUID_Enable_Auto_Download
),
397 GE(GUID_EnableTempo
),
398 GE(GUID_EnableTimeSig
),
399 GE(GUID_IgnoreBankSelectForGM
),
400 GE(GUID_SeedVariations
),
401 GE(GUID_StandardMIDIFile
),
403 GE(GUID_UnloadFromAudioPath
),
405 GE(GUID_PerfMasterTempo
),
406 GE(GUID_PerfMasterVolume
),
407 GE(GUID_PerfMasterGrooveLevel
),
408 GE(GUID_PerfAutoDownload
),
409 GE(GUID_DefaultGMCollection
),
410 GE(GUID_Synth_Default
),
411 GE(GUID_Buffer_Reverb
),
412 GE(GUID_Buffer_EnvReverb
),
413 GE(GUID_Buffer_Stereo
),
414 GE(GUID_Buffer_3D_Dry
),
415 GE(GUID_Buffer_Mono
),
416 GE(GUID_DMUS_PROP_GM_Hardware
),
417 GE(GUID_DMUS_PROP_GS_Capable
),
418 GE(GUID_DMUS_PROP_GS_Hardware
),
419 GE(GUID_DMUS_PROP_DLS1
),
420 GE(GUID_DMUS_PROP_DLS2
),
421 GE(GUID_DMUS_PROP_Effects
),
422 GE(GUID_DMUS_PROP_INSTRUMENT2
),
423 GE(GUID_DMUS_PROP_LegacyCaps
),
424 GE(GUID_DMUS_PROP_MemorySize
),
425 GE(GUID_DMUS_PROP_SampleMemorySize
),
426 GE(GUID_DMUS_PROP_SamplePlaybackRate
),
427 GE(GUID_DMUS_PROP_SetSynthSink
),
428 GE(GUID_DMUS_PROP_SinkUsesDSound
),
429 GE(GUID_DMUS_PROP_SynthSink_DSOUND
),
430 GE(GUID_DMUS_PROP_SynthSink_WAVE
),
431 GE(GUID_DMUS_PROP_Volume
),
432 GE(GUID_DMUS_PROP_WavesReverb
),
433 GE(GUID_DMUS_PROP_WriteLatency
),
434 GE(GUID_DMUS_PROP_WritePeriod
),
435 GE(GUID_DMUS_PROP_XG_Capable
),
436 GE(GUID_DMUS_PROP_XG_Hardware
)
441 if (!id
) return "(null)";
442 for (i
= 0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++) {
443 if (IsEqualGUID(id
, guids
[i
].guid
))
444 return guids
[i
].name
;
447 /* if we didn't find it, act like standard debugstr_guid */
448 return debugstr_guid(id
);
451 /* generic flag-dumping function */
452 static const char* debugstr_flags (DWORD flags
, const flag_info
* names
, size_t num_names
){
453 static char buffer
[128] = "", *ptr
= &buffer
[0];
455 int size
= sizeof(buffer
);
457 for (i
=0; i
< num_names
; i
++) {
458 if ((flags
& names
[i
].val
)) {
459 int cnt
= snprintf(ptr
, size
, "%s ", names
[i
].name
);
460 if (cnt
< 0 || cnt
>= size
) break;
470 /* dump DMUS_OBJ flags */
471 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask
) {
472 static const flag_info flags
[] = {
476 FE(DMUS_OBJ_CATEGORY
),
477 FE(DMUS_OBJ_FILENAME
),
478 FE(DMUS_OBJ_FULLPATH
),
480 FE(DMUS_OBJ_VERSION
),
486 return debugstr_flags (flagmask
, flags
, sizeof(flags
)/sizeof(flags
[0]));
489 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc
) {
491 char buffer
[1024], *ptr
= buffer
;
493 ptr
+= sprintf(ptr
, "DMUS_OBJECTDESC (%p):\n", pDesc
);
494 ptr
+= sprintf(ptr
, " - dwSize = 0x%08X\n", pDesc
->dwSize
);
495 ptr
+= sprintf(ptr
, " - dwValidData = 0x%08X ( %s)\n", pDesc
->dwValidData
, debugstr_DMUS_OBJ_FLAGS (pDesc
->dwValidData
));
496 if (pDesc
->dwValidData
& DMUS_OBJ_CLASS
) ptr
+= sprintf(ptr
, " - guidClass = %s\n", debugstr_dmguid(&pDesc
->guidClass
));
497 if (pDesc
->dwValidData
& DMUS_OBJ_OBJECT
) ptr
+= sprintf(ptr
, " - guidObject = %s\n", debugstr_guid(&pDesc
->guidObject
));
498 if (pDesc
->dwValidData
& DMUS_OBJ_DATE
) ptr
+= sprintf(ptr
, " - ftDate = %s\n", debugstr_filetime (&pDesc
->ftDate
));
499 if (pDesc
->dwValidData
& DMUS_OBJ_VERSION
) ptr
+= sprintf(ptr
, " - vVersion = %s\n", debugstr_dmversion(&pDesc
->vVersion
));
500 if (pDesc
->dwValidData
& DMUS_OBJ_NAME
) ptr
+= sprintf(ptr
, " - wszName = %s\n", debugstr_w(pDesc
->wszName
));
501 if (pDesc
->dwValidData
& DMUS_OBJ_CATEGORY
) ptr
+= sprintf(ptr
, " - wszCategory = %s\n", debugstr_w(pDesc
->wszCategory
));
502 if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
) ptr
+= sprintf(ptr
, " - wszFileName = %s\n", debugstr_w(pDesc
->wszFileName
));
503 if (pDesc
->dwValidData
& DMUS_OBJ_MEMORY
) ptr
+= sprintf(ptr
, " - llMemLength = 0x%s\n - pbMemData = %p\n",
504 wine_dbgstr_longlong(pDesc
->llMemLength
), pDesc
->pbMemData
);
505 if (pDesc
->dwValidData
& DMUS_OBJ_STREAM
) ptr
+= sprintf(ptr
, " - pStream = %p\n", pDesc
->pStream
);
507 return wine_dbg_sprintf("%s", buffer
);
509 return wine_dbg_sprintf("(NULL)");