d3dx9: Use parameter data for the first constant only in d3dx_set_shader_const_state().
[wine.git] / dlls / dmcompos / dmcompos_main.c
blob2e68775084423e5c4a17ae523370648665ac6972
1 /* DirectMusicComposer 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 "initguid.h"
35 #include "dmusici.h"
37 #include "dmcompos_private.h"
38 #include "rpcproxy.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(dmcompos);
42 static HINSTANCE instance;
43 LONG DMCOMPOS_refCount = 0;
45 typedef struct {
46 IClassFactory IClassFactory_iface;
47 HRESULT WINAPI (*fnCreateInstance)(REFIID riid, void **ret_iface);
48 } IClassFactoryImpl;
50 static HRESULT WINAPI create_direct_music_template(REFIID riid, void **ret_iface)
52 FIXME("(%s, %p) stub\n", debugstr_dmguid(riid), ret_iface);
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 DMCOMPOS_LockModule();
89 return 2; /* non-heap based object */
92 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
94 DMCOMPOS_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 if (pUnkOuter) {
107 *ppv = NULL;
108 return CLASS_E_NOAGGREGATION;
111 return This->fnCreateInstance(riid, ppv);
114 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
116 TRACE("(%d)\n", dolock);
118 if (dolock)
119 DMCOMPOS_LockModule();
120 else
121 DMCOMPOS_UnlockModule();
123 return S_OK;
126 static const IClassFactoryVtbl classfactory_vtbl = {
127 ClassFactory_QueryInterface,
128 ClassFactory_AddRef,
129 ClassFactory_Release,
130 ClassFactory_CreateInstance,
131 ClassFactory_LockServer
134 static IClassFactoryImpl ChordMap_CF = {{&classfactory_vtbl}, create_dmchordmap};
135 static IClassFactoryImpl Composer_CF = {{&classfactory_vtbl}, create_dmcomposer};
136 static IClassFactoryImpl ChordMapTrack_CF = {{&classfactory_vtbl}, create_dmchordmaptrack};
137 static IClassFactoryImpl Template_CF = {{&classfactory_vtbl}, create_direct_music_template};
138 static IClassFactoryImpl SignPostTrack_CF = {{&classfactory_vtbl}, create_dmsignposttrack};
140 /******************************************************************
141 * DllMain
145 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
146 if (fdwReason == DLL_PROCESS_ATTACH) {
147 instance = hinstDLL;
148 DisableThreadLibraryCalls(hinstDLL);
150 return TRUE;
154 /******************************************************************
155 * DllCanUnloadNow (DMCOMPOS.@)
159 HRESULT WINAPI DllCanUnloadNow(void) {
160 return DMCOMPOS_refCount != 0 ? S_FALSE : S_OK;
164 /******************************************************************
165 * DllGetClassObject (DMCOMPOS.@)
169 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) {
170 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
171 if (IsEqualCLSID (rclsid, &CLSID_DirectMusicChordMap) && IsEqualIID (riid, &IID_IClassFactory)) {
172 *ppv = &ChordMap_CF;
173 IClassFactory_AddRef((IClassFactory*)*ppv);
174 return S_OK;
175 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicComposer) && IsEqualIID (riid, &IID_IClassFactory)) {
176 *ppv = &Composer_CF;
177 IClassFactory_AddRef((IClassFactory*)*ppv);
178 return S_OK;
179 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicChordMapTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
180 *ppv = &ChordMapTrack_CF;
181 IClassFactory_AddRef((IClassFactory*)*ppv);
182 return S_OK;
183 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicTemplate) && IsEqualIID (riid, &IID_IClassFactory)) {
184 *ppv = &Template_CF;
185 IClassFactory_AddRef((IClassFactory*)*ppv);
186 return S_OK;
187 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicSignPostTrack) && IsEqualIID (riid, &IID_IClassFactory)) {
188 *ppv = &SignPostTrack_CF;
189 IClassFactory_AddRef((IClassFactory*)*ppv);
190 return S_OK;
193 WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
194 return CLASS_E_CLASSNOTAVAILABLE;
197 /***********************************************************************
198 * DllRegisterServer (DMCOMPOS.@)
200 HRESULT WINAPI DllRegisterServer(void)
202 return __wine_register_resources( instance );
205 /***********************************************************************
206 * DllUnregisterServer (DMCOMPOS.@)
208 HRESULT WINAPI DllUnregisterServer(void)
210 return __wine_unregister_resources( instance );
213 /******************************************************************
214 * Helper functions
218 /* FOURCC to string conversion for debug messages */
219 const char *debugstr_fourcc (DWORD fourcc) {
220 if (!fourcc) return "'null'";
221 return wine_dbg_sprintf ("\'%c%c%c%c\'",
222 (char)(fourcc), (char)(fourcc >> 8),
223 (char)(fourcc >> 16), (char)(fourcc >> 24));
226 /* DMUS_VERSION struct to string conversion for debug messages */
227 static const char *debugstr_dmversion (const DMUS_VERSION *version) {
228 if (!version) return "'null'";
229 return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
230 (int)((version->dwVersionMS & 0xFFFF0000) >> 8), (int)(version->dwVersionMS & 0x0000FFFF),
231 (int)((version->dwVersionLS & 0xFFFF0000) >> 8), (int)(version->dwVersionLS & 0x0000FFFF));
234 /* returns name of given GUID */
235 const char *debugstr_dmguid (const GUID *id) {
236 static const guid_info guids[] = {
237 /* CLSIDs */
238 GE(CLSID_AudioVBScript),
239 GE(CLSID_DirectMusic),
240 GE(CLSID_DirectMusicAudioPathConfig),
241 GE(CLSID_DirectMusicAuditionTrack),
242 GE(CLSID_DirectMusicBand),
243 GE(CLSID_DirectMusicBandTrack),
244 GE(CLSID_DirectMusicChordMapTrack),
245 GE(CLSID_DirectMusicChordMap),
246 GE(CLSID_DirectMusicChordTrack),
247 GE(CLSID_DirectMusicCollection),
248 GE(CLSID_DirectMusicCommandTrack),
249 GE(CLSID_DirectMusicComposer),
250 GE(CLSID_DirectMusicContainer),
251 GE(CLSID_DirectMusicGraph),
252 GE(CLSID_DirectMusicLoader),
253 GE(CLSID_DirectMusicLyricsTrack),
254 GE(CLSID_DirectMusicMarkerTrack),
255 GE(CLSID_DirectMusicMelodyFormulationTrack),
256 GE(CLSID_DirectMusicMotifTrack),
257 GE(CLSID_DirectMusicMuteTrack),
258 GE(CLSID_DirectMusicParamControlTrack),
259 GE(CLSID_DirectMusicPatternTrack),
260 GE(CLSID_DirectMusicPerformance),
261 GE(CLSID_DirectMusicScript),
262 GE(CLSID_DirectMusicScriptAutoImpSegment),
263 GE(CLSID_DirectMusicScriptAutoImpPerformance),
264 GE(CLSID_DirectMusicScriptAutoImpSegmentState),
265 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig),
266 GE(CLSID_DirectMusicScriptAutoImpAudioPath),
267 GE(CLSID_DirectMusicScriptAutoImpSong),
268 GE(CLSID_DirectMusicScriptSourceCodeLoader),
269 GE(CLSID_DirectMusicScriptTrack),
270 GE(CLSID_DirectMusicSection),
271 GE(CLSID_DirectMusicSegment),
272 GE(CLSID_DirectMusicSegmentState),
273 GE(CLSID_DirectMusicSegmentTriggerTrack),
274 GE(CLSID_DirectMusicSegTriggerTrack),
275 GE(CLSID_DirectMusicSeqTrack),
276 GE(CLSID_DirectMusicSignPostTrack),
277 GE(CLSID_DirectMusicSong),
278 GE(CLSID_DirectMusicStyle),
279 GE(CLSID_DirectMusicStyleTrack),
280 GE(CLSID_DirectMusicSynth),
281 GE(CLSID_DirectMusicSynthSink),
282 GE(CLSID_DirectMusicSysExTrack),
283 GE(CLSID_DirectMusicTemplate),
284 GE(CLSID_DirectMusicTempoTrack),
285 GE(CLSID_DirectMusicTimeSigTrack),
286 GE(CLSID_DirectMusicWaveTrack),
287 GE(CLSID_DirectSoundWave),
288 /* IIDs */
289 GE(IID_IDirectMusic),
290 GE(IID_IDirectMusic2),
291 GE(IID_IDirectMusic8),
292 GE(IID_IDirectMusicAudioPath),
293 GE(IID_IDirectMusicBand),
294 GE(IID_IDirectMusicBuffer),
295 GE(IID_IDirectMusicChordMap),
296 GE(IID_IDirectMusicCollection),
297 GE(IID_IDirectMusicComposer),
298 GE(IID_IDirectMusicContainer),
299 GE(IID_IDirectMusicDownload),
300 GE(IID_IDirectMusicDownloadedInstrument),
301 GE(IID_IDirectMusicGetLoader),
302 GE(IID_IDirectMusicGraph),
303 GE(IID_IDirectMusicInstrument),
304 GE(IID_IDirectMusicLoader),
305 GE(IID_IDirectMusicLoader8),
306 GE(IID_IDirectMusicObject),
307 GE(IID_IDirectMusicPatternTrack),
308 GE(IID_IDirectMusicPerformance),
309 GE(IID_IDirectMusicPerformance2),
310 GE(IID_IDirectMusicPerformance8),
311 GE(IID_IDirectMusicPort),
312 GE(IID_IDirectMusicPortDownload),
313 GE(IID_IDirectMusicScript),
314 GE(IID_IDirectMusicSegment),
315 GE(IID_IDirectMusicSegment2),
316 GE(IID_IDirectMusicSegment8),
317 GE(IID_IDirectMusicSegmentState),
318 GE(IID_IDirectMusicSegmentState8),
319 GE(IID_IDirectMusicStyle),
320 GE(IID_IDirectMusicStyle8),
321 GE(IID_IDirectMusicSynth),
322 GE(IID_IDirectMusicSynth8),
323 GE(IID_IDirectMusicSynthSink),
324 GE(IID_IDirectMusicThru),
325 GE(IID_IDirectMusicTool),
326 GE(IID_IDirectMusicTool8),
327 GE(IID_IDirectMusicTrack),
328 GE(IID_IDirectMusicTrack8),
329 GE(IID_IUnknown),
330 GE(IID_IPersistStream),
331 GE(IID_IStream),
332 GE(IID_IClassFactory),
333 /* GUIDs */
334 GE(GUID_DirectMusicAllTypes),
335 GE(GUID_NOTIFICATION_CHORD),
336 GE(GUID_NOTIFICATION_COMMAND),
337 GE(GUID_NOTIFICATION_MEASUREANDBEAT),
338 GE(GUID_NOTIFICATION_PERFORMANCE),
339 GE(GUID_NOTIFICATION_RECOMPOSE),
340 GE(GUID_NOTIFICATION_SEGMENT),
341 GE(GUID_BandParam),
342 GE(GUID_ChordParam),
343 GE(GUID_CommandParam),
344 GE(GUID_CommandParam2),
345 GE(GUID_CommandParamNext),
346 GE(GUID_IDirectMusicBand),
347 GE(GUID_IDirectMusicChordMap),
348 GE(GUID_IDirectMusicStyle),
349 GE(GUID_MuteParam),
350 GE(GUID_Play_Marker),
351 GE(GUID_RhythmParam),
352 GE(GUID_TempoParam),
353 GE(GUID_TimeSignature),
354 GE(GUID_Valid_Start_Time),
355 GE(GUID_Clear_All_Bands),
356 GE(GUID_ConnectToDLSCollection),
357 GE(GUID_Disable_Auto_Download),
358 GE(GUID_DisableTempo),
359 GE(GUID_DisableTimeSig),
360 GE(GUID_Download),
361 GE(GUID_DownloadToAudioPath),
362 GE(GUID_Enable_Auto_Download),
363 GE(GUID_EnableTempo),
364 GE(GUID_EnableTimeSig),
365 GE(GUID_IgnoreBankSelectForGM),
366 GE(GUID_SeedVariations),
367 GE(GUID_StandardMIDIFile),
368 GE(GUID_Unload),
369 GE(GUID_UnloadFromAudioPath),
370 GE(GUID_Variations),
371 GE(GUID_PerfMasterTempo),
372 GE(GUID_PerfMasterVolume),
373 GE(GUID_PerfMasterGrooveLevel),
374 GE(GUID_PerfAutoDownload),
375 GE(GUID_DefaultGMCollection),
376 GE(GUID_Synth_Default),
377 GE(GUID_Buffer_Reverb),
378 GE(GUID_Buffer_EnvReverb),
379 GE(GUID_Buffer_Stereo),
380 GE(GUID_Buffer_3D_Dry),
381 GE(GUID_Buffer_Mono),
382 GE(GUID_DMUS_PROP_GM_Hardware),
383 GE(GUID_DMUS_PROP_GS_Capable),
384 GE(GUID_DMUS_PROP_GS_Hardware),
385 GE(GUID_DMUS_PROP_DLS1),
386 GE(GUID_DMUS_PROP_DLS2),
387 GE(GUID_DMUS_PROP_Effects),
388 GE(GUID_DMUS_PROP_INSTRUMENT2),
389 GE(GUID_DMUS_PROP_LegacyCaps),
390 GE(GUID_DMUS_PROP_MemorySize),
391 GE(GUID_DMUS_PROP_SampleMemorySize),
392 GE(GUID_DMUS_PROP_SamplePlaybackRate),
393 GE(GUID_DMUS_PROP_SetSynthSink),
394 GE(GUID_DMUS_PROP_SinkUsesDSound),
395 GE(GUID_DMUS_PROP_SynthSink_DSOUND),
396 GE(GUID_DMUS_PROP_SynthSink_WAVE),
397 GE(GUID_DMUS_PROP_Volume),
398 GE(GUID_DMUS_PROP_WavesReverb),
399 GE(GUID_DMUS_PROP_WriteLatency),
400 GE(GUID_DMUS_PROP_WritePeriod),
401 GE(GUID_DMUS_PROP_XG_Capable),
402 GE(GUID_DMUS_PROP_XG_Hardware)
405 unsigned int i;
407 if (!id) return "(null)";
409 for (i = 0; i < ARRAY_SIZE(guids); i++) {
410 if (IsEqualGUID(id, guids[i].guid))
411 return guids[i].name;
413 /* if we didn't find it, act like standard debugstr_guid */
414 return debugstr_guid(id);
417 /* generic flag-dumping function */
418 static const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
419 char buffer[128] = "", *ptr = &buffer[0];
420 unsigned int i;
421 int size = sizeof(buffer);
423 for (i=0; i < num_names; i++)
425 if ((flags & names[i].val) || /* standard flag*/
426 ((!flags) && (!names[i].val))) { /* zero value only */
427 int cnt = snprintf(ptr, size, "%s ", names[i].name);
428 if (cnt < 0 || cnt >= size) break;
429 size -= cnt;
430 ptr += cnt;
434 return wine_dbg_sprintf("%s", buffer);
437 /* dump DMUS_OBJ flags */
438 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask) {
439 static const flag_info flags[] = {
440 FE(DMUS_OBJ_OBJECT),
441 FE(DMUS_OBJ_CLASS),
442 FE(DMUS_OBJ_NAME),
443 FE(DMUS_OBJ_CATEGORY),
444 FE(DMUS_OBJ_FILENAME),
445 FE(DMUS_OBJ_FULLPATH),
446 FE(DMUS_OBJ_URL),
447 FE(DMUS_OBJ_VERSION),
448 FE(DMUS_OBJ_DATE),
449 FE(DMUS_OBJ_LOADED),
450 FE(DMUS_OBJ_MEMORY),
451 FE(DMUS_OBJ_STREAM)
453 return debugstr_flags(flagmask, flags, ARRAY_SIZE(flags));
456 /* dump whole DMUS_OBJECTDESC struct */
457 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc) {
458 if (pDesc) {
459 char buffer[1024] = "", *ptr = &buffer[0];
461 ptr += sprintf(ptr, "DMUS_OBJECTDESC (%p):\n", pDesc);
462 ptr += sprintf(ptr, " - dwSize = %d\n", pDesc->dwSize);
463 ptr += sprintf(ptr, " - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc->dwValidData));
464 if (pDesc->dwValidData & DMUS_OBJ_CLASS) ptr += sprintf(ptr, " - guidClass = %s\n", debugstr_dmguid(&pDesc->guidClass));
465 if (pDesc->dwValidData & DMUS_OBJ_OBJECT) ptr += sprintf(ptr, " - guidObject = %s\n", debugstr_guid(&pDesc->guidObject));
466 if (pDesc->dwValidData & DMUS_OBJ_DATE) ptr += sprintf(ptr, " - ftDate = FIXME\n");
467 if (pDesc->dwValidData & DMUS_OBJ_VERSION) ptr += sprintf(ptr, " - vVersion = %s\n", debugstr_dmversion(&pDesc->vVersion));
468 if (pDesc->dwValidData & DMUS_OBJ_NAME) ptr += sprintf(ptr, " - wszName = %s\n", debugstr_w(pDesc->wszName));
469 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY) ptr += sprintf(ptr, " - wszCategory = %s\n", debugstr_w(pDesc->wszCategory));
470 if (pDesc->dwValidData & DMUS_OBJ_FILENAME) ptr += sprintf(ptr, " - wszFileName = %s\n", debugstr_w(pDesc->wszFileName));
471 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) ptr += sprintf(ptr, " - llMemLength = 0x%s\n - pbMemData = %p\n",
472 wine_dbgstr_longlong(pDesc->llMemLength), pDesc->pbMemData);
473 if (pDesc->dwValidData & DMUS_OBJ_STREAM) ptr += sprintf(ptr, " - pStream = %p", pDesc->pStream);
475 return wine_dbg_sprintf("%s", buffer);
476 } else {
477 return wine_dbg_sprintf("(NULL)");