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);
36 } else if (IsEqualGUID(riid, &IID_IDirectMusicPortDownload) ||
37 IsEqualGUID(riid, &IID_IDirectMusicPortDownload8)) {
38 *ppobj = &This->lpDownloadVtbl;
39 IDirectMusicPortDownload_AddRef((LPDIRECTMUSICPORTDOWNLOAD)*ppobj);
41 } else if (IsEqualGUID(riid, &IID_IDirectMusicThru) ||
42 IsEqualGUID(riid, &IID_IDirectMusicThru8)) {
43 *ppobj = &This->lpThruVtbl;
44 IDirectMusicThru_AddRef((LPDIRECTMUSICTHRU)*ppobj);
47 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
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);
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);
69 HeapFree(GetProcessHeap(), 0, This);
72 DMUSIC_UnlockModule();
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);
84 static HRESULT WINAPI IDirectMusicPortImpl_SetReadNotificationHandle (LPDIRECTMUSICPORT iface, HANDLE hEvent) {
85 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
86 FIXME("(%p, %p): stub\n", This, hEvent);
90 static HRESULT WINAPI IDirectMusicPortImpl_Read (LPDIRECTMUSICPORT iface, LPDIRECTMUSICBUFFER pBuffer) {
91 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
92 FIXME("(%p, %p): stub\n", This, pBuffer);
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))
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);
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);
121 static HRESULT WINAPI IDirectMusicPortImpl_GetRunningStats (LPDIRECTMUSICPORT iface, LPDMUS_SYNTHSTATS pStats) {
122 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
123 FIXME("(%p, %p): stub\n", This, pStats);
127 static HRESULT WINAPI IDirectMusicPortImpl_Compact (LPDIRECTMUSICPORT iface) {
128 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
129 FIXME("(%p): stub\n", This);
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;
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);
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;
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;
160 static HRESULT WINAPI IDirectMusicPortImpl_Activate (LPDIRECTMUSICPORT iface, BOOL fActive)
162 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
163 TRACE("(%p, %d)\n", This, fActive);
164 This->fActive = fActive;
168 static HRESULT WINAPI IDirectMusicPortImpl_SetChannelPriority (LPDIRECTMUSICPORT iface, DWORD dwChannelGroup, DWORD dwChannel, DWORD dwPriority) {
169 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
170 FIXME("(%p, %d, %d, %d): semi-stub\n", This, dwChannelGroup, dwChannel, dwPriority);
171 if (dwChannel > 16) {
172 WARN("isn't there supposed to be 16 channels (no. %d requested)?! (faking as it is ok)\n", dwChannel);
173 /*return E_INVALIDARG;*/
178 static HRESULT WINAPI IDirectMusicPortImpl_GetChannelPriority (LPDIRECTMUSICPORT iface, DWORD dwChannelGroup, DWORD dwChannel, LPDWORD pdwPriority) {
179 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
180 TRACE("(%p, %d, %d, %p)\n", This, dwChannelGroup, dwChannel, pdwPriority);
181 *pdwPriority = This->group[dwChannelGroup-1].channel[dwChannel].priority;
185 static HRESULT WINAPI IDirectMusicPortImpl_SetDirectSound (LPDIRECTMUSICPORT iface, LPDIRECTSOUND pDirectSound, LPDIRECTSOUNDBUFFER pDirectSoundBuffer) {
186 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
187 FIXME("(%p, %p, %p): stub\n", This, pDirectSound, pDirectSoundBuffer);
191 static HRESULT WINAPI IDirectMusicPortImpl_GetFormat (LPDIRECTMUSICPORT iface, LPWAVEFORMATEX pWaveFormatEx, LPDWORD pdwWaveFormatExSize, LPDWORD pdwBufferSize) {
192 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
194 FIXME("(%p, %p, %p, %p): stub\n", This, pWaveFormatEx, pdwWaveFormatExSize, pdwBufferSize);
196 if (pWaveFormatEx == NULL)
198 if (pdwWaveFormatExSize)
199 *pdwWaveFormatExSize = sizeof(format);
205 if (pdwWaveFormatExSize == NULL)
208 /* Just fill this in with something that will not crash Direct Sound for now. */
209 /* It won't be used anyway until Performances are completed */
210 format.wFormatTag = WAVE_FORMAT_PCM;
211 format.nChannels = 2; /* This->params.dwAudioChannels; */
212 format.nSamplesPerSec = 44100; /* This->params.dwSampleRate; */
213 format.wBitsPerSample = 16; /* FIXME: check this */
214 format.nBlockAlign = (format.wBitsPerSample * format.nChannels) / 8;
215 format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
218 if (*pdwWaveFormatExSize >= sizeof(format))
220 CopyMemory(pWaveFormatEx, &format, min(sizeof(format), *pdwWaveFormatExSize));
221 *pdwWaveFormatExSize = sizeof(format); /* FIXME check if this is set */
224 return E_POINTER; /* FIXME find right error */
228 *pdwBufferSize = 44100 * 2 * 2;
235 static const IDirectMusicPortVtbl DirectMusicPort_Vtbl = {
236 IDirectMusicPortImpl_QueryInterface,
237 IDirectMusicPortImpl_AddRef,
238 IDirectMusicPortImpl_Release,
239 IDirectMusicPortImpl_PlayBuffer,
240 IDirectMusicPortImpl_SetReadNotificationHandle,
241 IDirectMusicPortImpl_Read,
242 IDirectMusicPortImpl_DownloadInstrument,
243 IDirectMusicPortImpl_UnloadInstrument,
244 IDirectMusicPortImpl_GetLatencyClock,
245 IDirectMusicPortImpl_GetRunningStats,
246 IDirectMusicPortImpl_Compact,
247 IDirectMusicPortImpl_GetCaps,
248 IDirectMusicPortImpl_DeviceIoControl,
249 IDirectMusicPortImpl_SetNumChannelGroups,
250 IDirectMusicPortImpl_GetNumChannelGroups,
251 IDirectMusicPortImpl_Activate,
252 IDirectMusicPortImpl_SetChannelPriority,
253 IDirectMusicPortImpl_GetChannelPriority,
254 IDirectMusicPortImpl_SetDirectSound,
255 IDirectMusicPortImpl_GetFormat
258 /* IDirectMusicPortDownload IUnknown parts follow: */
259 static HRESULT WINAPI IDirectMusicPortDownloadImpl_QueryInterface (LPDIRECTMUSICPORTDOWNLOAD iface, REFIID riid, LPVOID *ppobj) {
260 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpDownloadVtbl, iface);
261 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_dmguid(riid), ppobj);
262 return IUnknown_QueryInterface((IUnknown *)&(This->lpVtbl), riid, ppobj);
265 static ULONG WINAPI IDirectMusicPortDownloadImpl_AddRef (LPDIRECTMUSICPORTDOWNLOAD iface) {
266 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpDownloadVtbl, iface);
267 TRACE("(%p/%p)->()\n", This, iface);
268 return IUnknown_AddRef((IUnknown *)&(This->lpVtbl));
271 static ULONG WINAPI IDirectMusicPortDownloadImpl_Release (LPDIRECTMUSICPORTDOWNLOAD iface) {
272 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpDownloadVtbl, iface);
273 TRACE("(%p/%p)->()\n", This, iface);
274 return IUnknown_Release((IUnknown *)&(This->lpVtbl));
277 /* IDirectMusicPortDownload Interface follow: */
278 static HRESULT WINAPI IDirectMusicPortDownloadImpl_GetBuffer (LPDIRECTMUSICPORTDOWNLOAD iface, DWORD dwDLId, IDirectMusicDownload** ppIDMDownload) {
279 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpDownloadVtbl, iface);
281 FIXME("(%p/%p)->(%d, %p): stub\n", This, iface, dwDLId, ppIDMDownload);
286 return DMUSIC_CreateDirectMusicDownloadImpl(&IID_IDirectMusicDownload, (LPVOID*)ppIDMDownload, NULL);
289 static HRESULT WINAPI IDirectMusicPortDownloadImpl_AllocateBuffer (LPDIRECTMUSICPORTDOWNLOAD iface, DWORD dwSize, IDirectMusicDownload** ppIDMDownload) {
290 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpDownloadVtbl, iface);
291 FIXME("(%p/%p)->(%d, %p): stub\n", This, iface, dwSize, ppIDMDownload);
295 static HRESULT WINAPI IDirectMusicPortDownloadImpl_GetDLId (LPDIRECTMUSICPORTDOWNLOAD iface, DWORD* pdwStartDLId, DWORD dwCount) {
296 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpDownloadVtbl, iface);
297 FIXME("(%p/%p)->(%p, %d): stub\n", This, iface, pdwStartDLId, dwCount);
301 static HRESULT WINAPI IDirectMusicPortDownloadImpl_GetAppend (LPDIRECTMUSICPORTDOWNLOAD iface, DWORD* pdwAppend) {
302 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
303 FIXME("(%p/%p)->(%p): stub\n", This, iface, pdwAppend);
307 static HRESULT WINAPI IDirectMusicPortDownloadImpl_Download (LPDIRECTMUSICPORTDOWNLOAD iface, IDirectMusicDownload* pIDMDownload) {
308 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
309 FIXME("(%p/%p)->(%p): stub\n", This, iface, pIDMDownload);
313 static HRESULT WINAPI IDirectMusicPortDownloadImpl_Unload (LPDIRECTMUSICPORTDOWNLOAD iface, IDirectMusicDownload* pIDMDownload) {
314 IDirectMusicPortImpl *This = (IDirectMusicPortImpl *)iface;
315 FIXME("(%p/%p)->(%p): stub\n", This, iface, pIDMDownload);
319 static const IDirectMusicPortDownloadVtbl DirectMusicPortDownload_Vtbl = {
320 IDirectMusicPortDownloadImpl_QueryInterface,
321 IDirectMusicPortDownloadImpl_AddRef,
322 IDirectMusicPortDownloadImpl_Release,
323 IDirectMusicPortDownloadImpl_GetBuffer,
324 IDirectMusicPortDownloadImpl_AllocateBuffer,
325 IDirectMusicPortDownloadImpl_GetDLId,
326 IDirectMusicPortDownloadImpl_GetAppend,
327 IDirectMusicPortDownloadImpl_Download,
328 IDirectMusicPortDownloadImpl_Unload
331 /* IDirectMusicThru IUnknown parts follow: */
332 static HRESULT WINAPI IDirectMusicThruImpl_QueryInterface (LPDIRECTMUSICTHRU iface, REFIID riid, LPVOID *ppobj) {
333 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpThruVtbl, iface);
334 TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_dmguid(riid), ppobj);
335 return IUnknown_QueryInterface((IUnknown *)&(This->lpVtbl), riid, ppobj);
338 static ULONG WINAPI IDirectMusicThruImpl_AddRef (LPDIRECTMUSICTHRU iface) {
339 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpThruVtbl, iface);
340 TRACE("(%p/%p)->()\n", This, iface);
341 return IUnknown_AddRef((IUnknown *)&(This->lpVtbl));
344 static ULONG WINAPI IDirectMusicThruImpl_Release (LPDIRECTMUSICTHRU iface) {
345 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpThruVtbl, iface);
346 TRACE("(%p/%p)->()\n", This, iface);
347 return IUnknown_Release((IUnknown *)&(This->lpVtbl));
350 /* IDirectMusicThru Interface follow: */
351 static HRESULT WINAPI IDirectMusicThruImpl_ThruChannel (LPDIRECTMUSICTHRU iface, DWORD dwSourceChannelGroup, DWORD dwSourceChannel, DWORD dwDestinationChannelGroup, DWORD dwDestinationChannel, LPDIRECTMUSICPORT pDestinationPort) {
352 ICOM_THIS_MULTI(IDirectMusicPortImpl, lpThruVtbl, iface);
353 FIXME("(%p/%p)->(%d, %d, %d, %d, %p): stub\n", This, iface, dwSourceChannelGroup, dwSourceChannel, dwDestinationChannelGroup, dwDestinationChannel, pDestinationPort);
357 static const IDirectMusicThruVtbl DirectMusicThru_Vtbl = {
358 IDirectMusicThruImpl_QueryInterface,
359 IDirectMusicThruImpl_AddRef,
360 IDirectMusicThruImpl_Release,
361 IDirectMusicThruImpl_ThruChannel
364 HRESULT DMUSIC_CreateDirectMusicPortImpl (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter, LPDMUS_PORTPARAMS pPortParams, LPDMUS_PORTCAPS pPortCaps) {
365 IDirectMusicPortImpl *obj;
369 TRACE("(%p,%p,%p)\n", lpcGUID, ppobj, pUnkOuter);
371 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicPortImpl));
374 return E_OUTOFMEMORY;
376 obj->lpVtbl = &DirectMusicPort_Vtbl;
377 obj->lpDownloadVtbl = &DirectMusicPortDownload_Vtbl;
378 obj->lpThruVtbl = &DirectMusicThru_Vtbl;
379 obj->ref = 0; /* will be inited by QueryInterface */
380 obj->fActive = FALSE;
381 obj->params = *pPortParams;
382 obj->caps = *pPortCaps;
383 obj->pDirectSound = NULL;
384 obj->pLatencyClock = NULL;
385 hr = DMUSIC_CreateReferenceClockImpl(&IID_IReferenceClock, (LPVOID*)&obj->pLatencyClock, NULL);
388 HeapFree(GetProcessHeap(), 0, obj);
394 if (pPortParams->dwValidParams & DMUS_PORTPARAMS_CHANNELGROUPS) {
395 obj->nrofgroups = pPortParams->dwChannelGroups;
396 /* setting default priorities */
397 for (j = 0; j < obj->nrofgroups; j++) {
398 TRACE ("Setting default channel priorities on channel group %i\n", j + 1);
399 obj->group[j].channel[0].priority = DAUD_CHAN1_DEF_VOICE_PRIORITY;
400 obj->group[j].channel[1].priority = DAUD_CHAN2_DEF_VOICE_PRIORITY;
401 obj->group[j].channel[2].priority = DAUD_CHAN3_DEF_VOICE_PRIORITY;
402 obj->group[j].channel[3].priority = DAUD_CHAN4_DEF_VOICE_PRIORITY;
403 obj->group[j].channel[4].priority = DAUD_CHAN5_DEF_VOICE_PRIORITY;
404 obj->group[j].channel[5].priority = DAUD_CHAN6_DEF_VOICE_PRIORITY;
405 obj->group[j].channel[6].priority = DAUD_CHAN7_DEF_VOICE_PRIORITY;
406 obj->group[j].channel[7].priority = DAUD_CHAN8_DEF_VOICE_PRIORITY;
407 obj->group[j].channel[8].priority = DAUD_CHAN9_DEF_VOICE_PRIORITY;
408 obj->group[j].channel[9].priority = DAUD_CHAN10_DEF_VOICE_PRIORITY;
409 obj->group[j].channel[10].priority = DAUD_CHAN11_DEF_VOICE_PRIORITY;
410 obj->group[j].channel[11].priority = DAUD_CHAN12_DEF_VOICE_PRIORITY;
411 obj->group[j].channel[12].priority = DAUD_CHAN13_DEF_VOICE_PRIORITY;
412 obj->group[j].channel[13].priority = DAUD_CHAN14_DEF_VOICE_PRIORITY;
413 obj->group[j].channel[14].priority = DAUD_CHAN15_DEF_VOICE_PRIORITY;
414 obj->group[j].channel[15].priority = DAUD_CHAN16_DEF_VOICE_PRIORITY;
419 return IDirectMusicPortImpl_QueryInterface ((LPDIRECTMUSICPORT)obj, lpcGUID, ppobj);