dmusic.c 8.97 KB
Newer Older
1
/* IDirectMusic8 Implementation
2
 *
3
 * Copyright (C) 2003-2004 Rok Mandeljc
4
 *
5 6 7 8
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
9 10 11
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
14
 *
15 16 17
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 19 20 21 22
 */
#include "dmusic_private.h"

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);
27

28
	if (IsEqualIID (riid, &IID_IUnknown) || 
29
	    IsEqualIID (riid, &IID_IDirectMusic) ||
30 31
	    IsEqualIID (riid, &IID_IDirectMusic2) ||
	    IsEqualIID (riid, &IID_IDirectMusic8)) {
32
		IUnknown_AddRef(iface);
33
		*ppobj = This;
Rok Mandeljc's avatar
Rok Mandeljc committed
34
		return S_OK;
35
	}
36

37
	WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
38 39 40
	return E_NOINTERFACE;
}

41
static ULONG WINAPI IDirectMusic8Impl_AddRef (LPDIRECTMUSIC8 iface) {
42
	IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
43 44
	ULONG refCount = InterlockedIncrement(&This->ref);

45
	TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
46

47 48
	DMUSIC_LockModule();

49
	return refCount;
50 51
}

52
static ULONG WINAPI IDirectMusic8Impl_Release (LPDIRECTMUSIC8 iface) {
53
	IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
54 55
	ULONG refCount = InterlockedDecrement(&This->ref);

56
	TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
57 58

	if (!refCount) {
59 60
		HeapFree(GetProcessHeap(), 0, This);
	}
61 62 63

	DMUSIC_UnlockModule();
	
64
	return refCount;
65 66
}

67
/* IDirectMusic8Impl IDirectMusic part: */
68
static HRESULT WINAPI IDirectMusic8Impl_EnumPort(LPDIRECTMUSIC8 iface, DWORD dwIndex, LPDMUS_PORTCAPS pPortCaps) {
69
	IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
70
	TRACE("(%p, %d, %p)\n", This, dwIndex, pPortCaps);
71
	if (NULL == pPortCaps) { return E_POINTER; }
Rok Mandeljc's avatar
Rok Mandeljc committed
72
	/* i guess the first port shown is always software synthesizer */
73
	if (dwIndex == 0) 
Rok Mandeljc's avatar
Rok Mandeljc committed
74
	{
75
		IDirectMusicSynth8* synth;
Rok Mandeljc's avatar
Rok Mandeljc committed
76
		TRACE("enumerating 'Microsoft Software Synthesizer' port\n");
77 78 79
		CoCreateInstance (&CLSID_DirectMusicSynth, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicSynth8, (void**)&synth);
		IDirectMusicSynth8_GetPortCaps (synth, pPortCaps);
		IDirectMusicSynth8_Release (synth);
Rok Mandeljc's avatar
Rok Mandeljc committed
80 81
		return S_OK;
	}
82 83 84 85 86 87

/* it seems that the rest of devices are obtained thru dmusic32.EnumLegacyDevices...*sigh*...which is undocumented*/
#if 0
	int numMIDI = midiOutGetNumDevs();
	int numWAVE = waveOutGetNumDevs();
	int i;
Rok Mandeljc's avatar
Rok Mandeljc committed
88 89 90 91 92 93
	/* then return digital sound ports */
	for (i = 1; i <= numWAVE; i++)
	{
		TRACE("enumerating 'digital sound' ports\n");	
		if (i == dwIndex)
		{
94
			DirectSoundEnumerateA(register_waveport, pPortCaps);
Rok Mandeljc's avatar
Rok Mandeljc committed
95 96 97 98
			return S_OK;	
		}
	}
	/* finally, list all *real* MIDI ports*/
99
	for (i = numWAVE + 1; i <= numWAVE + numMIDI; i++) 
Rok Mandeljc's avatar
Rok Mandeljc committed
100 101 102 103 104
	{
		TRACE("enumerating 'real MIDI' ports\n");		
		if (i == dwIndex)
			FIXME("Found MIDI port, but *real* MIDI ports not supported yet\n");
	}
105
#endif	
Rok Mandeljc's avatar
Rok Mandeljc committed
106
	return S_FALSE;
107 108
}

