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
19 #include "dmusic_private.h"
21 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
23 /* IDirectMusic8Impl IUnknown part: */
24 static HRESULT WINAPI IDirectMusic8Impl_QueryInterface (LPDIRECTMUSIC8 iface, REFIID riid, LPVOID *ppobj) {
25 IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
26 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
28 if (IsEqualIID (riid, &IID_IUnknown) ||
29 IsEqualIID (riid, &IID_IDirectMusic) ||
30 IsEqualIID (riid, &IID_IDirectMusic2) ||
31 IsEqualIID (riid, &IID_IDirectMusic8)) {
32 IUnknown_AddRef(iface);
37 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
41 static ULONG WINAPI IDirectMusic8Impl_AddRef (LPDIRECTMUSIC8 iface) {
42 IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
43 ULONG refCount = InterlockedIncrement(&This->ref);
45 TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
52 static ULONG WINAPI IDirectMusic8Impl_Release (LPDIRECTMUSIC8 iface) {
53 IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
54 ULONG refCount = InterlockedDecrement(&This->ref);
56 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
59 HeapFree(GetProcessHeap(), 0, This->ppPorts);
60 HeapFree(GetProcessHeap(), 0, This);
63 DMUSIC_UnlockModule();
68 /* IDirectMusic8Impl IDirectMusic part: */
69 static HRESULT WINAPI IDirectMusic8Impl_EnumPort(LPDIRECTMUSIC8 iface, DWORD dwIndex, LPDMUS_PORTCAPS pPortCaps) {
70 IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
71 TRACE("(%p, %d, %p)\n", This, dwIndex, pPortCaps);
72 if (NULL == pPortCaps) { return E_POINTER; }
73 /* i guess the first port shown is always software synthesizer */
76 IDirectMusicSynth8* synth;
77 TRACE("enumerating 'Microsoft Software Synthesizer' port\n");
78 CoCreateInstance (&CLSID_DirectMusicSynth, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicSynth8, (void**)&synth);
79 IDirectMusicSynth8_GetPortCaps (synth, pPortCaps);
80 IDirectMusicSynth8_Release (synth);
84 /* it seems that the rest of devices are obtained thru dmusic32.EnumLegacyDevices...*sigh*...which is undocumented*/
86 int numMIDI = midiOutGetNumDevs();
87 int numWAVE = waveOutGetNumDevs();
89 /* then return digital sound ports */
90 for (i = 1; i <= numWAVE; i++)
92 TRACE("enumerating 'digital sound' ports\n");
95 DirectSoundEnumerateA(register_waveport, pPortCaps);
99 /* finally, list all *real* MIDI ports*/
100 for (i = numWAVE + 1; i <= numWAVE + numMIDI; i++)
102 TRACE("enumerating 'real MIDI' ports\n");
104 FIXME("Found MIDI port, but *real* MIDI ports not supported yet\n");
110 static HRESULT WINAPI IDirectMusic8Impl_CreateMusicBuffer (LPDIRECTMUSIC8 iface, LPDMUS_BUFFERDESC pBufferDesc, LPDIRECTMUSICBUFFER** ppBuffer, LPUNKNOWN pUnkOuter) {
111 IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
113 TRACE("(%p, %p, %p, %p)\n", This, pBufferDesc, ppBuffer, pUnkOuter);
116 return CLASS_E_NOAGGREGATION;
118 if (!pBufferDesc || !ppBuffer)
121 return DMUSIC_CreateDirectMusicBufferImpl(&IID_IDirectMusicBuffer, (LPVOID)ppBuffer, NULL);
124 static HRESULT WINAPI IDirectMusic8Impl_CreatePort (LPDIRECTMUSIC8 iface, REFCLSID rclsidPort, LPDMUS_PORTPARAMS pPortParams, LPDIRECTMUSICPORT* ppPort, LPUNKNOWN pUnkOuter) {
125 IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
127 DMUS_PORTCAPS PortCaps;
128 IDirectMusicPort* pNewPort = NULL;
131 const GUID *request_port = rclsidPort;
133 TRACE("(%p, %s, %p, %p, %p)\n", This, debugstr_dmguid(rclsidPort), pPortParams, ppPort, pUnkOuter);
138 ZeroMemory(&PortCaps, sizeof(DMUS_PORTCAPS));
139 PortCaps.dwSize = sizeof(DMUS_PORTCAPS);
141 if(IsEqualGUID(request_port, &GUID_NULL)){
142 hr = IDirectMusic8_GetDefaultPort(iface, &default_port);
145 request_port = &default_port;
148 for (i = 0; S_FALSE != IDirectMusic8Impl_EnumPort(iface, i, &PortCaps); i++) {
149 if (IsEqualCLSID (request_port, &PortCaps.guidPort)) {
150 hr = DMUSIC_CreateDirectMusicPortImpl(&IID_IDirectMusicPort, (LPVOID*) &pNewPort, (LPUNKNOWN) This, pPortParams, &PortCaps);
156 if (!This->ppPorts) This->ppPorts = HeapAlloc(GetProcessHeap(), 0, sizeof(LPDIRECTMUSICPORT) * This->nrofports);
157 else This->ppPorts = HeapReAlloc(GetProcessHeap(), 0, This->ppPorts, sizeof(LPDIRECTMUSICPORT) * This->nrofports);
158 This->ppPorts[This->nrofports - 1] = pNewPort;
163 return E_NOINTERFACE;
166 static HRESULT WINAPI IDirectMusic8Impl_EnumMasterClock (LPDIRECTMUSIC8 iface, DWORD dwIndex, LPDMUS_CLOCKINFO lpClockInfo) {
167 IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
168 FIXME("(%p, %d, %p): stub\n", This, dwIndex, lpClockInfo);
172 static HRESULT WINAPI IDirectMusic8Impl_GetMasterClock (LPDIRECTMUSIC8 iface, LPGUID pguidClock, IReferenceClock** ppReferenceClock) {
173 IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
175 TRACE("(%p, %p, %p)\n", This, pguidClock, ppReferenceClock);
177 *pguidClock = This->pMasterClock->pClockInfo.guidClock;
179 *ppReferenceClock = (IReferenceClock *)This->pMasterClock;
184 static HRESULT WINAPI IDirectMusic8Impl_SetMasterClock (LPDIRECTMUSIC8 iface, REFGUID rguidClock) {
185 IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
186 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidClock));
190 static HRESULT WINAPI IDirectMusic8Impl_Activate (LPDIRECTMUSIC8 iface, BOOL fEnable) {
191 IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
194 FIXME("(%p, %d): stub\n", This, fEnable);
195 for (i = 0; i < This->nrofports; i++) {
196 IDirectMusicPortImpl_Activate(This->ppPorts[i], fEnable);
202 static HRESULT WINAPI IDirectMusic8Impl_GetDefaultPort (LPDIRECTMUSIC8 iface, LPGUID pguidPort) {
203 IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
205 DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
206 char returnBuffer[51];
207 GUID defaultPortGUID;
210 TRACE("(%p, %p)\n", This, pguidPort);
211 if ((RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\DirectMusic\\Defaults" , 0, KEY_READ, &hkGUID) != ERROR_SUCCESS) ||
212 (RegQueryValueExA(hkGUID, "DefaultOutputPort", NULL, &returnTypeGUID, (LPBYTE)returnBuffer, &sizeOfReturnBuffer) != ERROR_SUCCESS))
214 WARN(": registry entry missing\n" );
215 *pguidPort = CLSID_DirectMusicSynth;
218 /* FIXME: Check return types to ensure we're interpreting data right */
219 MultiByteToWideChar(CP_ACP, 0, returnBuffer, -1, buff, sizeof(buff) / sizeof(WCHAR));
220 CLSIDFromString(buff, &defaultPortGUID);
221 *pguidPort = defaultPortGUID;
226 static HRESULT WINAPI IDirectMusic8Impl_SetDirectSound (LPDIRECTMUSIC8 iface, LPDIRECTSOUND pDirectSound, HWND hWnd) {
227 IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
228 FIXME("(%p, %p, %p): stub\n", This, pDirectSound, hWnd);
232 static HRESULT WINAPI IDirectMusic8Impl_SetExternalMasterClock (LPDIRECTMUSIC8 iface, IReferenceClock* pClock) {
233 IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
234 FIXME("(%p, %p): stub\n", This, pClock);
238 static const IDirectMusic8Vtbl DirectMusic8_Vtbl = {
239 IDirectMusic8Impl_QueryInterface,
240 IDirectMusic8Impl_AddRef,
241 IDirectMusic8Impl_Release,
242 IDirectMusic8Impl_EnumPort,
243 IDirectMusic8Impl_CreateMusicBuffer,
244 IDirectMusic8Impl_CreatePort,
245 IDirectMusic8Impl_EnumMasterClock,
246 IDirectMusic8Impl_GetMasterClock,
247 IDirectMusic8Impl_SetMasterClock,
248 IDirectMusic8Impl_Activate,
249 IDirectMusic8Impl_GetDefaultPort,
250 IDirectMusic8Impl_SetDirectSound,
251 IDirectMusic8Impl_SetExternalMasterClock
254 /* for ClassFactory */
255 HRESULT WINAPI DMUSIC_CreateDirectMusicImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
256 IDirectMusic8Impl *dmusic;
258 TRACE("(%p,%p,%p)\n",lpcGUID, ppobj, pUnkOuter);
260 dmusic = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusic8Impl));
261 if (NULL == dmusic) {
263 return E_OUTOFMEMORY;
265 dmusic->lpVtbl = &DirectMusic8_Vtbl;
266 dmusic->ref = 0; /* will be inited with QueryInterface */
267 dmusic->pMasterClock = NULL;
268 dmusic->ppPorts = NULL;
269 dmusic->nrofports = 0;
270 DMUSIC_CreateReferenceClockImpl (&IID_IReferenceClock, (LPVOID*)&dmusic->pMasterClock, NULL);
272 return IDirectMusic8Impl_QueryInterface ((LPDIRECTMUSIC8)dmusic, lpcGUID, ppobj);