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 static inline IDirectMusicDownloadedInstrumentImpl
* impl_from_IDirectMusicDownloadedInstrument(IDirectMusicDownloadedInstrument
*iface
)
28 return CONTAINING_RECORD(iface
, IDirectMusicDownloadedInstrumentImpl
, IDirectMusicDownloadedInstrument_iface
);
31 static inline SynthPortImpl
*impl_from_SynthPortImpl_IDirectMusicPort(IDirectMusicPort
*iface
)
33 return CONTAINING_RECORD(iface
, SynthPortImpl
, IDirectMusicPort_iface
);
36 static inline SynthPortImpl
*impl_from_SynthPortImpl_IDirectMusicPortDownload(IDirectMusicPortDownload
*iface
)
38 return CONTAINING_RECORD(iface
, SynthPortImpl
, IDirectMusicPortDownload_iface
);
41 static inline SynthPortImpl
*impl_from_SynthPortImpl_IDirectMusicThru(IDirectMusicThru
*iface
)
43 return CONTAINING_RECORD(iface
, SynthPortImpl
, IDirectMusicThru_iface
);
46 /* IDirectMusicDownloadedInstrument IUnknown part follows: */
47 static HRESULT WINAPI
IDirectMusicDownloadedInstrumentImpl_QueryInterface(IDirectMusicDownloadedInstrument
*iface
, REFIID riid
, VOID
**ret_iface
)
49 TRACE("(%p, %s, %p)\n", iface
, debugstr_dmguid(riid
), ret_iface
);
51 if (IsEqualIID(riid
, &IID_IUnknown
) ||
52 IsEqualIID(riid
, &IID_IDirectMusicDownloadedInstrument
) ||
53 IsEqualIID(riid
, &IID_IDirectMusicDownloadedInstrument8
))
55 IDirectMusicDownloadedInstrument_AddRef(iface
);
60 WARN("(%p, %s, %p): not found\n", iface
, debugstr_dmguid(riid
), ret_iface
);
65 static ULONG WINAPI
IDirectMusicDownloadedInstrumentImpl_AddRef(LPDIRECTMUSICDOWNLOADEDINSTRUMENT iface
)
67 IDirectMusicDownloadedInstrumentImpl
*This
= impl_from_IDirectMusicDownloadedInstrument(iface
);
68 ULONG ref
= InterlockedIncrement(&This
->ref
);
70 TRACE("(%p)->(): new ref = %u\n", iface
, ref
);
77 static ULONG WINAPI
IDirectMusicDownloadedInstrumentImpl_Release(LPDIRECTMUSICDOWNLOADEDINSTRUMENT iface
)
79 IDirectMusicDownloadedInstrumentImpl
*This
= impl_from_IDirectMusicDownloadedInstrument(iface
);
80 ULONG ref
= InterlockedDecrement(&This
->ref
);
82 TRACE("(%p)->(): new ref = %u\n", iface
, ref
);
86 HeapFree(GetProcessHeap(), 0, This
->data
);
87 HeapFree(GetProcessHeap(), 0, This
);
90 DMUSIC_UnlockModule();
95 static const IDirectMusicDownloadedInstrumentVtbl DirectMusicDownloadedInstrument_Vtbl
= {
96 IDirectMusicDownloadedInstrumentImpl_QueryInterface
,
97 IDirectMusicDownloadedInstrumentImpl_AddRef
,
98 IDirectMusicDownloadedInstrumentImpl_Release
101 static inline IDirectMusicDownloadedInstrumentImpl
* unsafe_impl_from_IDirectMusicDownloadedInstrument(IDirectMusicDownloadedInstrument
*iface
)
105 assert(iface
->lpVtbl
== &DirectMusicDownloadedInstrument_Vtbl
);
107 return impl_from_IDirectMusicDownloadedInstrument(iface
);
110 static HRESULT
DMUSIC_CreateDirectMusicDownloadedInstrumentImpl(IDirectMusicDownloadedInstrument
**instrument
)
112 IDirectMusicDownloadedInstrumentImpl
*object
;
114 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
118 return E_OUTOFMEMORY
;
121 object
->IDirectMusicDownloadedInstrument_iface
.lpVtbl
= &DirectMusicDownloadedInstrument_Vtbl
;
124 *instrument
= &object
->IDirectMusicDownloadedInstrument_iface
;
129 /* SynthPortImpl IDirectMusicPort IUnknown part follows: */
130 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_QueryInterface(LPDIRECTMUSICPORT iface
, REFIID riid
, LPVOID
*ret_iface
)
132 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
134 TRACE("(%p/%p)->(%s, %p)\n", iface
, This
, debugstr_dmguid(riid
), ret_iface
);
136 if (IsEqualIID (riid
, &IID_IUnknown
) ||
137 IsEqualGUID(riid
, &IID_IDirectMusicPort
) ||
138 IsEqualGUID(riid
, &IID_IDirectMusicPort8
)) {
139 *ret_iface
= &This
->IDirectMusicPort_iface
;
140 IDirectMusicPort_AddRef((LPDIRECTMUSICPORT
)*ret_iface
);
142 } else if (IsEqualGUID(riid
, &IID_IDirectMusicPortDownload
) ||
143 IsEqualGUID(riid
, &IID_IDirectMusicPortDownload8
)) {
144 *ret_iface
= &This
->IDirectMusicPortDownload_iface
;
145 IDirectMusicPortDownload_AddRef((LPDIRECTMUSICPORTDOWNLOAD
)*ret_iface
);
147 } else if (IsEqualGUID(riid
, &IID_IDirectMusicThru
) ||
148 IsEqualGUID(riid
, &IID_IDirectMusicThru8
)) {
149 *ret_iface
= &This
->IDirectMusicThru_iface
;
150 IDirectMusicThru_AddRef((LPDIRECTMUSICTHRU
)*ret_iface
);
154 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ret_iface
);
156 return E_NOINTERFACE
;
159 static ULONG WINAPI
SynthPortImpl_IDirectMusicPort_AddRef(LPDIRECTMUSICPORT iface
)
161 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
162 ULONG ref
= InterlockedIncrement(&This
->ref
);
164 TRACE("(%p)->(): new ref = %u\n", This
, ref
);
171 static ULONG WINAPI
SynthPortImpl_IDirectMusicPort_Release(LPDIRECTMUSICPORT iface
)
173 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
174 ULONG ref
= InterlockedDecrement(&This
->ref
);
176 TRACE("(%p)->(): new ref = %u\n", This
, ref
);
180 IDirectMusicSynth_Activate(This
->synth
, FALSE
);
181 IDirectMusicSynth_Close(This
->synth
);
182 IDirectMusicSynth_Release(This
->synth
);
183 IDirectMusicSynthSink_Release(This
->synth_sink
);
184 IReferenceClock_Release(This
->pLatencyClock
);
185 HeapFree(GetProcessHeap(), 0, This
);
188 DMUSIC_UnlockModule();
193 /* SynthPortImpl IDirectMusicPort interface follows: */
194 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_PlayBuffer(LPDIRECTMUSICPORT iface
, LPDIRECTMUSICBUFFER buffer
)
196 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
202 TRACE("(%p/%p)->(%p)\n", iface
, This
, buffer
);
207 hr
= IDirectMusicBuffer_GetStartTime(buffer
, &time
);
210 hr
= IDirectMusicBuffer_GetRawBufferPtr(buffer
, &data
);
213 hr
= IDirectMusicBuffer_GetUsedBytes(buffer
, &size
);
216 hr
= IDirectMusicSynth_PlayBuffer(This
->synth
, time
, data
, size
);
221 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_SetReadNotificationHandle(LPDIRECTMUSICPORT iface
, HANDLE event
)
223 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
225 FIXME("(%p/%p)->(%p): stub\n", iface
, This
, event
);
230 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_Read(LPDIRECTMUSICPORT iface
, LPDIRECTMUSICBUFFER buffer
)
232 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
234 FIXME("(%p/%p)->(%p): stub\n", iface
, This
, buffer
);
239 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_DownloadInstrument(LPDIRECTMUSICPORT iface
, IDirectMusicInstrument
* instrument
, IDirectMusicDownloadedInstrument
** downloaded_instrument
, DMUS_NOTERANGE
* note_ranges
, DWORD num_note_ranges
)
241 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
242 IDirectMusicInstrumentImpl
*instrument_object
;
246 DMUS_DOWNLOADINFO
*info
;
247 DMUS_OFFSETTABLE
*offset_table
;
248 DMUS_INSTRUMENT
*instrument_info
;
255 TRACE("(%p/%p)->(%p, %p, %p, %d)\n", iface
, This
, instrument
, downloaded_instrument
, note_ranges
, num_note_ranges
);
257 if (!instrument
|| !downloaded_instrument
|| (num_note_ranges
&& !note_ranges
))
260 instrument_object
= impl_from_IDirectMusicInstrument(instrument
);
262 nb_regions
= instrument_object
->header
.cRegions
;
263 size
= sizeof(DMUS_DOWNLOADINFO
) + sizeof(ULONG
) * (1 + nb_regions
) + sizeof(DMUS_INSTRUMENT
) + sizeof(DMUS_REGION
) * nb_regions
;
265 data
= HeapAlloc(GetProcessHeap(), 0, size
);
267 return E_OUTOFMEMORY
;
269 info
= (DMUS_DOWNLOADINFO
*)data
;
270 offset_table
= (DMUS_OFFSETTABLE
*)(data
+ sizeof(DMUS_DOWNLOADINFO
));
271 offset
= sizeof(DMUS_DOWNLOADINFO
) + sizeof(ULONG
) * (1 + nb_regions
);
273 info
->dwDLType
= DMUS_DOWNLOADINFO_INSTRUMENT2
;
275 info
->dwNumOffsetTableEntries
= 1 + instrument_object
->header
.cRegions
;
278 offset_table
->ulOffsetTable
[0] = offset
;
279 instrument_info
= (DMUS_INSTRUMENT
*)(data
+ offset
);
280 offset
+= sizeof(DMUS_INSTRUMENT
);
281 instrument_info
->ulPatch
= MIDILOCALE2Patch(&instrument_object
->header
.Locale
);
282 instrument_info
->ulFirstRegionIdx
= 1;
283 instrument_info
->ulGlobalArtIdx
= 0; /* FIXME */
284 instrument_info
->ulFirstExtCkIdx
= 0; /* FIXME */
285 instrument_info
->ulCopyrightIdx
= 0; /* FIXME */
286 instrument_info
->ulFlags
= 0; /* FIXME */
288 for (i
= 0; i
< nb_regions
; i
++)
290 DMUS_REGION
*region
= (DMUS_REGION
*)(data
+ offset
);
292 offset_table
->ulOffsetTable
[1 + i
] = offset
;
293 offset
+= sizeof(DMUS_REGION
);
294 region
->RangeKey
= instrument_object
->regions
[i
].header
.RangeKey
;
295 region
->RangeVelocity
= instrument_object
->regions
[i
].header
.RangeVelocity
;
296 region
->fusOptions
= instrument_object
->regions
[i
].header
.fusOptions
;
297 region
->usKeyGroup
= instrument_object
->regions
[i
].header
.usKeyGroup
;
298 region
->ulRegionArtIdx
= 0; /* FIXME */
299 region
->ulNextRegionIdx
= i
!= (nb_regions
- 1) ? (i
+ 2) : 0;
300 region
->ulFirstExtCkIdx
= 0; /* FIXME */
301 region
->WaveLink
= instrument_object
->regions
[i
].wave_link
;
302 region
->WSMP
= instrument_object
->regions
[i
].wave_sample
;
303 region
->WLOOP
[0] = instrument_object
->regions
[i
].wave_loop
;
306 ret
= IDirectMusicSynth8_Download(This
->synth
, &download
, (VOID
*)data
, &free
);
309 ret
= DMUSIC_CreateDirectMusicDownloadedInstrumentImpl(downloaded_instrument
);
313 IDirectMusicDownloadedInstrumentImpl
*downloaded_object
= impl_from_IDirectMusicDownloadedInstrument(*downloaded_instrument
);
315 downloaded_object
->data
= data
;
316 downloaded_object
->downloaded
= TRUE
;
319 *downloaded_instrument
= NULL
;
320 HeapFree(GetProcessHeap(), 0, data
);
325 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_UnloadInstrument(LPDIRECTMUSICPORT iface
, IDirectMusicDownloadedInstrument
*downloaded_instrument
)
327 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
328 IDirectMusicDownloadedInstrumentImpl
*downloaded_object
= unsafe_impl_from_IDirectMusicDownloadedInstrument(downloaded_instrument
);
330 TRACE("(%p/%p)->(%p)\n", iface
, This
, downloaded_instrument
);
332 if (!downloaded_instrument
)
335 if (!downloaded_object
->downloaded
)
336 return DMUS_E_NOT_DOWNLOADED_TO_PORT
;
338 HeapFree(GetProcessHeap(), 0, downloaded_object
->data
);
339 downloaded_object
->data
= NULL
;
340 downloaded_object
->downloaded
= FALSE
;
345 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_GetLatencyClock(LPDIRECTMUSICPORT iface
, IReferenceClock
** clock
)
347 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
349 TRACE("(%p/%p)->(%p)\n", iface
, This
, clock
);
351 *clock
= This
->pLatencyClock
;
352 IReferenceClock_AddRef(*clock
);
357 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_GetRunningStats(LPDIRECTMUSICPORT iface
, LPDMUS_SYNTHSTATS stats
)
359 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
361 FIXME("(%p/%p)->(%p): stub\n", iface
, This
, stats
);
366 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_Compact(LPDIRECTMUSICPORT iface
)
368 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
370 FIXME("(%p/%p)->(): stub\n", iface
, This
);
375 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_GetCaps(LPDIRECTMUSICPORT iface
, LPDMUS_PORTCAPS port_caps
)
377 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
379 TRACE("(%p/%p)->(%p)\n", iface
, This
, port_caps
);
381 *port_caps
= This
->caps
;
386 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_DeviceIoControl(LPDIRECTMUSICPORT iface
, DWORD io_control_code
, LPVOID in_buffer
, DWORD in_buffer_size
,
387 LPVOID out_buffer
, DWORD out_buffer_size
, LPDWORD bytes_returned
, LPOVERLAPPED overlapped
)
389 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
391 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
);
396 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_SetNumChannelGroups(LPDIRECTMUSICPORT iface
, DWORD channel_groups
)
398 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
400 FIXME("(%p/%p)->(%d): semi-stub\n", iface
, This
, channel_groups
);
402 This
->nrofgroups
= channel_groups
;
407 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_GetNumChannelGroups(LPDIRECTMUSICPORT iface
, LPDWORD channel_groups
)
409 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
411 TRACE("(%p/%p)->(%p)\n", iface
, This
, channel_groups
);
413 *channel_groups
= This
->nrofgroups
;
418 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_Activate(LPDIRECTMUSICPORT iface
, BOOL active
)
420 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
422 TRACE("(%p/%p)->(%d)\n", iface
, This
, active
);
424 This
->fActive
= active
;
429 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_SetChannelPriority(LPDIRECTMUSICPORT iface
, DWORD channel_group
, DWORD channel
, DWORD priority
)
431 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
433 FIXME("(%p/%p)->(%d, %d, %d): semi-stub\n", iface
, This
, channel_group
, channel
, priority
);
437 WARN("isn't there supposed to be 16 channels (no. %d requested)?! (faking as it is ok)\n", channel
);
438 /*return E_INVALIDARG;*/
444 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_GetChannelPriority(LPDIRECTMUSICPORT iface
, DWORD channel_group
, DWORD channel
, LPDWORD priority
)
446 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
448 TRACE("(%p/%p)->(%u, %u, %p)\n", iface
, This
, channel_group
, channel
, priority
);
450 *priority
= This
->group
[channel_group
- 1].channel
[channel
].priority
;
455 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_SetDirectSound(LPDIRECTMUSICPORT iface
, LPDIRECTSOUND direct_sound
, LPDIRECTSOUNDBUFFER direct_sound_buffer
)
457 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
459 FIXME("(%p/%p)->(%p, %p): stub\n", iface
, This
, direct_sound
, direct_sound_buffer
);
464 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPort_GetFormat(LPDIRECTMUSICPORT iface
, LPWAVEFORMATEX pWaveFormatEx
, LPDWORD pdwWaveFormatExSize
, LPDWORD pdwBufferSize
)
466 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPort(iface
);
468 FIXME("(%p, %p, %p, %p): stub\n", This
, pWaveFormatEx
, pdwWaveFormatExSize
, pdwBufferSize
);
470 if (pWaveFormatEx
== NULL
)
472 if (pdwWaveFormatExSize
)
473 *pdwWaveFormatExSize
= sizeof(format
);
479 if (pdwWaveFormatExSize
== NULL
)
482 /* Just fill this in with something that will not crash Direct Sound for now. */
483 /* It won't be used anyway until Performances are completed */
484 format
.wFormatTag
= WAVE_FORMAT_PCM
;
485 format
.nChannels
= 2; /* This->params.dwAudioChannels; */
486 format
.nSamplesPerSec
= 44100; /* This->params.dwSampleRate; */
487 format
.wBitsPerSample
= 16; /* FIXME: check this */
488 format
.nBlockAlign
= (format
.wBitsPerSample
* format
.nChannels
) / 8;
489 format
.nAvgBytesPerSec
= format
.nSamplesPerSec
* format
.nBlockAlign
;
492 if (*pdwWaveFormatExSize
>= sizeof(format
))
494 CopyMemory(pWaveFormatEx
, &format
, min(sizeof(format
), *pdwWaveFormatExSize
));
495 *pdwWaveFormatExSize
= sizeof(format
); /* FIXME check if this is set */
498 return E_POINTER
; /* FIXME find right error */
502 *pdwBufferSize
= 44100 * 2 * 2;
509 static const IDirectMusicPortVtbl SynthPortImpl_DirectMusicPort_Vtbl
= {
510 /**** IDirectMusicPort IUnknown part methods ***/
511 SynthPortImpl_IDirectMusicPort_QueryInterface
,
512 SynthPortImpl_IDirectMusicPort_AddRef
,
513 SynthPortImpl_IDirectMusicPort_Release
,
514 /**** IDirectMusicPort methods ***/
515 SynthPortImpl_IDirectMusicPort_PlayBuffer
,
516 SynthPortImpl_IDirectMusicPort_SetReadNotificationHandle
,
517 SynthPortImpl_IDirectMusicPort_Read
,
518 SynthPortImpl_IDirectMusicPort_DownloadInstrument
,
519 SynthPortImpl_IDirectMusicPort_UnloadInstrument
,
520 SynthPortImpl_IDirectMusicPort_GetLatencyClock
,
521 SynthPortImpl_IDirectMusicPort_GetRunningStats
,
522 SynthPortImpl_IDirectMusicPort_Compact
,
523 SynthPortImpl_IDirectMusicPort_GetCaps
,
524 SynthPortImpl_IDirectMusicPort_DeviceIoControl
,
525 SynthPortImpl_IDirectMusicPort_SetNumChannelGroups
,
526 SynthPortImpl_IDirectMusicPort_GetNumChannelGroups
,
527 SynthPortImpl_IDirectMusicPort_Activate
,
528 SynthPortImpl_IDirectMusicPort_SetChannelPriority
,
529 SynthPortImpl_IDirectMusicPort_GetChannelPriority
,
530 SynthPortImpl_IDirectMusicPort_SetDirectSound
,
531 SynthPortImpl_IDirectMusicPort_GetFormat
534 /* SynthPortImpl IDirectMusicPortDownload IUnknown part follows: */
535 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPortDownload_QueryInterface(LPDIRECTMUSICPORTDOWNLOAD iface
, REFIID riid
, LPVOID
*ret_iface
)
537 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
539 TRACE("(%p/%p)->(%s, %p)\n", iface
, This
, debugstr_dmguid(riid
), ret_iface
);
541 return IDirectMusicPort_QueryInterface(&This
->IDirectMusicPort_iface
, riid
, ret_iface
);
544 static ULONG WINAPI
SynthPortImpl_IDirectMusicPortDownload_AddRef (LPDIRECTMUSICPORTDOWNLOAD iface
)
546 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
548 TRACE("(%p/%p)->()\n", iface
, This
);
550 return IDirectMusicPort_AddRef(&This
->IDirectMusicPort_iface
);
553 static ULONG WINAPI
SynthPortImpl_IDirectMusicPortDownload_Release(LPDIRECTMUSICPORTDOWNLOAD iface
)
555 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
557 TRACE("(%p/%p)->()\n", iface
, This
);
559 return IDirectMusicPort_Release(&This
->IDirectMusicPort_iface
);
562 /* SynthPortImpl IDirectMusicPortDownload Interface follows: */
563 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPortDownload_GetBuffer(LPDIRECTMUSICPORTDOWNLOAD iface
, DWORD DLId
, IDirectMusicDownload
** IDMDownload
)
565 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
567 FIXME("(%p/%p)->(%u, %p): stub\n", iface
, This
, DLId
, IDMDownload
);
572 return DMUSIC_CreateDirectMusicDownloadImpl(&IID_IDirectMusicDownload
, (LPVOID
*)IDMDownload
, NULL
);
575 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPortDownload_AllocateBuffer(LPDIRECTMUSICPORTDOWNLOAD iface
, DWORD size
, IDirectMusicDownload
** IDMDownload
)
577 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
579 FIXME("(%p/%p)->(%u, %p): stub\n", iface
, This
, size
, IDMDownload
);
584 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPortDownload_GetDLId(LPDIRECTMUSICPORTDOWNLOAD iface
, DWORD
* start_DLId
, DWORD count
)
586 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
588 FIXME("(%p/%p)->(%p, %u): stub\n", iface
, This
, start_DLId
, count
);
593 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPortDownload_GetAppend (LPDIRECTMUSICPORTDOWNLOAD iface
, DWORD
* append
)
595 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
597 FIXME("(%p/%p)->(%p): stub\n", iface
, This
, append
);
602 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPortDownload_Download(LPDIRECTMUSICPORTDOWNLOAD iface
, IDirectMusicDownload
* IDMDownload
)
604 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
606 FIXME("(%p/%p)->(%p): stub\n", iface
, This
, IDMDownload
);
611 static HRESULT WINAPI
SynthPortImpl_IDirectMusicPortDownload_Unload(LPDIRECTMUSICPORTDOWNLOAD iface
, IDirectMusicDownload
* IDMDownload
)
613 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicPortDownload(iface
);
615 FIXME("(%p/%p)->(%p): stub\n", iface
, This
, IDMDownload
);
620 static const IDirectMusicPortDownloadVtbl SynthPortImpl_DirectMusicPortDownload_Vtbl
= {
621 /*** IDirectMusicPortDownload IUnknown part methods ***/
622 SynthPortImpl_IDirectMusicPortDownload_QueryInterface
,
623 SynthPortImpl_IDirectMusicPortDownload_AddRef
,
624 SynthPortImpl_IDirectMusicPortDownload_Release
,
625 /*** IDirectMusicPortDownload methods ***/
626 SynthPortImpl_IDirectMusicPortDownload_GetBuffer
,
627 SynthPortImpl_IDirectMusicPortDownload_AllocateBuffer
,
628 SynthPortImpl_IDirectMusicPortDownload_GetDLId
,
629 SynthPortImpl_IDirectMusicPortDownload_GetAppend
,
630 SynthPortImpl_IDirectMusicPortDownload_Download
,
631 SynthPortImpl_IDirectMusicPortDownload_Unload
634 /* SynthPortImpl IDirectMusicThru IUnknown part follows: */
635 static HRESULT WINAPI
SynthPortImpl_IDirectMusicThru_QueryInterface(LPDIRECTMUSICTHRU iface
, REFIID riid
, LPVOID
*ret_iface
)
637 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicThru(iface
);
639 TRACE("(%p/%p)->(%s, %p)\n", iface
, This
, debugstr_dmguid(riid
), ret_iface
);
641 return IDirectMusicPort_QueryInterface(&This
->IDirectMusicPort_iface
, riid
, ret_iface
);
644 static ULONG WINAPI
SynthPortImpl_IDirectMusicThru_AddRef(LPDIRECTMUSICTHRU iface
)
646 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicThru(iface
);
648 TRACE("(%p/%p)->()\n", iface
, This
);
650 return IDirectMusicPort_AddRef(&This
->IDirectMusicPort_iface
);
653 static ULONG WINAPI
SynthPortImpl_IDirectMusicThru_Release(LPDIRECTMUSICTHRU iface
)
655 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicThru(iface
);
657 TRACE("(%p/%p)->()\n", iface
, This
);
659 return IDirectMusicPort_Release(&This
->IDirectMusicPort_iface
);
662 /* SynthPortImpl IDirectMusicThru Interface follows: */
663 static HRESULT WINAPI
SynthPortImpl_IDirectMusicThru_ThruChannel(LPDIRECTMUSICTHRU iface
, DWORD source_channel_group
, DWORD source_channel
, DWORD destination_channel_group
,
664 DWORD destination_channel
, LPDIRECTMUSICPORT destination_port
)
666 SynthPortImpl
*This
= impl_from_SynthPortImpl_IDirectMusicThru(iface
);
668 FIXME("(%p/%p)->(%d, %d, %d, %d, %p): stub\n", iface
, This
, source_channel_group
, source_channel
, destination_channel_group
, destination_channel
, destination_port
);
673 static const IDirectMusicThruVtbl SynthPortImpl_DirectMusicThru_Vtbl
= {
674 /*** IDirectMusicThru IUnknown part methods */
675 SynthPortImpl_IDirectMusicThru_QueryInterface
,
676 SynthPortImpl_IDirectMusicThru_AddRef
,
677 SynthPortImpl_IDirectMusicThru_Release
,
678 /*** IDirectMusicThru methods ***/
679 SynthPortImpl_IDirectMusicThru_ThruChannel
682 HRESULT
DMUSIC_CreateSynthPortImpl(LPCGUID guid
, LPVOID
*object
, LPUNKNOWN unkouter
, LPDMUS_PORTPARAMS port_params
, LPDMUS_PORTCAPS port_caps
, DWORD device
)
688 TRACE("(%p,%p,%p,%p,%p%d)\n", guid
, object
, unkouter
, port_params
, port_caps
, device
);
692 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SynthPortImpl
));
694 return E_OUTOFMEMORY
;
696 obj
->IDirectMusicPort_iface
.lpVtbl
= &SynthPortImpl_DirectMusicPort_Vtbl
;
697 obj
->IDirectMusicPortDownload_iface
.lpVtbl
= &SynthPortImpl_DirectMusicPortDownload_Vtbl
;
698 obj
->IDirectMusicThru_iface
.lpVtbl
= &SynthPortImpl_DirectMusicThru_Vtbl
;
699 obj
->ref
= 0; /* Will be inited by QueryInterface */
700 obj
->fActive
= FALSE
;
701 obj
->params
= *port_params
;
702 obj
->caps
= *port_caps
;
704 hr
= DMUSIC_CreateReferenceClockImpl(&IID_IReferenceClock
, (LPVOID
*)&obj
->pLatencyClock
, NULL
);
707 HeapFree(GetProcessHeap(), 0, obj
);
712 hr
= CoCreateInstance(&CLSID_DirectMusicSynth
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectMusicSynth
, (void**)&obj
->synth
);
715 hr
= CoCreateInstance(&CLSID_DirectMusicSynthSink
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectMusicSynthSink
, (void**)&obj
->synth_sink
);
718 hr
= IDirectMusicSynth_SetMasterClock(obj
->synth
, obj
->pLatencyClock
);
721 hr
= IDirectMusicSynthSink_SetMasterClock(obj
->synth_sink
, obj
->pLatencyClock
);
724 hr
= IDirectMusicSynth_SetSynthSink(obj
->synth
, obj
->synth_sink
);
727 hr
= IDirectMusicSynth_Open(obj
->synth
, port_params
);
731 if (port_params
->dwValidParams
& DMUS_PORTPARAMS_CHANNELGROUPS
) {
732 obj
->nrofgroups
= port_params
->dwChannelGroups
;
733 /* Setting default priorities */
734 for (i
= 0; i
< obj
->nrofgroups
; i
++) {
735 TRACE ("Setting default channel priorities on channel group %i\n", i
+ 1);
736 obj
->group
[i
].channel
[0].priority
= DAUD_CHAN1_DEF_VOICE_PRIORITY
;
737 obj
->group
[i
].channel
[1].priority
= DAUD_CHAN2_DEF_VOICE_PRIORITY
;
738 obj
->group
[i
].channel
[2].priority
= DAUD_CHAN3_DEF_VOICE_PRIORITY
;
739 obj
->group
[i
].channel
[3].priority
= DAUD_CHAN4_DEF_VOICE_PRIORITY
;
740 obj
->group
[i
].channel
[4].priority
= DAUD_CHAN5_DEF_VOICE_PRIORITY
;
741 obj
->group
[i
].channel
[5].priority
= DAUD_CHAN6_DEF_VOICE_PRIORITY
;
742 obj
->group
[i
].channel
[6].priority
= DAUD_CHAN7_DEF_VOICE_PRIORITY
;
743 obj
->group
[i
].channel
[7].priority
= DAUD_CHAN8_DEF_VOICE_PRIORITY
;
744 obj
->group
[i
].channel
[8].priority
= DAUD_CHAN9_DEF_VOICE_PRIORITY
;
745 obj
->group
[i
].channel
[9].priority
= DAUD_CHAN10_DEF_VOICE_PRIORITY
;
746 obj
->group
[i
].channel
[10].priority
= DAUD_CHAN11_DEF_VOICE_PRIORITY
;
747 obj
->group
[i
].channel
[11].priority
= DAUD_CHAN12_DEF_VOICE_PRIORITY
;
748 obj
->group
[i
].channel
[12].priority
= DAUD_CHAN13_DEF_VOICE_PRIORITY
;
749 obj
->group
[i
].channel
[13].priority
= DAUD_CHAN14_DEF_VOICE_PRIORITY
;
750 obj
->group
[i
].channel
[14].priority
= DAUD_CHAN15_DEF_VOICE_PRIORITY
;
751 obj
->group
[i
].channel
[15].priority
= DAUD_CHAN16_DEF_VOICE_PRIORITY
;
757 return IDirectMusicPort_QueryInterface((LPDIRECTMUSICPORT
)obj
, guid
, object
);
760 IDirectMusicSynth_Release(obj
->synth
);
762 IDirectMusicSynthSink_Release(obj
->synth_sink
);
763 if (obj
->pLatencyClock
)
764 IReferenceClock_Release(obj
->pLatencyClock
);
765 HeapFree(GetProcessHeap(), 0, obj
);
770 HRESULT
DMUSIC_CreateMidiOutPortImpl(LPCGUID guid
, LPVOID
*object
, LPUNKNOWN unkouter
, LPDMUS_PORTPARAMS port_params
, LPDMUS_PORTCAPS port_caps
, DWORD device
)
772 TRACE("(%p,%p,%p,%p,%p,%d): stub\n", guid
, object
, unkouter
, port_params
, port_caps
, device
);
777 HRESULT
DMUSIC_CreateMidiInPortImpl(LPCGUID guid
, LPVOID
*object
, LPUNKNOWN unkouter
, LPDMUS_PORTPARAMS port_params
, LPDMUS_PORTCAPS port_caps
, DWORD device
)
779 TRACE("(%p,%p,%p,%p,%p,%d): stub\n", guid
, object
, unkouter
, port_params
, port_caps
, device
);