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_DirectMusicAudioPathConfig
),
277 GE(CLSID_DirectMusicAuditionTrack
),
278 GE(CLSID_DirectMusicBand
),
279 GE(CLSID_DirectMusicBandTrack
),
280 GE(CLSID_DirectMusicChordMapTrack
),
281 GE(CLSID_DirectMusicChordMap
),
282 GE(CLSID_DirectMusicChordTrack
),
283 GE(CLSID_DirectMusicCollection
),
284 GE(CLSID_DirectMusicCommandTrack
),
285 GE(CLSID_DirectMusicComposer
),
286 GE(CLSID_DirectMusicContainer
),
287 GE(CLSID_DirectMusicGraph
),
288 GE(CLSID_DirectMusicLoader
),
289 GE(CLSID_DirectMusicLyricsTrack
),
290 GE(CLSID_DirectMusicMarkerTrack
),
291 GE(CLSID_DirectMusicMelodyFormulationTrack
),
292 GE(CLSID_DirectMusicMotifTrack
),
293 GE(CLSID_DirectMusicMuteTrack
),
294 GE(CLSID_DirectMusicParamControlTrack
),
295 GE(CLSID_DirectMusicPatternTrack
),
296 GE(CLSID_DirectMusicPerformance
),
297 GE(CLSID_DirectMusicScript
),
298 GE(CLSID_DirectMusicScriptAutoImpSegment
),
299 GE(CLSID_DirectMusicScriptAutoImpPerformance
),
300 GE(CLSID_DirectMusicScriptAutoImpSegmentState
),
301 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig
),
302 GE(CLSID_DirectMusicScriptAutoImpAudioPath
),
303 GE(CLSID_DirectMusicScriptAutoImpSong
),
304 GE(CLSID_DirectMusicScriptSourceCodeLoader
),
305 GE(CLSID_DirectMusicScriptTrack
),
306 GE(CLSID_DirectMusicSection
),
307 GE(CLSID_DirectMusicSegment
),
308 GE(CLSID_DirectMusicSegmentState
),
309 GE(CLSID_DirectMusicSegmentTriggerTrack
),
310 GE(CLSID_DirectMusicSegTriggerTrack
),
311 GE(CLSID_DirectMusicSeqTrack
),
312 GE(CLSID_DirectMusicSignPostTrack
),
313 GE(CLSID_DirectMusicSong
),
314 GE(CLSID_DirectMusicStyle
),
315 GE(CLSID_DirectMusicStyleTrack
),
316 GE(CLSID_DirectMusicSynth
),
317 GE(CLSID_DirectMusicSynthSink
),
318 GE(CLSID_DirectMusicSysExTrack
),
319 GE(CLSID_DirectMusicTemplate
),
320 GE(CLSID_DirectMusicTempoTrack
),
321 GE(CLSID_DirectMusicTimeSigTrack
),
322 GE(CLSID_DirectMusicWaveTrack
),
323 GE(CLSID_DirectSoundWave
),
325 GE(IID_IDirectMusic
),
326 GE(IID_IDirectMusic2
),
327 GE(IID_IDirectMusic8
),
328 GE(IID_IDirectMusicAudioPath
),
329 GE(IID_IDirectMusicBand
),
330 GE(IID_IDirectMusicBuffer
),
331 GE(IID_IDirectMusicChordMap
),
332 GE(IID_IDirectMusicCollection
),
333 GE(IID_IDirectMusicComposer
),
334 GE(IID_IDirectMusicContainer
),
335 GE(IID_IDirectMusicDownload
),
336 GE(IID_IDirectMusicDownloadedInstrument
),
337 GE(IID_IDirectMusicGetLoader
),
338 GE(IID_IDirectMusicGraph
),
339 GE(IID_IDirectMusicInstrument
),
340 GE(IID_IDirectMusicLoader
),
341 GE(IID_IDirectMusicLoader8
),
342 GE(IID_IDirectMusicObject
),
343 GE(IID_IDirectMusicPatternTrack
),
344 GE(IID_IDirectMusicPerformance
),
345 GE(IID_IDirectMusicPerformance2
),
346 GE(IID_IDirectMusicPerformance8
),
347 GE(IID_IDirectMusicPort
),
348 GE(IID_IDirectMusicPortDownload
),
349 GE(IID_IDirectMusicScript
),
350 GE(IID_IDirectMusicSegment
),
351 GE(IID_IDirectMusicSegment2
),
352 GE(IID_IDirectMusicSegment8
),
353 GE(IID_IDirectMusicSegmentState
),
354 GE(IID_IDirectMusicSegmentState8
),
355 GE(IID_IDirectMusicStyle
),
356 GE(IID_IDirectMusicStyle8
),
357 GE(IID_IDirectMusicSynth
),
358 GE(IID_IDirectMusicSynth8
),
359 GE(IID_IDirectMusicSynthSink
),
360 GE(IID_IDirectMusicThru
),
361 GE(IID_IDirectMusicTool
),
362 GE(IID_IDirectMusicTool8
),
363 GE(IID_IDirectMusicTrack
),
364 GE(IID_IDirectMusicTrack8
),
366 GE(IID_IPersistStream
),
368 GE(IID_IClassFactory
),
370 GE(GUID_DirectMusicAllTypes
),
371 GE(GUID_NOTIFICATION_CHORD
),
372 GE(GUID_NOTIFICATION_COMMAND
),
373 GE(GUID_NOTIFICATION_MEASUREANDBEAT
),
374 GE(GUID_NOTIFICATION_PERFORMANCE
),
375 GE(GUID_NOTIFICATION_RECOMPOSE
),
376 GE(GUID_NOTIFICATION_SEGMENT
),
379 GE(GUID_CommandParam
),
380 GE(GUID_CommandParam2
),
381 GE(GUID_CommandParamNext
),
382 GE(GUID_IDirectMusicBand
),
383 GE(GUID_IDirectMusicChordMap
),
384 GE(GUID_IDirectMusicStyle
),
386 GE(GUID_Play_Marker
),
387 GE(GUID_RhythmParam
),
389 GE(GUID_TimeSignature
),
390 GE(GUID_Valid_Start_Time
),
391 GE(GUID_Clear_All_Bands
),
392 GE(GUID_ConnectToDLSCollection
),
393 GE(GUID_Disable_Auto_Download
),
394 GE(GUID_DisableTempo
),
395 GE(GUID_DisableTimeSig
),
397 GE(GUID_DownloadToAudioPath
),
398 GE(GUID_Enable_Auto_Download
),
399 GE(GUID_EnableTempo
),
400 GE(GUID_EnableTimeSig
),
401 GE(GUID_IgnoreBankSelectForGM
),
402 GE(GUID_SeedVariations
),
403 GE(GUID_StandardMIDIFile
),
405 GE(GUID_UnloadFromAudioPath
),
407 GE(GUID_PerfMasterTempo
),
408 GE(GUID_PerfMasterVolume
),
409 GE(GUID_PerfMasterGrooveLevel
),
410 GE(GUID_PerfAutoDownload
),
411 GE(GUID_DefaultGMCollection
),
412 GE(GUID_Synth_Default
),
413 GE(GUID_Buffer_Reverb
),
414 GE(GUID_Buffer_EnvReverb
),
415 GE(GUID_Buffer_Stereo
),
416 GE(GUID_Buffer_3D_Dry
),
417 GE(GUID_Buffer_Mono
),
418 GE(GUID_DMUS_PROP_GM_Hardware
),
419 GE(GUID_DMUS_PROP_GS_Capable
),
420 GE(GUID_DMUS_PROP_GS_Hardware
),
421 GE(GUID_DMUS_PROP_DLS1
),
422 GE(GUID_DMUS_PROP_DLS2
),
423 GE(GUID_DMUS_PROP_Effects
),
424 GE(GUID_DMUS_PROP_INSTRUMENT2
),
425 GE(GUID_DMUS_PROP_LegacyCaps
),
426 GE(GUID_DMUS_PROP_MemorySize
),
427 GE(GUID_DMUS_PROP_SampleMemorySize
),
428 GE(GUID_DMUS_PROP_SamplePlaybackRate
),
429 GE(GUID_DMUS_PROP_SetSynthSink
),
430 GE(GUID_DMUS_PROP_SinkUsesDSound
),
431 GE(GUID_DMUS_PROP_SynthSink_DSOUND
),
432 GE(GUID_DMUS_PROP_SynthSink_WAVE
),
433 GE(GUID_DMUS_PROP_Volume
),
434 GE(GUID_DMUS_PROP_WavesReverb
),
435 GE(GUID_DMUS_PROP_WriteLatency
),
436 GE(GUID_DMUS_PROP_WritePeriod
),
437 GE(GUID_DMUS_PROP_XG_Capable
),
438 GE(GUID_DMUS_PROP_XG_Hardware
)
443 if (!id
) return "(null)";
444 for (i
= 0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++) {
445 if (IsEqualGUID(id
, guids
[i
].guid
))
446 return guids
[i
].name
;
449 /* if we didn't find it, act like standard debugstr_guid */
450 return debugstr_guid(id
);
453 /* generic flag-dumping function */
454 static const char* debugstr_flags (DWORD flags
, const flag_info
* names
, size_t num_names
){
455 static char buffer
[128] = "", *ptr
= &buffer
[0];
457 int size
= sizeof(buffer
);
459 for (i
=0; i
< num_names
; i
++) {
460 if ((flags
& names
[i
].val
)) {
461 int cnt
= snprintf(ptr
, size
, "%s ", names
[i
].name
);
462 if (cnt
< 0 || cnt
>= size
) break;
472 /* dump DMUS_OBJ flags */
473 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask
) {
474 static const flag_info flags
[] = {
478 FE(DMUS_OBJ_CATEGORY
),
479 FE(DMUS_OBJ_FILENAME
),
480 FE(DMUS_OBJ_FULLPATH
),
482 FE(DMUS_OBJ_VERSION
),
488 return debugstr_flags (flagmask
, flags
, sizeof(flags
)/sizeof(flags
[0]));
491 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc
) {
493 char buffer
[1024], *ptr
= buffer
;
495 ptr
+= sprintf(ptr
, "DMUS_OBJECTDESC (%p):\n", pDesc
);
496 ptr
+= sprintf(ptr
, " - dwSize = 0x%08X\n", pDesc
->dwSize
);
497 ptr
+= sprintf(ptr
, " - dwValidData = 0x%08X ( %s)\n", pDesc
->dwValidData
, debugstr_DMUS_OBJ_FLAGS (pDesc
->dwValidData
));
498 if (pDesc
->dwValidData
& DMUS_OBJ_CLASS
) ptr
+= sprintf(ptr
, " - guidClass = %s\n", debugstr_dmguid(&pDesc
->guidClass
));
499 if (pDesc
->dwValidData
& DMUS_OBJ_OBJECT
) ptr
+= sprintf(ptr
, " - guidObject = %s\n", debugstr_guid(&pDesc
->guidObject
));
500 if (pDesc
->dwValidData
& DMUS_OBJ_DATE
) ptr
+= sprintf(ptr
, " - ftDate = %s\n", debugstr_filetime (&pDesc
->ftDate
));
501 if (pDesc
->dwValidData
& DMUS_OBJ_VERSION
) ptr
+= sprintf(ptr
, " - vVersion = %s\n", debugstr_dmversion(&pDesc
->vVersion
));
502 if (pDesc
->dwValidData
& DMUS_OBJ_NAME
) ptr
+= sprintf(ptr
, " - wszName = %s\n", debugstr_w(pDesc
->wszName
));
503 if (pDesc
->dwValidData
& DMUS_OBJ_CATEGORY
) ptr
+= sprintf(ptr
, " - wszCategory = %s\n", debugstr_w(pDesc
->wszCategory
));
504 if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
) ptr
+= sprintf(ptr
, " - wszFileName = %s\n", debugstr_w(pDesc
->wszFileName
));
505 if (pDesc
->dwValidData
& DMUS_OBJ_MEMORY
) ptr
+= sprintf(ptr
, " - llMemLength = 0x%s\n - pbMemData = %p\n",
506 wine_dbgstr_longlong(pDesc
->llMemLength
), pDesc
->pbMemData
);
507 if (pDesc
->dwValidData
& DMUS_OBJ_STREAM
) ptr
+= sprintf(ptr
, " - pStream = %p\n", pDesc
->pStream
);
509 return wine_dbg_sprintf("%s", buffer
);
511 return wine_dbg_sprintf("(NULL)");