ntoskrnl.exe/tests: Add some IOCTL_HID_WRITE_REPORT tests.
[wine.git] / dlls / dmusic / dmusic_main.c
blob2446dc188525b5c3c6291ddb7f07c8e07d71c1ee
1 /* DirectMusic 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 <stdio.h>
22 #include <stdarg.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnt.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winreg.h"
32 #include "objbase.h"
33 #include "rpcproxy.h"
34 #include "initguid.h"
35 #include "dmusici.h"
37 #include "dmusic_private.h"
38 #include "dmobject.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
42 LONG DMUSIC_refCount = 0;
44 typedef struct {
45 IClassFactory IClassFactory_iface;
46 HRESULT WINAPI (*fnCreateInstance)(REFIID riid, void **ppv, IUnknown *pUnkOuter);
47 } IClassFactoryImpl;
49 /******************************************************************
50 * IClassFactory implementation
52 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
54 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
57 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
59 if (ppv == NULL)
60 return E_POINTER;
62 if (IsEqualGUID(&IID_IUnknown, riid))
63 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
64 else if (IsEqualGUID(&IID_IClassFactory, riid))
65 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
66 else {
67 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
68 *ppv = NULL;
69 return E_NOINTERFACE;
72 *ppv = iface;
73 IUnknown_AddRef((IUnknown*)*ppv);
74 return S_OK;
77 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
79 DMUSIC_LockModule();
81 return 2; /* non-heap based object */
84 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
86 DMUSIC_UnlockModule();
88 return 1; /* non-heap based object */
91 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
92 REFIID riid, void **ppv)
94 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
96 TRACE ("(%p, %s, %p)\n", pUnkOuter, debugstr_dmguid(riid), ppv);
98 return This->fnCreateInstance(riid, ppv, pUnkOuter);
101 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
103 TRACE("(%d)\n", dolock);
105 if (dolock)
106 DMUSIC_LockModule();
107 else
108 DMUSIC_UnlockModule();
110 return S_OK;
113 static const IClassFactoryVtbl classfactory_vtbl = {
114 ClassFactory_QueryInterface,
115 ClassFactory_AddRef,
116 ClassFactory_Release,
117 ClassFactory_CreateInstance,
118 ClassFactory_LockServer
121 static IClassFactoryImpl DirectMusic_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicImpl};
122 static IClassFactoryImpl Collection_CF = {{&classfactory_vtbl},
123 DMUSIC_CreateDirectMusicCollectionImpl};
125 /******************************************************************
126 * DllCanUnloadNow (DMUSIC.@)
130 HRESULT WINAPI DllCanUnloadNow(void)
132 return DMUSIC_refCount != 0 ? S_FALSE : S_OK;
136 /******************************************************************
137 * DllGetClassObject (DMUSIC.@)
141 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
143 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
144 if (IsEqualCLSID (rclsid, &CLSID_DirectMusic) && IsEqualIID (riid, &IID_IClassFactory)) {
145 *ppv = &DirectMusic_CF;
146 IClassFactory_AddRef((IClassFactory*)*ppv);
147 return S_OK;
148 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicCollection) && IsEqualIID (riid, &IID_IClassFactory)) {
149 *ppv = &Collection_CF;
150 IClassFactory_AddRef((IClassFactory*)*ppv);
151 return S_OK;
154 WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
155 return CLASS_E_CLASSNOTAVAILABLE;
158 /******************************************************************
159 * Helper functions
163 /* dwPatch from MIDILOCALE */
164 DWORD MIDILOCALE2Patch (const MIDILOCALE *pLocale) {
165 DWORD dwPatch = 0;
166 if (!pLocale) return 0;
167 dwPatch |= (pLocale->ulBank & F_INSTRUMENT_DRUMS); /* set drum bit */
168 dwPatch |= ((pLocale->ulBank & 0x00007F7F) << 8); /* set MIDI bank location */
169 dwPatch |= (pLocale->ulInstrument & 0x0000007F); /* set PC value */
170 return dwPatch;
173 /* MIDILOCALE from dwPatch */
174 void Patch2MIDILOCALE (DWORD dwPatch, LPMIDILOCALE pLocale) {
175 memset (pLocale, 0, sizeof(MIDILOCALE));
177 pLocale->ulInstrument = (dwPatch & 0x7F); /* get PC value */
178 pLocale->ulBank = ((dwPatch & 0x007F7F00) >> 8); /* get MIDI bank location */
179 pLocale->ulBank |= (dwPatch & F_INSTRUMENT_DRUMS); /* get drum bit */
182 /* check whether the given DWORD is even (return 0) or odd (return 1) */
183 int even_or_odd (DWORD number) {
184 return (number & 0x1); /* basically, check if bit 0 is set ;) */
187 /* generic flag-dumping function */
188 static const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
189 char buffer[128] = "", *ptr = &buffer[0];
190 unsigned int i;
191 int size = sizeof(buffer);
193 for (i=0; i < num_names; i++)
195 if ((flags & names[i].val) || /* standard flag*/
196 ((!flags) && (!names[i].val))) { /* zero value only */
197 int cnt = snprintf(ptr, size, "%s ", names[i].name);
198 if (cnt < 0 || cnt >= size) break;
199 size -= cnt;
200 ptr += cnt;
204 return wine_dbg_sprintf("%s", buffer);
207 /* Dump DMUS_PORTPARAMS flags */
208 static const char* debugstr_DMUS_PORTPARAMS_FLAGS(DWORD flagmask)
210 static const flag_info flags[] = {
211 FE(DMUS_PORTPARAMS_VOICES),
212 FE(DMUS_PORTPARAMS_CHANNELGROUPS),
213 FE(DMUS_PORTPARAMS_AUDIOCHANNELS),
214 FE(DMUS_PORTPARAMS_SAMPLERATE),
215 FE(DMUS_PORTPARAMS_EFFECTS),
216 FE(DMUS_PORTPARAMS_SHARE)
218 return debugstr_flags(flagmask, flags, ARRAY_SIZE(flags));
221 /* Dump whole DMUS_PORTPARAMS struct */
222 void dump_DMUS_PORTPARAMS(LPDMUS_PORTPARAMS params)
224 TRACE("DMUS_PORTPARAMS (%p):\n", params);
225 TRACE(" - dwSize = %d\n", params->dwSize);
226 TRACE(" - dwValidParams = %s\n", debugstr_DMUS_PORTPARAMS_FLAGS(params->dwValidParams));
227 if (params->dwValidParams & DMUS_PORTPARAMS_VOICES) TRACE(" - dwVoices = %u\n", params->dwVoices);
228 if (params->dwValidParams & DMUS_PORTPARAMS_CHANNELGROUPS) TRACE(" - dwChannelGroup = %u\n", params->dwChannelGroups);
229 if (params->dwValidParams & DMUS_PORTPARAMS_AUDIOCHANNELS) TRACE(" - dwAudioChannels = %u\n", params->dwAudioChannels);
230 if (params->dwValidParams & DMUS_PORTPARAMS_SAMPLERATE) TRACE(" - dwSampleRate = %u\n", params->dwSampleRate);
231 if (params->dwValidParams & DMUS_PORTPARAMS_EFFECTS) TRACE(" - dwEffectFlags = %x\n", params->dwEffectFlags);
232 if (params->dwValidParams & DMUS_PORTPARAMS_SHARE) TRACE(" - fShare = %u\n", params->fShare);