atl: Add support for the registrar parameter of AtlModuleUpdateRegistryFromResourceD.
[wine] / dlls / dmstyle / 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 /* translate STREAM_SEEK flag to string */
237 const char *resolve_STREAM_SEEK (DWORD flag) {
238         switch (flag) {
239                 case STREAM_SEEK_SET:
240                         return wine_dbg_sprintf ("STREAM_SEEK_SET");
241                 case STREAM_SEEK_CUR:
242                         return wine_dbg_sprintf ("STREAM_SEEK_CUR");
243                 case STREAM_SEEK_END:
244                         return wine_dbg_sprintf ("STREAM_SEEK_END");
245                 default:
246                         return wine_dbg_sprintf ("()");                 
247         }
248 }
249
250 /* FOURCC to string conversion for debug messages */
251 const char *debugstr_fourcc (DWORD fourcc) {
252     if (!fourcc) return "'null'";
253     return wine_dbg_sprintf ("\'%c%c%c%c\'",
254                 (char)(fourcc), (char)(fourcc >> 8),
255         (char)(fourcc >> 16), (char)(fourcc >> 24));
256 }
257
258 /* DMUS_VERSION struct to string conversion for debug messages */
259 static const char *debugstr_dmversion (LPDMUS_VERSION version) {
260         if (!version) return "'null'";
261         return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
262                 HIWORD(version->dwVersionMS),LOWORD(version->dwVersionMS),
263                 HIWORD(version->dwVersionLS), LOWORD(version->dwVersionLS));
264 }
265
266 /* month number into month name (for debugstr_filetime) */
267 static const char *debugstr_month (DWORD dwMonth) {
268         switch (dwMonth) {
269                 case 1: return "January";
270                 case 2: return "February";
271                 case 3: return "March";
272                 case 4: return "April";
273                 case 5: return "May";
274                 case 6: return "June";
275                 case 7: return "July";
276                 case 8: return "August";
277                 case 9: return "September";
278                 case 10: return "October";
279                 case 11: return "November";
280                 case 12: return "December";
281                 default: return "Invalid";
282         }
283 }
284
285 /* FILETIME struct to string conversion for debug messages */
286 static const char *debugstr_filetime (LPFILETIME time) {
287         SYSTEMTIME sysTime;
288
289         if (!time) return "'null'";
290         
291         FileTimeToSystemTime (time, &sysTime);
292         
293         return wine_dbg_sprintf ("\'%02i. %s %04i %02i:%02i:%02i\'",
294                 sysTime.wDay, debugstr_month(sysTime.wMonth), sysTime.wYear,
295                 sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
296 }
297
298 /* returns name of given GUID */
299 const char *debugstr_dmguid (const GUID *id) {
300         static const guid_info guids[] = {
301                 /* CLSIDs */
302                 GE(CLSID_AudioVBScript),
303                 GE(CLSID_DirectMusic),
304                 GE(CLSID_DirectMusicAudioPath),
305                 GE(CLSID_DirectMusicAudioPathConfig),
306                 GE(CLSID_DirectMusicAuditionTrack),
307                 GE(CLSID_DirectMusicBand),
308                 GE(CLSID_DirectMusicBandTrack),
309                 GE(CLSID_DirectMusicChordMapTrack),
310                 GE(CLSID_DirectMusicChordMap),
311                 GE(CLSID_DirectMusicChordTrack),
312                 GE(CLSID_DirectMusicCollection),
313                 GE(CLSID_DirectMusicCommandTrack),
314                 GE(CLSID_DirectMusicComposer),
315                 GE(CLSID_DirectMusicContainer),
316                 GE(CLSID_DirectMusicGraph),
317                 GE(CLSID_DirectMusicLoader),
318                 GE(CLSID_DirectMusicLyricsTrack),
319                 GE(CLSID_DirectMusicMarkerTrack),
320                 GE(CLSID_DirectMusicMelodyFormulationTrack),
321                 GE(CLSID_DirectMusicMotifTrack),
322                 GE(CLSID_DirectMusicMuteTrack),
323                 GE(CLSID_DirectMusicParamControlTrack),
324                 GE(CLSID_DirectMusicPatternTrack),
325                 GE(CLSID_DirectMusicPerformance),
326                 GE(CLSID_DirectMusicScript),
327                 GE(CLSID_DirectMusicScriptAutoImpSegment),
328                 GE(CLSID_DirectMusicScriptAutoImpPerformance),
329                 GE(CLSID_DirectMusicScriptAutoImpSegmentState),
330                 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
331                 GE(CLSID_DirectMusicScriptAutoImpAudioPath),
332                 GE(CLSID_DirectMusicScriptAutoImpSong),
333                 GE(CLSID_DirectMusicScriptSourceCodeLoader),
334                 GE(CLSID_DirectMusicScriptTrack),
335                 GE(CLSID_DirectMusicSection),
336                 GE(CLSID_DirectMusicSegment),
337                 GE(CLSID_DirectMusicSegmentState),
338                 GE(CLSID_DirectMusicSegmentTriggerTrack),
339                 GE(CLSID_DirectMusicSegTriggerTrack),
340                 GE(CLSID_DirectMusicSeqTrack),
341                 GE(CLSID_DirectMusicSignPostTrack),
342                 GE(CLSID_DirectMusicSong),
343                 GE(CLSID_DirectMusicStyle),
344                 GE(CLSID_DirectMusicStyleTrack),
345                 GE(CLSID_DirectMusicSynth),
346                 GE(CLSID_DirectMusicSynthSink),
347                 GE(CLSID_DirectMusicSysExTrack),
348                 GE(CLSID_DirectMusicTemplate),
349                 GE(CLSID_DirectMusicTempoTrack),
350                 GE(CLSID_DirectMusicTimeSigTrack),
351                 GE(CLSID_DirectMusicWaveTrack),
352                 GE(CLSID_DirectSoundWave),
353                 /* IIDs */
354                 GE(IID_IDirectMusic),
355                 GE(IID_IDirectMusic2),
356                 GE(IID_IDirectMusic8),
357                 GE(IID_IDirectMusicAudioPath),
358                 GE(IID_IDirectMusicBand),
359                 GE(IID_IDirectMusicBuffer),
360                 GE(IID_IDirectMusicChordMap),
361                 GE(IID_IDirectMusicCollection),
362                 GE(IID_IDirectMusicComposer),
363                 GE(IID_IDirectMusicContainer),
364                 GE(IID_IDirectMusicDownload),
365                 GE(IID_IDirectMusicDownloadedInstrument),
366                 GE(IID_IDirectMusicGetLoader),
367                 GE(IID_IDirectMusicGraph),
368                 GE(IID_IDirectMusicInstrument),
369                 GE(IID_IDirectMusicLoader),
370                 GE(IID_IDirectMusicLoader8),
371                 GE(IID_IDirectMusicObject),
372                 GE(IID_IDirectMusicPatternTrack),
373                 GE(IID_IDirectMusicPerformance),
374                 GE(IID_IDirectMusicPerformance2),
375                 GE(IID_IDirectMusicPerformance8),
376                 GE(IID_IDirectMusicPort),
377                 GE(IID_IDirectMusicPortDownload),
378                 GE(IID_IDirectMusicScript),
379                 GE(IID_IDirectMusicSegment),
380                 GE(IID_IDirectMusicSegment2),
381                 GE(IID_IDirectMusicSegment8),
382                 GE(IID_IDirectMusicSegmentState),
383                 GE(IID_IDirectMusicSegmentState8),
384                 GE(IID_IDirectMusicStyle),
385                 GE(IID_IDirectMusicStyle8),
386                 GE(IID_IDirectMusicSynth),
387                 GE(IID_IDirectMusicSynth8),
388                 GE(IID_IDirectMusicSynthSink),
389                 GE(IID_IDirectMusicThru),
390                 GE(IID_IDirectMusicTool),
391                 GE(IID_IDirectMusicTool8),
392                 GE(IID_IDirectMusicTrack),
393                 GE(IID_IDirectMusicTrack8),
394                 GE(IID_IUnknown),
395                 GE(IID_IPersistStream),
396                 GE(IID_IStream),
397                 GE(IID_IClassFactory),
398                 /* GUIDs */
399                 GE(GUID_DirectMusicAllTypes),
400                 GE(GUID_NOTIFICATION_CHORD),
401                 GE(GUID_NOTIFICATION_COMMAND),
402                 GE(GUID_NOTIFICATION_MEASUREANDBEAT),
403                 GE(GUID_NOTIFICATION_PERFORMANCE),
404                 GE(GUID_NOTIFICATION_RECOMPOSE),
405                 GE(GUID_NOTIFICATION_SEGMENT),
406                 GE(GUID_BandParam),
407                 GE(GUID_ChordParam),
408                 GE(GUID_CommandParam),
409                 GE(GUID_CommandParam2),
410                 GE(GUID_CommandParamNext),
411                 GE(GUID_IDirectMusicBand),
412                 GE(GUID_IDirectMusicChordMap),
413                 GE(GUID_IDirectMusicStyle),
414                 GE(GUID_MuteParam),
415                 GE(GUID_Play_Marker),
416                 GE(GUID_RhythmParam),
417                 GE(GUID_TempoParam),
418                 GE(GUID_TimeSignature),
419                 GE(GUID_Valid_Start_Time),
420                 GE(GUID_Clear_All_Bands),
421                 GE(GUID_ConnectToDLSCollection),
422                 GE(GUID_Disable_Auto_Download),
423                 GE(GUID_DisableTempo),
424                 GE(GUID_DisableTimeSig),
425                 GE(GUID_Download),
426                 GE(GUID_DownloadToAudioPath),
427                 GE(GUID_Enable_Auto_Download),
428                 GE(GUID_EnableTempo),
429                 GE(GUID_EnableTimeSig),
430                 GE(GUID_IgnoreBankSelectForGM),
431                 GE(GUID_SeedVariations),
432                 GE(GUID_StandardMIDIFile),
433                 GE(GUID_Unload),
434                 GE(GUID_UnloadFromAudioPath),
435                 GE(GUID_Variations),
436                 GE(GUID_PerfMasterTempo),
437                 GE(GUID_PerfMasterVolume),
438                 GE(GUID_PerfMasterGrooveLevel),
439                 GE(GUID_PerfAutoDownload),
440                 GE(GUID_DefaultGMCollection),
441                 GE(GUID_Synth_Default),
442                 GE(GUID_Buffer_Reverb),
443                 GE(GUID_Buffer_EnvReverb),
444                 GE(GUID_Buffer_Stereo),
445                 GE(GUID_Buffer_3D_Dry),
446                 GE(GUID_Buffer_Mono),
447                 GE(GUID_DMUS_PROP_GM_Hardware),
448                 GE(GUID_DMUS_PROP_GS_Capable),
449                 GE(GUID_DMUS_PROP_GS_Hardware),
450                 GE(GUID_DMUS_PROP_DLS1),
451                 GE(GUID_DMUS_PROP_DLS2),
452                 GE(GUID_DMUS_PROP_Effects),
453                 GE(GUID_DMUS_PROP_INSTRUMENT2),
454                 GE(GUID_DMUS_PROP_LegacyCaps),
455                 GE(GUID_DMUS_PROP_MemorySize),
456                 GE(GUID_DMUS_PROP_SampleMemorySize),
457                 GE(GUID_DMUS_PROP_SamplePlaybackRate),
458                 GE(GUID_DMUS_PROP_SetSynthSink),
459                 GE(GUID_DMUS_PROP_SinkUsesDSound),
460                 GE(GUID_DMUS_PROP_SynthSink_DSOUND),
461                 GE(GUID_DMUS_PROP_SynthSink_WAVE),
462                 GE(GUID_DMUS_PROP_Volume),
463                 GE(GUID_DMUS_PROP_WavesReverb),
464                 GE(GUID_DMUS_PROP_WriteLatency),
465                 GE(GUID_DMUS_PROP_WritePeriod),
466                 GE(GUID_DMUS_PROP_XG_Capable),
467                 GE(GUID_DMUS_PROP_XG_Hardware)
468         };
469
470         unsigned int i;
471
472         if (!id) return "(null)";
473         for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
474                 if (IsEqualGUID(id, guids[i].guid))
475                         return guids[i].name;
476         }
477         
478         /* if we didn't find it, act like standard debugstr_guid */     
479         return debugstr_guid(id);
480 }       
481
482 /* returns name of given error code */
483 const char *debugstr_dmreturn (DWORD code) {
484         static const flag_info codes[] = {
485                 FE(S_OK),
486                 FE(S_FALSE),
487                 FE(DMUS_S_PARTIALLOAD),
488                 FE(DMUS_S_PARTIALDOWNLOAD),
489                 FE(DMUS_S_REQUEUE),
490                 FE(DMUS_S_FREE),
491                 FE(DMUS_S_END),
492                 FE(DMUS_S_STRING_TRUNCATED),
493                 FE(DMUS_S_LAST_TOOL),
494                 FE(DMUS_S_OVER_CHORD),
495                 FE(DMUS_S_UP_OCTAVE),
496                 FE(DMUS_S_DOWN_OCTAVE),
497                 FE(DMUS_S_NOBUFFERCONTROL),
498                 FE(DMUS_S_GARBAGE_COLLECTED),
499                 FE(E_NOTIMPL),
500                 FE(E_NOINTERFACE),
501                 FE(E_POINTER),
502                 FE(CLASS_E_NOAGGREGATION),
503                 FE(CLASS_E_CLASSNOTAVAILABLE),
504                 FE(REGDB_E_CLASSNOTREG),
505                 FE(E_OUTOFMEMORY),
506                 FE(E_FAIL),
507                 FE(E_INVALIDARG),
508                 FE(DMUS_E_DRIVER_FAILED),
509                 FE(DMUS_E_PORTS_OPEN),
510                 FE(DMUS_E_DEVICE_IN_USE),
511                 FE(DMUS_E_INSUFFICIENTBUFFER),
512                 FE(DMUS_E_BUFFERNOTSET),
513                 FE(DMUS_E_BUFFERNOTAVAILABLE),
514                 FE(DMUS_E_NOTADLSCOL),
515                 FE(DMUS_E_INVALIDOFFSET),
516                 FE(DMUS_E_ALREADY_LOADED),
517                 FE(DMUS_E_INVALIDPOS),
518                 FE(DMUS_E_INVALIDPATCH),
519                 FE(DMUS_E_CANNOTSEEK),
520                 FE(DMUS_E_CANNOTWRITE),
521                 FE(DMUS_E_CHUNKNOTFOUND),
522                 FE(DMUS_E_INVALID_DOWNLOADID),
523                 FE(DMUS_E_NOT_DOWNLOADED_TO_PORT),
524                 FE(DMUS_E_ALREADY_DOWNLOADED),
525                 FE(DMUS_E_UNKNOWN_PROPERTY),
526                 FE(DMUS_E_SET_UNSUPPORTED),
527                 FE(DMUS_E_GET_UNSUPPORTED),
528                 FE(DMUS_E_NOTMONO),
529                 FE(DMUS_E_BADARTICULATION),
530                 FE(DMUS_E_BADINSTRUMENT),
531                 FE(DMUS_E_BADWAVELINK),
532                 FE(DMUS_E_NOARTICULATION),
533                 FE(DMUS_E_NOTPCM),
534                 FE(DMUS_E_BADWAVE),
535                 FE(DMUS_E_BADOFFSETTABLE),
536                 FE(DMUS_E_UNKNOWNDOWNLOAD),
537                 FE(DMUS_E_NOSYNTHSINK),
538                 FE(DMUS_E_ALREADYOPEN),
539                 FE(DMUS_E_ALREADYCLOSED),
540                 FE(DMUS_E_SYNTHNOTCONFIGURED),
541                 FE(DMUS_E_SYNTHACTIVE),
542                 FE(DMUS_E_CANNOTREAD),
543                 FE(DMUS_E_DMUSIC_RELEASED),
544                 FE(DMUS_E_BUFFER_EMPTY),
545                 FE(DMUS_E_BUFFER_FULL),
546                 FE(DMUS_E_PORT_NOT_CAPTURE),
547                 FE(DMUS_E_PORT_NOT_RENDER),
548                 FE(DMUS_E_DSOUND_NOT_SET),
549                 FE(DMUS_E_ALREADY_ACTIVATED),
550                 FE(DMUS_E_INVALIDBUFFER),
551                 FE(DMUS_E_WAVEFORMATNOTSUPPORTED),
552                 FE(DMUS_E_SYNTHINACTIVE),
553                 FE(DMUS_E_DSOUND_ALREADY_SET),
554                 FE(DMUS_E_INVALID_EVENT),
555                 FE(DMUS_E_UNSUPPORTED_STREAM),
556                 FE(DMUS_E_ALREADY_INITED),
557                 FE(DMUS_E_INVALID_BAND),
558                 FE(DMUS_E_TRACK_HDR_NOT_FIRST_CK),
559                 FE(DMUS_E_TOOL_HDR_NOT_FIRST_CK),
560                 FE(DMUS_E_INVALID_TRACK_HDR),
561                 FE(DMUS_E_INVALID_TOOL_HDR),
562                 FE(DMUS_E_ALL_TOOLS_FAILED),
563                 FE(DMUS_E_ALL_TRACKS_FAILED),
564                 FE(DMUS_E_NOT_FOUND),
565                 FE(DMUS_E_NOT_INIT),
566                 FE(DMUS_E_TYPE_DISABLED),
567                 FE(DMUS_E_TYPE_UNSUPPORTED),
568                 FE(DMUS_E_TIME_PAST),
569                 FE(DMUS_E_TRACK_NOT_FOUND),
570                 FE(DMUS_E_TRACK_NO_CLOCKTIME_SUPPORT),
571                 FE(DMUS_E_NO_MASTER_CLOCK),
572                 FE(DMUS_E_LOADER_NOCLASSID),
573                 FE(DMUS_E_LOADER_BADPATH),
574                 FE(DMUS_E_LOADER_FAILEDOPEN),
575                 FE(DMUS_E_LOADER_FORMATNOTSUPPORTED),
576                 FE(DMUS_E_LOADER_FAILEDCREATE),
577                 FE(DMUS_E_LOADER_OBJECTNOTFOUND),
578                 FE(DMUS_E_LOADER_NOFILENAME),
579                 FE(DMUS_E_INVALIDFILE),
580                 FE(DMUS_E_ALREADY_EXISTS),
581                 FE(DMUS_E_OUT_OF_RANGE),
582                 FE(DMUS_E_SEGMENT_INIT_FAILED),
583                 FE(DMUS_E_ALREADY_SENT),
584                 FE(DMUS_E_CANNOT_FREE),
585                 FE(DMUS_E_CANNOT_OPEN_PORT),
586                 FE(DMUS_E_CANNOT_CONVERT),
587                 FE(DMUS_E_DESCEND_CHUNK_FAIL),
588                 FE(DMUS_E_NOT_LOADED),
589                 FE(DMUS_E_SCRIPT_LANGUAGE_INCOMPATIBLE),
590                 FE(DMUS_E_SCRIPT_UNSUPPORTED_VARTYPE),
591                 FE(DMUS_E_SCRIPT_ERROR_IN_SCRIPT),
592                 FE(DMUS_E_SCRIPT_CANTLOAD_OLEAUT32),
593                 FE(DMUS_E_SCRIPT_LOADSCRIPT_ERROR),
594                 FE(DMUS_E_SCRIPT_INVALID_FILE),
595                 FE(DMUS_E_INVALID_SCRIPTTRACK),
596                 FE(DMUS_E_SCRIPT_VARIABLE_NOT_FOUND),
597                 FE(DMUS_E_SCRIPT_ROUTINE_NOT_FOUND),
598                 FE(DMUS_E_SCRIPT_CONTENT_READONLY),
599                 FE(DMUS_E_SCRIPT_NOT_A_REFERENCE),
600                 FE(DMUS_E_SCRIPT_VALUE_NOT_SUPPORTED),
601                 FE(DMUS_E_INVALID_SEGMENTTRIGGERTRACK),
602                 FE(DMUS_E_INVALID_LYRICSTRACK),
603                 FE(DMUS_E_INVALID_PARAMCONTROLTRACK),
604                 FE(DMUS_E_AUDIOVBSCRIPT_SYNTAXERROR),
605                 FE(DMUS_E_AUDIOVBSCRIPT_RUNTIMEERROR),
606                 FE(DMUS_E_AUDIOVBSCRIPT_OPERATIONFAILURE),
607                 FE(DMUS_E_AUDIOPATHS_NOT_VALID),
608                 FE(DMUS_E_AUDIOPATHS_IN_USE),
609                 FE(DMUS_E_NO_AUDIOPATH_CONFIG),
610                 FE(DMUS_E_AUDIOPATH_INACTIVE),
611                 FE(DMUS_E_AUDIOPATH_NOBUFFER),
612                 FE(DMUS_E_AUDIOPATH_NOPORT),
613                 FE(DMUS_E_NO_AUDIOPATH),
614                 FE(DMUS_E_INVALIDCHUNK),
615                 FE(DMUS_E_AUDIOPATH_NOGLOBALFXBUFFER),
616                 FE(DMUS_E_INVALID_CONTAINER_OBJECT)
617         };
618         
619         unsigned int i;
620         for (i = 0; i < sizeof(codes)/sizeof(codes[0]); i++) {
621                 if (code == codes[i].val)
622                         return codes[i].name;
623         }
624         
625         /* if we didn't find it, return value */
626         return wine_dbg_sprintf("0x%08X", code);
627 }
628
629
630 /* generic flag-dumping function */
631 const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
632         static char buffer[128] = "", *ptr = &buffer[0];
633         unsigned int i, size = sizeof(buffer);
634                 
635         for (i=0; i < num_names; i++) {
636                 if ((flags & names[i].val)) {
637                         int cnt = snprintf(ptr, size, "%s ", names[i].name);
638                         if (cnt < 0 || cnt >= size) break;
639                         size -= cnt;
640                         ptr += cnt;
641                 }
642         }
643         
644         ptr = &buffer[0];
645         return ptr;
646 }
647
648 /* dump DMUS_OBJ flags */
649 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
650     static const flag_info flags[] = {
651             FE(DMUS_OBJ_OBJECT),
652             FE(DMUS_OBJ_CLASS),
653             FE(DMUS_OBJ_NAME),
654             FE(DMUS_OBJ_CATEGORY),
655             FE(DMUS_OBJ_FILENAME),
656             FE(DMUS_OBJ_FULLPATH),
657             FE(DMUS_OBJ_URL),
658             FE(DMUS_OBJ_VERSION),
659             FE(DMUS_OBJ_DATE),
660             FE(DMUS_OBJ_LOADED),
661             FE(DMUS_OBJ_MEMORY),
662             FE(DMUS_OBJ_STREAM)
663         };
664     return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
665 }
666
667 /* dump DMUS_CONTAINER flags */
668 static const char *debugstr_DMUS_CONTAINER_FLAGS (DWORD flagmask) {
669     static const flag_info flags[] = {
670             FE(DMUS_CONTAINER_NOLOADS)
671         };
672     return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
673 }
674
675 /* dump DMUS_CONTAINED_OBJF flags */
676 static const char *debugstr_DMUS_CONTAINED_OBJF_FLAGS (DWORD flagmask) {
677     static const flag_info flags[] = {
678             FE(DMUS_CONTAINED_OBJF_KEEP)
679         };
680     return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
681 }
682
683 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
684         if (pDesc) {
685                 char buffer[1024], *ptr = buffer;
686                 
687                 ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
688                 ptr += sprintf(ptr, " - dwSize = 0x%08X\n", pDesc->dwSize);
689                 ptr += sprintf(ptr, " - dwValidData = 0x%08X ( %s)\n", pDesc->dwValidData, debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
690                 if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
691                 if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
692                 if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = %s\n", debugstr_filetime (&pDesc->ftDate));
693                 if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
694                 if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
695                 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
696                 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
697                 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = 0x%s\n  - pbMemData = %p\n",
698                                                                      wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
699                 if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p\n", pDesc->pStream);
700                 
701                 return wine_dbg_sprintf("%s", buffer);
702         } else {
703                 return wine_dbg_sprintf("(NULL)");
704         }
705 }
706
707 void debug_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
708         if (pDesc) {
709                 TRACE("DMUS_OBJECTDESC (%p):\n", pDesc);
710                 TRACE(" - dwSize = %d\n", pDesc->dwSize);
711                 TRACE(" - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
712                 if (pDesc->dwValidData & DMUS_OBJ_NAME)     TRACE(" - wszName = %s\n", debugstr_w(pDesc->wszName));
713                 if (pDesc->dwValidData & DMUS_OBJ_CLASS)    TRACE(" - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
714                 if (pDesc->dwValidData & DMUS_OBJ_OBJECT)   TRACE(" - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
715                 if (pDesc->dwValidData & DMUS_OBJ_DATE)     TRACE(" - ftDate = FIXME\n");
716                 if (pDesc->dwValidData & DMUS_OBJ_VERSION)  TRACE(" - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
717                 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) TRACE(" - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
718                 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) TRACE(" - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
719                 if (pDesc->dwValidData & DMUS_OBJ_MEMORY)   TRACE(" - llMemLength = 0x%s\n  - pbMemData = %p\n",
720                                                                 wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
721                 if (pDesc->dwValidData & DMUS_OBJ_STREAM)   TRACE(" - pStream = %p\n", pDesc->pStream);
722         } else {
723                 TRACE("(NULL)\n");
724         }
725 }
726
727 const char *debugstr_DMUS_IO_CONTAINER_HEADER (LPDMUS_IO_CONTAINER_HEADER pHeader) {
728         if (pHeader) {
729                 char buffer[1024], *ptr = buffer;
730                 
731                 ptr += sprintf(ptr, "DMUS_IO_CONTAINER_HEADER (%p):\n", pHeader);
732                 ptr += sprintf(ptr, " - dwFlags = %s\n", debugstr_DMUS_CONTAINER_FLAGS(pHeader->dwFlags));
733                 
734                 return wine_dbg_sprintf("%s", buffer);
735         } else {
736                 return wine_dbg_sprintf("(NULL)");
737         }
738 }
739
740 const char *debugstr_DMUS_IO_CONTAINED_OBJECT_HEADER (LPDMUS_IO_CONTAINED_OBJECT_HEADER pHeader) {
741         if (pHeader) {
742                 char buffer[1024], *ptr = buffer;
743                 
744                 ptr += sprintf(ptr, "DMUS_IO_CONTAINED_OBJECT_HEADER (%p):\n", pHeader);
745                 ptr += sprintf(ptr, " - guidClassID = %s\n", debugstr_dmguid(&pHeader->guidClassID));
746                 ptr += sprintf(ptr, " - dwFlags = %s\n", debugstr_DMUS_CONTAINED_OBJF_FLAGS (pHeader->dwFlags));
747                 ptr += sprintf(ptr, " - ckid = %s\n", debugstr_fourcc (pHeader->ckid));
748                 ptr += sprintf(ptr, " - fccType = %s\n", debugstr_fourcc (pHeader->fccType));
749
750                 return wine_dbg_sprintf("%s", buffer);
751         } else {
752                 return wine_dbg_sprintf("(NULL)");
753         }
754 }