ddraw: Set dwMaxVertexCount to 2048.
[wine.git] / dlls / dmusic / dmusic_main.c
blobeabf9f131b901573c8613023fb7e991c93000c26
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"
39 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
41 typedef struct {
42 IClassFactory IClassFactory_iface;
43 HRESULT (*create_instance)(IUnknown **ret_iface);
44 } IClassFactoryImpl;
46 /******************************************************************
47 * IClassFactory implementation
49 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
51 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
54 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
56 if (ppv == NULL)
57 return E_POINTER;
59 if (IsEqualGUID(&IID_IUnknown, riid))
60 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
61 else if (IsEqualGUID(&IID_IClassFactory, riid))
62 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
63 else {
64 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
65 *ppv = NULL;
66 return E_NOINTERFACE;
69 *ppv = iface;
70 IUnknown_AddRef((IUnknown*)*ppv);
71 return S_OK;
74 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
76 return 2; /* non-heap based object */
79 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
81 return 1; /* non-heap based object */
84 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *unk_outer, REFIID riid, void **ret_iface)
86 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
87 IUnknown *object;
88 HRESULT hr;
90 TRACE("(%p, %s, %p)\n", unk_outer, debugstr_dmguid(riid), ret_iface);
92 *ret_iface = NULL;
93 if (unk_outer) return CLASS_E_NOAGGREGATION;
94 if (SUCCEEDED(hr = This->create_instance(&object)))
96 hr = IUnknown_QueryInterface(object, riid, ret_iface);
97 IUnknown_Release(object);
100 return hr;
103 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
105 TRACE("(%d)\n", dolock);
106 return S_OK;
109 static const IClassFactoryVtbl classfactory_vtbl = {
110 ClassFactory_QueryInterface,
111 ClassFactory_AddRef,
112 ClassFactory_Release,
113 ClassFactory_CreateInstance,
114 ClassFactory_LockServer
117 static IClassFactoryImpl DirectMusic_CF = {{&classfactory_vtbl}, music_create};
118 static IClassFactoryImpl Collection_CF = {{&classfactory_vtbl}, collection_create};
122 /******************************************************************
123 * DllGetClassObject (DMUSIC.@)
127 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
129 TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
130 if (IsEqualCLSID (rclsid, &CLSID_DirectMusic) && IsEqualIID (riid, &IID_IClassFactory)) {
131 *ppv = &DirectMusic_CF;
132 IClassFactory_AddRef((IClassFactory*)*ppv);
133 return S_OK;
134 } else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicCollection) && IsEqualIID (riid, &IID_IClassFactory)) {
135 *ppv = &Collection_CF;
136 IClassFactory_AddRef((IClassFactory*)*ppv);
137 return S_OK;
140 WARN("(%s, %s, %p): no interface found.\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
141 return CLASS_E_CLASSNOTAVAILABLE;
144 /******************************************************************
145 * Helper functions
149 /* dwPatch from MIDILOCALE */
150 DWORD MIDILOCALE2Patch (const MIDILOCALE *pLocale) {
151 DWORD dwPatch = 0;
152 if (!pLocale) return 0;
153 dwPatch |= (pLocale->ulBank & F_INSTRUMENT_DRUMS); /* set drum bit */
154 dwPatch |= ((pLocale->ulBank & 0x00007F7F) << 8); /* set MIDI bank location */
155 dwPatch |= (pLocale->ulInstrument & 0x0000007F); /* set PC value */
156 return dwPatch;
159 /* MIDILOCALE from dwPatch */
160 void Patch2MIDILOCALE (DWORD dwPatch, LPMIDILOCALE pLocale) {
161 memset (pLocale, 0, sizeof(MIDILOCALE));
163 pLocale->ulInstrument = (dwPatch & 0x7F); /* get PC value */
164 pLocale->ulBank = ((dwPatch & 0x007F7F00) >> 8); /* get MIDI bank location */
165 pLocale->ulBank |= (dwPatch & F_INSTRUMENT_DRUMS); /* get drum bit */
168 /* generic flag-dumping function */
169 static const char* debugstr_flags (DWORD flags, const flag_info* names, size_t num_names){
170 char buffer[128] = "", *ptr = &buffer[0];
171 unsigned int i;
172 int size = sizeof(buffer);
174 for (i=0; i < num_names; i++)
176 if ((flags & names[i].val) || /* standard flag*/
177 ((!flags) && (!names[i].val))) { /* zero value only */
178 int cnt = snprintf(ptr, size, "%s ", names[i].name);
179 if (cnt < 0 || cnt >= size) break;
180 size -= cnt;
181 ptr += cnt;
185 return wine_dbg_sprintf("%s", buffer);
188 /* Dump DMUS_PORTPARAMS flags */
189 static const char* debugstr_DMUS_PORTPARAMS_FLAGS(DWORD flagmask)
191 static const flag_info flags[] = {
192 FE(DMUS_PORTPARAMS_VOICES),
193 FE(DMUS_PORTPARAMS_CHANNELGROUPS),
194 FE(DMUS_PORTPARAMS_AUDIOCHANNELS),
195 FE(DMUS_PORTPARAMS_SAMPLERATE),
196 FE(DMUS_PORTPARAMS_EFFECTS),
197 FE(DMUS_PORTPARAMS_SHARE)
199 return debugstr_flags(flagmask, flags, ARRAY_SIZE(flags));
202 /* Dump whole DMUS_PORTPARAMS struct */
203 void dump_DMUS_PORTPARAMS(LPDMUS_PORTPARAMS params)
205 TRACE("DMUS_PORTPARAMS (%p):\n", params);
206 TRACE(" - dwSize = %ld\n", params->dwSize);
207 TRACE(" - dwValidParams = %s\n", debugstr_DMUS_PORTPARAMS_FLAGS(params->dwValidParams));
208 if (params->dwValidParams & DMUS_PORTPARAMS_VOICES) TRACE(" - dwVoices = %lu\n", params->dwVoices);
209 if (params->dwValidParams & DMUS_PORTPARAMS_CHANNELGROUPS) TRACE(" - dwChannelGroup = %lu\n", params->dwChannelGroups);
210 if (params->dwValidParams & DMUS_PORTPARAMS_AUDIOCHANNELS) TRACE(" - dwAudioChannels = %lu\n", params->dwAudioChannels);
211 if (params->dwValidParams & DMUS_PORTPARAMS_SAMPLERATE) TRACE(" - dwSampleRate = %lu\n", params->dwSampleRate);
212 if (params->dwValidParams & DMUS_PORTPARAMS_EFFECTS) TRACE(" - dwEffectFlags = %lx\n", params->dwEffectFlags);
213 if (params->dwValidParams & DMUS_PORTPARAMS_SHARE) TRACE(" - fShare = %u\n", params->fShare);