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
21 #include "wine/port.h"
23 #include "dmcompos_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(dmcompos
);
28 static HINSTANCE instance
;
29 LONG DMCOMPOS_refCount
= 0;
32 IClassFactory IClassFactory_iface
;
33 HRESULT
WINAPI (*fnCreateInstance
)(REFIID riid
, void **ret_iface
);
36 static HRESULT WINAPI
create_direct_music_template(REFIID riid
, void **ret_iface
)
38 FIXME("(%s, %p) stub\n", debugstr_dmguid(riid
), ret_iface
);
40 return CLASS_E_CLASSNOTAVAILABLE
;
43 /******************************************************************
44 * IClassFactory implementation
46 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
48 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
51 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
56 if (IsEqualGUID(&IID_IUnknown
, riid
))
57 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
58 else if (IsEqualGUID(&IID_IClassFactory
, riid
))
59 TRACE("(%p)->(IID_IClassFactory %p)\n", iface
, ppv
);
61 FIXME("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
67 IUnknown_AddRef((IUnknown
*)*ppv
);
71 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
73 DMCOMPOS_LockModule();
75 return 2; /* non-heap based object */
78 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
80 DMCOMPOS_UnlockModule();
82 return 1; /* non-heap based object */
85 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
86 REFIID riid
, void **ppv
)
88 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
90 TRACE ("(%p, %s, %p)\n", pUnkOuter
, debugstr_dmguid(riid
), ppv
);
94 return CLASS_E_NOAGGREGATION
;
97 return This
->fnCreateInstance(riid
, ppv
);
100 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
102 TRACE("(%d)\n", dolock
);
105 DMCOMPOS_LockModule();
107 DMCOMPOS_UnlockModule();
112 static const IClassFactoryVtbl classfactory_vtbl
= {
113 ClassFactory_QueryInterface
,
115 ClassFactory_Release
,
116 ClassFactory_CreateInstance
,
117 ClassFactory_LockServer
120 static IClassFactoryImpl ChordMap_CF
= {{&classfactory_vtbl
}, create_dmchordmap
};
121 static IClassFactoryImpl Composer_CF
= {{&classfactory_vtbl
}, create_dmcomposer
};
122 static IClassFactoryImpl ChordMapTrack_CF
= {{&classfactory_vtbl
}, create_dmchordmaptrack
};
123 static IClassFactoryImpl Template_CF
= {{&classfactory_vtbl
}, create_direct_music_template
};
124 static IClassFactoryImpl SignPostTrack_CF
= {{&classfactory_vtbl
}, create_dmsignposttrack
};
126 /******************************************************************
131 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
) {
132 if (fdwReason
== DLL_PROCESS_ATTACH
) {
134 DisableThreadLibraryCalls(hinstDLL
);
140 /******************************************************************
141 * DllCanUnloadNow (DMCOMPOS.@)
145 HRESULT WINAPI
DllCanUnloadNow(void) {
146 return DMCOMPOS_refCount
!= 0 ? S_FALSE
: S_OK
;
150 /******************************************************************
151 * DllGetClassObject (DMCOMPOS.@)
155 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
) {
156 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid
), debugstr_dmguid(riid
), ppv
);
157 if (IsEqualCLSID (rclsid
, &CLSID_DirectMusicChordMap
) && IsEqualIID (riid
, &IID_IClassFactory
)) {
159 IClassFactory_AddRef((IClassFactory
*)*ppv
);
161 } else if (IsEqualCLSID (rclsid
, &CLSID_DirectMusicComposer
) && IsEqualIID (riid
, &IID_IClassFactory
)) {
163 IClassFactory_AddRef((IClassFactory
*)*ppv
);
165 } else if (IsEqualCLSID (rclsid
, &CLSID_DirectMusicChordMapTrack
) && IsEqualIID (riid
, &IID_IClassFactory
)) {
166 *ppv
= &ChordMapTrack_CF
;
167 IClassFactory_AddRef((IClassFactory
*)*ppv
);
169 } else if (IsEqualCLSID (rclsid
, &CLSID_DirectMusicTemplate
) && IsEqualIID (riid
, &IID_IClassFactory
)) {
171 IClassFactory_AddRef((IClassFactory
*)*ppv
);
173 } else if (IsEqualCLSID (rclsid
, &CLSID_DirectMusicSignPostTrack
) && IsEqualIID (riid
, &IID_IClassFactory
)) {
174 *ppv
= &SignPostTrack_CF
;
175 IClassFactory_AddRef((IClassFactory
*)*ppv
);
179 WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid
), debugstr_dmguid(riid
), ppv
);
180 return CLASS_E_CLASSNOTAVAILABLE
;
183 /***********************************************************************
184 * DllRegisterServer (DMCOMPOS.@)
186 HRESULT WINAPI
DllRegisterServer(void)
188 return __wine_register_resources( instance
);
191 /***********************************************************************
192 * DllUnregisterServer (DMCOMPOS.@)
194 HRESULT WINAPI
DllUnregisterServer(void)
196 return __wine_unregister_resources( instance
);
199 /******************************************************************
204 /* FOURCC to string conversion for debug messages */
205 const char *debugstr_fourcc (DWORD fourcc
) {
206 if (!fourcc
) return "'null'";
207 return wine_dbg_sprintf ("\'%c%c%c%c\'",
208 (char)(fourcc
), (char)(fourcc
>> 8),
209 (char)(fourcc
>> 16), (char)(fourcc
>> 24));
212 /* DMUS_VERSION struct to string conversion for debug messages */
213 static const char *debugstr_dmversion (const DMUS_VERSION
*version
) {
214 if (!version
) return "'null'";
215 return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
216 (int)((version
->dwVersionMS
& 0xFFFF0000) >> 8), (int)(version
->dwVersionMS
& 0x0000FFFF),
217 (int)((version
->dwVersionLS
& 0xFFFF0000) >> 8), (int)(version
->dwVersionLS
& 0x0000FFFF));
220 /* returns name of given GUID */
221 const char *debugstr_dmguid (const GUID
*id
) {
222 static const guid_info guids
[] = {
224 GE(CLSID_AudioVBScript
),
225 GE(CLSID_DirectMusic
),
226 GE(CLSID_DirectMusicAudioPathConfig
),
227 GE(CLSID_DirectMusicAuditionTrack
),
228 GE(CLSID_DirectMusicBand
),
229 GE(CLSID_DirectMusicBandTrack
),
230 GE(CLSID_DirectMusicChordMapTrack
),
231 GE(CLSID_DirectMusicChordMap
),
232 GE(CLSID_DirectMusicChordTrack
),
233 GE(CLSID_DirectMusicCollection
),
234 GE(CLSID_DirectMusicCommandTrack
),
235 GE(CLSID_DirectMusicComposer
),
236 GE(CLSID_DirectMusicContainer
),
237 GE(CLSID_DirectMusicGraph
),
238 GE(CLSID_DirectMusicLoader
),
239 GE(CLSID_DirectMusicLyricsTrack
),
240 GE(CLSID_DirectMusicMarkerTrack
),
241 GE(CLSID_DirectMusicMelodyFormulationTrack
),
242 GE(CLSID_DirectMusicMotifTrack
),
243 GE(CLSID_DirectMusicMuteTrack
),
244 GE(CLSID_DirectMusicParamControlTrack
),
245 GE(CLSID_DirectMusicPatternTrack
),
246 GE(CLSID_DirectMusicPerformance
),
247 GE(CLSID_DirectMusicScript
),
248 GE(CLSID_DirectMusicScriptAutoImpSegment
),
249 GE(CLSID_DirectMusicScriptAutoImpPerformance
),
250 GE(CLSID_DirectMusicScriptAutoImpSegmentState
),
251 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig
),
252 GE(CLSID_DirectMusicScriptAutoImpAudioPath
),
253 GE(CLSID_DirectMusicScriptAutoImpSong
),
254 GE(CLSID_DirectMusicScriptSourceCodeLoader
),
255 GE(CLSID_DirectMusicScriptTrack
),
256 GE(CLSID_DirectMusicSection
),
257 GE(CLSID_DirectMusicSegment
),
258 GE(CLSID_DirectMusicSegmentState
),
259 GE(CLSID_DirectMusicSegmentTriggerTrack
),
260 GE(CLSID_DirectMusicSegTriggerTrack
),
261 GE(CLSID_DirectMusicSeqTrack
),
262 GE(CLSID_DirectMusicSignPostTrack
),
263 GE(CLSID_DirectMusicSong
),
264 GE(CLSID_DirectMusicStyle
),
265 GE(CLSID_DirectMusicStyleTrack
),
266 GE(CLSID_DirectMusicSynth
),
267 GE(CLSID_DirectMusicSynthSink
),
268 GE(CLSID_DirectMusicSysExTrack
),
269 GE(CLSID_DirectMusicTemplate
),
270 GE(CLSID_DirectMusicTempoTrack
),
271 GE(CLSID_DirectMusicTimeSigTrack
),
272 GE(CLSID_DirectMusicWaveTrack
),
273 GE(CLSID_DirectSoundWave
),
275 GE(IID_IDirectMusic
),
276 GE(IID_IDirectMusic2
),
277 GE(IID_IDirectMusic8
),
278 GE(IID_IDirectMusicAudioPath
),
279 GE(IID_IDirectMusicBand
),
280 GE(IID_IDirectMusicBuffer
),
281 GE(IID_IDirectMusicChordMap
),
282 GE(IID_IDirectMusicCollection
),
283 GE(IID_IDirectMusicComposer
),
284 GE(IID_IDirectMusicContainer
),
285 GE(IID_IDirectMusicDownload
),
286 GE(IID_IDirectMusicDownloadedInstrument
),
287 GE(IID_IDirectMusicGetLoader
),
288 GE(IID_IDirectMusicGraph
),
289 GE(IID_IDirectMusicInstrument
),
290 GE(IID_IDirectMusicLoader
),
291 GE(IID_IDirectMusicLoader8
),
292 GE(IID_IDirectMusicObject
),
293 GE(IID_IDirectMusicPatternTrack
),
294 GE(IID_IDirectMusicPerformance
),
295 GE(IID_IDirectMusicPerformance2
),
296 GE(IID_IDirectMusicPerformance8
),
297 GE(IID_IDirectMusicPort
),
298 GE(IID_IDirectMusicPortDownload
),
299 GE(IID_IDirectMusicScript
),
300 GE(IID_IDirectMusicSegment
),
301 GE(IID_IDirectMusicSegment2
),
302 GE(IID_IDirectMusicSegment8
),
303 GE(IID_IDirectMusicSegmentState
),
304 GE(IID_IDirectMusicSegmentState8
),
305 GE(IID_IDirectMusicStyle
),
306 GE(IID_IDirectMusicStyle8
),
307 GE(IID_IDirectMusicSynth
),
308 GE(IID_IDirectMusicSynth8
),
309 GE(IID_IDirectMusicSynthSink
),
310 GE(IID_IDirectMusicThru
),
311 GE(IID_IDirectMusicTool
),
312 GE(IID_IDirectMusicTool8
),
313 GE(IID_IDirectMusicTrack
),
314 GE(IID_IDirectMusicTrack8
),
316 GE(IID_IPersistStream
),
318 GE(IID_IClassFactory
),
320 GE(GUID_DirectMusicAllTypes
),
321 GE(GUID_NOTIFICATION_CHORD
),
322 GE(GUID_NOTIFICATION_COMMAND
),
323 GE(GUID_NOTIFICATION_MEASUREANDBEAT
),
324 GE(GUID_NOTIFICATION_PERFORMANCE
),
325 GE(GUID_NOTIFICATION_RECOMPOSE
),
326 GE(GUID_NOTIFICATION_SEGMENT
),
329 GE(GUID_CommandParam
),
330 GE(GUID_CommandParam2
),
331 GE(GUID_CommandParamNext
),
332 GE(GUID_IDirectMusicBand
),
333 GE(GUID_IDirectMusicChordMap
),
334 GE(GUID_IDirectMusicStyle
),
336 GE(GUID_Play_Marker
),
337 GE(GUID_RhythmParam
),
339 GE(GUID_TimeSignature
),
340 GE(GUID_Valid_Start_Time
),
341 GE(GUID_Clear_All_Bands
),
342 GE(GUID_ConnectToDLSCollection
),
343 GE(GUID_Disable_Auto_Download
),
344 GE(GUID_DisableTempo
),
345 GE(GUID_DisableTimeSig
),
347 GE(GUID_DownloadToAudioPath
),
348 GE(GUID_Enable_Auto_Download
),
349 GE(GUID_EnableTempo
),
350 GE(GUID_EnableTimeSig
),
351 GE(GUID_IgnoreBankSelectForGM
),
352 GE(GUID_SeedVariations
),
353 GE(GUID_StandardMIDIFile
),
355 GE(GUID_UnloadFromAudioPath
),
357 GE(GUID_PerfMasterTempo
),
358 GE(GUID_PerfMasterVolume
),
359 GE(GUID_PerfMasterGrooveLevel
),
360 GE(GUID_PerfAutoDownload
),
361 GE(GUID_DefaultGMCollection
),
362 GE(GUID_Synth_Default
),
363 GE(GUID_Buffer_Reverb
),
364 GE(GUID_Buffer_EnvReverb
),
365 GE(GUID_Buffer_Stereo
),
366 GE(GUID_Buffer_3D_Dry
),
367 GE(GUID_Buffer_Mono
),
368 GE(GUID_DMUS_PROP_GM_Hardware
),
369 GE(GUID_DMUS_PROP_GS_Capable
),
370 GE(GUID_DMUS_PROP_GS_Hardware
),
371 GE(GUID_DMUS_PROP_DLS1
),
372 GE(GUID_DMUS_PROP_DLS2
),
373 GE(GUID_DMUS_PROP_Effects
),
374 GE(GUID_DMUS_PROP_INSTRUMENT2
),
375 GE(GUID_DMUS_PROP_LegacyCaps
),
376 GE(GUID_DMUS_PROP_MemorySize
),
377 GE(GUID_DMUS_PROP_SampleMemorySize
),
378 GE(GUID_DMUS_PROP_SamplePlaybackRate
),
379 GE(GUID_DMUS_PROP_SetSynthSink
),
380 GE(GUID_DMUS_PROP_SinkUsesDSound
),
381 GE(GUID_DMUS_PROP_SynthSink_DSOUND
),
382 GE(GUID_DMUS_PROP_SynthSink_WAVE
),
383 GE(GUID_DMUS_PROP_Volume
),
384 GE(GUID_DMUS_PROP_WavesReverb
),
385 GE(GUID_DMUS_PROP_WriteLatency
),
386 GE(GUID_DMUS_PROP_WritePeriod
),
387 GE(GUID_DMUS_PROP_XG_Capable
),
388 GE(GUID_DMUS_PROP_XG_Hardware
)
393 if (!id
) return "(null)";
395 for (i
= 0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++) {
396 if (IsEqualGUID(id
, guids
[i
].guid
))
397 return guids
[i
].name
;
399 /* if we didn't find it, act like standard debugstr_guid */
400 return debugstr_guid(id
);
403 /* generic flag-dumping function */
404 static const char* debugstr_flags (DWORD flags
, const flag_info
* names
, size_t num_names
){
405 char buffer
[128] = "", *ptr
= &buffer
[0];
407 int size
= sizeof(buffer
);
409 for (i
=0; i
< num_names
; i
++)
411 if ((flags
& names
[i
].val
) || /* standard flag*/
412 ((!flags
) && (!names
[i
].val
))) { /* zero value only */
413 int cnt
= snprintf(ptr
, size
, "%s ", names
[i
].name
);
414 if (cnt
< 0 || cnt
>= size
) break;
420 return wine_dbg_sprintf("%s", buffer
);
423 /* dump DMUS_OBJ flags */
424 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask
) {
425 static const flag_info flags
[] = {
429 FE(DMUS_OBJ_CATEGORY
),
430 FE(DMUS_OBJ_FILENAME
),
431 FE(DMUS_OBJ_FULLPATH
),
433 FE(DMUS_OBJ_VERSION
),
439 return debugstr_flags (flagmask
, flags
, sizeof(flags
)/sizeof(flags
[0]));
442 /* dump whole DMUS_OBJECTDESC struct */
443 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc
) {
445 char buffer
[1024] = "", *ptr
= &buffer
[0];
447 ptr
+= sprintf(ptr
, "DMUS_OBJECTDESC (%p):\n", pDesc
);
448 ptr
+= sprintf(ptr
, " - dwSize = %d\n", pDesc
->dwSize
);
449 ptr
+= sprintf(ptr
, " - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc
->dwValidData
));
450 if (pDesc
->dwValidData
& DMUS_OBJ_CLASS
) ptr
+= sprintf(ptr
, " - guidClass = %s\n", debugstr_dmguid(&pDesc
->guidClass
));
451 if (pDesc
->dwValidData
& DMUS_OBJ_OBJECT
) ptr
+= sprintf(ptr
, " - guidObject = %s\n", debugstr_guid(&pDesc
->guidObject
));
452 if (pDesc
->dwValidData
& DMUS_OBJ_DATE
) ptr
+= sprintf(ptr
, " - ftDate = FIXME\n");
453 if (pDesc
->dwValidData
& DMUS_OBJ_VERSION
) ptr
+= sprintf(ptr
, " - vVersion = %s\n", debugstr_dmversion(&pDesc
->vVersion
));
454 if (pDesc
->dwValidData
& DMUS_OBJ_NAME
) ptr
+= sprintf(ptr
, " - wszName = %s\n", debugstr_w(pDesc
->wszName
));
455 if (pDesc
->dwValidData
& DMUS_OBJ_CATEGORY
) ptr
+= sprintf(ptr
, " - wszCategory = %s\n", debugstr_w(pDesc
->wszCategory
));
456 if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
) ptr
+= sprintf(ptr
, " - wszFileName = %s\n", debugstr_w(pDesc
->wszFileName
));
457 if (pDesc
->dwValidData
& DMUS_OBJ_MEMORY
) ptr
+= sprintf(ptr
, " - llMemLength = 0x%s\n - pbMemData = %p\n",
458 wine_dbgstr_longlong(pDesc
->llMemLength
), pDesc
->pbMemData
);
459 if (pDesc
->dwValidData
& DMUS_OBJ_STREAM
) ptr
+= sprintf(ptr
, " - pStream = %p", pDesc
->pStream
);
461 return wine_dbg_sprintf("%s", buffer
);
463 return wine_dbg_sprintf("(NULL)");