msxml3/tests: Add test for parsing from IStream.
[wine] / dlls / dmusic / dmusic_main.c
1 /* DirectMusic Main
2  *
3  * Copyright (C) 2003-2004 Rok Mandeljc
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include "config.h"
21 #include "wine/port.h"
22
23 #include <stdio.h>
24
25 #include "dmusic_private.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
28
29 LONG DMUSIC_refCount = 0;
30
31 typedef struct {
32     const IClassFactoryVtbl *lpVtbl;
33 } IClassFactoryImpl;
34
35 /******************************************************************
36  *              DirectMusic ClassFactory
37  */
38 static HRESULT WINAPI DirectMusicCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
39         FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
40
41         if (ppobj == NULL) return E_POINTER;
42         
43         return E_NOINTERFACE;
44 }
45
46 static ULONG WINAPI DirectMusicCF_AddRef(LPCLASSFACTORY iface) {
47         DMUSIC_LockModule();
48
49         return 2; /* non-heap based object */
50 }
51
52 static ULONG WINAPI DirectMusicCF_Release(LPCLASSFACTORY iface) {
53         DMUSIC_UnlockModule();
54
55         return 1; /* non-heap based object */
56 }
57
58 static HRESULT WINAPI DirectMusicCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
59         TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
60         return DMUSIC_CreateDirectMusicImpl (riid, ppobj, pOuter);
61 }
62
63 static HRESULT WINAPI DirectMusicCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
64         TRACE("(%d)\n", dolock);
65
66         if (dolock)
67                 DMUSIC_LockModule();
68         else
69                 DMUSIC_UnlockModule();
70         
71         return S_OK;
72 }
73
74 static const IClassFactoryVtbl DirectMusicCF_Vtbl = {
75         DirectMusicCF_QueryInterface,
76         DirectMusicCF_AddRef,
77         DirectMusicCF_Release,
78         DirectMusicCF_CreateInstance,
79         DirectMusicCF_LockServer
80 };
81
82 static IClassFactoryImpl DirectMusic_CF = {&DirectMusicCF_Vtbl};
83
84 /******************************************************************
85  *              DirectMusicCollection ClassFactory
86  */
87 static HRESULT WINAPI CollectionCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
88         FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
89
90         if (ppobj == NULL) return E_POINTER;
91         
92         return E_NOINTERFACE;
93 }
94
95 static ULONG WINAPI CollectionCF_AddRef(LPCLASSFACTORY iface) {
96         DMUSIC_LockModule();
97
98         return 2; /* non-heap based object */
99 }
100
101 static ULONG WINAPI CollectionCF_Release(LPCLASSFACTORY iface) {
102         DMUSIC_UnlockModule();
103
104         return 1; /* non-heap based object */
105 }
106
107 static HRESULT WINAPI CollectionCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
108         TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
109         return DMUSIC_CreateDirectMusicCollectionImpl (riid, ppobj, pOuter);
110 }
111
112 static HRESULT WINAPI CollectionCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
113         TRACE("(%d)\n", dolock);
114
115         if (dolock)
116                 DMUSIC_LockModule();
117         else
118                 DMUSIC_UnlockModule();
119         
120         return S_OK;
121 }
122
123 static const IClassFactoryVtbl CollectionCF_Vtbl = {
124         CollectionCF_QueryInterface,
125         CollectionCF_AddRef,
126         CollectionCF_Release,
127         CollectionCF_CreateInstance,
128         CollectionCF_LockServer
129 };
130
131 static IClassFactoryImpl Collection_CF = {&CollectionCF_Vtbl};
132
133 /******************************************************************
134  *              DllMain
135  *
136  *
137  */
138 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
139         if (fdwReason == DLL_PROCESS_ATTACH) {
140             DisableThreadLibraryCalls(hinstDLL);
141                 /* FIXME: Initialisation */
142         } else if (fdwReason == DLL_PROCESS_DETACH) {
143                 /* FIXME: Cleanup */
144         }
145
146         return TRUE;
147 }
148
149
150 /******************************************************************
151  *              DllCanUnloadNow (DMUSIC.@)
152  *
153  *
154  */
155 HRESULT WINAPI DllCanUnloadNow(void)
156 {
157         return DMUSIC_refCount != 0 ? S_FALSE : S_OK;
158 }
159
160
161 /******************************************************************
162  *              DllGetClassObject (DMUSIC.@)
163  *
164  *
165  */
166 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
167 {
168         TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
169         if (IsEqualCLSID (rclsid, &CLSID_DirectMusic) && IsEqualIID (riid, &IID_IClassFactory)) {
170                 *ppv = (LPVOID) &DirectMusic_CF;
171                 IClassFactory_AddRef((IClassFactory*)*ppv);
172                 return S_OK;
173         } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicCollection) && IsEqualIID (riid, &IID_IClassFactory)) {
174                 *ppv = (LPVOID) &Collection_CF;
175                 IClassFactory_AddRef((IClassFactory*)*ppv);
176                 return S_OK;
177         }
178         
179     WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
180     return CLASS_E_CLASSNOTAVAILABLE;
181 }
182
183
184 /******************************************************************
185  *              Helper functions
186  *
187  *
188  */
189 /* dwPatch from MIDILOCALE */
190 DWORD MIDILOCALE2Patch (LPMIDILOCALE pLocale) {
191         DWORD dwPatch = 0;
192         if (!pLocale) return 0;
193         dwPatch |= (pLocale->ulBank & F_INSTRUMENT_DRUMS); /* set drum bit */
194         dwPatch |= ((pLocale->ulBank & 0x00007F7F) << 8); /* set MIDI bank location */
195         dwPatch |= (pLocale->ulInstrument & 0x0000007F); /* set PC value */
196         return dwPatch; 
197 }
198
199 /* MIDILOCALE from dwPatch */
200 void Patch2MIDILOCALE (DWORD dwPatch, LPMIDILOCALE pLocale) {
201         memset (pLocale, 0, sizeof(MIDILOCALE));
202         
203         pLocale->ulInstrument = (dwPatch & 0x7F); /* get PC value */
204         pLocale->ulBank = ((dwPatch & 0x007F7F00) >> 8); /* get MIDI bank location */
205         pLocale->ulBank |= (dwPatch & F_INSTRUMENT_DRUMS); /* get drum bit */
206 }
207
208 /* check whether the given DWORD is even (return 0) or odd (return 1) */
209 int even_or_odd (DWORD number) {
210         return (number & 0x1); /* basically, check if bit 0 is set ;) */
211 }
212
213 /* FOURCC to string conversion for debug messages */
214 const char *debugstr_fourcc (DWORD fourcc) {
215     if (!fourcc) return "'null'";
216     return wine_dbg_sprintf ("\'%c%c%c%c\'",
217                 (char)(fourcc), (char)(fourcc >> 8),
218         (char)(fourcc >> 16), (char)(fourcc >> 24));
219 }
220
221 /* DMUS_VERSION struct to string conversion for debug messages */
222 const char *debugstr_dmversion (const DMUS_VERSION *version) {
223         if (!version) return "'null'";
224         return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
225                 (int)((version->dwVersionMS & 0xFFFF0000) >> 8), (int)(version->dwVersionMS & 0x0000FFFF), 
226                 (int)((version->dwVersionLS & 0xFFFF0000) >> 8), (int)(version->dwVersionLS & 0x0000FFFF));
227 }
228
229 /* returns name of given GUID */
230 const char *debugstr_dmguid (const GUID *id) {
231         static const guid_info guids[] = {
232                 /* CLSIDs */
233                 GE(CLSID_AudioVBScript),
234                 GE(CLSID_DirectMusic),
235                 GE(CLSID_DirectMusicAudioPath),
236                 GE(CLSID_DirectMusicAudioPathConfig),
237                 GE(CLSID_DirectMusicAuditionTrack),
238                 GE(CLSID_DirectMusicBand),
239                 GE(CLSID_DirectMusicBandTrack),
240                 GE(CLSID_DirectMusicChordMapTrack),
241                 GE(CLSID_DirectMusicChordMap),
242                 GE(CLSID_DirectMusicChordTrack),
243                 GE(CLSID_DirectMusicCollection),
244                 GE(CLSID_DirectMusicCommandTrack),
245                 GE(CLSID_DirectMusicComposer),
246                 GE(CLSID_DirectMusicContainer),
247                 GE(CLSID_DirectMusicGraph),
248                 GE(CLSID_DirectMusicLoader),
249                 GE(CLSID_DirectMusicLyricsTrack),
250                 GE(CLSID_DirectMusicMarkerTrack),
251                 GE(CLSID_DirectMusicMelodyFormulationTrack),
252                 GE(CLSID_DirectMusicMotifTrack),
253                 GE(CLSID_DirectMusicMuteTrack),
254                 GE(CLSID_DirectMusicParamControlTrack),
255                 GE(CLSID_DirectMusicPatternTrack),
256                 GE(CLSID_DirectMusicPerformance),
257                 GE(CLSID_DirectMusicScript),
258                 GE(CLSID_DirectMusicScriptAutoImpSegment),
259                 GE(CLSID_DirectMusicScriptAutoImpPerformance),
260                 GE(CLSID_DirectMusicScriptAutoImpSegmentState),
261                 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
262                 GE(CLSID_DirectMusicScriptAutoImpAudioPath),
263                 GE(CLSID_DirectMusicScriptAutoImpSong),
264                 GE(CLSID_DirectMusicScriptSourceCodeLoader),
265                 GE(CLSID_DirectMusicScriptTrack),
266                 GE(CLSID_DirectMusicSection),
267                 GE(CLSID_DirectMusicSegment),
268                 GE(CLSID_DirectMusicSegmentState),
269                 GE(CLSID_DirectMusicSegmentTriggerTrack),
270                 GE(CLSID_DirectMusicSegTriggerTrack),
271                 GE(CLSID_DirectMusicSeqTrack),
272                 GE(CLSID_DirectMusicSignPostTrack),
273                 GE(CLSID_DirectMusicSong),
274                 GE(CLSID_DirectMusicStyle),
275                 GE(CLSID_DirectMusicStyleTrack),
276                 GE(CLSID_DirectMusicSynth),
277                 GE(CLSID_DirectMusicSynthSink),
278                 GE(CLSID_DirectMusicSysExTrack),
279                 GE(CLSID_DirectMusicTemplate),
280                 GE(CLSID_DirectMusicTempoTrack),
281                 GE(CLSID_DirectMusicTimeSigTrack),
282                 GE(CLSID_DirectMusicWaveTrack),
283                 GE(CLSID_DirectSoundWave),
284                 /* IIDs */
285                 GE(IID_IDirectMusic),
286                 GE(IID_IDirectMusic2),
287                 GE(IID_IDirectMusic8),
288                 GE(IID_IDirectMusicAudioPath),
289                 GE(IID_IDirectMusicBand),
290                 GE(IID_IDirectMusicBuffer),
291                 GE(IID_IDirectMusicChordMap),
292                 GE(IID_IDirectMusicCollection),
293                 GE(IID_IDirectMusicComposer),
294                 GE(IID_IDirectMusicContainer),
295                 GE(IID_IDirectMusicDownload),
296                 GE(IID_IDirectMusicDownloadedInstrument),
297                 GE(IID_IDirectMusicGetLoader),
298                 GE(IID_IDirectMusicGraph),
299                 GE(IID_IDirectMusicInstrument),
300                 GE(IID_IDirectMusicLoader),
301                 GE(IID_IDirectMusicLoader8),
302                 GE(IID_IDirectMusicObject),
303                 GE(IID_IDirectMusicPatternTrack),
304                 GE(IID_IDirectMusicPerformance),
305                 GE(IID_IDirectMusicPerformance2),
306                 GE(IID_IDirectMusicPerformance8),
307                 GE(IID_IDirectMusicPort),
308                 GE(IID_IDirectMusicPortDownload),
309                 GE(IID_IDirectMusicScript),
310                 GE(IID_IDirectMusicSegment),
311                 GE(IID_IDirectMusicSegment2),
312                 GE(IID_IDirectMusicSegment8),
313                 GE(IID_IDirectMusicSegmentState),
314                 GE(IID_IDirectMusicSegmentState8),
315                 GE(IID_IDirectMusicStyle),
316                 GE(IID_IDirectMusicStyle8),
317                 GE(IID_IDirectMusicSynth),
318                 GE(IID_IDirectMusicSynth8),
319                 GE(IID_IDirectMusicSynthSink),
320                 GE(IID_IDirectMusicThru),
321                 GE(IID_IDirectMusicTool),
322                 GE(IID_IDirectMusicTool8),
323                 GE(IID_IDirectMusicTrack),
324                 GE(IID_IDirectMusicTrack8),
325                 GE(IID_IUnknown),
326                 GE(IID_IPersistStream),
327                 GE(IID_IStream),
328                 GE(IID_IClassFactory),
329                 /* GUIDs */
330                 GE(GUID_DirectMusicAllTypes),
331                 GE(GUID_NOTIFICATION_CHORD),
332                 GE(GUID_NOTIFICATION_COMMAND),
333                 GE(GUID_NOTIFICATION_MEASUREANDBEAT),
334                 GE(GUID_NOTIFICATION_PERFORMANCE),
335                 GE(GUID_NOTIFICATION_RECOMPOSE),
336                 GE(GUID_NOTIFICATION_SEGMENT),
337                 GE(GUID_BandParam),
338                 GE(GUID_ChordParam),
339                 GE(GUID_CommandParam),
340                 GE(GUID_CommandParam2),
341                 GE(GUID_CommandParamNext),
342                 GE(GUID_IDirectMusicBand),
343                 GE(GUID_IDirectMusicChordMap),
344                 GE(GUID_IDirectMusicStyle),
345                 GE(GUID_MuteParam),
346                 GE(GUID_Play_Marker),
347                 GE(GUID_RhythmParam),
348                 GE(GUID_TempoParam),
349                 GE(GUID_TimeSignature),
350                 GE(GUID_Valid_Start_Time),
351                 GE(GUID_Clear_All_Bands),
352                 GE(GUID_ConnectToDLSCollection),
353                 GE(GUID_Disable_Auto_Download),
354                 GE(GUID_DisableTempo),
355                 GE(GUID_DisableTimeSig),
356                 GE(GUID_Download),
357                 GE(GUID_DownloadToAudioPath),
358                 GE(GUID_Enable_Auto_Download),
359                 GE(GUID_EnableTempo),
360                 GE(GUID_EnableTimeSig),
361                 GE(GUID_IgnoreBankSelectForGM),
362                 GE(GUID_SeedVariations),
363                 GE(GUID_StandardMIDIFile),
364                 GE(GUID_Unload),
365                 GE(GUID_UnloadFromAudioPath),
366                 GE(GUID_Variations),
367                 GE(GUID_PerfMasterTempo),
368                 GE(GUID_PerfMasterVolume),
369                 GE(GUID_PerfMasterGrooveLevel),
370                 GE(GUID_PerfAutoDownload),
371                 GE(GUID_DefaultGMCollection),
372                 GE(GUID_Synth_Default),
373                 GE(GUID_Buffer_Reverb),
374                 GE(GUID_Buffer_EnvReverb),
375                 GE(GUID_Buffer_Stereo),
376                 GE(GUID_Buffer_3D_Dry),
377                 GE(GUID_Buffer_Mono),
378                 GE(GUID_DMUS_PROP_GM_Hardware),
379                 GE(GUID_DMUS_PROP_GS_Capable),
380                 GE(GUID_DMUS_PROP_GS_Hardware),
381                 GE(GUID_DMUS_PROP_DLS1),
382                 GE(GUID_DMUS_PROP_DLS2),
383                 GE(GUID_DMUS_PROP_Effects),
384                 GE(GUID_DMUS_PROP_INSTRUMENT2),
385                 GE(GUID_DMUS_PROP_LegacyCaps),
386                 GE(GUID_DMUS_PROP_MemorySize),
387                 GE(GUID_DMUS_PROP_SampleMemorySize),
388                 GE(GUID_DMUS_PROP_SamplePlaybackRate),
389                 GE(GUID_DMUS_PROP_SetSynthSink),
390                 GE(GUID_DMUS_PROP_SinkUsesDSound),
391                 GE(GUID_DMUS_PROP_SynthSink_DSOUND),
392                 GE(GUID_DMUS_PROP_SynthSink_WAVE),
393                 GE(GUID_DMUS_PROP_Volume),
394                 GE(GUID_DMUS_PROP_WavesReverb),
395                 GE(GUID_DMUS_PROP_WriteLatency),
396                 GE(GUID_DMUS_PROP_WritePeriod),
397                 GE(GUID_DMUS_PROP_XG_Capable),
398                 GE(GUID_DMUS_PROP_XG_Hardware)
399         };
400
401         unsigned int i;
402
403         if (!id) return "(null)";
404
405         for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
406                 if (IsEqualGUID(id, guids[i].guid))
407                         return guids[i].name;
408         }
409         /* if we didn't find it, act like standard debugstr_guid */     
410         return debugstr_guid(id);
411 }       
412
413 /* returns name of given error code */
414 const char *debugstr_dmreturn (DWORD code) {
415         static const flag_info codes[] = {
416                 FE(S_OK),
417                 FE(S_FALSE),
418                 FE(DMUS_S_PARTIALLOAD),
419                 FE(DMUS_S_PARTIALDOWNLOAD),
420                 FE(DMUS_S_REQUEUE),
421                 FE(DMUS_S_FREE),
422                 FE(DMUS_S_END),
423                 FE(DMUS_S_STRING_TRUNCATED),
424                 FE(DMUS_S_LAST_TOOL),
425                 FE(DMUS_S_OVER_CHORD),
426                 FE(DMUS_S_UP_OCTAVE),
427                 FE(DMUS_S_DOWN_OCTAVE),
428                 FE(DMUS_S_NOBUFFERCONTROL),
429                 FE(DMUS_S_GARBAGE_COLLECTED),
430                 FE(DMUS_E_DRIVER_FAILED),
431                 FE(DMUS_E_PORTS_OPEN),
432                 FE(DMUS_E_DEVICE_IN_USE),
433                 FE(DMUS_E_INSUFFICIENTBUFFER),
434                 FE(DMUS_E_BUFFERNOTSET),
435                 FE(DMUS_E_BUFFERNOTAVAILABLE),
436                 FE(DMUS_E_NOTADLSCOL),
437                 FE(DMUS_E_INVALIDOFFSET),
438                 FE(DMUS_E_ALREADY_LOADED),
439                 FE(DMUS_E_INVALIDPOS),
440                 FE(DMUS_E_INVALIDPATCH),
441                 FE(DMUS_E_CANNOTSEEK),
442                 FE(DMUS_E_CANNOTWRITE),
443                 FE(DMUS_E_CHUNKNOTFOUND),
444                 FE(DMUS_E_INVALID_DOWNLOADID),
445                 FE(DMUS_E_NOT_DOWNLOADED_TO_PORT),
446                 FE(DMUS_E_ALREADY_DOWNLOADED),
447                 FE(DMUS_E_UNKNOWN_PROPERTY),
448                 FE(DMUS_E_SET_UNSUPPORTED),
449                 FE(DMUS_E_GET_UNSUPPORTED),
450                 FE(DMUS_E_NOTMONO),
451                 FE(DMUS_E_BADARTICULATION),
452                 FE(DMUS_E_BADINSTRUMENT),
453                 FE(DMUS_E_BADWAVELINK),
454                 FE(DMUS_E_NOARTICULATION),
455                 FE(DMUS_E_NOTPCM),
456                 FE(DMUS_E_BADWAVE),
457                 FE(DMUS_E_BADOFFSETTABLE),
458                 FE(DMUS_E_UNKNOWNDOWNLOAD),
459                 FE(DMUS_E_NOSYNTHSINK),
460                 FE(DMUS_E_ALREADYOPEN),
461                 FE(DMUS_E_ALREADYCLOSED),
462                 FE(DMUS_E_SYNTHNOTCONFIGURED),
463                 FE(DMUS_E_SYNTHACTIVE),
464                 FE(DMUS_E_CANNOTREAD),
465                 FE(DMUS_E_DMUSIC_RELEASED),
466                 FE(DMUS_E_BUFFER_EMPTY),
467                 FE(DMUS_E_BUFFER_FULL),
468                 FE(DMUS_E_PORT_NOT_CAPTURE),
469                 FE(DMUS_E_PORT_NOT_RENDER),
470                 FE(DMUS_E_DSOUND_NOT_SET),
471                 FE(DMUS_E_ALREADY_ACTIVATED),
472                 FE(DMUS_E_INVALIDBUFFER),
473                 FE(DMUS_E_WAVEFORMATNOTSUPPORTED),
474                 FE(DMUS_E_SYNTHINACTIVE),
475                 FE(DMUS_E_DSOUND_ALREADY_SET),
476                 FE(DMUS_E_INVALID_EVENT),
477                 FE(DMUS_E_UNSUPPORTED_STREAM),
478                 FE(DMUS_E_ALREADY_INITED),
479                 FE(DMUS_E_INVALID_BAND),
480                 FE(DMUS_E_TRACK_HDR_NOT_FIRST_CK),
481                 FE(DMUS_E_TOOL_HDR_NOT_FIRST_CK),
482                 FE(DMUS_E_INVALID_TRACK_HDR),
483                 FE(DMUS_E_INVALID_TOOL_HDR),
484                 FE(DMUS_E_ALL_TOOLS_FAILED),
485                 FE(DMUS_E_ALL_TRACKS_FAILED),
486                 FE(DMUS_E_NOT_FOUND),
487                 FE(DMUS_E_NOT_INIT),
488                 FE(DMUS_E_TYPE_DISABLED),
489                 FE(DMUS_E_TYPE_UNSUPPORTED),
490                 FE(DMUS_E_TIME_PAST),
491                 FE(DMUS_E_TRACK_NOT_FOUND),
492                 FE(DMUS_E_TRACK_NO_CLOCKTIME_SUPPORT),
493                 FE(DMUS_E_NO_MASTER_CLOCK),
494                 FE(DMUS_E_LOADER_NOCLASSID),
495                 FE(DMUS_E_LOADER_BADPATH),
496                 FE(DMUS_E_LOADER_FAILEDOPEN),
497                 FE(DMUS_E_LOADER_FORMATNOTSUPPORTED),
498                 FE(DMUS_E_LOADER_FAILEDCREATE),
499                 FE(DMUS_E_LOADER_OBJECTNOTFOUND),
500                 FE(DMUS_E_LOADER_NOFILENAME),
501                 FE(DMUS_E_INVALIDFILE),
502                 FE(DMUS_E_ALREADY_EXISTS),
503                 FE(DMUS_E_OUT_OF_RANGE),
504                 FE(DMUS_E_SEGMENT_INIT_FAILED),
505                 FE(DMUS_E_ALREADY_SENT),
506                 FE(DMUS_E_CANNOT_FREE),
507                 FE(DMUS_E_CANNOT_OPEN_PORT),
508                 FE(DMUS_E_CANNOT_CONVERT),
509                 FE(DMUS_E_DESCEND_CHUNK_FAIL),
510                 FE(DMUS_E_NOT_LOADED),
511                 FE(DMUS_E_SCRIPT_LANGUAGE_INCOMPATIBLE),
512                 FE(DMUS_E_SCRIPT_UNSUPPORTED_VARTYPE),
513                 FE(DMUS_E_SCRIPT_ERROR_IN_SCRIPT),
514                 FE(DMUS_E_SCRIPT_CANTLOAD_OLEAUT32),
515                 FE(DMUS_E_SCRIPT_LOADSCRIPT_ERROR),
516                 FE(DMUS_E_SCRIPT_INVALID_FILE),
517                 FE(DMUS_E_INVALID_SCRIPTTRACK),
518                 FE(DMUS_E_SCRIPT_VARIABLE_NOT_FOUND),
519                 FE(DMUS_E_SCRIPT_ROUTINE_NOT_FOUND),
520                 FE(DMUS_E_SCRIPT_CONTENT_READONLY),
521                 FE(DMUS_E_SCRIPT_NOT_A_REFERENCE),
522                 FE(DMUS_E_SCRIPT_VALUE_NOT_SUPPORTED),
523                 FE(DMUS_E_INVALID_SEGMENTTRIGGERTRACK),
524                 FE(DMUS_E_INVALID_LYRICSTRACK),
525                 FE(DMUS_E_INVALID_PARAMCONTROLTRACK),
526                 FE(DMUS_E_AUDIOVBSCRIPT_SYNTAXERROR),
527                 FE(DMUS_E_AUDIOVBSCRIPT_RUNTIMEERROR),
528                 FE(DMUS_E_AUDIOVBSCRIPT_OPERATIONFAILURE),
529                 FE(DMUS_E_AUDIOPATHS_NOT_VALID),
530                 FE(DMUS_E_AUDIOPATHS_IN_USE),
531                 FE(DMUS_E_NO_AUDIOPATH_CONFIG),
532                 FE(DMUS_E_AUDIOPATH_INACTIVE),
533                 FE(DMUS_E_AUDIOPATH_NOBUFFER),
534                 FE(DMUS_E_AUDIOPATH_NOPORT),
535                 FE(DMUS_E_NO_AUDIOPATH),
536                 FE(DMUS_E_INVALIDCHUNK),
537                 FE(DMUS_E_AUDIOPATH_NOGLOBALFXBUFFER),
538                 FE(DMUS_E_INVALID_CONTAINER_OBJECT)
539         };
540         unsigned int i;
541         for (i = 0; i < sizeof(codes)/sizeof(codes[0]); i++) {
542                 if (code == codes[i].val)
543                         return codes[i].name;
544         }
545         /* if we didn't find it, return value */
546         return wine_dbg_sprintf("0x%08x", code);
547 }
548
549 /* generic flag-dumping function */
550 const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
551         char buffer[128] = "", *ptr = &buffer[0];
552         unsigned int i, size = sizeof(buffer);
553         
554         for (i=0; i < num_names; i++)
555         {
556                 if ((flags & names[i].val) ||   /* standard flag*/
557                         ((!flags) && (!names[i].val))) { /* zero value only */
558                                 int cnt = snprintf(ptr, size, "%s ", names[i].name);
559                                 if (cnt < 0 || cnt >= size) break;
560                                 size -= cnt;
561                                 ptr += cnt;
562                 }
563         }
564         
565         return wine_dbg_sprintf("%s", buffer);
566 }
567
568 /* dump DMUS_OBJ flags */
569 const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
570     static const flag_info flags[] = {
571             FE(DMUS_OBJ_OBJECT),
572             FE(DMUS_OBJ_CLASS),
573             FE(DMUS_OBJ_NAME),
574             FE(DMUS_OBJ_CATEGORY),
575             FE(DMUS_OBJ_FILENAME),
576             FE(DMUS_OBJ_FULLPATH),
577             FE(DMUS_OBJ_URL),
578             FE(DMUS_OBJ_VERSION),
579             FE(DMUS_OBJ_DATE),
580             FE(DMUS_OBJ_LOADED),
581             FE(DMUS_OBJ_MEMORY),
582             FE(DMUS_OBJ_STREAM)
583         };
584     return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
585 }
586
587 /* dump whole DMUS_OBJECTDESC struct */
588 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
589         if (pDesc) {
590                 char buffer[1024] = "", *ptr = &buffer[0];
591                 
592                 ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
593                 ptr += sprintf(ptr, " - dwSize = %d\n", pDesc->dwSize);
594                 ptr += sprintf(ptr, " - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
595                 if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
596                 if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
597                 if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = FIXME\n");
598                 if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
599                 if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
600                 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
601                 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
602                 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = 0x%s\n  - pbMemData = %p\n",
603                                                                      wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
604                 if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p", pDesc->pStream);
605
606                 return wine_dbg_sprintf("%s", buffer);
607         } else {
608                 return wine_dbg_sprintf("(NULL)");
609         }
610 }