wined3d: Remove some unnecessary casts in process_vertices_strided().
[wine] / dlls / dmband / dmutils.c
1 /* Debug and Helper Functions
2  *
3  * Copyright (C) 2004 Rok Mandeljc
4  * Copyright (C) 2004 Raphael Junqueira
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #define COBJMACROS
22
23 #include "config.h"
24 #include "wine/port.h"
25
26 #include <stdio.h>
27 #include <stdarg.h>
28 #include <string.h>
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winnt.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
38 #include "objbase.h"
39
40 #include "dmusici.h"
41 #include "dmusicf.h"
42 #include "dmusics.h"
43
44 #include "dmutils.h"
45
46 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
47 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
48
49 /* check whether the given DWORD is even (return 0) or odd (return 1) */
50 int even_or_odd (DWORD number) {
51         return (number & 0x1); /* basically, check if bit 0 is set ;) */
52 }
53
54 /* figures out whether given FOURCC is valid DirectMusic form ID */
55 BOOL IS_VALID_DMFORM (FOURCC chunkID) {
56         if ((chunkID == DMUS_FOURCC_AUDIOPATH_FORM) || (chunkID == DMUS_FOURCC_BAND_FORM) || (chunkID == DMUS_FOURCC_CHORDMAP_FORM)
57                 || (chunkID == DMUS_FOURCC_CONTAINER_FORM) || (chunkID == FOURCC_DLS) || (chunkID == DMUS_FOURCC_SCRIPT_FORM)
58                 || (chunkID == DMUS_FOURCC_SEGMENT_FORM) || (chunkID == DMUS_FOURCC_STYLE_FORM) || (chunkID == DMUS_FOURCC_TOOLGRAPH_FORM)
59                 || (chunkID == DMUS_FOURCC_TRACK_FORM) || (chunkID == mmioFOURCC('W','A','V','E')))  return TRUE;
60         else return FALSE;
61 }
62
63 /* generic flag-dumping function */
64 static const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
65         static char buffer[128] = "", *ptr = &buffer[0];
66         unsigned int i;
67         int size = sizeof(buffer);
68
69         for (i=0; i < num_names; i++) {
70                 if ((flags & names[i].val)) {
71                         int cnt = snprintf(ptr, size, "%s ", names[i].name);
72                         if (cnt < 0 || cnt >= size) break;
73                         size -= cnt;
74                         ptr += cnt;
75                 }
76         }
77
78         ptr = &buffer[0];
79         return ptr;
80 }
81
82 /* dump DMUS_OBJ flags */
83 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
84     static const flag_info flags[] = {
85             FE(DMUS_OBJ_OBJECT),
86             FE(DMUS_OBJ_CLASS),
87             FE(DMUS_OBJ_NAME),
88             FE(DMUS_OBJ_CATEGORY),
89             FE(DMUS_OBJ_FILENAME),
90             FE(DMUS_OBJ_FULLPATH),
91             FE(DMUS_OBJ_URL),
92             FE(DMUS_OBJ_VERSION),
93             FE(DMUS_OBJ_DATE),
94             FE(DMUS_OBJ_LOADED),
95             FE(DMUS_OBJ_MEMORY),
96             FE(DMUS_OBJ_STREAM)
97         };
98     return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
99 }
100
101 /* month number into month name (for debugstr_filetime) */
102 static const char *debugstr_month (DWORD dwMonth) {
103         switch (dwMonth) {
104                 case 1: return "January";
105                 case 2: return "February";
106                 case 3: return "March";
107                 case 4: return "April";
108                 case 5: return "May";
109                 case 6: return "June";
110                 case 7: return "July";
111                 case 8: return "August";
112                 case 9: return "September";
113                 case 10: return "October";
114                 case 11: return "November";
115                 case 12: return "December";
116                 default: return "Invalid";
117         }
118 }
119
120 /* FILETIME struct to string conversion for debug messages */
121 static const char *debugstr_filetime (const FILETIME *time) {
122         SYSTEMTIME sysTime;
123
124         if (!time) return "'null'";
125
126         FileTimeToSystemTime (time, &sysTime);
127
128         return wine_dbg_sprintf ("\'%02i. %s %04i %02i:%02i:%02i\'",
129                 sysTime.wDay, debugstr_month(sysTime.wMonth), sysTime.wYear,
130                 sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
131 }
132
133 /* DMUS_VERSION struct to string conversion for debug messages */
134 static const char *debugstr_dmversion (const DMUS_VERSION *version) {
135         if (!version) return "'null'";
136         return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
137                 HIWORD(version->dwVersionMS),LOWORD(version->dwVersionMS),
138                 HIWORD(version->dwVersionLS), LOWORD(version->dwVersionLS));
139 }
140
141 /* dump whole DMUS_OBJECTDESC struct */
142 static const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
143         if (pDesc) {
144                 char buffer[1024] = "", *ptr = &buffer[0];
145
146                 ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
147                 ptr += sprintf(ptr, " - dwSize = 0x%08X\n", pDesc->dwSize);
148                 ptr += sprintf(ptr, " - dwValidData = 0x%08X ( %s)\n", pDesc->dwValidData, debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
149                 if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
150                 if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
151                 if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = %s\n", debugstr_filetime (&pDesc->ftDate));
152                 if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
153                 if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
154                 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
155                 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
156                 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = 0x%s\n  - pbMemData = %p\n",
157                                                                      wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
158                 if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p\n", pDesc->pStream);
159
160                 return wine_dbg_sprintf("%s", buffer);
161         } else {
162                 return "(NULL)";
163         }
164 }
165
166 HRESULT IDirectMusicUtils_IPersistStream_ParseDescGeneric (DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, LPDMUS_OBJECTDESC pDesc) {
167
168   switch (pChunk->fccID) {
169   case DMUS_FOURCC_GUID_CHUNK: {
170     TRACE_(dmfile)(": GUID chunk\n");
171     pDesc->dwValidData |= DMUS_OBJ_OBJECT;
172     IStream_Read (pStm, &pDesc->guidObject, pChunk->dwSize, NULL);
173     break;
174   }
175   case DMUS_FOURCC_DATE_CHUNK: {
176     TRACE_(dmfile)(": file date chunk\n");
177     pDesc->dwValidData |= DMUS_OBJ_DATE;
178     IStream_Read (pStm, &pDesc->ftDate, pChunk->dwSize, NULL);
179     break;
180   }
181   case DMUS_FOURCC_NAME_CHUNK: {
182     TRACE_(dmfile)(": name chunk\n");
183     pDesc->dwValidData |= DMUS_OBJ_NAME;
184     IStream_Read (pStm, pDesc->wszName, pChunk->dwSize, NULL);
185     break;
186   }
187   case DMUS_FOURCC_FILE_CHUNK: {
188     TRACE_(dmfile)(": file name chunk\n");
189     pDesc->dwValidData |= DMUS_OBJ_FILENAME;
190     IStream_Read (pStm, pDesc->wszFileName, pChunk->dwSize, NULL);
191     break;
192   }
193   case DMUS_FOURCC_VERSION_CHUNK: {
194     TRACE_(dmfile)(": version chunk\n");
195     pDesc->dwValidData |= DMUS_OBJ_VERSION;
196     IStream_Read (pStm, &pDesc->vVersion, pChunk->dwSize, NULL);
197     break;
198   }
199   case DMUS_FOURCC_CATEGORY_CHUNK: {
200     TRACE_(dmfile)(": category chunk\n");
201     pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
202     IStream_Read (pStm, pDesc->wszCategory, pChunk->dwSize, NULL);
203     break;
204   }
205   default:
206     /* not handled */
207     return S_FALSE;
208   }
209
210   return S_OK;
211 }
212
213 HRESULT IDirectMusicUtils_IPersistStream_ParseUNFOGeneric (DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, LPDMUS_OBJECTDESC pDesc) {
214
215   LARGE_INTEGER liMove; /* used when skipping chunks */
216
217   /**
218    * don't ask me why, but M$ puts INFO elements in UNFO list sometimes
219    * (though strings seem to be valid unicode) 
220    */
221   switch (pChunk->fccID) {
222
223   case mmioFOURCC('I','N','A','M'):
224   case DMUS_FOURCC_UNAM_CHUNK: {
225     TRACE_(dmfile)(": name chunk\n");
226     pDesc->dwValidData |= DMUS_OBJ_NAME;
227     IStream_Read (pStm, pDesc->wszName, pChunk->dwSize, NULL);
228     TRACE_(dmfile)(" - wszName: %s\n", debugstr_w(pDesc->wszName));
229     break;
230   }
231
232   case mmioFOURCC('I','A','R','T'):
233   case DMUS_FOURCC_UART_CHUNK: {
234     TRACE_(dmfile)(": artist chunk (ignored)\n");
235     liMove.QuadPart = pChunk->dwSize;
236     IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
237     break;
238   }
239   case mmioFOURCC('I','C','O','P'):
240   case DMUS_FOURCC_UCOP_CHUNK: {
241     TRACE_(dmfile)(": copyright chunk (ignored)\n");
242     liMove.QuadPart = pChunk->dwSize;
243     IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
244     break;
245   }
246   case mmioFOURCC('I','S','B','J'):
247   case DMUS_FOURCC_USBJ_CHUNK: {
248     TRACE_(dmfile)(": subject chunk (ignored)\n");
249     liMove.QuadPart = pChunk->dwSize;
250     IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
251     break;
252   }
253   case mmioFOURCC('I','C','M','T'):
254   case DMUS_FOURCC_UCMT_CHUNK: {
255     TRACE_(dmfile)(": comment chunk (ignored)\n");
256     liMove.QuadPart = pChunk->dwSize;
257     IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
258     break;
259   }
260   default:
261     /* not handled */
262     return S_FALSE;
263   }
264
265   return S_OK;
266 }
267
268 HRESULT IDirectMusicUtils_IPersistStream_ParseReference (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicObject** ppObject) {
269   DMUS_PRIVATE_CHUNK Chunk;
270   DWORD ListSize[3], ListCount[3];
271   LARGE_INTEGER liMove; /* used when skipping chunks */
272   HRESULT hr;
273
274   DMUS_IO_REFERENCE ref;
275   DMUS_OBJECTDESC ref_desc;
276
277   memset(&ref, 0, sizeof(ref));
278   memset(&ref_desc, 0, sizeof(ref_desc));
279
280   if (pChunk->fccID != DMUS_FOURCC_REF_LIST) {
281     ERR_(dmfile)(": %s chunk should be a REF list\n", debugstr_fourcc (pChunk->fccID));
282     return E_FAIL;
283   }
284
285   ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
286   ListCount[0] = 0;
287
288   do {
289     IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
290     ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
291     TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
292
293     hr = IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk, pStm, &ref_desc);
294     if (FAILED(hr)) return hr;
295     
296     if (hr == S_FALSE) {
297       switch (Chunk.fccID) { 
298       case DMUS_FOURCC_REF_CHUNK: {
299         TRACE_(dmfile)(": Reference chunk\n");
300         if (Chunk.dwSize != sizeof(DMUS_IO_REFERENCE)) return E_FAIL;
301         IStream_Read (pStm, &ref, sizeof(DMUS_IO_REFERENCE), NULL);
302         TRACE_(dmfile)(" - guidClassID: %s\n", debugstr_dmguid(&ref.guidClassID));
303         TRACE_(dmfile)(" - dwValidData: %u\n", ref.dwValidData);
304         break;
305       } 
306       default: {
307         TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
308         liMove.QuadPart = Chunk.dwSize;
309         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
310         break;                                          
311       }
312       }
313     }
314     TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
315   } while (ListCount[0] < ListSize[0]);
316
317   ref_desc.dwValidData |= DMUS_OBJ_CLASS;
318   ref_desc.guidClass = ref.guidClassID;
319
320   TRACE_(dmfile)("** DM Reference Begin of Load ***\n");
321   TRACE_(dmfile)("With Desc:\n");
322   debugstr_DMUS_OBJECTDESC(&ref_desc);
323
324   {
325     LPDIRECTMUSICGETLOADER pGetLoader = NULL;
326     LPDIRECTMUSICLOADER pLoader = NULL;
327
328     IStream_QueryInterface (pStm, &IID_IDirectMusicGetLoader, (LPVOID*)&pGetLoader);
329     IDirectMusicGetLoader_GetLoader (pGetLoader, &pLoader);
330     IDirectMusicGetLoader_Release (pGetLoader);
331   
332     hr = IDirectMusicLoader_GetObject (pLoader, &ref_desc, &IID_IDirectMusicObject, (LPVOID*)ppObject);
333     IDirectMusicLoader_Release (pLoader); /* release loader */
334   }
335   TRACE_(dmfile)("** DM Reference End of Load ***\n");
336
337   return S_OK;
338 }
339
340 /* translate STREAM_SEEK flag to string */
341 const char *resolve_STREAM_SEEK (DWORD flag) {
342         switch (flag) {
343                 case STREAM_SEEK_SET:
344                         return "STREAM_SEEK_SET";
345                 case STREAM_SEEK_CUR:
346                         return "STREAM_SEEK_CUR";
347                 case STREAM_SEEK_END:
348                         return "STREAM_SEEK_END";
349                 default:
350                         return "()";                    
351         }
352 }
353
354 /* FOURCC to string conversion for debug messages */
355 const char *debugstr_fourcc (DWORD fourcc) {
356     if (!fourcc) return "'null'";
357     return wine_dbg_sprintf ("\'%c%c%c%c\'",
358                 (char)(fourcc), (char)(fourcc >> 8),
359         (char)(fourcc >> 16), (char)(fourcc >> 24));
360 }
361
362 /* returns name of given GUID */
363 const char *debugstr_dmguid (const GUID *id) {
364         static const guid_info guids[] = {
365                 /* CLSIDs */
366                 GE(CLSID_AudioVBScript),
367                 GE(CLSID_DirectMusic),
368                 GE(CLSID_DirectMusicAudioPath),
369                 GE(CLSID_DirectMusicAudioPathConfig),
370                 GE(CLSID_DirectMusicAuditionTrack),
371                 GE(CLSID_DirectMusicBand),
372                 GE(CLSID_DirectMusicBandTrack),
373                 GE(CLSID_DirectMusicChordMapTrack),
374                 GE(CLSID_DirectMusicChordMap),
375                 GE(CLSID_DirectMusicChordTrack),
376                 GE(CLSID_DirectMusicCollection),
377                 GE(CLSID_DirectMusicCommandTrack),
378                 GE(CLSID_DirectMusicComposer),
379                 GE(CLSID_DirectMusicContainer),
380                 GE(CLSID_DirectMusicGraph),
381                 GE(CLSID_DirectMusicLoader),
382                 GE(CLSID_DirectMusicLyricsTrack),
383                 GE(CLSID_DirectMusicMarkerTrack),
384                 GE(CLSID_DirectMusicMelodyFormulationTrack),
385                 GE(CLSID_DirectMusicMotifTrack),
386                 GE(CLSID_DirectMusicMuteTrack),
387                 GE(CLSID_DirectMusicParamControlTrack),
388                 GE(CLSID_DirectMusicPatternTrack),
389                 GE(CLSID_DirectMusicPerformance),
390                 GE(CLSID_DirectMusicScript),
391                 GE(CLSID_DirectMusicScriptAutoImpSegment),
392                 GE(CLSID_DirectMusicScriptAutoImpPerformance),
393                 GE(CLSID_DirectMusicScriptAutoImpSegmentState),
394                 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
395                 GE(CLSID_DirectMusicScriptAutoImpAudioPath),
396                 GE(CLSID_DirectMusicScriptAutoImpSong),
397                 GE(CLSID_DirectMusicScriptSourceCodeLoader),
398                 GE(CLSID_DirectMusicScriptTrack),
399                 GE(CLSID_DirectMusicSection),
400                 GE(CLSID_DirectMusicSegment),
401                 GE(CLSID_DirectMusicSegmentState),
402                 GE(CLSID_DirectMusicSegmentTriggerTrack),
403                 GE(CLSID_DirectMusicSegTriggerTrack),
404                 GE(CLSID_DirectMusicSeqTrack),
405                 GE(CLSID_DirectMusicSignPostTrack),
406                 GE(CLSID_DirectMusicSong),
407                 GE(CLSID_DirectMusicStyle),
408                 GE(CLSID_DirectMusicStyleTrack),
409                 GE(CLSID_DirectMusicSynth),
410                 GE(CLSID_DirectMusicSynthSink),
411                 GE(CLSID_DirectMusicSysExTrack),
412                 GE(CLSID_DirectMusicTemplate),
413                 GE(CLSID_DirectMusicTempoTrack),
414                 GE(CLSID_DirectMusicTimeSigTrack),
415                 GE(CLSID_DirectMusicWaveTrack),
416                 GE(CLSID_DirectSoundWave),
417                 /* IIDs */
418                 GE(IID_IDirectMusic),
419                 GE(IID_IDirectMusic2),
420                 GE(IID_IDirectMusic8),
421                 GE(IID_IDirectMusicAudioPath),
422                 GE(IID_IDirectMusicBand),
423                 GE(IID_IDirectMusicBuffer),
424                 GE(IID_IDirectMusicChordMap),
425                 GE(IID_IDirectMusicCollection),
426                 GE(IID_IDirectMusicComposer),
427                 GE(IID_IDirectMusicContainer),
428                 GE(IID_IDirectMusicDownload),
429                 GE(IID_IDirectMusicDownloadedInstrument),
430                 GE(IID_IDirectMusicGetLoader),
431                 GE(IID_IDirectMusicGraph),
432                 GE(IID_IDirectMusicInstrument),
433                 GE(IID_IDirectMusicLoader),
434                 GE(IID_IDirectMusicLoader8),
435                 GE(IID_IDirectMusicObject),
436                 GE(IID_IDirectMusicPatternTrack),
437                 GE(IID_IDirectMusicPerformance),
438                 GE(IID_IDirectMusicPerformance2),
439                 GE(IID_IDirectMusicPerformance8),
440                 GE(IID_IDirectMusicPort),
441                 GE(IID_IDirectMusicPortDownload),
442                 GE(IID_IDirectMusicScript),
443                 GE(IID_IDirectMusicSegment),
444                 GE(IID_IDirectMusicSegment2),
445                 GE(IID_IDirectMusicSegment8),
446                 GE(IID_IDirectMusicSegmentState),
447                 GE(IID_IDirectMusicSegmentState8),
448                 GE(IID_IDirectMusicStyle),
449                 GE(IID_IDirectMusicStyle8),
450                 GE(IID_IDirectMusicSynth),
451                 GE(IID_IDirectMusicSynth8),
452                 GE(IID_IDirectMusicSynthSink),
453                 GE(IID_IDirectMusicThru),
454                 GE(IID_IDirectMusicTool),
455                 GE(IID_IDirectMusicTool8),
456                 GE(IID_IDirectMusicTrack),
457                 GE(IID_IDirectMusicTrack8),
458                 GE(IID_IUnknown),
459                 GE(IID_IPersistStream),
460                 GE(IID_IStream),
461                 GE(IID_IClassFactory),
462                 /* GUIDs */
463                 GE(GUID_DirectMusicAllTypes),
464                 GE(GUID_NOTIFICATION_CHORD),
465                 GE(GUID_NOTIFICATION_COMMAND),
466                 GE(GUID_NOTIFICATION_MEASUREANDBEAT),
467                 GE(GUID_NOTIFICATION_PERFORMANCE),
468                 GE(GUID_NOTIFICATION_RECOMPOSE),
469                 GE(GUID_NOTIFICATION_SEGMENT),
470                 GE(GUID_BandParam),
471                 GE(GUID_ChordParam),
472                 GE(GUID_CommandParam),
473                 GE(GUID_CommandParam2),
474                 GE(GUID_CommandParamNext),
475                 GE(GUID_IDirectMusicBand),
476                 GE(GUID_IDirectMusicChordMap),
477                 GE(GUID_IDirectMusicStyle),
478                 GE(GUID_MuteParam),
479                 GE(GUID_Play_Marker),
480                 GE(GUID_RhythmParam),
481                 GE(GUID_TempoParam),
482                 GE(GUID_TimeSignature),
483                 GE(GUID_Valid_Start_Time),
484                 GE(GUID_Clear_All_Bands),
485                 GE(GUID_ConnectToDLSCollection),
486                 GE(GUID_Disable_Auto_Download),
487                 GE(GUID_DisableTempo),
488                 GE(GUID_DisableTimeSig),
489                 GE(GUID_Download),
490                 GE(GUID_DownloadToAudioPath),
491                 GE(GUID_Enable_Auto_Download),
492                 GE(GUID_EnableTempo),
493                 GE(GUID_EnableTimeSig),
494                 GE(GUID_IgnoreBankSelectForGM),
495                 GE(GUID_SeedVariations),
496                 GE(GUID_StandardMIDIFile),
497                 GE(GUID_Unload),
498                 GE(GUID_UnloadFromAudioPath),
499                 GE(GUID_Variations),
500                 GE(GUID_PerfMasterTempo),
501                 GE(GUID_PerfMasterVolume),
502                 GE(GUID_PerfMasterGrooveLevel),
503                 GE(GUID_PerfAutoDownload),
504                 GE(GUID_DefaultGMCollection),
505                 GE(GUID_Synth_Default),
506                 GE(GUID_Buffer_Reverb),
507                 GE(GUID_Buffer_EnvReverb),
508                 GE(GUID_Buffer_Stereo),
509                 GE(GUID_Buffer_3D_Dry),
510                 GE(GUID_Buffer_Mono),
511                 GE(GUID_DMUS_PROP_GM_Hardware),
512                 GE(GUID_DMUS_PROP_GS_Capable),
513                 GE(GUID_DMUS_PROP_GS_Hardware),
514                 GE(GUID_DMUS_PROP_DLS1),
515                 GE(GUID_DMUS_PROP_DLS2),
516                 GE(GUID_DMUS_PROP_Effects),
517                 GE(GUID_DMUS_PROP_INSTRUMENT2),
518                 GE(GUID_DMUS_PROP_LegacyCaps),
519                 GE(GUID_DMUS_PROP_MemorySize),
520                 GE(GUID_DMUS_PROP_SampleMemorySize),
521                 GE(GUID_DMUS_PROP_SamplePlaybackRate),
522                 GE(GUID_DMUS_PROP_SetSynthSink),
523                 GE(GUID_DMUS_PROP_SinkUsesDSound),
524                 GE(GUID_DMUS_PROP_SynthSink_DSOUND),
525                 GE(GUID_DMUS_PROP_SynthSink_WAVE),
526                 GE(GUID_DMUS_PROP_Volume),
527                 GE(GUID_DMUS_PROP_WavesReverb),
528                 GE(GUID_DMUS_PROP_WriteLatency),
529                 GE(GUID_DMUS_PROP_WritePeriod),
530                 GE(GUID_DMUS_PROP_XG_Capable),
531                 GE(GUID_DMUS_PROP_XG_Hardware)
532         };
533
534         unsigned int i;
535
536         if (!id) return "(null)";
537         for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
538                 if (IsEqualGUID(id, guids[i].guid))
539                         return guids[i].name;
540         }
541         
542         /* if we didn't find it, act like standard debugstr_guid */     
543         return debugstr_guid(id);
544 }       
545
546 /* returns name of given error code */
547 const char *debugstr_dmreturn (DWORD code) {
548         static const flag_info codes[] = {
549                 FE(S_OK),
550                 FE(S_FALSE),
551                 FE(DMUS_S_PARTIALLOAD),
552                 FE(DMUS_S_PARTIALDOWNLOAD),
553                 FE(DMUS_S_REQUEUE),
554                 FE(DMUS_S_FREE),
555                 FE(DMUS_S_END),
556                 FE(DMUS_S_STRING_TRUNCATED),
557                 FE(DMUS_S_LAST_TOOL),
558                 FE(DMUS_S_OVER_CHORD),
559                 FE(DMUS_S_UP_OCTAVE),
560                 FE(DMUS_S_DOWN_OCTAVE),
561                 FE(DMUS_S_NOBUFFERCONTROL),
562                 FE(DMUS_S_GARBAGE_COLLECTED),
563                 FE(E_NOTIMPL),
564                 FE(E_NOINTERFACE),
565                 FE(E_POINTER),
566                 FE(CLASS_E_NOAGGREGATION),
567                 FE(CLASS_E_CLASSNOTAVAILABLE),
568                 FE(REGDB_E_CLASSNOTREG),
569                 FE(E_OUTOFMEMORY),
570                 FE(E_FAIL),
571                 FE(E_INVALIDARG),
572                 FE(DMUS_E_DRIVER_FAILED),
573                 FE(DMUS_E_PORTS_OPEN),
574                 FE(DMUS_E_DEVICE_IN_USE),
575                 FE(DMUS_E_INSUFFICIENTBUFFER),
576                 FE(DMUS_E_BUFFERNOTSET),
577                 FE(DMUS_E_BUFFERNOTAVAILABLE),
578                 FE(DMUS_E_NOTADLSCOL),
579                 FE(DMUS_E_INVALIDOFFSET),
580                 FE(DMUS_E_ALREADY_LOADED),
581                 FE(DMUS_E_INVALIDPOS),
582                 FE(DMUS_E_INVALIDPATCH),
583                 FE(DMUS_E_CANNOTSEEK),
584                 FE(DMUS_E_CANNOTWRITE),
585                 FE(DMUS_E_CHUNKNOTFOUND),
586                 FE(DMUS_E_INVALID_DOWNLOADID),
587                 FE(DMUS_E_NOT_DOWNLOADED_TO_PORT),
588                 FE(DMUS_E_ALREADY_DOWNLOADED),
589                 FE(DMUS_E_UNKNOWN_PROPERTY),
590                 FE(DMUS_E_SET_UNSUPPORTED),
591                 FE(DMUS_E_GET_UNSUPPORTED),
592                 FE(DMUS_E_NOTMONO),
593                 FE(DMUS_E_BADARTICULATION),
594                 FE(DMUS_E_BADINSTRUMENT),
595                 FE(DMUS_E_BADWAVELINK),
596                 FE(DMUS_E_NOARTICULATION),
597                 FE(DMUS_E_NOTPCM),
598                 FE(DMUS_E_BADWAVE),
599                 FE(DMUS_E_BADOFFSETTABLE),
600                 FE(DMUS_E_UNKNOWNDOWNLOAD),
601                 FE(DMUS_E_NOSYNTHSINK),
602                 FE(DMUS_E_ALREADYOPEN),
603                 FE(DMUS_E_ALREADYCLOSED),
604                 FE(DMUS_E_SYNTHNOTCONFIGURED),
605                 FE(DMUS_E_SYNTHACTIVE),
606                 FE(DMUS_E_CANNOTREAD),
607                 FE(DMUS_E_DMUSIC_RELEASED),
608                 FE(DMUS_E_BUFFER_EMPTY),
609                 FE(DMUS_E_BUFFER_FULL),
610                 FE(DMUS_E_PORT_NOT_CAPTURE),
611                 FE(DMUS_E_PORT_NOT_RENDER),
612                 FE(DMUS_E_DSOUND_NOT_SET),
613                 FE(DMUS_E_ALREADY_ACTIVATED),
614                 FE(DMUS_E_INVALIDBUFFER),
615                 FE(DMUS_E_WAVEFORMATNOTSUPPORTED),
616                 FE(DMUS_E_SYNTHINACTIVE),
617                 FE(DMUS_E_DSOUND_ALREADY_SET),
618                 FE(DMUS_E_INVALID_EVENT),
619                 FE(DMUS_E_UNSUPPORTED_STREAM),
620                 FE(DMUS_E_ALREADY_INITED),
621                 FE(DMUS_E_INVALID_BAND),
622                 FE(DMUS_E_TRACK_HDR_NOT_FIRST_CK),
623                 FE(DMUS_E_TOOL_HDR_NOT_FIRST_CK),
624                 FE(DMUS_E_INVALID_TRACK_HDR),
625                 FE(DMUS_E_INVALID_TOOL_HDR),
626                 FE(DMUS_E_ALL_TOOLS_FAILED),
627                 FE(DMUS_E_ALL_TRACKS_FAILED),
628                 FE(DMUS_E_NOT_FOUND),
629                 FE(DMUS_E_NOT_INIT),
630                 FE(DMUS_E_TYPE_DISABLED),
631                 FE(DMUS_E_TYPE_UNSUPPORTED),
632                 FE(DMUS_E_TIME_PAST),
633                 FE(DMUS_E_TRACK_NOT_FOUND),
634                 FE(DMUS_E_TRACK_NO_CLOCKTIME_SUPPORT),
635                 FE(DMUS_E_NO_MASTER_CLOCK),
636                 FE(DMUS_E_LOADER_NOCLASSID),
637                 FE(DMUS_E_LOADER_BADPATH),
638                 FE(DMUS_E_LOADER_FAILEDOPEN),
639                 FE(DMUS_E_LOADER_FORMATNOTSUPPORTED),
640                 FE(DMUS_E_LOADER_FAILEDCREATE),
641                 FE(DMUS_E_LOADER_OBJECTNOTFOUND),
642                 FE(DMUS_E_LOADER_NOFILENAME),
643                 FE(DMUS_E_INVALIDFILE),
644                 FE(DMUS_E_ALREADY_EXISTS),
645                 FE(DMUS_E_OUT_OF_RANGE),
646                 FE(DMUS_E_SEGMENT_INIT_FAILED),
647                 FE(DMUS_E_ALREADY_SENT),
648                 FE(DMUS_E_CANNOT_FREE),
649                 FE(DMUS_E_CANNOT_OPEN_PORT),
650                 FE(DMUS_E_CANNOT_CONVERT),
651                 FE(DMUS_E_DESCEND_CHUNK_FAIL),
652                 FE(DMUS_E_NOT_LOADED),
653                 FE(DMUS_E_SCRIPT_LANGUAGE_INCOMPATIBLE),
654                 FE(DMUS_E_SCRIPT_UNSUPPORTED_VARTYPE),
655                 FE(DMUS_E_SCRIPT_ERROR_IN_SCRIPT),
656                 FE(DMUS_E_SCRIPT_CANTLOAD_OLEAUT32),
657                 FE(DMUS_E_SCRIPT_LOADSCRIPT_ERROR),
658                 FE(DMUS_E_SCRIPT_INVALID_FILE),
659                 FE(DMUS_E_INVALID_SCRIPTTRACK),
660                 FE(DMUS_E_SCRIPT_VARIABLE_NOT_FOUND),
661                 FE(DMUS_E_SCRIPT_ROUTINE_NOT_FOUND),
662                 FE(DMUS_E_SCRIPT_CONTENT_READONLY),
663                 FE(DMUS_E_SCRIPT_NOT_A_REFERENCE),
664                 FE(DMUS_E_SCRIPT_VALUE_NOT_SUPPORTED),
665                 FE(DMUS_E_INVALID_SEGMENTTRIGGERTRACK),
666                 FE(DMUS_E_INVALID_LYRICSTRACK),
667                 FE(DMUS_E_INVALID_PARAMCONTROLTRACK),
668                 FE(DMUS_E_AUDIOVBSCRIPT_SYNTAXERROR),
669                 FE(DMUS_E_AUDIOVBSCRIPT_RUNTIMEERROR),
670                 FE(DMUS_E_AUDIOVBSCRIPT_OPERATIONFAILURE),
671                 FE(DMUS_E_AUDIOPATHS_NOT_VALID),
672                 FE(DMUS_E_AUDIOPATHS_IN_USE),
673                 FE(DMUS_E_NO_AUDIOPATH_CONFIG),
674                 FE(DMUS_E_AUDIOPATH_INACTIVE),
675                 FE(DMUS_E_AUDIOPATH_NOBUFFER),
676                 FE(DMUS_E_AUDIOPATH_NOPORT),
677                 FE(DMUS_E_NO_AUDIOPATH),
678                 FE(DMUS_E_INVALIDCHUNK),
679                 FE(DMUS_E_AUDIOPATH_NOGLOBALFXBUFFER),
680                 FE(DMUS_E_INVALID_CONTAINER_OBJECT)
681         };
682         
683         unsigned int i;
684         for (i = 0; i < sizeof(codes)/sizeof(codes[0]); i++) {
685                 if (code == codes[i].val)
686                         return codes[i].name;
687         }
688         
689         /* if we didn't find it, return value */
690         return wine_dbg_sprintf("0x%08X", code);
691 }
692
693
694 /* dump DMUS_CONTAINER flags */
695 static const char *debugstr_DMUS_CONTAINER_FLAGS (DWORD flagmask) {
696     static const flag_info flags[] = {
697             FE(DMUS_CONTAINER_NOLOADS)
698         };
699     return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
700 }
701
702 /* dump DMUS_CONTAINED_OBJF flags */
703 static const char *debugstr_DMUS_CONTAINED_OBJF_FLAGS (DWORD flagmask) {
704     static const flag_info flags[] = {
705             FE(DMUS_CONTAINED_OBJF_KEEP)
706         };
707     return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
708 }
709
710 void debug_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
711         if (pDesc) {
712                 TRACE("DMUS_OBJECTDESC (%p):\n", pDesc);
713                 TRACE(" - dwSize = %d\n", pDesc->dwSize);
714                 TRACE(" - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
715                 if (pDesc->dwValidData & DMUS_OBJ_NAME)     TRACE(" - wszName = %s\n", debugstr_w(pDesc->wszName));
716                 if (pDesc->dwValidData & DMUS_OBJ_CLASS)    TRACE(" - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
717                 if (pDesc->dwValidData & DMUS_OBJ_OBJECT)   TRACE(" - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
718                 if (pDesc->dwValidData & DMUS_OBJ_DATE)     TRACE(" - ftDate = FIXME\n");
719                 if (pDesc->dwValidData & DMUS_OBJ_VERSION)  TRACE(" - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
720                 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) TRACE(" - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
721                 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) TRACE(" - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
722                 if (pDesc->dwValidData & DMUS_OBJ_MEMORY)   TRACE(" - llMemLength = 0x%s\n  - pbMemData = %p\n",
723                                                                 wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
724                 if (pDesc->dwValidData & DMUS_OBJ_STREAM)   TRACE(" - pStream = %p\n", pDesc->pStream);
725         } else {
726                 TRACE("(NULL)\n");
727         }
728 }
729
730 const char *debugstr_DMUS_IO_CONTAINER_HEADER (LPDMUS_IO_CONTAINER_HEADER pHeader) {
731         if (pHeader) {
732                 char buffer[1024] = "", *ptr = &buffer[0];
733                 
734                 ptr += sprintf(ptr, "DMUS_IO_CONTAINER_HEADER (%p):\n", pHeader);
735                 ptr += sprintf(ptr, " - dwFlags = %s\n", debugstr_DMUS_CONTAINER_FLAGS(pHeader->dwFlags));
736                 
737                 return wine_dbg_sprintf("%s", buffer);
738         } else {
739                 return "(NULL)";
740         }
741 }
742
743 const char *debugstr_DMUS_IO_CONTAINED_OBJECT_HEADER (LPDMUS_IO_CONTAINED_OBJECT_HEADER pHeader) {
744         if (pHeader) {
745                 char buffer[1024] = "", *ptr = &buffer[0];
746                 
747                 ptr += sprintf(ptr, "DMUS_IO_CONTAINED_OBJECT_HEADER (%p):\n", pHeader);
748                 ptr += sprintf(ptr, " - guidClassID = %s\n", debugstr_dmguid(&pHeader->guidClassID));
749                 ptr += sprintf(ptr, " - dwFlags = %s\n", debugstr_DMUS_CONTAINED_OBJF_FLAGS (pHeader->dwFlags));
750                 ptr += sprintf(ptr, " - ckid = %s\n", debugstr_fourcc (pHeader->ckid));
751                 ptr += sprintf(ptr, " - fccType = %s\n", debugstr_fourcc (pHeader->fccType));
752
753                 return wine_dbg_sprintf("%s", buffer);
754         } else {
755                 return "(NULL)";
756         }
757 }