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"
25 #include "dmusic_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(dmusic
);
30 static HINSTANCE instance
;
31 LONG DMUSIC_refCount
= 0;
34 const IClassFactoryVtbl
*lpVtbl
;
37 /******************************************************************
38 * DirectMusic ClassFactory
40 static HRESULT WINAPI
DirectMusicCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
) {
41 FIXME("- no interface IID: %s\n", debugstr_guid(riid
));
43 if (ppobj
== NULL
) return E_POINTER
;
48 static ULONG WINAPI
DirectMusicCF_AddRef(LPCLASSFACTORY iface
) {
51 return 2; /* non-heap based object */
54 static ULONG WINAPI
DirectMusicCF_Release(LPCLASSFACTORY iface
) {
55 DMUSIC_UnlockModule();
57 return 1; /* non-heap based object */
60 static HRESULT WINAPI
DirectMusicCF_CreateInstance(LPCLASSFACTORY iface
, LPUNKNOWN pOuter
, REFIID riid
, LPVOID
*ppobj
) {
61 TRACE ("(%p, %s, %p)\n", pOuter
, debugstr_dmguid(riid
), ppobj
);
62 return DMUSIC_CreateDirectMusicImpl (riid
, ppobj
, pOuter
);
65 static HRESULT WINAPI
DirectMusicCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
66 TRACE("(%d)\n", dolock
);
71 DMUSIC_UnlockModule();
76 static const IClassFactoryVtbl DirectMusicCF_Vtbl
= {
77 DirectMusicCF_QueryInterface
,
79 DirectMusicCF_Release
,
80 DirectMusicCF_CreateInstance
,
81 DirectMusicCF_LockServer
84 static IClassFactoryImpl DirectMusic_CF
= {&DirectMusicCF_Vtbl
};
86 /******************************************************************
87 * DirectMusicCollection ClassFactory
89 static HRESULT WINAPI
CollectionCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
) {
90 FIXME("- no interface IID: %s\n", debugstr_guid(riid
));
92 if (ppobj
== NULL
) return E_POINTER
;
97 static ULONG WINAPI
CollectionCF_AddRef(LPCLASSFACTORY iface
) {
100 return 2; /* non-heap based object */
103 static ULONG WINAPI
CollectionCF_Release(LPCLASSFACTORY iface
) {
104 DMUSIC_UnlockModule();
106 return 1; /* non-heap based object */
109 static HRESULT WINAPI
CollectionCF_CreateInstance(LPCLASSFACTORY iface
, LPUNKNOWN pOuter
, REFIID riid
, LPVOID
*ppobj
) {
110 TRACE ("(%p, %s, %p)\n", pOuter
, debugstr_dmguid(riid
), ppobj
);
111 return DMUSIC_CreateDirectMusicCollectionImpl (riid
, ppobj
, pOuter
);
114 static HRESULT WINAPI
CollectionCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
) {
115 TRACE("(%d)\n", dolock
);
120 DMUSIC_UnlockModule();
125 static const IClassFactoryVtbl CollectionCF_Vtbl
= {
126 CollectionCF_QueryInterface
,
128 CollectionCF_Release
,
129 CollectionCF_CreateInstance
,
130 CollectionCF_LockServer
133 static IClassFactoryImpl Collection_CF
= {&CollectionCF_Vtbl
};
135 /******************************************************************
140 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
) {
141 if (fdwReason
== DLL_PROCESS_ATTACH
) {
143 DisableThreadLibraryCalls(hinstDLL
);
144 /* FIXME: Initialisation */
145 } else if (fdwReason
== DLL_PROCESS_DETACH
) {
153 /******************************************************************
154 * DllCanUnloadNow (DMUSIC.@)
158 HRESULT WINAPI
DllCanUnloadNow(void)
160 return DMUSIC_refCount
!= 0 ? S_FALSE
: S_OK
;
164 /******************************************************************
165 * DllGetClassObject (DMUSIC.@)
169 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
171 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid
), debugstr_dmguid(riid
), ppv
);
172 if (IsEqualCLSID (rclsid
, &CLSID_DirectMusic
) && IsEqualIID (riid
, &IID_IClassFactory
)) {
173 *ppv
= &DirectMusic_CF
;
174 IClassFactory_AddRef((IClassFactory
*)*ppv
);
176 } else if (IsEqualCLSID (rclsid
, &CLSID_DirectMusicCollection
) && IsEqualIID (riid
, &IID_IClassFactory
)) {
177 *ppv
= &Collection_CF
;
178 IClassFactory_AddRef((IClassFactory
*)*ppv
);
182 WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid
), debugstr_dmguid(riid
), ppv
);
183 return CLASS_E_CLASSNOTAVAILABLE
;
186 /***********************************************************************
187 * DllRegisterServer (DMUSIC.@)
189 HRESULT WINAPI
DllRegisterServer(void)
191 return __wine_register_resources( instance
, NULL
);
194 /***********************************************************************
195 * DllUnregisterServer (DMUSIC.@)
197 HRESULT WINAPI
DllUnregisterServer(void)
199 return __wine_unregister_resources( instance
, NULL
);
202 /******************************************************************
207 /* dwPatch from MIDILOCALE */
208 DWORD
MIDILOCALE2Patch (const MIDILOCALE
*pLocale
) {
210 if (!pLocale
) return 0;
211 dwPatch
|= (pLocale
->ulBank
& F_INSTRUMENT_DRUMS
); /* set drum bit */
212 dwPatch
|= ((pLocale
->ulBank
& 0x00007F7F) << 8); /* set MIDI bank location */
213 dwPatch
|= (pLocale
->ulInstrument
& 0x0000007F); /* set PC value */
217 /* MIDILOCALE from dwPatch */
218 void Patch2MIDILOCALE (DWORD dwPatch
, LPMIDILOCALE pLocale
) {
219 memset (pLocale
, 0, sizeof(MIDILOCALE
));
221 pLocale
->ulInstrument
= (dwPatch
& 0x7F); /* get PC value */
222 pLocale
->ulBank
= ((dwPatch
& 0x007F7F00) >> 8); /* get MIDI bank location */
223 pLocale
->ulBank
|= (dwPatch
& F_INSTRUMENT_DRUMS
); /* get drum bit */
226 /* check whether the given DWORD is even (return 0) or odd (return 1) */
227 int even_or_odd (DWORD number
) {
228 return (number
& 0x1); /* basically, check if bit 0 is set ;) */
231 /* FOURCC to string conversion for debug messages */
232 const char *debugstr_fourcc (DWORD fourcc
) {
233 if (!fourcc
) return "'null'";
234 return wine_dbg_sprintf ("\'%c%c%c%c\'",
235 (char)(fourcc
), (char)(fourcc
>> 8),
236 (char)(fourcc
>> 16), (char)(fourcc
>> 24));
239 /* DMUS_VERSION struct to string conversion for debug messages */
240 static const char *debugstr_dmversion (const DMUS_VERSION
*version
) {
241 if (!version
) return "'null'";
242 return wine_dbg_sprintf ("\'%i,%i,%i,%i\'",
243 (int)((version
->dwVersionMS
& 0xFFFF0000) >> 8), (int)(version
->dwVersionMS
& 0x0000FFFF),
244 (int)((version
->dwVersionLS
& 0xFFFF0000) >> 8), (int)(version
->dwVersionLS
& 0x0000FFFF));
247 /* returns name of given GUID */
248 const char *debugstr_dmguid (const GUID
*id
) {
249 static const guid_info guids
[] = {
251 GE(CLSID_AudioVBScript
),
252 GE(CLSID_DirectMusic
),
253 GE(CLSID_DirectMusicAudioPath
),
254 GE(CLSID_DirectMusicAudioPathConfig
),
255 GE(CLSID_DirectMusicAuditionTrack
),
256 GE(CLSID_DirectMusicBand
),
257 GE(CLSID_DirectMusicBandTrack
),
258 GE(CLSID_DirectMusicChordMapTrack
),
259 GE(CLSID_DirectMusicChordMap
),
260 GE(CLSID_DirectMusicChordTrack
),
261 GE(CLSID_DirectMusicCollection
),
262 GE(CLSID_DirectMusicCommandTrack
),
263 GE(CLSID_DirectMusicComposer
),
264 GE(CLSID_DirectMusicContainer
),
265 GE(CLSID_DirectMusicGraph
),
266 GE(CLSID_DirectMusicLoader
),
267 GE(CLSID_DirectMusicLyricsTrack
),
268 GE(CLSID_DirectMusicMarkerTrack
),
269 GE(CLSID_DirectMusicMelodyFormulationTrack
),
270 GE(CLSID_DirectMusicMotifTrack
),
271 GE(CLSID_DirectMusicMuteTrack
),
272 GE(CLSID_DirectMusicParamControlTrack
),
273 GE(CLSID_DirectMusicPatternTrack
),
274 GE(CLSID_DirectMusicPerformance
),
275 GE(CLSID_DirectMusicScript
),
276 GE(CLSID_DirectMusicScriptAutoImpSegment
),
277 GE(CLSID_DirectMusicScriptAutoImpPerformance
),
278 GE(CLSID_DirectMusicScriptAutoImpSegmentState
),
279 GE(CLSID_DirectMusicScriptAutoImpAudioPathConfig
),
280 GE(CLSID_DirectMusicScriptAutoImpAudioPath
),
281 GE(CLSID_DirectMusicScriptAutoImpSong
),
282 GE(CLSID_DirectMusicScriptSourceCodeLoader
),
283 GE(CLSID_DirectMusicScriptTrack
),
284 GE(CLSID_DirectMusicSection
),
285 GE(CLSID_DirectMusicSegment
),
286 GE(CLSID_DirectMusicSegmentState
),
287 GE(CLSID_DirectMusicSegmentTriggerTrack
),
288 GE(CLSID_DirectMusicSegTriggerTrack
),
289 GE(CLSID_DirectMusicSeqTrack
),
290 GE(CLSID_DirectMusicSignPostTrack
),
291 GE(CLSID_DirectMusicSong
),
292 GE(CLSID_DirectMusicStyle
),
293 GE(CLSID_DirectMusicStyleTrack
),
294 GE(CLSID_DirectMusicSynth
),
295 GE(CLSID_DirectMusicSynthSink
),
296 GE(CLSID_DirectMusicSysExTrack
),
297 GE(CLSID_DirectMusicTemplate
),
298 GE(CLSID_DirectMusicTempoTrack
),
299 GE(CLSID_DirectMusicTimeSigTrack
),
300 GE(CLSID_DirectMusicWaveTrack
),
301 GE(CLSID_DirectSoundWave
),
303 GE(IID_IDirectMusic
),
304 GE(IID_IDirectMusic2
),
305 GE(IID_IDirectMusic8
),
306 GE(IID_IDirectMusicAudioPath
),
307 GE(IID_IDirectMusicBand
),
308 GE(IID_IDirectMusicBuffer
),
309 GE(IID_IDirectMusicChordMap
),
310 GE(IID_IDirectMusicCollection
),
311 GE(IID_IDirectMusicComposer
),
312 GE(IID_IDirectMusicContainer
),
313 GE(IID_IDirectMusicDownload
),
314 GE(IID_IDirectMusicDownloadedInstrument
),
315 GE(IID_IDirectMusicGetLoader
),
316 GE(IID_IDirectMusicGraph
),
317 GE(IID_IDirectMusicInstrument
),
318 GE(IID_IDirectMusicLoader
),
319 GE(IID_IDirectMusicLoader8
),
320 GE(IID_IDirectMusicObject
),
321 GE(IID_IDirectMusicPatternTrack
),
322 GE(IID_IDirectMusicPerformance
),
323 GE(IID_IDirectMusicPerformance2
),
324 GE(IID_IDirectMusicPerformance8
),
325 GE(IID_IDirectMusicPort
),
326 GE(IID_IDirectMusicPortDownload
),
327 GE(IID_IDirectMusicScript
),
328 GE(IID_IDirectMusicSegment
),
329 GE(IID_IDirectMusicSegment2
),
330 GE(IID_IDirectMusicSegment8
),
331 GE(IID_IDirectMusicSegmentState
),
332 GE(IID_IDirectMusicSegmentState8
),
333 GE(IID_IDirectMusicStyle
),
334 GE(IID_IDirectMusicStyle8
),
335 GE(IID_IDirectMusicSynth
),
336 GE(IID_IDirectMusicSynth8
),
337 GE(IID_IDirectMusicSynthSink
),
338 GE(IID_IDirectMusicThru
),
339 GE(IID_IDirectMusicTool
),
340 GE(IID_IDirectMusicTool8
),
341 GE(IID_IDirectMusicTrack
),
342 GE(IID_IDirectMusicTrack8
),
344 GE(IID_IPersistStream
),
346 GE(IID_IClassFactory
),
348 GE(GUID_DirectMusicAllTypes
),
349 GE(GUID_NOTIFICATION_CHORD
),
350 GE(GUID_NOTIFICATION_COMMAND
),
351 GE(GUID_NOTIFICATION_MEASUREANDBEAT
),
352 GE(GUID_NOTIFICATION_PERFORMANCE
),
353 GE(GUID_NOTIFICATION_RECOMPOSE
),
354 GE(GUID_NOTIFICATION_SEGMENT
),
357 GE(GUID_CommandParam
),
358 GE(GUID_CommandParam2
),
359 GE(GUID_CommandParamNext
),
360 GE(GUID_IDirectMusicBand
),
361 GE(GUID_IDirectMusicChordMap
),
362 GE(GUID_IDirectMusicStyle
),
364 GE(GUID_Play_Marker
),
365 GE(GUID_RhythmParam
),
367 GE(GUID_TimeSignature
),
368 GE(GUID_Valid_Start_Time
),
369 GE(GUID_Clear_All_Bands
),
370 GE(GUID_ConnectToDLSCollection
),
371 GE(GUID_Disable_Auto_Download
),
372 GE(GUID_DisableTempo
),
373 GE(GUID_DisableTimeSig
),
375 GE(GUID_DownloadToAudioPath
),
376 GE(GUID_Enable_Auto_Download
),
377 GE(GUID_EnableTempo
),
378 GE(GUID_EnableTimeSig
),
379 GE(GUID_IgnoreBankSelectForGM
),
380 GE(GUID_SeedVariations
),
381 GE(GUID_StandardMIDIFile
),
383 GE(GUID_UnloadFromAudioPath
),
385 GE(GUID_PerfMasterTempo
),
386 GE(GUID_PerfMasterVolume
),
387 GE(GUID_PerfMasterGrooveLevel
),
388 GE(GUID_PerfAutoDownload
),
389 GE(GUID_DefaultGMCollection
),
390 GE(GUID_Synth_Default
),
391 GE(GUID_Buffer_Reverb
),
392 GE(GUID_Buffer_EnvReverb
),
393 GE(GUID_Buffer_Stereo
),
394 GE(GUID_Buffer_3D_Dry
),
395 GE(GUID_Buffer_Mono
),
396 GE(GUID_DMUS_PROP_GM_Hardware
),
397 GE(GUID_DMUS_PROP_GS_Capable
),
398 GE(GUID_DMUS_PROP_GS_Hardware
),
399 GE(GUID_DMUS_PROP_DLS1
),
400 GE(GUID_DMUS_PROP_DLS2
),
401 GE(GUID_DMUS_PROP_Effects
),
402 GE(GUID_DMUS_PROP_INSTRUMENT2
),
403 GE(GUID_DMUS_PROP_LegacyCaps
),
404 GE(GUID_DMUS_PROP_MemorySize
),
405 GE(GUID_DMUS_PROP_SampleMemorySize
),
406 GE(GUID_DMUS_PROP_SamplePlaybackRate
),
407 GE(GUID_DMUS_PROP_SetSynthSink
),
408 GE(GUID_DMUS_PROP_SinkUsesDSound
),
409 GE(GUID_DMUS_PROP_SynthSink_DSOUND
),
410 GE(GUID_DMUS_PROP_SynthSink_WAVE
),
411 GE(GUID_DMUS_PROP_Volume
),
412 GE(GUID_DMUS_PROP_WavesReverb
),
413 GE(GUID_DMUS_PROP_WriteLatency
),
414 GE(GUID_DMUS_PROP_WritePeriod
),
415 GE(GUID_DMUS_PROP_XG_Capable
),
416 GE(GUID_DMUS_PROP_XG_Hardware
)
421 if (!id
) return "(null)";
423 for (i
= 0; i
< sizeof(guids
)/sizeof(guids
[0]); i
++) {
424 if (IsEqualGUID(id
, guids
[i
].guid
))
425 return guids
[i
].name
;
427 /* if we didn't find it, act like standard debugstr_guid */
428 return debugstr_guid(id
);
431 /* generic flag-dumping function */
432 static const char* debugstr_flags (DWORD flags
, const flag_info
* names
, size_t num_names
){
433 char buffer
[128] = "", *ptr
= &buffer
[0];
435 int size
= sizeof(buffer
);
437 for (i
=0; i
< num_names
; i
++)
439 if ((flags
& names
[i
].val
) || /* standard flag*/
440 ((!flags
) && (!names
[i
].val
))) { /* zero value only */
441 int cnt
= snprintf(ptr
, size
, "%s ", names
[i
].name
);
442 if (cnt
< 0 || cnt
>= size
) break;
448 return wine_dbg_sprintf("%s", buffer
);
451 /* dump DMUS_OBJ flags */
452 static const char *debugstr_DMUS_OBJ_FLAGS (DWORD flagmask
) {
453 static const flag_info flags
[] = {
457 FE(DMUS_OBJ_CATEGORY
),
458 FE(DMUS_OBJ_FILENAME
),
459 FE(DMUS_OBJ_FULLPATH
),
461 FE(DMUS_OBJ_VERSION
),
467 return debugstr_flags (flagmask
, flags
, sizeof(flags
)/sizeof(flags
[0]));
470 /* dump whole DMUS_OBJECTDESC struct */
471 const char *debugstr_DMUS_OBJECTDESC (LPDMUS_OBJECTDESC pDesc
) {
473 char buffer
[1024] = "", *ptr
= &buffer
[0];
475 ptr
+= sprintf(ptr
, "DMUS_OBJECTDESC (%p):\n", pDesc
);
476 ptr
+= sprintf(ptr
, " - dwSize = %d\n", pDesc
->dwSize
);
477 ptr
+= sprintf(ptr
, " - dwValidData = %s\n", debugstr_DMUS_OBJ_FLAGS (pDesc
->dwValidData
));
478 if (pDesc
->dwValidData
& DMUS_OBJ_CLASS
) ptr
+= sprintf(ptr
, " - guidClass = %s\n", debugstr_dmguid(&pDesc
->guidClass
));
479 if (pDesc
->dwValidData
& DMUS_OBJ_OBJECT
) ptr
+= sprintf(ptr
, " - guidObject = %s\n", debugstr_guid(&pDesc
->guidObject
));
480 if (pDesc
->dwValidData
& DMUS_OBJ_DATE
) ptr
+= sprintf(ptr
, " - ftDate = FIXME\n");
481 if (pDesc
->dwValidData
& DMUS_OBJ_VERSION
) ptr
+= sprintf(ptr
, " - vVersion = %s\n", debugstr_dmversion(&pDesc
->vVersion
));
482 if (pDesc
->dwValidData
& DMUS_OBJ_NAME
) ptr
+= sprintf(ptr
, " - wszName = %s\n", debugstr_w(pDesc
->wszName
));
483 if (pDesc
->dwValidData
& DMUS_OBJ_CATEGORY
) ptr
+= sprintf(ptr
, " - wszCategory = %s\n", debugstr_w(pDesc
->wszCategory
));
484 if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
) ptr
+= sprintf(ptr
, " - wszFileName = %s\n", debugstr_w(pDesc
->wszFileName
));
485 if (pDesc
->dwValidData
& DMUS_OBJ_MEMORY
) ptr
+= sprintf(ptr
, " - llMemLength = 0x%s\n - pbMemData = %p\n",
486 wine_dbgstr_longlong(pDesc
->llMemLength
), pDesc
->pbMemData
);
487 if (pDesc
->dwValidData
& DMUS_OBJ_STREAM
) ptr
+= sprintf(ptr
, " - pStream = %p", pDesc
->pStream
);
489 return wine_dbg_sprintf("%s", buffer
);
491 return wine_dbg_sprintf("(NULL)");