strmbase: Print the debug string and not the pointer to it.
[wine/multimedia.git] / dlls / dmusic / dmusic.c
blob1a00236a34aef5e86673f797ca54df1e935c456a
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
20 #include <stdio.h>
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);
42 *ppobj = This;
43 return S_OK;
46 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
47 return E_NOINTERFACE;
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);
57 DMUSIC_LockModule();
59 return refCount;
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);
69 if (!refCount) {
70 HeapFree(GetProcessHeap(), 0, This->ppPorts);
71 HeapFree(GetProcessHeap(), 0, This);
74 DMUSIC_UnlockModule();
76 return refCount;
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);
83 ULONG nb_midi_out;
84 ULONG nb_midi_in;
85 const WCHAR emulated[] = {' ','[','E','m','u','l','a','t','e','d',']',0};
87 TRACE("(%p, %d, %p)\n", This, index, port_caps);
89 if (!port_caps)
90 return E_POINTER;
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;
103 /* Fake port GUID */
104 port_caps->guidPort = IID_IUnknown;
105 port_caps->guidPort.Data1 = index + 1;
107 nb_midi_out = midiOutGetNumDevs();
109 if (index == 0)
111 MIDIOUTCAPSW caps;
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));
118 return S_OK;
121 if (index < (nb_midi_out + 1))
123 MIDIOUTCAPSW caps;
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));
130 return S_OK;
133 nb_midi_in = midiInGetNumDevs();
135 if (index < (nb_midi_in + nb_midi_out + 1))
137 MIDIINCAPSW caps;
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));
144 return S_OK;
147 if (index == (nb_midi_in + nb_midi_out + 1))
149 IDirectMusicSynth8* synth = NULL;
150 HRESULT hr;
151 hr = CoCreateInstance(&CLSID_DirectMusicSynth, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicSynth8, (void**)&synth);
152 if (SUCCEEDED(hr))
153 hr = IDirectMusicSynth8_GetPortCaps(synth, port_caps);
154 if (SUCCEEDED(hr))
155 TRACE("Enumerating port: %s\n", debugstr_w(port_caps->wszDescription));
156 if (synth)
157 IDirectMusicSynth8_Release(synth);
158 return hr;
161 return S_FALSE;
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);
170 if (pUnkOuter)
171 return CLASS_E_NOAGGREGATION;
173 if (!pBufferDesc || !ppBuffer)
174 return E_POINTER;
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);
182 int i;
183 DMUS_PORTCAPS PortCaps;
184 IDirectMusicPort* pNewPort = NULL;
185 HRESULT hr;
186 GUID default_port;
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);
194 if (!rclsidPort)
195 return E_POINTER;
196 if (!pPortParams)
197 return E_INVALIDARG;
198 if (!ppPort)
199 return E_POINTER;
200 if (pUnkOuter)
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);
211 if(FAILED(hr))
212 return hr;
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);
219 if (FAILED(hr)) {
220 *ppPort = NULL;
221 return hr;
223 This->nrofports++;
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;
227 *ppPort = pNewPort;
228 return S_OK;
231 return E_NOINTERFACE;
234 static HRESULT WINAPI IDirectMusic8Impl_EnumMasterClock(LPDIRECTMUSIC8 iface, DWORD index, LPDMUS_CLOCKINFO clock_info)
236 TRACE("(%p)->(%d, %p)\n", iface, index, clock_info);
238 if (!clock_info)
239 return E_POINTER;
241 if (index > 1)
242 return S_FALSE;
244 if (!index)
246 static const GUID guid_system_clock = { 0x58d58419, 0x71b4, 0x11d1, { 0xa7, 0x4c, 0x00, 0x00, 0xf8, 0x75, 0xac, 0x12 } };
247 static const WCHAR name_system_clock[] = { 'S','y','s','t','e','m',' ','C','l','o','c','k',0 };
249 clock_info->ctType = 0;
250 clock_info->guidClock = guid_system_clock;
251 strcpyW(clock_info->wszDescription, name_system_clock);
253 else
255 static const GUID guid_dsound_clock = { 0x58d58420, 0x71b4, 0x11d1, { 0xa7, 0x4c, 0x00, 0x00, 0xf8, 0x75, 0xac, 0x12 } };
256 static const WCHAR name_dsound_clock[] = { 'D','i','r','e','c','t','S','o','u','n','d',' ','C','l','o','c','k',0 };
258 clock_info->ctType = 0;
259 clock_info->guidClock = guid_dsound_clock;
260 strcpyW(clock_info->wszDescription, name_dsound_clock);
263 return S_OK;
266 static HRESULT WINAPI IDirectMusic8Impl_GetMasterClock(LPDIRECTMUSIC8 iface, LPGUID pguidClock, IReferenceClock** ppReferenceClock)
268 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
270 TRACE("(%p, %p, %p)\n", This, pguidClock, ppReferenceClock);
271 if (pguidClock)
272 *pguidClock = This->pMasterClock->pClockInfo.guidClock;
273 if(ppReferenceClock)
274 *ppReferenceClock = (IReferenceClock *)This->pMasterClock;
276 return S_OK;
279 static HRESULT WINAPI IDirectMusic8Impl_SetMasterClock(LPDIRECTMUSIC8 iface, REFGUID rguidClock)
281 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
283 FIXME("(%p)->(%s): stub\n", This, debugstr_dmguid(rguidClock));
285 return S_OK;
288 static HRESULT WINAPI IDirectMusic8Impl_Activate(LPDIRECTMUSIC8 iface, BOOL enable)
290 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
291 int i;
292 HRESULT hr;
294 TRACE("(%p)->(%u)\n", This, enable);
296 for (i = 0; i < This->nrofports; i++)
298 hr = IDirectMusicPort_Activate(This->ppPorts[i], enable);
299 if (FAILED(hr))
300 return hr;
303 return S_OK;
306 static HRESULT WINAPI IDirectMusic8Impl_GetDefaultPort(LPDIRECTMUSIC8 iface, LPGUID pguidPort)
308 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
309 HKEY hkGUID;
310 DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
311 char returnBuffer[51];
312 GUID defaultPortGUID;
313 WCHAR buff[51];
315 TRACE("(%p, %p)\n", This, pguidPort);
316 if ((RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\DirectMusic\\Defaults" , 0, KEY_READ, &hkGUID) != ERROR_SUCCESS) ||
317 (RegQueryValueExA(hkGUID, "DefaultOutputPort", NULL, &returnTypeGUID, (LPBYTE)returnBuffer, &sizeOfReturnBuffer) != ERROR_SUCCESS))
319 WARN(": registry entry missing\n" );
320 *pguidPort = CLSID_DirectMusicSynth;
321 return S_OK;
323 /* FIXME: Check return types to ensure we're interpreting data right */
324 MultiByteToWideChar(CP_ACP, 0, returnBuffer, -1, buff, sizeof(buff) / sizeof(WCHAR));
325 CLSIDFromString(buff, &defaultPortGUID);
326 *pguidPort = defaultPortGUID;
328 return S_OK;
331 static HRESULT WINAPI IDirectMusic8Impl_SetDirectSound(LPDIRECTMUSIC8 iface, LPDIRECTSOUND dsound, HWND wnd)
333 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
335 FIXME("(%p)->(%p, %p): stub\n", This, dsound, wnd);
337 return S_OK;
340 static HRESULT WINAPI IDirectMusic8Impl_SetExternalMasterClock(LPDIRECTMUSIC8 iface, IReferenceClock* clock)
342 IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface);
344 FIXME("(%p)->(%p): stub\n", This, clock);
346 return S_OK;
349 static const IDirectMusic8Vtbl DirectMusic8_Vtbl = {
350 IDirectMusic8Impl_QueryInterface,
351 IDirectMusic8Impl_AddRef,
352 IDirectMusic8Impl_Release,
353 IDirectMusic8Impl_EnumPort,
354 IDirectMusic8Impl_CreateMusicBuffer,
355 IDirectMusic8Impl_CreatePort,
356 IDirectMusic8Impl_EnumMasterClock,
357 IDirectMusic8Impl_GetMasterClock,
358 IDirectMusic8Impl_SetMasterClock,
359 IDirectMusic8Impl_Activate,
360 IDirectMusic8Impl_GetDefaultPort,
361 IDirectMusic8Impl_SetDirectSound,
362 IDirectMusic8Impl_SetExternalMasterClock
365 /* for ClassFactory */
366 HRESULT WINAPI DMUSIC_CreateDirectMusicImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
367 IDirectMusic8Impl *dmusic;
369 TRACE("(%p,%p,%p)\n",lpcGUID, ppobj, pUnkOuter);
371 dmusic = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusic8Impl));
372 if (NULL == dmusic) {
373 *ppobj = NULL;
374 return E_OUTOFMEMORY;
376 dmusic->IDirectMusic8_iface.lpVtbl = &DirectMusic8_Vtbl;
377 dmusic->ref = 0; /* will be inited with QueryInterface */
378 dmusic->pMasterClock = NULL;
379 dmusic->ppPorts = NULL;
380 dmusic->nrofports = 0;
381 DMUSIC_CreateReferenceClockImpl (&IID_IReferenceClock, (LPVOID*)&dmusic->pMasterClock, NULL);
383 return IDirectMusic8Impl_QueryInterface ((LPDIRECTMUSIC8)dmusic, lpcGUID, ppobj);