krnl386.exe16: Make a couple of functions static.
[wine.git] / dlls / dmscript / dmscript_main.c
blob6a3c686629e922cb38aba9d5fb4650095da72bd9
1 /* DirectMusicScript Main
3 * Copyright (C) 2003-2004 Rok Mandeljc
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.
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.
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
20 #include "config.h"
21 #include "wine/port.h"
23 #include <stdarg.h>
25 #define COBJMACROS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winnt.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winreg.h"
33 #include "objbase.h"
34 #include "rpcproxy.h"
35 #include "initguid.h"
36 #include "dmusici.h"
38 #include "dmscript_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(dmscript);
42 static HINSTANCE instance;
43 LONG DMSCRIPT_refCount = 0;
45 typedef struct {
46 IClassFactory IClassFactory_iface;
47 HRESULT WINAPI (*fnCreateInstance)(REFIID riid, void **ppv, IUnknown *pUnkOuter);
48 } IClassFactoryImpl;
50 static HRESULT WINAPI create_unimpl_instance(REFIID riid, void **ppv, IUnknown *pUnkOuter)
52 FIXME("(%p, %s, %p) stub\n", pUnkOuter, debugstr_dmguid(riid), ppv);
54 return CLASS_E_CLASSNOTAVAILABLE;
57 /******************************************************************
58 * IClassFactory implementation
60 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
62 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
65 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
67 if (ppv == NULL)
68 return E_POINTER;
70 if (IsEqualGUID(&IID_IUnknown, riid))
71 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
72 else if (IsEqualGUID(&IID_IClassFactory, riid))
73 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
74 else {
75 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
76 *ppv = NULL;
77 return E_NOINTERFACE;
80 *ppv = iface;
81 IUnknown_AddRef((IUnknown*)*ppv);
82 return S_OK;
85 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
87 DMSCRIPT_LockModule();
89 return 2; /* non-heap based object */
92 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
94 DMSCRIPT_UnlockModule();
96 return 1; /* non-heap based object */
99 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
100 REFIID riid, void **ppv)
102 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
104 TRACE ("(%p, %s, %p)\n", pUnkOuter, debugstr_dmguid(riid), ppv);
106 return This->fnCreateInstance(riid, ppv, pUnkOuter);
109 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
111 TRACE("(%d)\n", dolock);
113 if (dolock)
114 DMSCRIPT_LockModule();
115 else
116 DMSCRIPT_UnlockModule();
118 return S_OK;
121 static const IClassFactoryVtbl classfactory_vtbl = {
122 ClassFactory_QueryInterface,
123 ClassFactory_AddRef,
124 ClassFactory_Release,
125 ClassFactory_CreateInstance,
126 ClassFactory_LockServer
129 static IClassFactoryImpl ScriptAutoImplSegment_CF = {{&classfactory_vtbl}, create_unimpl_instance};
130 static IClassFactoryImpl ScriptTrack_CF = {{&classfactory_vtbl},
131 DMUSIC_CreateDirectMusicScriptTrack};
132 static IClassFactoryImpl AudioVBScript_CF = {{&classfactory_vtbl}, create_unimpl_instance};
133 static IClassFactoryImpl Script_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicScriptImpl};
134 static IClassFactoryImpl ScriptAutoImplPerformance_CF = {{&classfactory_vtbl},
135 create_unimpl_instance};
136 static IClassFactoryImpl ScriptSourceCodeLoader_CF = {{&classfactory_vtbl}, create_unimpl_instance};
137 static IClassFactoryImpl ScriptAutoImplSegmentState_CF = {{&classfactory_vtbl},
138 create_unimpl_instance};
139 static IClassFactoryImpl ScriptAutoImplAudioPathConfig_CF = {{&classfactory_vtbl},
140 create_unimpl_instance};
141 static IClassFactoryImpl ScriptAutoImplAudioPath_CF = {{&classfactory_vtbl},
142 create_unimpl_instance};
143 static IClassFactoryImpl ScriptAutoImplSong_CF = {{&classfactory_vtbl}, create_unimpl_instance};
145 /******************************************************************
146 * DllMain
150 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
151 if (fdwReason == DLL_PROCESS_ATTACH) {
152 instance = hinstDLL;
153 DisableThreadLibraryCalls(hinstDLL);
156 return TRUE;
160 /******************************************************************
161 * DllCanUnloadNow (DMSCRIPT.@)
165 HRESULT WINAPI DllCanUnloadNow(void)
167 return DMSCRIPT_refCount != 0 ? S_FALSE : S_OK;
171 /******************************************************************
172 * DllGetClassObject (DMSCRIPT.@)
176 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
178 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
179 if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSegment) && IsEqualIID (riid, &IID_IClassFactory)) {
180 *ppv = &ScriptAutoImplSegment_CF;
181 IClassFactory_AddRef((IClassFactory*)*ppv);
182 return S_OK;
183 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
184 *ppv = &ScriptTrack_CF;
185 IClassFactory_AddRef((IClassFactory*)*ppv);
186 return S_OK;
187 } else if (IsEqualCLSID (rclsid, &CLSID_AudioVBScript) && IsEqualIID (riid, &IID_IClassFactory)) {
188 *ppv = &AudioVBScript_CF;
189 IClassFactory_AddRef((IClassFactory*)*ppv);
190 return S_OK;
191 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScript) && IsEqualIID (riid, &IID_IClassFactory)) {
192 *ppv = &Script_CF;
193 IClassFactory_AddRef((IClassFactory*)*ppv);
194 return S_OK;
195 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpPerformance) && IsEqualIID (riid, &IID_IClassFactory)) {
196 *ppv = &ScriptAutoImplPerformance_CF;
197 IClassFactory_AddRef((IClassFactory*)*ppv);
198 return S_OK;
199 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptSourceCodeLoader) && IsEqualIID (riid, &IID_IClassFactory)) {
200 *ppv = &ScriptSourceCodeLoader_CF;
201 IClassFactory_AddRef((IClassFactory*)*ppv);
202 return S_OK;
203 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSegmentState) && IsEqualIID (riid, &IID_IClassFactory)) {
204 *ppv = &ScriptAutoImplSegmentState_CF;
205 IClassFactory_AddRef((IClassFactory*)*ppv);
206 return S_OK;
207 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpAudioPathConfig) && IsEqualIID (riid, &IID_IClassFactory)) {
208 *ppv = &ScriptAutoImplAudioPathConfig_CF;
209 IClassFactory_AddRef((IClassFactory*)*ppv);
210 return S_OK;
211 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpAudioPath) && IsEqualIID (riid, &IID_IClassFactory)) {
212 *ppv = &ScriptAutoImplAudioPath_CF;
213 IClassFactory_AddRef((IClassFactory*)*ppv);
214 return S_OK;
215 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicScriptAutoImpSong) && IsEqualIID (riid, &IID_IClassFactory)) {
216 *ppv = &ScriptAutoImplSong_CF;
217 IClassFactory_AddRef((IClassFactory*)*ppv);
218 return S_OK;
221 WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
222 return CLASS_E_CLASSNOTAVAILABLE;
226 /***********************************************************************
227 * DllRegisterServer (DMSCRIPT.@)
229 HRESULT WINAPI DllRegisterServer(void)
231 return __wine_register_resources( instance );
234 /***********************************************************************
235 * DllUnregisterServer (DMSCRIPT.@)
237 HRESULT WINAPI DllUnregisterServer(void)
239 return __wine_unregister_resources( instance );
242 /******************************************************************
243 * Helper functions
248 /* FOURCC to string conversion for debug messages */
249 const char *debugstr_fourcc (DWORD fourcc) {
250 if (!fourcc) return "'null'";
251 return wine_dbg_sprintf ("\'%c%c%c%c\'",
252 (char)(fourcc), (char)(fourcc >> 8),
253 (char)(fourcc >> 16), (char)(fourcc >> 24));
256 /* DMUS_VERSION struct to string conversion for debug messages */
257 static const char *debugstr_dmversion (const DMUS_VERSION *version) {
258 if (!version) return "'null'";
259 return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
260 (int)((version->dwVersionMS & 0xFFFF0000) >> 8), (int)(version->dwVersionMS & 0x0000FFFF),
261 (int)((version->dwVersionLS & 0xFFFF0000) >> 8), (int)(version->dwVersionLS & 0x0000FFFF));
264 /* returns name of given GUID */
265 const char *debugstr_dmguid (const GUID *id) {
266 static const guid_info guids[] = {
267 /* CLSIDs */
268 GE(CLSID_AudioVBScript),
269 GE(CLSID_DirectMusic),
270 GE(CLSID_DirectMusicAudioPathConfig),
271 GE(CLSID_DirectMusicAuditionTrack),
272 GE(CLSID_DirectMusicBand),
273 GE(CLSID_DirectMusicBandTrack),
274 GE(CLSID_DirectMusicChordMapTrack),
275 GE(CLSID_DirectMusicChordMap),
276 GE(CLSID_DirectMusicChordTrack),
277 GE(CLSID_DirectMusicCollection),
278 GE(CLSID_DirectMusicCommandTrack),
279 GE(CLSID_DirectMusicComposer),
280 GE(CLSID_DirectMusicContainer),
281 GE(CLSID_DirectMusicGraph),
282 GE(CLSID_DirectMusicLoader),
283 GE(CLSID_DirectMusicLyricsTrack),
284 GE(CLSID_DirectMusicMarkerTrack),
285 GE(CLSID_DirectMusicMelodyFormulationTrack),
286 GE(CLSID_DirectMusicMotifTrack),
287 GE(CLSID_DirectMusicMuteTrack),
288 GE(CLSID_DirectMusicParamControlTrack),
289 GE(CLSID_DirectMusicPatternTrack),
290 GE(CLSID_DirectMusicPerformance),
291 GE(CLSID_DirectMusicScript),
292 GE(CLSID_DirectMusicScriptAutoImpSegment),
293 GE(CLSID_DirectMusicScriptAutoImpPerformance),
294 GE(CLSID_DirectMusicScriptAutoImpSegmentState),
295 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
296 GE(CLSID_DirectMusicScriptAutoImpAudioPath),
297 GE(CLSID_DirectMusicScriptAutoImpSong),
298 GE(CLSID_DirectMusicScriptSourceCodeLoader),
299 GE(CLSID_DirectMusicScriptTrack),
300 GE(CLSID_DirectMusicSection),
301 GE(CLSID_DirectMusicSegment),
302 GE(CLSID_DirectMusicSegmentState),
303 GE(CLSID_DirectMusicSegmentTriggerTrack),
304 GE(CLSID_DirectMusicSegTriggerTrack),
305 GE(CLSID_DirectMusicSeqTrack),
306 GE(CLSID_DirectMusicSignPostTrack),
307 GE(CLSID_DirectMusicSong),
308 GE(CLSID_DirectMusicStyle),
309 GE(CLSID_DirectMusicStyleTrack),
310 GE(CLSID_DirectMusicSynth),
311 GE(CLSID_DirectMusicSynthSink),
312 GE(CLSID_DirectMusicSysExTrack),
313 GE(CLSID_DirectMusicTemplate),
314 GE(CLSID_DirectMusicTempoTrack),
315 GE(CLSID_DirectMusicTimeSigTrack),
316 GE(CLSID_DirectMusicWaveTrack),
317 GE(CLSID_DirectSoundWave),
318 /* IIDs */
319 GE(IID_IDirectMusic),
320 GE(IID_IDirectMusic2),
321 GE(IID_IDirectMusic8),
322 GE(IID_IDirectMusicAudioPath),
323 GE(IID_IDirectMusicBand),
324 GE(IID_IDirectMusicBuffer),
325 GE(IID_IDirectMusicChordMap),
326 GE(IID_IDirectMusicCollection),
327 GE(IID_IDirectMusicComposer),
328 GE(IID_IDirectMusicContainer),
329 GE(IID_IDirectMusicDownload),
330 GE(IID_IDirectMusicDownloadedInstrument),
331 GE(IID_IDirectMusicGetLoader),
332 GE(IID_IDirectMusicGraph),
333 GE(IID_IDirectMusicInstrument),
334 GE(IID_IDirectMusicLoader),
335 GE(IID_IDirectMusicLoader8),
336 GE(IID_IDirectMusicObject),
337 GE(IID_IDirectMusicPatternTrack),
338 GE(IID_IDirectMusicPerformance),
339 GE(IID_IDirectMusicPerformance2),
340 GE(IID_IDirectMusicPerformance8),
341 GE(IID_IDirectMusicPort),
342 GE(IID_IDirectMusicPortDownload),
343 GE(IID_IDirectMusicScript),
344 GE(IID_IDirectMusicSegment),
345 GE(IID_IDirectMusicSegment2),
346 GE(IID_IDirectMusicSegment8),
347 GE(IID_IDirectMusicSegmentState),
348 GE(IID_IDirectMusicSegmentState8),
349 GE(IID_IDirectMusicStyle),
350 GE(IID_IDirectMusicStyle8),
351 GE(IID_IDirectMusicSynth),
352 GE(IID_IDirectMusicSynth8),
353 GE(IID_IDirectMusicSynthSink),
354 GE(IID_IDirectMusicThru),
355 GE(IID_IDirectMusicTool),
356 GE(IID_IDirectMusicTool8),
357 GE(IID_IDirectMusicTrack),
358 GE(IID_IDirectMusicTrack8),
359 GE(IID_IUnknown),
360 GE(IID_IPersistStream),
361 GE(IID_IStream),
362 GE(IID_IClassFactory),
363 /* GUIDs */
364 GE(GUID_DirectMusicAllTypes),
365 GE(GUID_NOTIFICATION_CHORD),
366 GE(GUID_NOTIFICATION_COMMAND),
367 GE(GUID_NOTIFICATION_MEASUREANDBEAT),
368 GE(GUID_NOTIFICATION_PERFORMANCE),
369 GE(GUID_NOTIFICATION_RECOMPOSE),
370 GE(GUID_NOTIFICATION_SEGMENT),
371 GE(GUID_BandParam),
372 GE(GUID_ChordParam),
373 GE(GUID_CommandParam),
374 GE(GUID_CommandParam2),
375 GE(GUID_CommandParamNext),
376 GE(GUID_IDirectMusicBand),
377 GE(GUID_IDirectMusicChordMap),
378 GE(GUID_IDirectMusicStyle),
379 GE(GUID_MuteParam),
380 GE(GUID_Play_Marker),
381 GE(GUID_RhythmParam),
382 GE(GUID_TempoParam),
383 GE(GUID_TimeSignature),
384 GE(GUID_Valid_Start_Time),
385 GE(GUID_Clear_All_Bands),
386 GE(GUID_ConnectToDLSCollection),
387 GE(GUID_Disable_Auto_Download),
388 GE(GUID_DisableTempo),
389 GE(GUID_DisableTimeSig),
390 GE(GUID_Download),
391 GE(GUID_DownloadToAudioPath),
392 GE(GUID_Enable_Auto_Download),
393 GE(GUID_EnableTempo),
394 GE(GUID_EnableTimeSig),
395 GE(GUID_IgnoreBankSelectForGM),
396 GE(GUID_SeedVariations),
397 GE(GUID_StandardMIDIFile),
398 GE(GUID_Unload),
399 GE(GUID_UnloadFromAudioPath),
400 GE(GUID_Variations),
401 GE(GUID_PerfMasterTempo),
402 GE(GUID_PerfMasterVolume),
403 GE(GUID_PerfMasterGrooveLevel),
404 GE(GUID_PerfAutoDownload),
405 GE(GUID_DefaultGMCollection),
406 GE(GUID_Synth_Default),
407 GE(GUID_Buffer_Reverb),
408 GE(GUID_Buffer_EnvReverb),
409 GE(GUID_Buffer_Stereo),
410 GE(GUID_Buffer_3D_Dry),
411 GE(GUID_Buffer_Mono),
412 GE(GUID_DMUS_PROP_GM_Hardware),
413 GE(GUID_DMUS_PROP_GS_Capable),
414 GE(GUID_DMUS_PROP_GS_Hardware),
415 GE(GUID_DMUS_PROP_DLS1),
416 GE(GUID_DMUS_PROP_DLS2),
417 GE(GUID_DMUS_PROP_Effects),
418 GE(GUID_DMUS_PROP_INSTRUMENT2),
419 GE(GUID_DMUS_PROP_LegacyCaps),
420 GE(GUID_DMUS_PROP_MemorySize),
421 GE(GUID_DMUS_PROP_SampleMemorySize),
422 GE(GUID_DMUS_PROP_SamplePlaybackRate),
423 GE(GUID_DMUS_PROP_SetSynthSink),
424 GE(GUID_DMUS_PROP_SinkUsesDSound),
425 GE(GUID_DMUS_PROP_SynthSink_DSOUND),
426 GE(GUID_DMUS_PROP_SynthSink_WAVE),
427 GE(GUID_DMUS_PROP_Volume),
428 GE(GUID_DMUS_PROP_WavesReverb),
429 GE(GUID_DMUS_PROP_WriteLatency),
430 GE(GUID_DMUS_PROP_WritePeriod),
431 GE(GUID_DMUS_PROP_XG_Capable),
432 GE(GUID_DMUS_PROP_XG_Hardware)
435 unsigned int i;
437 if (!id) return "(null)";
439 for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
440 if (IsEqualGUID(id, guids[i].guid))
441 return guids[i].name;
443 /* if we didn't find it, act like standard debugstr_guid */
444 return debugstr_guid(id);
447 /* generic flag-dumping function */
448 static const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
449 char buffer[128] = "", *ptr = &buffer[0];
450 unsigned int i;
451 int size = sizeof(buffer);
453 for (i=0; i < num_names; i++)
455 if ((flags & names[i].val) || /* standard flag*/
456 ((!flags) && (!names[i].val))) { /* zero value only */
457 int cnt = snprintf(ptr, size, "%s ", names[i].name);
458 if (cnt < 0 || cnt >= size) break;
459 size -= cnt;
460 ptr += cnt;
464 return wine_dbg_sprintf("%s", buffer);
467 /* dump DMUS_OBJ flags */
468 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
469 static const flag_info flags[] = {
470 FE(DMUS_OBJ_OBJECT),
471 FE(DMUS_OBJ_CLASS),
472 FE(DMUS_OBJ_NAME),
473 FE(DMUS_OBJ_CATEGORY),
474 FE(DMUS_OBJ_FILENAME),
475 FE(DMUS_OBJ_FULLPATH),
476 FE(DMUS_OBJ_URL),
477 FE(DMUS_OBJ_VERSION),
478 FE(DMUS_OBJ_DATE),
479 FE(DMUS_OBJ_LOADED),
480 FE(DMUS_OBJ_MEMORY),
481 FE(DMUS_OBJ_STREAM)
483 return debugstr_flags (flagmask, flags, sizeof(flags)/sizeof(flags[0]));
486 /* dump whole DMUS_OBJECTDESC struct */
487 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
488 if (pDesc) {
489 char buffer[1024] = "", *ptr = &buffer[0];
491 ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
492 ptr += sprintf(ptr, " - dwSize = %d\n", pDesc->dwSize);
493 ptr += sprintf(ptr, " - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
494 if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
495 if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
496 if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = FIXME\n");
497 if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
498 if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
499 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
500 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
501 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = 0x%s\n - pbMemData = %p\n",
502 wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
503 if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p", pDesc->pStream);
505 return wine_dbg_sprintf("%s", buffer);
506 } else {
507 return wine_dbg_sprintf("(NULL)");