109
static HRESULT WINAPI IDirectMusic8Impl_CreateMusicBuffer (LPDIRECTMUSIC8 iface, LPDMUS_BUFFERDESC pBufferDesc, LPDIRECTMUSICBUFFER** ppBuffer, LPUNKNOWN pUnkOuter) {
110
	IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
111 112 113 114 115 116 117 118 119 120

	TRACE("(%p, %p, %p, %p)\n", This, pBufferDesc, ppBuffer, pUnkOuter);

	if (pUnkOuter)
		return CLASS_E_NOAGGREGATION;

	if (!pBufferDesc || !ppBuffer)
		return E_POINTER;

	return DMUSIC_CreateDirectMusicBufferImpl(&IID_IDirectMusicBuffer, (LPVOID)ppBuffer, NULL);
121 122
}

123
static HRESULT WINAPI IDirectMusic8Impl_CreatePort (LPDIRECTMUSIC8 iface, REFCLSID rclsidPort, LPDMUS_PORTPARAMS pPortParams, LPDIRECTMUSICPORT* ppPort, LPUNKNOWN pUnkOuter) {
124
	IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
125
	int i/*, j*/;
Rok Mandeljc's avatar
Rok Mandeljc committed
126
	DMUS_PORTCAPS PortCaps;
127 128
	IDirectMusicPort* pNewPort = NULL;
	HRESULT hr = E_FAIL;
129

130 131 132 133 134 135 136 137
	TRACE("(%p, %s, %p, %p, %p)\n", This, debugstr_dmguid(rclsidPort), pPortParams, ppPort, pUnkOuter);	
	ZeroMemory(&PortCaps, sizeof(DMUS_PORTCAPS));
	PortCaps.dwSize = sizeof(DMUS_PORTCAPS);

	for (i = 0; S_FALSE != IDirectMusic8Impl_EnumPort(iface, i, &PortCaps); i++) {				
		if (IsEqualCLSID (rclsidPort, &PortCaps.guidPort)) {
			hr = DMUSIC_CreateDirectMusicPortImpl(&IID_IDirectMusicPort, (LPVOID*) &pNewPort, (LPUNKNOWN) This, pPortParams, &PortCaps);
			if (FAILED(hr)) {
138
                          *ppPort = NULL;
139
			  return hr;
140 141
			}
			This->nrofports++;
142 143
			if (!This->ppPorts) This->ppPorts = HeapAlloc(GetProcessHeap(), 0, sizeof(LPDIRECTMUSICPORT) * This->nrofports);
			else This->ppPorts = HeapReAlloc(GetProcessHeap(), 0, This->ppPorts, sizeof(LPDIRECTMUSICPORT) * This->nrofports); 			
144
			This->ppPorts[This->nrofports - 1] = pNewPort;
145
			*ppPort = pNewPort;
Rok Mandeljc's avatar
Rok Mandeljc committed
146 147 148 149 150
			return S_OK;			
		}
	}
	/* FIXME: place correct error here */
	return E_NOINTERFACE;
151 152
}

153
static HRESULT WINAPI IDirectMusic8Impl_EnumMasterClock (LPDIRECTMUSIC8 iface, DWORD dwIndex, LPDMUS_CLOCKINFO lpClockInfo) {
154
	IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
155
	FIXME("(%p, %d, %p): stub\n", This, dwIndex, lpClockInfo);
156
	return S_FALSE;
157 158
}

159
static HRESULT WINAPI IDirectMusic8Impl_GetMasterClock (LPDIRECTMUSIC8 iface, LPGUID pguidClock, IReferenceClock** ppReferenceClock) {
160
	IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
Rok Mandeljc's avatar
Rok Mandeljc committed
161

162 163 164 165 166
	TRACE("(%p, %p, %p)\n", This, pguidClock, ppReferenceClock);
	if (pguidClock)
		*pguidClock = This->pMasterClock->pClockInfo.guidClock;
	if(ppReferenceClock)
		*ppReferenceClock = (IReferenceClock *)This->pMasterClock;
Rok Mandeljc's avatar
Rok Mandeljc committed
167 168

	return S_OK;
169 170
}

171
static HRESULT WINAPI IDirectMusic8Impl_SetMasterClock (LPDIRECTMUSIC8 iface, REFGUID rguidClock) {
172
	IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
173
	FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidClock));
Rok Mandeljc's avatar
Rok Mandeljc committed
174
	return S_OK;
175 176
}

177
static HRESULT WINAPI IDirectMusic8Impl_Activate (LPDIRECTMUSIC8 iface, BOOL fEnable) {
178
	IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
Rok Mandeljc's avatar
Rok Mandeljc committed
179 180 181
	int i;
	
	FIXME("(%p, %d): stub\n", This, fEnable);
182
	for (i = 0; i < This->nrofports; i++) {
183
            IDirectMusicPortImpl_Activate(This->ppPorts[i], fEnable);
Rok Mandeljc's avatar
Rok Mandeljc committed
184 185 186
	}
	
	return S_OK;
187 188
}

