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