1 /* IDirectMusic8 Implementation
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
22 #include "dmusic_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
26 static inline IDirectMusic8Impl *impl_from_IDirectMusic8(IDirectMusic8 *iface)
28 return CONTAINING_RECORD(iface, IDirectMusic8Impl, IDirectMusic8_iface);
31 /* IDirectMusic8Impl IUnknown part: */
32 static HRESULT WINAPI IDirectMusic8Impl_QueryInterface(LPDIRECTMUSIC8 iface, REFIID riid, LPVOID *ppobj)
34 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
35 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
37 if (IsEqualIID (riid, &IID_IUnknown) ||
38 IsEqualIID (riid, &IID_IDirectMusic) ||
39 IsEqualIID (riid, &IID_IDirectMusic2) ||
40 IsEqualIID (riid, &IID_IDirectMusic8)) {
41 IUnknown_AddRef(iface);
46 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
50 static ULONG WINAPI IDirectMusic8Impl_AddRef(LPDIRECTMUSIC8 iface)
52 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
53 ULONG refCount = InterlockedIncrement(&This->ref);
55 TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
62 static ULONG WINAPI IDirectMusic8Impl_Release(LPDIRECTMUSIC8 iface)
64 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
65 ULONG refCount = InterlockedDecrement(&This->ref);
67 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
70 HeapFree(GetProcessHeap(), 0, This->ppPorts);
71 HeapFree(GetProcessHeap(), 0, This);
74 DMUSIC_UnlockModule();
79 /* IDirectMusic8Impl IDirectMusic part: */
80 static HRESULT WINAPI IDirectMusic8Impl_EnumPort(LPDIRECTMUSIC8 iface, DWORD index, LPDMUS_PORTCAPS port_caps)
82 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
85 const WCHAR emulated[] = {' ','[','E','m','u','l','a','t','e','d',']',0};
87 TRACE("(%p, %d, %p)\n", This, index, port_caps);
92 /* NOTE: It seems some native versions get the rest of devices through dmusic32.EnumLegacyDevices...*sigh*...which is undocumented */
94 /* NOTE: Should we enum wave devices ? Native does not seem to */
96 /* Fill common port caps for winmm ports */
97 port_caps->dwType = DMUS_PORT_WINMM_DRIVER;
98 port_caps->dwMemorySize = 0;
99 port_caps->dwMaxChannelGroups = 1;
100 port_caps->dwMaxVoices = 0;
101 port_caps->dwMaxAudioChannels = 0;
102 port_caps->dwEffectFlags = DMUS_EFFECT_NONE;
104 port_caps->guidPort = IID_IUnknown;
105 port_caps->guidPort.Data1 = index + 1;
107 nb_midi_out = midiOutGetNumDevs();
112 midiOutGetDevCapsW(MIDI_MAPPER, &caps, sizeof(caps));
113 strcpyW(port_caps->wszDescription, caps.szPname);
114 strcatW(port_caps->wszDescription, emulated);
115 port_caps->dwFlags = DMUS_PC_SHAREABLE;
116 port_caps->dwClass = DMUS_PC_OUTPUTCLASS;
117 TRACE("Enumerating port: %s\n", debugstr_w(port_caps->wszDescription));
121 if (index < (nb_midi_out + 1))
124 midiOutGetDevCapsW(index - 1, &caps, sizeof(caps));
125 strcpyW(port_caps->wszDescription, caps.szPname);
126 strcatW(port_caps->wszDescription, emulated);
127 port_caps->dwFlags = DMUS_PC_SHAREABLE | DMUS_PC_EXTERNAL;
128 port_caps->dwClass = DMUS_PC_OUTPUTCLASS;
129 TRACE("Enumerating port: %s\n", debugstr_w(port_caps->wszDescription));
133 nb_midi_in = midiInGetNumDevs();
135 if (index < (nb_midi_in + nb_midi_out + 1))
138 midiInGetDevCapsW(index - nb_midi_out - 1, &caps, sizeof(caps));
139 strcpyW(port_caps->wszDescription, caps.szPname);
140 strcatW(port_caps->wszDescription, emulated);
141 port_caps->dwFlags = DMUS_PC_EXTERNAL;
142 port_caps->dwClass = DMUS_PC_INPUTCLASS;
143 TRACE("Enumerating port: %s\n", debugstr_w(port_caps->wszDescription));
147 if (index == (nb_midi_in + nb_midi_out + 1))
149 IDirectMusicSynth8* synth = NULL;
151 hr = CoCreateInstance(&CLSID_DirectMusicSynth, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicSynth8, (void**)&synth);
153 hr = IDirectMusicSynth8_GetPortCaps(synth, port_caps);
155 TRACE("Enumerating port: %s\n", debugstr_w(port_caps->wszDescription));
157 IDirectMusicSynth8_Release(synth);
164 static HRESULT WINAPI IDirectMusic8Impl_CreateMusicBuffer(LPDIRECTMUSIC8 iface, LPDMUS_BUFFERDESC pBufferDesc, LPDIRECTMUSICBUFFER* ppBuffer, LPUNKNOWN pUnkOuter)
166 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
168 TRACE("(%p, %p, %p, %p)\n", This, pBufferDesc, ppBuffer, pUnkOuter);
171 return CLASS_E_NOAGGREGATION;
173 if (!pBufferDesc || !ppBuffer)
176 return DMUSIC_CreateDirectMusicBufferImpl(pBufferDesc, (LPVOID)ppBuffer);
179 static HRESULT WINAPI IDirectMusic8Impl_CreatePort(LPDIRECTMUSIC8 iface, REFCLSID rclsidPort, LPDMUS_PORTPARAMS pPortParams, LPDIRECTMUSICPORT* ppPort, LPUNKNOWN pUnkOuter)
181 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
183 DMUS_PORTCAPS PortCaps;
184 IDirectMusicPort* pNewPort = NULL;
187 const GUID *request_port = rclsidPort;
189 TRACE("(%p, %s, %p, %p, %p)\n", This, debugstr_dmguid(rclsidPort), pPortParams, ppPort, pUnkOuter);
191 if (TRACE_ON(dmusic))
192 dump_DMUS_PORTPARAMS(pPortParams);
201 return CLASS_E_NOAGGREGATION;
203 if (TRACE_ON(dmusic))
204 dump_DMUS_PORTPARAMS(pPortParams);
206 ZeroMemory(&PortCaps, sizeof(DMUS_PORTCAPS));
207 PortCaps.dwSize = sizeof(DMUS_PORTCAPS);
209 if(IsEqualGUID(request_port, &GUID_NULL)){
210 hr = IDirectMusic8_GetDefaultPort(iface, &default_port);
213 request_port = &default_port;
216 for (i = 0; S_FALSE != IDirectMusic8Impl_EnumPort(iface, i, &PortCaps); i++) {
217 if (IsEqualCLSID (request_port, &PortCaps.guidPort)) {
218 hr = DMUSIC_CreateDirectMusicPortImpl(&IID_IDirectMusicPort, (LPVOID*) &pNewPort, (LPUNKNOWN) This, pPortParams, &PortCaps);
224 if (!This->ppPorts) This->ppPorts = HeapAlloc(GetProcessHeap(), 0, sizeof(LPDIRECTMUSICPORT) * This->nrofports);
225 else This->ppPorts = HeapReAlloc(GetProcessHeap(), 0, This->ppPorts, sizeof(LPDIRECTMUSICPORT) * This->nrofports);
226 This->ppPorts[This->nrofports - 1] = pNewPort;
231 return E_NOINTERFACE;
234 static HRESULT WINAPI IDirectMusic8Impl_EnumMasterClock(LPDIRECTMUSIC8 iface, DWORD index, LPDMUS_CLOCKINFO clock_info)
236 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
238 FIXME("(%p)->(%d, %p): stub\n", This, index, clock_info);
243 static HRESULT WINAPI IDirectMusic8Impl_GetMasterClock(LPDIRECTMUSIC8 iface, LPGUID pguidClock, IReferenceClock** ppReferenceClock)
245 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
247 TRACE("(%p, %p, %p)\n", This, pguidClock, ppReferenceClock);
249 *pguidClock = This->pMasterClock->pClockInfo.guidClock;
251 *ppReferenceClock = (IReferenceClock *)This->pMasterClock;
256 static HRESULT WINAPI IDirectMusic8Impl_SetMasterClock(LPDIRECTMUSIC8 iface, REFGUID rguidClock)
258 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
260 FIXME("(%p)->(%s): stub\n", This, debugstr_dmguid(rguidClock));
265 static HRESULT WINAPI IDirectMusic8Impl_Activate(LPDIRECTMUSIC8 iface, BOOL fEnable)
267 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
270 FIXME("(%p, %d): stub\n", This, fEnable);
271 for (i = 0; i < This->nrofports; i++) {
272 IDirectMusicPort_Activate(This->ppPorts[i], fEnable);
278 static HRESULT WINAPI IDirectMusic8Impl_GetDefaultPort(LPDIRECTMUSIC8 iface, LPGUID pguidPort)
280 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
282 DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
283 char returnBuffer[51];
284 GUID defaultPortGUID;
287 TRACE("(%p, %p)\n", This, pguidPort);
288 if ((RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\DirectMusic\\Defaults" , 0, KEY_READ, &hkGUID) != ERROR_SUCCESS) ||
289 (RegQueryValueExA(hkGUID, "DefaultOutputPort", NULL, &returnTypeGUID, (LPBYTE)returnBuffer, &sizeOfReturnBuffer) != ERROR_SUCCESS))
291 WARN(": registry entry missing\n" );
292 *pguidPort = CLSID_DirectMusicSynth;
295 /* FIXME: Check return types to ensure we're interpreting data right */
296 MultiByteToWideChar(CP_ACP, 0, returnBuffer, -1, buff, sizeof(buff) / sizeof(WCHAR));
297 CLSIDFromString(buff, &defaultPortGUID);
298 *pguidPort = defaultPortGUID;
303 static HRESULT WINAPI IDirectMusic8Impl_SetDirectSound(LPDIRECTMUSIC8 iface, LPDIRECTSOUND dsound, HWND wnd)
305 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
307 FIXME("(%p)->(%p, %p): stub\n", This, dsound, wnd);
312 static HRESULT WINAPI IDirectMusic8Impl_SetExternalMasterClock(LPDIRECTMUSIC8 iface, IReferenceClock* clock)
314 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
316 FIXME("(%p)->(%p): stub\n", This, clock);
321 static const IDirectMusic8Vtbl DirectMusic8_Vtbl = {
322 IDirectMusic8Impl_QueryInterface,
323 IDirectMusic8Impl_AddRef,
324 IDirectMusic8Impl_Release,
325 IDirectMusic8Impl_EnumPort,
326 IDirectMusic8Impl_CreateMusicBuffer,
327 IDirectMusic8Impl_CreatePort,
328 IDirectMusic8Impl_EnumMasterClock,
329 IDirectMusic8Impl_GetMasterClock,
330 IDirectMusic8Impl_SetMasterClock,
331 IDirectMusic8Impl_Activate,
332 IDirectMusic8Impl_GetDefaultPort,
333 IDirectMusic8Impl_SetDirectSound,
334 IDirectMusic8Impl_SetExternalMasterClock
337 /* for ClassFactory */
338 HRESULT WINAPI DMUSIC_CreateDirectMusicImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
339 IDirectMusic8Impl *dmusic;
341 TRACE("(%p,%p,%p)\n",lpcGUID, ppobj, pUnkOuter);
343 dmusic = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusic8Impl));
344 if (NULL == dmusic) {
346 return E_OUTOFMEMORY;
348 dmusic->IDirectMusic8_iface.lpVtbl = &DirectMusic8_Vtbl;
349 dmusic->ref = 0; /* will be inited with QueryInterface */
350 dmusic->pMasterClock = NULL;
351 dmusic->ppPorts = NULL;
352 dmusic->nrofports = 0;
353 DMUSIC_CreateReferenceClockImpl (&IID_IReferenceClock, (LPVOID*)&dmusic->pMasterClock, NULL);
355 return IDirectMusic8Impl_QueryInterface ((LPDIRECTMUSIC8)dmusic, lpcGUID, ppobj);