2 * IDirectMusicPort Implementation
4 * Copyright (C) 2003-2004 Rok Mandeljc
5 * Copyright (C) 2012 Christian Costa
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "dmusic_private.h"
26 typedef struct SynthPortImpl
{
27 IDirectMusicPort IDirectMusicPort_iface
;
28 IDirectMusicPortDownload IDirectMusicPortDownload_iface
;
29 IDirectMusicThru IDirectMusicThru_iface
;
30 IKsControl IKsControl_iface
;
32 IDirectMusic8Impl
*parent
;
34 IDirectSoundBuffer
*dsbuffer
;
35 IReferenceClock
*pLatencyClock
;
36 IDirectMusicSynth
*synth
;
37 IDirectMusicSynthSink
*synth_sink
;
40 DMUS_PORTPARAMS params
;
42 DMUSIC_PRIVATE_CHANNEL_GROUP group
[1];
45 static inline IDirectMusicDownloadedInstrumentImpl
* impl_from_IDirectMusicDownloadedInstrument(IDirectMusicDownloadedInstrument
*iface
)
47 return CONTAINING_RECORD(iface
, IDirectMusicDownloadedInstrumentImpl
, IDirectMusicDownloadedInstrument_iface
);
50 static inline SynthPortImpl
*impl_from_SynthPortImpl_IDirectMusicPort(IDirectMusicPort
*iface
)
52 return CONTAINING_RECORD(iface
, SynthPortImpl
, IDirectMusicPort_iface
);
55 static inline SynthPortImpl
*impl_from_SynthPortImpl_IDirectMusicPortDownload(IDirectMusicPortDownload
*iface
)
57 return CONTAINING_RECORD(iface
, SynthPortImpl
, IDirectMusicPortDownload_iface
);
60 static inline SynthPortImpl
*impl_from_SynthPortImpl_IDirectMusicThru(IDirectMusicThru
*iface
)
62 return CONTAINING_RECORD(iface
, SynthPortImpl
, IDirectMusicThru_iface
);
65 static inline SynthPortImpl
*impl_from_IKsControl(IKsControl
*iface
)
67 return CONTAINING_RECORD(iface
, SynthPortImpl
, IKsControl_iface
);
70 /* IDirectMusicDownloadedInstrument IUnknown part follows: */
71 static HRESULT WINAPI
IDirectMusicDownloadedInstrumentImpl_QueryInterface(IDirectMusicDownloadedInstrument
*iface
, REFIID riid
, VOID
**ret_iface
)
73 TRACE("(%p, %s, %p)\n", iface
, debugstr_dmguid(riid
), ret_iface
);
75 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDirectMusicDownloadedInstrument
))
77 IDirectMusicDownloadedInstrument_AddRef(iface
);
82 WARN("(%p, %s, %p): not found\n", iface
, debugstr_dmguid(riid
), ret_iface
);
87 static ULONG WINAPI
IDirectMusicDownloadedInstrumentImpl_AddRef(LPDIRECTMUSICDOWNLOADEDINSTRUMENT iface
)
89 IDirectMusicDownloadedInstrumentImpl
*This
= impl_from_IDirectMusicDownloadedInstrument(iface
);
90 ULONG ref
= InterlockedIncrement(&This
->ref
);
92 TRACE("(%p)->(): new ref = %u\n", iface
, ref
);
97 static ULONG WINAPI
IDirectMusicDownloadedInstrumentImpl_Release(LPDIRECTMUSICDOWNLOADEDINSTRUMENT iface
)
99 IDirectMusicDownloadedInstrumentImpl
*This
= impl_from_IDirectMusicDownloadedInstrument(iface
);
100 ULONG ref
= InterlockedDecrement(&This
->ref
);
102 TRACE("(%p)->(): new ref = %u\n", iface
, ref
);
106 HeapFree(GetProcessHeap(), 0, This
->data
);
107 HeapFree(GetProcessHeap(), 0, This
);
108 DMUSIC_UnlockModule();
114 static const IDirectMusicDownloadedInstrumentVtbl DirectMusicDownloadedInstrument_Vtbl
= {
115 IDirectMusicDownloadedInstrumentImpl_QueryInterface
,
116 IDirectMusicDownloadedInstrumentImpl_AddRef
,
117 IDirectMusicDownloadedInstrumentImpl_Release
120 static inline IDirectMusicDownloadedInstrumentImpl
* unsafe_impl_from_IDirectMusicDownloadedInstrument(IDirectMusicDownloadedInstrument
*iface
)
124 assert(iface
->lpVtbl
== &DirectMusicDownloadedInstrument_Vtbl
);
126 return impl_from_IDirectMusicDownloadedInstrument(iface
);
129 static HRESULT
DMUSIC_CreateDirectMusicDownloadedInstrumentImpl(IDirectMusicDownloadedInstrument
**instrument
)
131 IDirectMusicDownloadedInstrumentImpl
*object
;
133 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
137 return E_OUTOFMEMORY
;
140 object
->IDirectMusicDownloadedInstrument_iface
.lpVtbl
= &DirectMusicDownloadedInstrument_Vtbl
;
143 *instrument
= &object
->IDirectMusicDownloadedInstrument_iface
;
149 /* SynthPortImpl IDirectMusicPort IUnknown part follows: */
150 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_QueryInterface(LPDIRECTMUSICPORT iface
, REFIID riid
, LPVOID
*ret_iface
)
152 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
154 TRACE("(%p/%p)->(%s, %p)\n", iface
, This
, debugstr_dmguid(riid
), ret_iface
);
156 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_IDirectMusicPort
))
157 *ret_iface
= &This
->IDirectMusicPort_iface
;
158 else if (IsEqualGUID(riid
, &IID_IDirectMusicPortDownload
))
159 *ret_iface
= &This
->IDirectMusicPortDownload_iface
;
160 else if (IsEqualGUID(riid
, &IID_IDirectMusicThru
))
161 *ret_iface
= &This
->IDirectMusicThru_iface
;
162 else if (IsEqualGUID(riid
, &IID_IKsControl
))
163 *ret_iface
= &This
->IKsControl_iface
;
165 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ret_iface
);
167 return E_NOINTERFACE
;
170 IUnknown_AddRef((IUnknown
*)*ret_iface
);
175 static ULONG WINAPI
SynthPortImpl_IDirectMusicPort_AddRef(LPDIRECTMUSICPORT iface
)
177 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
178 ULONG ref
= InterlockedIncrement(&This
->ref
);
180 TRACE("(%p)->(): new ref = %u\n", This
, ref
);
187 static ULONG WINAPI
SynthPortImpl_IDirectMusicPort_Release(LPDIRECTMUSICPORT iface
)
189 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
190 ULONG ref
= InterlockedDecrement(&This
->ref
);
192 TRACE("(%p)->(): new ref = %u\n", This
, ref
);
196 dmusic_remove_port(This
->parent
, iface
);
197 IDirectMusicSynth_Activate(This
->synth
, FALSE
);
198 IDirectMusicSynth_Close(This
->synth
);
199 IDirectMusicSynth_Release(This
->synth
);
200 IDirectMusicSynthSink_Release(This
->synth_sink
);
201 IReferenceClock_Release(This
->pLatencyClock
);
203 IDirectSoundBuffer_Release(This
->dsbuffer
);
205 IDirectSound_Release(This
->dsound
);
206 HeapFree(GetProcessHeap(), 0, This
);
209 DMUSIC_UnlockModule();
214 /* SynthPortImpl IDirectMusicPort interface follows: */
215 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_PlayBuffer(LPDIRECTMUSICPORT iface
, LPDIRECTMUSICBUFFER buffer
)
217 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
223 TRACE("(%p/%p)->(%p)\n", iface
, This
, buffer
);
228 hr
= IDirectMusicBuffer_GetStartTime(buffer
, &time
);
231 hr
= IDirectMusicBuffer_GetRawBufferPtr(buffer
, &data
);
234 hr
= IDirectMusicBuffer_GetUsedBytes(buffer
, &size
);
237 hr
= IDirectMusicSynth_PlayBuffer(This
->synth
, time
, data
, size
);
242 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_SetReadNotificationHandle(LPDIRECTMUSICPORT iface
, HANDLE event
)
244 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
246 FIXME("(%p/%p)->(%p): stub\n", iface
, This
, event
);
251 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_Read(LPDIRECTMUSICPORT iface
, LPDIRECTMUSICBUFFER buffer
)
253 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
255 FIXME("(%p/%p)->(%p): stub\n", iface
, This
, buffer
);
260 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_DownloadInstrument(LPDIRECTMUSICPORT iface
, IDirectMusicInstrument
* instrument
, IDirectMusicDownloadedInstrument
** downloaded_instrument
, DMUS_NOTERANGE
* note_ranges
, DWORD num_note_ranges
)
262 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
263 IDirectMusicInstrumentImpl
*instrument_object
;
267 DMUS_DOWNLOADINFO
*info
;
268 DMUS_OFFSETTABLE
*offset_table
;
269 DMUS_INSTRUMENT
*instrument_info
;
276 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", iface
, This
, instrument
, downloaded_instrument
, note_ranges
, num_note_ranges
);
278 if (!instrument
|| !downloaded_instrument
|| (num_note_ranges
&& !note_ranges
))
281 instrument_object
= impl_from_IDirectMusicInstrument(instrument
);
283 nb_regions
= instrument_object
->header
.cRegions
;
284 size
= sizeof(DMUS_DOWNLOADINFO
) + sizeof(ULONG
) * (1 + nb_regions
) + sizeof(DMUS_INSTRUMENT
) + sizeof(DMUS_REGION
) * nb_regions
;
286 data
= HeapAlloc(GetProcessHeap(), 0, size
);
288 return E_OUTOFMEMORY
;
290 info
= (DMUS_DOWNLOADINFO
*)data
;
291 offset_table
= (DMUS_OFFSETTABLE
*)(data
+ sizeof(DMUS_DOWNLOADINFO
));
292 offset
= sizeof(DMUS_DOWNLOADINFO
) + sizeof(ULONG
) * (1 + nb_regions
);
294 info
->dwDLType
= DMUS_DOWNLOADINFO_INSTRUMENT2
;
296 info
->dwNumOffsetTableEntries
= 1 + instrument_object
->header
.cRegions
;
299 offset_table
->ulOffsetTable
[0] = offset
;
300 instrument_info
= (DMUS_INSTRUMENT
*)(data
+ offset
);
301 offset
+= sizeof(DMUS_INSTRUMENT
);
302 instrument_info
->ulPatch
= MIDILOCALE2Patch(&instrument_object
->header
.Locale
);
303 instrument_info
->ulFirstRegionIdx
= 1;
304 instrument_info
->ulGlobalArtIdx
= 0; /* FIXME */
305 instrument_info
->ulFirstExtCkIdx
= 0; /* FIXME */
306 instrument_info
->ulCopyrightIdx
= 0; /* FIXME */
307 instrument_info
->ulFlags
= 0; /* FIXME */
309 for (i
= 0; i
< nb_regions
; i
++)
311 DMUS_REGION
*region
= (DMUS_REGION
*)(data
+ offset
);
313 offset_table
->ulOffsetTable
[1 + i
] = offset
;
314 offset
+= sizeof(DMUS_REGION
);
315 region
->RangeKey
= instrument_object
->regions
[i
].header
.RangeKey
;
316 region
->RangeVelocity
= instrument_object
->regions
[i
].header
.RangeVelocity
;
317 region
->fusOptions
= instrument_object
->regions
[i
].header
.fusOptions
;
318 region
->usKeyGroup
= instrument_object
->regions
[i
].header
.usKeyGroup
;
319 region
->ulRegionArtIdx
= 0; /* FIXME */
320 region
->ulNextRegionIdx
= i
!= (nb_regions
- 1) ? (i
+ 2) : 0;
321 region
->ulFirstExtCkIdx
= 0; /* FIXME */
322 region
->WaveLink
= instrument_object
->regions
[i
].wave_link
;
323 region
->WSMP
= instrument_object
->regions
[i
].wave_sample
;
324 region
->WLOOP
[0] = instrument_object
->regions
[i
].wave_loop
;
327 ret
= IDirectMusicSynth8_Download(This
->synth
, &download
, (VOID
*)data
, &free
);
330 ret
= DMUSIC_CreateDirectMusicDownloadedInstrumentImpl(downloaded_instrument
);
334 IDirectMusicDownloadedInstrumentImpl
*downloaded_object
= impl_from_IDirectMusicDownloadedInstrument(*downloaded_instrument
);
336 downloaded_object
->data
= data
;
337 downloaded_object
->downloaded
= TRUE
;
340 *downloaded_instrument
= NULL
;
341 HeapFree(GetProcessHeap(), 0, data
);
346 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_UnloadInstrument(LPDIRECTMUSICPORT iface
, IDirectMusicDownloadedInstrument
*downloaded_instrument
)
348 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
349 IDirectMusicDownloadedInstrumentImpl
*downloaded_object
= unsafe_impl_from_IDirectMusicDownloadedInstrument(downloaded_instrument
);
351 TRACE("(%p/%p)->(%p)\n", iface
, This
, downloaded_instrument
);
353 if (!downloaded_instrument
)
356 if (!downloaded_object
->downloaded
)
357 return DMUS_E_NOT_DOWNLOADED_TO_PORT
;
359 HeapFree(GetProcessHeap(), 0, downloaded_object
->data
);
360 downloaded_object
->data
= NULL
;
361 downloaded_object
->downloaded
= FALSE
;
366 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_GetLatencyClock(LPDIRECTMUSICPORT iface
, IReferenceClock
** clock
)
368 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
370 TRACE("(%p/%p)->(%p)\n", iface
, This
, clock
);
372 *clock
= This
->pLatencyClock
;
373 IReferenceClock_AddRef(*clock
);
378 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_GetRunningStats(LPDIRECTMUSICPORT iface
, LPDMUS_SYNTHSTATS stats
)
380 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
382 FIXME("(%p/%p)->(%p): stub\n", iface
, This
, stats
);
387 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_Compact(LPDIRECTMUSICPORT iface
)
389 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
391 FIXME("(%p/%p)->(): stub\n", iface
, This
);
396 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_GetCaps(LPDIRECTMUSICPORT iface
, LPDMUS_PORTCAPS port_caps
)
398 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
400 TRACE("(%p/%p)->(%p)\n", iface
, This
, port_caps
);
402 *port_caps
= This
->caps
;
407 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_DeviceIoControl(LPDIRECTMUSICPORT iface
, DWORD io_control_code
, LPVOID in_buffer
, DWORD in_buffer_size
,
408 LPVOID out_buffer
, DWORD out_buffer_size
, LPDWORD bytes_returned
, LPOVERLAPPED overlapped
)
410 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
412 FIXME("(%p/%p)->(%d, %p, %d, %p, %d, %p, %p): stub\n", iface
, This
, io_control_code
, in_buffer
, in_buffer_size
, out_buffer
, out_buffer_size
, bytes_returned
, overlapped
);
417 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_SetNumChannelGroups(LPDIRECTMUSICPORT iface
, DWORD channel_groups
)
419 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
421 FIXME("(%p/%p)->(%d): semi-stub\n", iface
, This
, channel_groups
);
423 This
->nrofgroups
= channel_groups
;
428 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_GetNumChannelGroups(LPDIRECTMUSICPORT iface
, LPDWORD channel_groups
)
430 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
432 TRACE("(%p/%p)->(%p)\n", iface
, This
, channel_groups
);
434 *channel_groups
= This
->nrofgroups
;
439 static HRESULT WINAPI
synth_dmport_Activate(IDirectMusicPort
*iface
, BOOL active
)
441 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
443 FIXME("(%p/%p)->(%d): semi-stub\n", iface
, This
, active
);
445 if (This
->active
== active
)
449 /* Acquire the dsound */
451 IDirectSound_AddRef(This
->parent
->dsound
);
452 This
->dsound
= This
->parent
->dsound
;
454 IDirectSound_AddRef(This
->dsound
);
456 /* Release the dsound */
457 IDirectSound_Release(This
->dsound
);
458 IDirectSound_Release(This
->parent
->dsound
);
459 if (This
->dsound
== This
->parent
->dsound
)
463 This
->active
= active
;
468 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_SetChannelPriority(LPDIRECTMUSICPORT iface
, DWORD channel_group
, DWORD channel
, DWORD priority
)
470 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
472 FIXME("(%p/%p)->(%d, %d, %d): semi-stub\n", iface
, This
, channel_group
, channel
, priority
);
476 WARN("isn't there supposed to be 16 channels (no. %d requested)?! (faking as it is ok)\n", channel
);
477 /*return E_INVALIDARG;*/
483 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_GetChannelPriority(LPDIRECTMUSICPORT iface
, DWORD channel_group
, DWORD channel
, LPDWORD priority
)
485 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
487 TRACE("(%p/%p)->(%u, %u, %p)\n", iface
, This
, channel_group
, channel
, priority
);
489 *priority
= This
->group
[channel_group
- 1].channel
[channel
].priority
;
494 static HRESULT WINAPI
synth_dmport_SetDirectSound(IDirectMusicPort
*iface
, IDirectSound
*dsound
,
495 IDirectSoundBuffer
*dsbuffer
)
497 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
499 FIXME("(%p/%p)->(%p, %p): semi-stub\n", iface
, This
, dsound
, dsbuffer
);
502 return DMUS_E_DSOUND_ALREADY_SET
;
505 if (This
->dsound
!= This
->parent
->dsound
)
506 ERR("Not the same dsound in the port (%p) and parent dmusic (%p), expect trouble!\n",
507 This
->dsound
, This
->parent
->dsound
);
508 if (!IDirectSound_Release(This
->parent
->dsound
))
509 This
->parent
->dsound
= NULL
;
512 IDirectSound_Release(This
->dsbuffer
);
514 This
->dsound
= dsound
;
515 This
->dsbuffer
= dsbuffer
;
518 IDirectSound_AddRef(This
->dsound
);
520 IDirectSound_AddRef(This
->dsbuffer
);
525 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_GetFormat(LPDIRECTMUSICPORT iface
, LPWAVEFORMATEX pWaveFormatEx
, LPDWORD pdwWaveFormatExSize
, LPDWORD pdwBufferSize
)
527 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
529 FIXME("(%p, %p, %p, %p): stub\n", This
, pWaveFormatEx
, pdwWaveFormatExSize
, pdwBufferSize
);
531 if (pWaveFormatEx
== NULL
)
533 if (pdwWaveFormatExSize
)
534 *pdwWaveFormatExSize
= sizeof(format
);
540 if (pdwWaveFormatExSize
== NULL
)
543 /* Just fill this in with something that will not crash Direct Sound for now. */
544 /* It won't be used anyway until Performances are completed */
545 format
.wFormatTag
= WAVE_FORMAT_PCM
;
546 format
.nChannels
= 2; /* This->params.dwAudioChannels; */
547 format
.nSamplesPerSec
= 44100; /* This->params.dwSampleRate; */
548 format
.wBitsPerSample
= 16; /* FIXME: check this */
549 format
.nBlockAlign
= (format
.wBitsPerSample
* format
.nChannels
) / 8;
550 format
.nAvgBytesPerSec
= format
.nSamplesPerSec
* format
.nBlockAlign
;
553 if (*pdwWaveFormatExSize
>= sizeof(format
))
555 CopyMemory(pWaveFormatEx
, &format
, min(sizeof(format
), *pdwWaveFormatExSize
));
556 *pdwWaveFormatExSize
= sizeof(format
); /* FIXME check if this is set */
559 return E_POINTER
; /* FIXME find right error */
563 *pdwBufferSize
= 44100 * 2 * 2;
570 static const IDirectMusicPortVtbl SynthPortImpl_DirectMusicPort_Vtbl
= {
571 /**** IDirectMusicPort IUnknown part methods ***/
572 SynthPortImpl_IDirectMusicPort_QueryInterface
,
573 SynthPortImpl_IDirectMusicPort_AddRef
,
574 SynthPortImpl_IDirectMusicPort_Release
,
575 /**** IDirectMusicPort methods ***/
576 SynthPortImpl_IDirectMusicPort_PlayBuffer
,
577 SynthPortImpl_IDirectMusicPort_SetReadNotificationHandle
,
578 SynthPortImpl_IDirectMusicPort_Read
,
579 SynthPortImpl_IDirectMusicPort_DownloadInstrument
,
580 SynthPortImpl_IDirectMusicPort_UnloadInstrument
,
581 SynthPortImpl_IDirectMusicPort_GetLatencyClock
,
582 SynthPortImpl_IDirectMusicPort_GetRunningStats
,
583 SynthPortImpl_IDirectMusicPort_Compact
,
584 SynthPortImpl_IDirectMusicPort_GetCaps
,
585 SynthPortImpl_IDirectMusicPort_DeviceIoControl
,
586 SynthPortImpl_IDirectMusicPort_SetNumChannelGroups
,
587 SynthPortImpl_IDirectMusicPort_GetNumChannelGroups
,
588 synth_dmport_Activate
,
589 SynthPortImpl_IDirectMusicPort_SetChannelPriority
,
590 SynthPortImpl_IDirectMusicPort_GetChannelPriority
,
591 synth_dmport_SetDirectSound
,
592 SynthPortImpl_IDirectMusicPort_GetFormat
595 /* SynthPortImpl IDirectMusicPortDownload IUnknown part follows: */
596 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPortDownload_QueryInterface(LPDIRECTMUSICPORTDOWNLOAD iface
, REFIID riid
, LPVOID
*ret_iface
)
598 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
600 TRACE("(%p/%p)->(%s, %p)\n", iface
, This
, debugstr_dmguid(riid
), ret_iface
);
602 return IDirectMusicPort_QueryInterface(&This
->IDirectMusicPort_iface
, riid
, ret_iface
);
605 static ULONG WINAPI
SynthPortImpl_IDirectMusicPortDownload_AddRef (LPDIRECTMUSICPORTDOWNLOAD iface
)
607 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
609 TRACE("(%p/%p)->()\n", iface
, This
);
611 return IDirectMusicPort_AddRef(&This
->IDirectMusicPort_iface
);
614 static ULONG WINAPI
SynthPortImpl_IDirectMusicPortDownload_Release(LPDIRECTMUSICPORTDOWNLOAD iface
)
616 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
618 TRACE("(%p/%p)->()\n", iface
, This
);
620 return IDirectMusicPort_Release(&This
->IDirectMusicPort_iface
);
623 /* SynthPortImpl IDirectMusicPortDownload Interface follows: */
624 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPortDownload_GetBuffer(LPDIRECTMUSICPORTDOWNLOAD iface
, DWORD DLId
, IDirectMusicDownload
** IDMDownload
)
626 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
628 FIXME("(%p/%p)->(%u, %p): stub\n", iface
, This
, DLId
, IDMDownload
);
633 return DMUSIC_CreateDirectMusicDownloadImpl(&IID_IDirectMusicDownload
, (LPVOID
*)IDMDownload
, NULL
);
636 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPortDownload_AllocateBuffer(LPDIRECTMUSICPORTDOWNLOAD iface
, DWORD size
, IDirectMusicDownload
** IDMDownload
)
638 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
640 FIXME("(%p/%p)->(%u, %p): stub\n", iface
, This
, size
, IDMDownload
);
645 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPortDownload_GetDLId(LPDIRECTMUSICPORTDOWNLOAD iface
, DWORD
* start_DLId
, DWORD count
)
647 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
649 FIXME("(%p/%p)->(%p, %u): stub\n", iface
, This
, start_DLId
, count
);
654 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPortDownload_GetAppend (LPDIRECTMUSICPORTDOWNLOAD iface
, DWORD
* append
)
656 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
658 FIXME("(%p/%p)->(%p): stub\n", iface
, This
, append
);
663 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPortDownload_Download(LPDIRECTMUSICPORTDOWNLOAD iface
, IDirectMusicDownload
* IDMDownload
)
665 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
667 FIXME("(%p/%p)->(%p): stub\n", iface
, This
, IDMDownload
);
672 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPortDownload_Unload(LPDIRECTMUSICPORTDOWNLOAD iface
, IDirectMusicDownload
* IDMDownload
)
674 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
676 FIXME("(%p/%p)->(%p): stub\n", iface
, This
, IDMDownload
);
681 static const IDirectMusicPortDownloadVtbl SynthPortImpl_DirectMusicPortDownload_Vtbl
= {
682 /*** IDirectMusicPortDownload IUnknown part methods ***/
683 SynthPortImpl_IDirectMusicPortDownload_QueryInterface
,
684 SynthPortImpl_IDirectMusicPortDownload_AddRef
,
685 SynthPortImpl_IDirectMusicPortDownload_Release
,
686 /*** IDirectMusicPortDownload methods ***/
687 SynthPortImpl_IDirectMusicPortDownload_GetBuffer
,
688 SynthPortImpl_IDirectMusicPortDownload_AllocateBuffer
,
689 SynthPortImpl_IDirectMusicPortDownload_GetDLId
,
690 SynthPortImpl_IDirectMusicPortDownload_GetAppend
,
691 SynthPortImpl_IDirectMusicPortDownload_Download
,
692 SynthPortImpl_IDirectMusicPortDownload_Unload
695 /* SynthPortImpl IDirectMusicThru IUnknown part follows: */
696 static HRESULT WINAPI
SynthPortImpl_IDirectMusicThru_QueryInterface(LPDIRECTMUSICTHRU iface
, REFIID riid
, LPVOID
*ret_iface
)
698 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicThru(iface
);
700 TRACE("(%p/%p)->(%s, %p)\n", iface
, This
, debugstr_dmguid(riid
), ret_iface
);
702 return IDirectMusicPort_QueryInterface(&This
->IDirectMusicPort_iface
, riid
, ret_iface
);
705 static ULONG WINAPI
SynthPortImpl_IDirectMusicThru_AddRef(LPDIRECTMUSICTHRU iface
)
707 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicThru(iface
);
709 TRACE("(%p/%p)->()\n", iface
, This
);
711 return IDirectMusicPort_AddRef(&This
->IDirectMusicPort_iface
);
714 static ULONG WINAPI
SynthPortImpl_IDirectMusicThru_Release(LPDIRECTMUSICTHRU iface
)
716 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicThru(iface
);
718 TRACE("(%p/%p)->()\n", iface
, This
);
720 return IDirectMusicPort_Release(&This
->IDirectMusicPort_iface
);
723 /* SynthPortImpl IDirectMusicThru Interface follows: */
724 static HRESULT WINAPI
SynthPortImpl_IDirectMusicThru_ThruChannel(LPDIRECTMUSICTHRU iface
, DWORD source_channel_group
, DWORD source_channel
, DWORD destination_channel_group
,
725 DWORD destination_channel
, LPDIRECTMUSICPORT destination_port
)
727 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicThru(iface
);
729 FIXME("(%p/%p)->(%d, %d, %d, %d, %p): stub\n", iface
, This
, source_channel_group
, source_channel
, destination_channel_group
, destination_channel
, destination_port
);
734 static const IDirectMusicThruVtbl SynthPortImpl_DirectMusicThru_Vtbl
= {
735 /*** IDirectMusicThru IUnknown part methods */
736 SynthPortImpl_IDirectMusicThru_QueryInterface
,
737 SynthPortImpl_IDirectMusicThru_AddRef
,
738 SynthPortImpl_IDirectMusicThru_Release
,
739 /*** IDirectMusicThru methods ***/
740 SynthPortImpl_IDirectMusicThru_ThruChannel
743 static HRESULT WINAPI
IKsControlImpl_QueryInterface(IKsControl
*iface
, REFIID riid
,
746 SynthPortImpl
*This
= impl_from_IKsControl(iface
);
748 return IDirectMusicPort_QueryInterface(&This
->IDirectMusicPort_iface
, riid
, ret_iface
);
751 static ULONG WINAPI
IKsControlImpl_AddRef(IKsControl
*iface
)
753 SynthPortImpl
*This
= impl_from_IKsControl(iface
);
755 return IDirectMusicPort_AddRef(&This
->IDirectMusicPort_iface
);
758 static ULONG WINAPI
IKsControlImpl_Release(IKsControl
*iface
)
760 SynthPortImpl
*This
= impl_from_IKsControl(iface
);
762 return IDirectMusicPort_Release(&This
->IDirectMusicPort_iface
);
765 static HRESULT WINAPI
IKsControlImpl_KsProperty(IKsControl
*iface
, KSPROPERTY
*prop
,
766 ULONG prop_len
, void *data
, ULONG data_len
, ULONG
*ret_len
)
768 TRACE("(%p)->(%p, %u, %p, %u, %p)\n", iface
, prop
, prop_len
, data
, data_len
, ret_len
);
769 TRACE("prop = %s - %u - %u\n", debugstr_guid(&prop
->u
.s
.Set
), prop
->u
.s
.Id
, prop
->u
.s
.Flags
);
771 if (prop
->u
.s
.Flags
!= KSPROPERTY_TYPE_GET
)
773 FIXME("prop flags %u not yet supported\n", prop
->u
.s
.Flags
);
777 if (data_len
< sizeof(DWORD
))
778 return E_NOT_SUFFICIENT_BUFFER
;
780 FIXME("Unknown property %s\n", debugstr_guid(&prop
->u
.s
.Set
));
781 *(DWORD
*)data
= FALSE
;
782 *ret_len
= sizeof(DWORD
);
787 static HRESULT WINAPI
IKsControlImpl_KsMethod(IKsControl
*iface
, KSMETHOD
*method
,
788 ULONG method_len
, void *data
, ULONG data_len
, ULONG
*ret_len
)
790 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface
, method
, method_len
, data
, data_len
, ret_len
);
795 static HRESULT WINAPI
IKsControlImpl_KsEvent(IKsControl
*iface
, KSEVENT
*event
, ULONG event_len
,
796 void *data
, ULONG data_len
, ULONG
*ret_len
)
798 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface
, event
, event_len
, data
, data_len
, ret_len
);
803 static const IKsControlVtbl ikscontrol_vtbl
= {
804 IKsControlImpl_QueryInterface
,
805 IKsControlImpl_AddRef
,
806 IKsControlImpl_Release
,
807 IKsControlImpl_KsProperty
,
808 IKsControlImpl_KsMethod
,
809 IKsControlImpl_KsEvent
812 HRESULT
synth_port_create(IDirectMusic8Impl
*parent
, DMUS_PORTPARAMS
*port_params
,
813 DMUS_PORTCAPS
*port_caps
, IDirectMusicPort
**port
)
819 TRACE("(%p, %p, %p)\n", port_params
, port_caps
, port
);
823 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SynthPortImpl
));
825 return E_OUTOFMEMORY
;
827 obj
->IDirectMusicPort_iface
.lpVtbl
= &SynthPortImpl_DirectMusicPort_Vtbl
;
828 obj
->IDirectMusicPortDownload_iface
.lpVtbl
= &SynthPortImpl_DirectMusicPortDownload_Vtbl
;
829 obj
->IDirectMusicThru_iface
.lpVtbl
= &SynthPortImpl_DirectMusicThru_Vtbl
;
830 obj
->IKsControl_iface
.lpVtbl
= &ikscontrol_vtbl
;
832 obj
->parent
= parent
;
834 obj
->params
= *port_params
;
835 obj
->caps
= *port_caps
;
837 hr
= DMUSIC_CreateReferenceClockImpl(&IID_IReferenceClock
, (LPVOID
*)&obj
->pLatencyClock
, NULL
);
840 HeapFree(GetProcessHeap(), 0, obj
);
845 hr
= CoCreateInstance(&CLSID_DirectMusicSynth
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectMusicSynth
, (void**)&obj
->synth
);
848 hr
= CoCreateInstance(&CLSID_DirectMusicSynthSink
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectMusicSynthSink
, (void**)&obj
->synth_sink
);
851 hr
= IDirectMusicSynth_SetMasterClock(obj
->synth
, obj
->pLatencyClock
);
854 hr
= IDirectMusicSynthSink_SetMasterClock(obj
->synth_sink
, obj
->pLatencyClock
);
857 hr
= IDirectMusicSynth_SetSynthSink(obj
->synth
, obj
->synth_sink
);
860 hr
= IDirectMusicSynth_Open(obj
->synth
, port_params
);
864 if (port_params
->dwValidParams
& DMUS_PORTPARAMS_CHANNELGROUPS
) {
865 obj
->nrofgroups
= port_params
->dwChannelGroups
;
866 /* Setting default priorities */
867 for (i
= 0; i
< obj
->nrofgroups
; i
++) {
868 TRACE ("Setting default channel priorities on channel group %i\n", i
+ 1);
869 obj
->group
[i
].channel
[0].priority
= DAUD_CHAN1_DEF_VOICE_PRIORITY
;
870 obj
->group
[i
].channel
[1].priority
= DAUD_CHAN2_DEF_VOICE_PRIORITY
;
871 obj
->group
[i
].channel
[2].priority
= DAUD_CHAN3_DEF_VOICE_PRIORITY
;
872 obj
->group
[i
].channel
[3].priority
= DAUD_CHAN4_DEF_VOICE_PRIORITY
;
873 obj
->group
[i
].channel
[4].priority
= DAUD_CHAN5_DEF_VOICE_PRIORITY
;
874 obj
->group
[i
].channel
[5].priority
= DAUD_CHAN6_DEF_VOICE_PRIORITY
;
875 obj
->group
[i
].channel
[6].priority
= DAUD_CHAN7_DEF_VOICE_PRIORITY
;
876 obj
->group
[i
].channel
[7].priority
= DAUD_CHAN8_DEF_VOICE_PRIORITY
;
877 obj
->group
[i
].channel
[8].priority
= DAUD_CHAN9_DEF_VOICE_PRIORITY
;
878 obj
->group
[i
].channel
[9].priority
= DAUD_CHAN10_DEF_VOICE_PRIORITY
;
879 obj
->group
[i
].channel
[10].priority
= DAUD_CHAN11_DEF_VOICE_PRIORITY
;
880 obj
->group
[i
].channel
[11].priority
= DAUD_CHAN12_DEF_VOICE_PRIORITY
;
881 obj
->group
[i
].channel
[12].priority
= DAUD_CHAN13_DEF_VOICE_PRIORITY
;
882 obj
->group
[i
].channel
[13].priority
= DAUD_CHAN14_DEF_VOICE_PRIORITY
;
883 obj
->group
[i
].channel
[14].priority
= DAUD_CHAN15_DEF_VOICE_PRIORITY
;
884 obj
->group
[i
].channel
[15].priority
= DAUD_CHAN16_DEF_VOICE_PRIORITY
;
890 *port
= &obj
->IDirectMusicPort_iface
;
895 IDirectMusicSynth_Release(obj
->synth
);
897 IDirectMusicSynthSink_Release(obj
->synth_sink
);
898 if (obj
->pLatencyClock
)
899 IReferenceClock_Release(obj
->pLatencyClock
);
900 HeapFree(GetProcessHeap(), 0, obj
);
905 HRESULT
midi_out_port_create(IDirectMusic8Impl
*parent
, DMUS_PORTPARAMS
*port_params
,
906 DMUS_PORTCAPS
*port_caps
, IDirectMusicPort
**port
)
908 FIXME("(%p, %p, %p): stub\n", port_params
, port_caps
, port
);
913 HRESULT
midi_in_port_create(IDirectMusic8Impl
*parent
, DMUS_PORTPARAMS
*port_params
,
914 DMUS_PORTCAPS
*port_caps
, IDirectMusicPort
**port
)
916 FIXME("(%p, %p, %p): stub\n", port_params
, port_caps
, port
);