189
static HRESULT WINAPI IDirectMusic8Impl_GetDefaultPort (LPDIRECTMUSIC8 iface, LPGUID pguidPort) {
190
	IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
Rok Mandeljc's avatar
Rok Mandeljc committed
191 192 193 194
	HKEY hkGUID;
	DWORD returnTypeGUID, sizeOfReturnBuffer = 50;
	char returnBuffer[51];
	GUID defaultPortGUID;
195
	WCHAR buff[51];
Rok Mandeljc's avatar
Rok Mandeljc committed
196 197

	TRACE("(%p, %p)\n", This, pguidPort);
198
	if ((RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\DirectMusic\\Defaults" , 0, KEY_READ, &hkGUID) != ERROR_SUCCESS) || 
199
	    (RegQueryValueExA(hkGUID, "DefaultOutputPort", NULL, &returnTypeGUID, (LPBYTE)returnBuffer, &sizeOfReturnBuffer) != ERROR_SUCCESS))
Rok Mandeljc's avatar
Rok Mandeljc committed
200 201 202 203 204 205
	{
		WARN(": registry entry missing\n" );
		*pguidPort = CLSID_DirectMusicSynth;
		return S_OK;
	}
	/* FIXME: Check return types to ensure we're interpreting data right */
206
	MultiByteToWideChar(CP_ACP, 0, returnBuffer, -1, buff, sizeof(buff) / sizeof(WCHAR));
207
	CLSIDFromString(buff, &defaultPortGUID);
Rok Mandeljc's avatar
Rok Mandeljc committed
208 209 210
	*pguidPort = defaultPortGUID;
	
	return S_OK;
211 212
}

213
static HRESULT WINAPI IDirectMusic8Impl_SetDirectSound (LPDIRECTMUSIC8 iface, LPDIRECTSOUND pDirectSound, HWND hWnd) {
214
	IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
Rok Mandeljc's avatar
Rok Mandeljc committed
215 216
	FIXME("(%p, %p, %p): stub\n", This, pDirectSound, hWnd);
	return S_OK;
217 218
}

219
static HRESULT WINAPI IDirectMusic8Impl_SetExternalMasterClock (LPDIRECTMUSIC8 iface, IReferenceClock* pClock) {
220
	IDirectMusic8Impl *This = (IDirectMusic8Impl *)iface;
Rok Mandeljc's avatar
Rok Mandeljc committed
221 222
	FIXME("(%p, %p): stub\n", This, pClock);
	return S_OK;
223 224
}

225
static const IDirectMusic8Vtbl DirectMusic8_Vtbl = {
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
	IDirectMusic8Impl_QueryInterface,
	IDirectMusic8Impl_AddRef,
	IDirectMusic8Impl_Release,
	IDirectMusic8Impl_EnumPort,
	IDirectMusic8Impl_CreateMusicBuffer,
	IDirectMusic8Impl_CreatePort,
	IDirectMusic8Impl_EnumMasterClock,
	IDirectMusic8Impl_GetMasterClock,
	IDirectMusic8Impl_SetMasterClock,
	IDirectMusic8Impl_Activate,
	IDirectMusic8Impl_GetDefaultPort,
	IDirectMusic8Impl_SetDirectSound,
	IDirectMusic8Impl_SetExternalMasterClock
};

241
/* for ClassFactory */
242
HRESULT WINAPI DMUSIC_CreateDirectMusicImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
243 244
	IDirectMusic8Impl *dmusic;

245 246 247 248
	TRACE("(%p,%p,%p)\n",lpcGUID, ppobj, pUnkOuter);

	dmusic = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusic8Impl));
	if (NULL == dmusic) {
249
		*ppobj = NULL;
250
		return E_OUTOFMEMORY;
251
	}
252 253 254 255 256 257
	dmusic->lpVtbl = &DirectMusic8_Vtbl;
	dmusic->ref = 0; /* will be inited with QueryInterface */
	dmusic->pMasterClock = NULL;
	dmusic->ppPorts = NULL;
	dmusic->nrofports = 0;
	DMUSIC_CreateReferenceClockImpl (&IID_IReferenceClock, (LPVOID*)&dmusic->pMasterClock, NULL);
258
	
259
	return IDirectMusic8Impl_QueryInterface ((LPDIRECTMUSIC8)dmusic, lpcGUID, ppobj);
260
}