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
37 #include "dmusic_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(dmusic
);
42 static HINSTANCE instance
;
43 LONG DMUSIC_refCount
= 0;
46 IClassFactory IClassFactory_iface
;
47 HRESULT
WINAPI (*fnCreateInstance
)(REFIID riid
, void **ppv
, IUnknown
*pUnkOuter
);
50 /******************************************************************
51 * IClassFactory implementation
53 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
55 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
58 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
63 if (IsEqualGUID(&IID_IUnknown
, riid
))
64 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
65 else if (IsEqualGUID(&IID_IClassFactory
, riid
))
66 TRACE("(%p)->(IID_IClassFactory %p)\n", iface
, ppv
);
68 FIXME("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
74 IUnknown_AddRef((IUnknown
*)*ppv
);
78 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
82 return 2; /* non-heap based object */
85 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
87 DMUSIC_UnlockModule();
89 return 1; /* non-heap based object */
92 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*pUnkOuter
,
93 REFIID riid
, void **ppv
)
95 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
97 TRACE ("(%p, %s, %p)\n", pUnkOuter
, debugstr_dmguid(riid
), ppv
);
99 return This
->fnCreateInstance(riid
, ppv
, pUnkOuter
);
102 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
104 TRACE("(%d)\n", dolock
);
109 DMUSIC_UnlockModule();
114 static const IClassFactoryVtbl classfactory_vtbl
= {
115 ClassFactory_QueryInterface
,
117 ClassFactory_Release
,
118 ClassFactory_CreateInstance
,
119 ClassFactory_LockServer
122 static IClassFactoryImpl DirectMusic_CF
= {{&classfactory_vtbl
}, DMUSIC_CreateDirectMusicImpl
};
123 static IClassFactoryImpl Collection_CF
= {{&classfactory_vtbl
},
124 DMUSIC_CreateDirectMusicCollectionImpl
};
126 /******************************************************************
131 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
) {
132 if (fdwReason
== DLL_PROCESS_ATTACH
) {
134 DisableThreadLibraryCalls(hinstDLL
);
141 /******************************************************************
142 * DllCanUnloadNow (DMUSIC.@)
146 HRESULT WINAPI
DllCanUnloadNow(void)
148 return DMUSIC_refCount
!= 0 ? S_FALSE
: S_OK
;
152 /******************************************************************
153 * DllGetClassObject (DMUSIC.@)
157 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
159 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid
), debugstr_dmguid(riid
), ppv
);
160 if (IsEqualCLSID (rclsid
, &CLSID_DirectMusic
) && IsEqualIID (riid
, &IID_IClassFactory
)) {
161 *ppv
= &DirectMusic_CF
;
162 IClassFactory_AddRef((IClassFactory
*)*ppv
);
164 } else if (IsEqualCLSID (rclsid
, &CLSID_DirectMusicCollection
) && IsEqualIID (riid
, &IID_IClassFactory
)) {
165 *ppv
= &Collection_CF
;
166 IClassFactory_AddRef((IClassFactory
*)*ppv
);
170 WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid
), debugstr_dmguid(riid
), ppv
);
171 return CLASS_E_CLASSNOTAVAILABLE
;
174 /***********************************************************************
175 * DllRegisterServer (DMUSIC.@)
177 HRESULT WINAPI
DllRegisterServer(void)
179 return __wine_register_resources( instance
);
182 /***********************************************************************
183 * DllUnregisterServer (DMUSIC.@)
185 HRESULT WINAPI
DllUnregisterServer(void)
187 return __wine_unregister_resources( instance
);
190 /******************************************************************
195 /* dwPatch from MIDILOCALE */
196 DWORD
MIDILOCALE2Patch (const MIDILOCALE
*pLocale
) {
198 if (!pLocale
) return 0;
199 dwPatch
|= (pLocale
->ulBank
& F_INSTRUMENT_DRUMS
); /* set drum bit */
200 dwPatch
|= ((pLocale
->ulBank
& 0x00007F7F) << 8); /* set MIDI bank location */
201 dwPatch
|= (pLocale
->ulInstrument
& 0x0000007F); /* set PC value */
205 /* MIDILOCALE from dwPatch */
206 void Patch2MIDILOCALE (DWORD dwPatch
, LPMIDILOCALE pLocale
) {
207 memset (pLocale
, 0, sizeof(MIDILOCALE
));
209 pLocale
->ulInstrument
= (dwPatch
& 0x7F); /* get PC value */
210 pLocale
->ulBank
= ((dwPatch
& 0x007F7F00) >> 8); /* get MIDI bank location */
211 pLocale
->ulBank
|= (dwPatch
& F_INSTRUMENT_DRUMS
); /* get drum bit */
214 /* check whether the given DWORD is even (return 0) or odd (return 1) */
215 int even_or_odd (DWORD number
) {
216 return (number
& 0x1); /* basically, check if bit 0 is set ;) */
219 /* generic flag-dumping function */
220 static const char* debugstr_flags (DWORD flags
, const flag_info
* names
, size_t num_names
){
221 char buffer
[128] = "", *ptr
= &buffer
[0];
223 int size
= sizeof(buffer
);
225 for (i
=0; i
< num_names
; i
++)
227 if ((flags
& names
[i
].val
) || /* standard flag*/
228 ((!flags
) && (!names
[i
].val
))) { /* zero value only */
229 int cnt
= snprintf(ptr
, size
, "%s ", names
[i
].name
);
230 if (cnt
< 0 || cnt
>= size
) break;
236 return wine_dbg_sprintf("%s", buffer
);
239 /* Dump DMUS_PORTPARAMS flags */
240 static const char* debugstr_DMUS_PORTPARAMS_FLAGS(DWORD flagmask
)
242 static const flag_info flags
[] = {
243 FE(DMUS_PORTPARAMS_VOICES
),
244 FE(DMUS_PORTPARAMS_CHANNELGROUPS
),
245 FE(DMUS_PORTPARAMS_AUDIOCHANNELS
),
246 FE(DMUS_PORTPARAMS_SAMPLERATE
),
247 FE(DMUS_PORTPARAMS_EFFECTS
),
248 FE(DMUS_PORTPARAMS_SHARE
)
250 return debugstr_flags(flagmask
, flags
, ARRAY_SIZE(flags
));
253 /* Dump whole DMUS_PORTPARAMS struct */
254 void dump_DMUS_PORTPARAMS(LPDMUS_PORTPARAMS params
)
256 TRACE("DMUS_PORTPARAMS (%p):\n", params
);
257 TRACE(" - dwSize = %d\n", params
->dwSize
);
258 TRACE(" - dwValidParams = %s\n", debugstr_DMUS_PORTPARAMS_FLAGS(params
->dwValidParams
));
259 if (params
->dwValidParams
& DMUS_PORTPARAMS_VOICES
) TRACE(" - dwVoices = %u\n", params
->dwVoices
);
260 if (params
->dwValidParams
& DMUS_PORTPARAMS_CHANNELGROUPS
) TRACE(" - dwChannelGroup = %u\n", params
->dwChannelGroups
);
261 if (params
->dwValidParams
& DMUS_PORTPARAMS_AUDIOCHANNELS
) TRACE(" - dwAudioChannels = %u\n", params
->dwAudioChannels
);
262 if (params
->dwValidParams
& DMUS_PORTPARAMS_SAMPLERATE
) TRACE(" - dwSampleRate = %u\n", params
->dwSampleRate
);
263 if (params
->dwValidParams
& DMUS_PORTPARAMS_EFFECTS
) TRACE(" - dwEffectFlags = %x\n", params
->dwEffectFlags
);
264 if (params
->dwValidParams
& DMUS_PORTPARAMS_SHARE
) TRACE(" - fShare = %u\n", params
->fShare
);