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