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