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