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