dmusic: Fix IDirectMusicPortImpl_QueryInterface.
[wine/wine64.git] / dlls / dmusic / port.c
blob618c2e393406fa525f33da902a27134433476607
1 /* IDirectMusicPort 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 "dmusic_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
24 /* IDirectMusicPortImpl IUnknown part: */
25 static HRESULT WINAPI IDirectMusicPortImpl_QueryInterface (LPDIRECTMUSICPORT iface, REFIID riid, LPVOID *ppobj) {
26 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpVtbl, iface);
28 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
30 if (IsEqualIID (riid, &IID_IUnknown) ||
31 IsEqualGUID(riid, &IID_IDirectMusicPort) ||
32 IsEqualGUID(riid, &IID_IDirectMusicPort8)) {
33 *ppobj = &This->lpVtbl;
34 IDirectMusicPort_AddRef((LPDIRECTMUSICPORT)*ppobj);
35 return S_OK;
36 } else if (IsEqualGUID(riid, &IID_IDirectMusicPortDownload) ||
37 IsEqualGUID(riid, &IID_IDirectMusicPortDownload8)) {
38 *ppobj = &This->lpDownloadVtbl;
39 IDirectMusicPortDownload_AddRef((LPDIRECTMUSICPORTDOWNLOAD)*ppobj);
40 return S_OK;
41 } else if (IsEqualGUID(riid, &IID_IDirectMusicThru) ||
42 IsEqualGUID(riid, &IID_IDirectMusicThru8)) {
43 *ppobj = &This->lpThruVtbl;
44 IDirectMusicThru_AddRef((LPDIRECTMUSICTHRU)*ppobj);
45 return S_OK;
47 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
48 return E_NOINTERFACE;
51 static ULONG WINAPI IDirectMusicPortImpl_AddRef (LPDIRECTMUSICPORT iface) {
52 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)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 IDirectMusicPortImpl_Release (LPDIRECTMUSICPORT iface) {
63 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
64 ULONG refCount = InterlockedDecrement(&This->ref);
66 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
68 if (!refCount) {
69 HeapFree(GetProcessHeap(), 0, This);
72 DMUSIC_UnlockModule();
74 return refCount;
77 /* IDirectMusicPortImpl IDirectMusicPort part: */
78 static HRESULT WINAPI IDirectMusicPortImpl_PlayBuffer (LPDIRECTMUSICPORT iface, LPDIRECTMUSICBUFFER pBuffer) {
79 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
80 FIXME("(%p, %p): stub\n", This, pBuffer);
81 return S_OK;
84 static HRESULT WINAPI IDirectMusicPortImpl_SetReadNotificationHandle (LPDIRECTMUSICPORT iface, HANDLE hEvent) {
85 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
86 FIXME("(%p, %p): stub\n", This, hEvent);
87 return S_OK;
90 static HRESULT WINAPI IDirectMusicPortImpl_Read (LPDIRECTMUSICPORT iface, LPDIRECTMUSICBUFFER pBuffer) {
91 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
92 FIXME("(%p, %p): stub\n", This, pBuffer);
93 return S_OK;
96 static HRESULT WINAPI IDirectMusicPortImpl_DownloadInstrument (LPDIRECTMUSICPORT iface, IDirectMusicInstrument* pInstrument, IDirectMusicDownloadedInstrument** ppDownloadedInstrument, DMUS_NOTERANGE* pNoteRanges, DWORD dwNumNoteRanges) {
97 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
99 FIXME("(%p, %p, %p, %p, %d): stub\n", This, pInstrument, ppDownloadedInstrument, pNoteRanges, dwNumNoteRanges);
101 if (!pInstrument || !ppDownloadedInstrument || (dwNumNoteRanges && !pNoteRanges))
102 return E_POINTER;
104 return DMUSIC_CreateDirectMusicDownloadedInstrumentImpl(&IID_IDirectMusicDownloadedInstrument, (LPVOID*)ppDownloadedInstrument, NULL);
107 static HRESULT WINAPI IDirectMusicPortImpl_UnloadInstrument (LPDIRECTMUSICPORT iface, IDirectMusicDownloadedInstrument *pDownloadedInstrument) {
108 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
109 FIXME("(%p, %p): stub\n", This, pDownloadedInstrument);
110 return S_OK;
113 static HRESULT WINAPI IDirectMusicPortImpl_GetLatencyClock (LPDIRECTMUSICPORT iface, IReferenceClock** ppClock) {
114 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
115 TRACE("(%p, %p)\n", This, ppClock);
116 *ppClock = This->pLatencyClock;
117 IReferenceClock_AddRef (*ppClock);
118 return S_OK;
121 static HRESULT WINAPI IDirectMusicPortImpl_GetRunningStats (LPDIRECTMUSICPORT iface, LPDMUS_SYNTHSTATS pStats) {
122 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
123 FIXME("(%p, %p): stub\n", This, pStats);
124 return S_OK;
127 static HRESULT WINAPI IDirectMusicPortImpl_Compact (LPDIRECTMUSICPORT iface) {
128 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
129 FIXME("(%p): stub\n", This);
130 return S_OK;
133 static HRESULT WINAPI IDirectMusicPortImpl_GetCaps (LPDIRECTMUSICPORT iface, LPDMUS_PORTCAPS pPortCaps) {
134 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
135 TRACE("(%p, %p)\n", This, pPortCaps);
136 *pPortCaps = This->caps;
137 return S_OK;
140 static HRESULT WINAPI IDirectMusicPortImpl_DeviceIoControl (LPDIRECTMUSICPORT iface, DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize, LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped) {
141 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
142 FIXME("(%p, %d, %p, %d, %p, %d, %p, %p): stub\n", This, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned, lpOverlapped);
143 return S_OK;
146 static HRESULT WINAPI IDirectMusicPortImpl_SetNumChannelGroups (LPDIRECTMUSICPORT iface, DWORD dwChannelGroups) {
147 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
148 FIXME("(%p, %d): semi-stub\n", This, dwChannelGroups);
149 This->nrofgroups = dwChannelGroups;
150 return S_OK;
153 static HRESULT WINAPI IDirectMusicPortImpl_GetNumChannelGroups (LPDIRECTMUSICPORT iface, LPDWORD pdwChannelGroups) {
154 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
155 TRACE("(%p, %p)\n", This, pdwChannelGroups);
156 *pdwChannelGroups = This->nrofgroups;
157 return S_OK;
160 HRESULT WINAPI IDirectMusicPortImpl_Activate (LPDIRECTMUSICPORT iface, BOOL fActive) {
161 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
162 TRACE("(%p, %d)\n", This, fActive);
163 This->fActive = fActive;
164 return S_OK;
167 static HRESULT WINAPI IDirectMusicPortImpl_SetChannelPriority (LPDIRECTMUSICPORT iface, DWORD dwChannelGroup, DWORD dwChannel, DWORD dwPriority) {
168 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
169 FIXME("(%p, %d, %d, %d): semi-stub\n", This, dwChannelGroup, dwChannel, dwPriority);
170 if (dwChannel > 16) {
171 WARN("isn't there supposed to be 16 channels (no. %d requested)?! (faking as it is ok)\n", dwChannel);
172 /*return E_INVALIDARG;*/
174 return S_OK;
177 static HRESULT WINAPI IDirectMusicPortImpl_GetChannelPriority (LPDIRECTMUSICPORT iface, DWORD dwChannelGroup, DWORD dwChannel, LPDWORD pdwPriority) {
178 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
179 TRACE("(%p, %d, %d, %p)\n", This, dwChannelGroup, dwChannel, pdwPriority);
180 *pdwPriority = This->group[dwChannelGroup-1].channel[dwChannel].priority;
181 return S_OK;
184 static HRESULT WINAPI IDirectMusicPortImpl_SetDirectSound (LPDIRECTMUSICPORT iface, LPDIRECTSOUND pDirectSound, LPDIRECTSOUNDBUFFER pDirectSoundBuffer) {
185 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
186 FIXME("(%p, %p, %p): stub\n", This, pDirectSound, pDirectSoundBuffer);
187 return S_OK;
190 static HRESULT WINAPI IDirectMusicPortImpl_GetFormat (LPDIRECTMUSICPORT iface, LPWAVEFORMATEX pWaveFormatEx, LPDWORD pdwWaveFormatExSize, LPDWORD pdwBufferSize) {
191 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
192 WAVEFORMATEX format;
193 FIXME("(%p, %p, %p, %p): stub\n", This, pWaveFormatEx, pdwWaveFormatExSize, pdwBufferSize);
195 if (pWaveFormatEx == NULL)
197 if (pdwWaveFormatExSize)
198 *pdwWaveFormatExSize = sizeof(format);
199 else
200 return E_POINTER;
202 else
204 if (pdwWaveFormatExSize == NULL)
205 return E_POINTER;
207 /* Just fill this in with something that will not crash Direct Sound for now. */
208 /* It won't be used anyway until Performances are completed */
209 format.wFormatTag = WAVE_FORMAT_PCM;
210 format.nChannels = 2; /* This->params.dwAudioChannels; */
211 format.nSamplesPerSec = 44100; /* This->params.dwSampleRate; */
212 format.wBitsPerSample = 16; /* FIXME: check this */
213 format.nBlockAlign = (format.wBitsPerSample * format.nChannels) / 8;
214 format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
215 format.cbSize = 0;
217 if (*pdwWaveFormatExSize >= sizeof(format))
219 CopyMemory(pWaveFormatEx, &format, min(sizeof(format), *pdwWaveFormatExSize));
220 *pdwWaveFormatExSize = sizeof(format); /* FIXME check if this is set */
222 else
223 return E_POINTER; /* FIXME find right error */
226 if (pdwBufferSize)
227 *pdwBufferSize = 44100 * 2 * 2;
228 else
229 return E_POINTER;
231 return S_OK;
234 static const IDirectMusicPortVtbl DirectMusicPort_Vtbl = {
235 IDirectMusicPortImpl_QueryInterface,
236 IDirectMusicPortImpl_AddRef,
237 IDirectMusicPortImpl_Release,
238 IDirectMusicPortImpl_PlayBuffer,
239 IDirectMusicPortImpl_SetReadNotificationHandle,
240 IDirectMusicPortImpl_Read,
241 IDirectMusicPortImpl_DownloadInstrument,
242 IDirectMusicPortImpl_UnloadInstrument,
243 IDirectMusicPortImpl_GetLatencyClock,
244 IDirectMusicPortImpl_GetRunningStats,
245 IDirectMusicPortImpl_Compact,
246 IDirectMusicPortImpl_GetCaps,
247 IDirectMusicPortImpl_DeviceIoControl,
248 IDirectMusicPortImpl_SetNumChannelGroups,
249 IDirectMusicPortImpl_GetNumChannelGroups,
250 IDirectMusicPortImpl_Activate,
251 IDirectMusicPortImpl_SetChannelPriority,
252 IDirectMusicPortImpl_GetChannelPriority,
253 IDirectMusicPortImpl_SetDirectSound,
254 IDirectMusicPortImpl_GetFormat
257 /* IDirectMusicPortDownload IUnknown parts follow: */
258 static HRESULT WINAPI IDirectMusicPortDownloadImpl_QueryInterface (LPDIRECTMUSICPORTDOWNLOAD iface, REFIID riid, LPVOID *ppobj) {
259 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpDownloadVtbl, iface);
260 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_dmguid(riid), ppobj);
261 return IUnknown_QueryInterface((IUnknown *)&(This->lpVtbl), riid, ppobj);
264 static ULONG WINAPI IDirectMusicPortDownloadImpl_AddRef (LPDIRECTMUSICPORTDOWNLOAD iface) {
265 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpDownloadVtbl, iface);
266 TRACE("(%p/%p)->()\n", This, iface);
267 return IUnknown_AddRef((IUnknown *)&(This->lpVtbl));
270 static ULONG WINAPI IDirectMusicPortDownloadImpl_Release (LPDIRECTMUSICPORTDOWNLOAD iface) {
271 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpDownloadVtbl, iface);
272 TRACE("(%p/%p)->()\n", This, iface);
273 return IUnknown_Release((IUnknown *)&(This->lpVtbl));
276 /* IDirectMusicPortDownload Interface follow: */
277 static HRESULT WINAPI IDirectMusicPortDownloadImpl_GetBuffer (LPDIRECTMUSICPORTDOWNLOAD iface, DWORD dwDLId, IDirectMusicDownload** ppIDMDownload) {
278 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpDownloadVtbl, iface);
279 FIXME("(%p/%p)->(%d, %p): stub\n", This, iface, dwDLId, ppIDMDownload);
280 return S_OK;
283 static HRESULT WINAPI IDirectMusicPortDownloadImpl_AllocateBuffer (LPDIRECTMUSICPORTDOWNLOAD iface, DWORD dwSize, IDirectMusicDownload** ppIDMDownload) {
284 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpDownloadVtbl, iface);
285 FIXME("(%p/%p)->(%d, %p): stub\n", This, iface, dwSize, ppIDMDownload);
286 return S_OK;
289 static HRESULT WINAPI IDirectMusicPortDownloadImpl_GetDLId (LPDIRECTMUSICPORTDOWNLOAD iface, DWORD* pdwStartDLId, DWORD dwCount) {
290 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpDownloadVtbl, iface);
291 FIXME("(%p/%p)->(%p, %d): stub\n", This, iface, pdwStartDLId, dwCount);
292 return S_OK;
295 static HRESULT WINAPI IDirectMusicPortDownloadImpl_GetAppend (LPDIRECTMUSICPORTDOWNLOAD iface, DWORD* pdwAppend) {
296 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
297 FIXME("(%p/%p)->(%p): stub\n", This, iface, pdwAppend);
298 return S_OK;
301 static HRESULT WINAPI IDirectMusicPortDownloadImpl_Download (LPDIRECTMUSICPORTDOWNLOAD iface, IDirectMusicDownload* pIDMDownload) {
302 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
303 FIXME("(%p/%p)->(%p): stub\n", This, iface, pIDMDownload);
304 return S_OK;
307 static HRESULT WINAPI IDirectMusicPortDownloadImpl_Unload (LPDIRECTMUSICPORTDOWNLOAD iface, IDirectMusicDownload* pIDMDownload) {
308 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
309 FIXME("(%p/%p)->(%p): stub\n", This, iface, pIDMDownload);
310 return S_OK;
313 static const IDirectMusicPortDownloadVtbl DirectMusicPortDownload_Vtbl = {
314 IDirectMusicPortDownloadImpl_QueryInterface,
315 IDirectMusicPortDownloadImpl_AddRef,
316 IDirectMusicPortDownloadImpl_Release,
317 IDirectMusicPortDownloadImpl_GetBuffer,
318 IDirectMusicPortDownloadImpl_AllocateBuffer,
319 IDirectMusicPortDownloadImpl_GetDLId,
320 IDirectMusicPortDownloadImpl_GetAppend,
321 IDirectMusicPortDownloadImpl_Download,
322 IDirectMusicPortDownloadImpl_Unload
325 /* IDirectMusicThru IUnknown parts follow: */
326 static HRESULT WINAPI IDirectMusicThruImpl_QueryInterface (LPDIRECTMUSICTHRU iface, REFIID riid, LPVOID *ppobj) {
327 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpThruVtbl, iface);
328 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_dmguid(riid), ppobj);
329 return IUnknown_QueryInterface((IUnknown *)&(This->lpVtbl), riid, ppobj);
332 static ULONG WINAPI IDirectMusicThruImpl_AddRef (LPDIRECTMUSICTHRU iface) {
333 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpThruVtbl, iface);
334 TRACE("(%p/%p)->()\n", This, iface);
335 return IUnknown_AddRef((IUnknown *)&(This->lpVtbl));
338 static ULONG WINAPI IDirectMusicThruImpl_Release (LPDIRECTMUSICTHRU iface) {
339 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpThruVtbl, iface);
340 TRACE("(%p/%p)->()\n", This, iface);
341 return IUnknown_Release((IUnknown *)&(This->lpVtbl));
344 /* IDirectMusicThru Interface follow: */
345 static HRESULT WINAPI IDirectMusicThruImpl_ThruChannel (LPDIRECTMUSICTHRU iface, DWORD dwSourceChannelGroup, DWORD dwSourceChannel, DWORD dwDestinationChannelGroup, DWORD dwDestinationChannel, LPDIRECTMUSICPORT pDestinationPort) {
346 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpThruVtbl, iface);
347 FIXME("(%p/%p)->(%d, %d, %d, %d, %p): stub\n", This, iface, dwSourceChannelGroup, dwSourceChannel, dwDestinationChannelGroup, dwDestinationChannel, pDestinationPort);
348 return S_OK;
351 static const IDirectMusicThruVtbl DirectMusicThru_Vtbl = {
352 IDirectMusicThruImpl_QueryInterface,
353 IDirectMusicThruImpl_AddRef,
354 IDirectMusicThruImpl_Release,
355 IDirectMusicThruImpl_ThruChannel
358 HRESULT WINAPI DMUSIC_CreateDirectMusicPortImpl (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter, LPDMUS_PORTPARAMS pPortParams, LPDMUS_PORTCAPS pPortCaps) {
359 IDirectMusicPortImpl *obj;
360 HRESULT hr = E_FAIL;
362 TRACE("(%p,%p,%p)\n", lpcGUID, ppobj, pUnkOuter);
364 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicPortImpl));
365 if (NULL == obj) {
366 *ppobj = NULL;
367 return E_OUTOFMEMORY;
369 obj->lpVtbl = &DirectMusicPort_Vtbl;
370 obj->lpDownloadVtbl = &DirectMusicPortDownload_Vtbl;
371 obj->lpThruVtbl = &DirectMusicThru_Vtbl;
372 obj->ref = 0; /* will be inited by QueryInterface */
373 obj->fActive = FALSE;
374 obj->params = *pPortParams;
375 obj->caps = *pPortCaps;
376 obj->pDirectSound = NULL;
377 obj->pLatencyClock = NULL;
378 hr = DMUSIC_CreateReferenceClockImpl(&IID_IReferenceClock, (LPVOID*)&obj->pLatencyClock, NULL);
380 #if 0
381 if (pPortParams->dwValidParams & DMUS_PORTPARAMS_CHANNELGROUPS) {
382 obj->nrofgroups = pPortParams->dwChannelGroups;
383 /* setting default priorities */
384 for (j = 0; j < obj->nrofgroups; j++) {
385 TRACE ("Setting default channel priorities on channel group %i\n", j + 1);
386 obj->group[j].channel[0].priority = DAUD_CHAN1_DEF_VOICE_PRIORITY;
387 obj->group[j].channel[1].priority = DAUD_CHAN2_DEF_VOICE_PRIORITY;
388 obj->group[j].channel[2].priority = DAUD_CHAN3_DEF_VOICE_PRIORITY;
389 obj->group[j].channel[3].priority = DAUD_CHAN4_DEF_VOICE_PRIORITY;
390 obj->group[j].channel[4].priority = DAUD_CHAN5_DEF_VOICE_PRIORITY;
391 obj->group[j].channel[5].priority = DAUD_CHAN6_DEF_VOICE_PRIORITY;
392 obj->group[j].channel[6].priority = DAUD_CHAN7_DEF_VOICE_PRIORITY;
393 obj->group[j].channel[7].priority = DAUD_CHAN8_DEF_VOICE_PRIORITY;
394 obj->group[j].channel[8].priority = DAUD_CHAN9_DEF_VOICE_PRIORITY;
395 obj->group[j].channel[9].priority = DAUD_CHAN10_DEF_VOICE_PRIORITY;
396 obj->group[j].channel[10].priority = DAUD_CHAN11_DEF_VOICE_PRIORITY;
397 obj->group[j].channel[11].priority = DAUD_CHAN12_DEF_VOICE_PRIORITY;
398 obj->group[j].channel[12].priority = DAUD_CHAN13_DEF_VOICE_PRIORITY;
399 obj->group[j].channel[13].priority = DAUD_CHAN14_DEF_VOICE_PRIORITY;
400 obj->group[j].channel[14].priority = DAUD_CHAN15_DEF_VOICE_PRIORITY;
401 obj->group[j].channel[15].priority = DAUD_CHAN16_DEF_VOICE_PRIORITY;
404 #endif
406 return IDirectMusicPortImpl_QueryInterface ((LPDIRECTMUSICPORT)obj, lpcGUID, ppobj);