2 * IDirectMusicSynth8 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
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
30 #include "dmsynth_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(dmsynth);
34 static inline IDirectMusicSynth8Impl *impl_from_IDirectMusicSynth8(IDirectMusicSynth8 *iface)
36 return CONTAINING_RECORD(iface, IDirectMusicSynth8Impl, IDirectMusicSynth8_iface);
39 /* IDirectMusicSynth8Impl IUnknown part: */
40 static HRESULT WINAPI IDirectMusicSynth8Impl_QueryInterface(LPDIRECTMUSICSYNTH8 iface, REFIID riid, LPVOID *ret_iface)
42 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
44 TRACE("(%p)->(%s, %p)\n", iface, debugstr_dmguid(riid), ret_iface);
46 if (IsEqualIID (riid, &IID_IUnknown) ||
47 IsEqualIID (riid, &IID_IDirectMusicSynth) ||
48 IsEqualIID (riid, &IID_IDirectMusicSynth8))
50 IUnknown_AddRef(iface);
54 else if (IsEqualIID(riid, &IID_IKsControl))
56 IUnknown_AddRef(iface);
57 *ret_iface = &This->IKsControl_iface;
63 WARN("(%p)->(%s, %p): not found\n", iface, debugstr_dmguid(riid), ret_iface);
68 static ULONG WINAPI IDirectMusicSynth8Impl_AddRef(LPDIRECTMUSICSYNTH8 iface)
70 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
71 ULONG ref = InterlockedIncrement(&This->ref);
73 TRACE("(%p)->(): new ref = %u\n", This, ref);
80 static ULONG WINAPI IDirectMusicSynth8Impl_Release(LPDIRECTMUSICSYNTH8 iface)
82 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
83 ULONG ref = InterlockedDecrement(&This->ref);
85 TRACE("(%p)->(): new ref = %u\n", This, ref);
88 if (This->pLatencyClock)
89 IReferenceClock_Release(This->pLatencyClock);
90 HeapFree(GetProcessHeap(), 0, This);
93 DMSYNTH_UnlockModule();
98 /* IDirectMusicSynth8Impl IDirectMusicSynth part: */
99 static HRESULT WINAPI IDirectMusicSynth8Impl_Open(LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTPARAMS pPortParams)
101 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
103 FIXME("(%p)->(%p): stub\n", This, pPortParams);
108 static HRESULT WINAPI IDirectMusicSynth8Impl_Close(LPDIRECTMUSICSYNTH8 iface)
110 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
112 FIXME("(%p)->(): stub\n", This);
117 static HRESULT WINAPI IDirectMusicSynth8Impl_SetNumChannelGroups(LPDIRECTMUSICSYNTH8 iface, DWORD groups)
119 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
121 FIXME("(%p->(%d): stub\n", This, groups);
126 static HRESULT WINAPI IDirectMusicSynth8Impl_Download(LPDIRECTMUSICSYNTH8 iface, LPHANDLE hDownload, LPVOID data, LPBOOL free)
128 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
129 DMUS_DOWNLOADINFO* info = (DMUS_DOWNLOADINFO*)data;
131 FIXME("(%p)->(%p, %p, %p): stub\n", This, hDownload, data, free);
133 if (!hDownload || !data || !free)
136 if (TRACE_ON(dmsynth))
138 TRACE("Dump DMUS_DOWNLOADINFO struct:\n");
139 TRACE(" - dwDLType = %u\n", info->dwDLType);
140 TRACE(" - dwDLId = %u\n", info->dwDLId);
141 TRACE(" - dwNumOffsetTableEntries = %u\n", info->dwNumOffsetTableEntries);
142 TRACE(" - cbSize = %u\n", info->cbSize);
145 if (info->dwDLType == DMUS_DOWNLOADINFO_INSTRUMENT)
147 FIXME("Download type DMUS_DOWNLOADINFO_INSTRUMENT not yet supported\n");
149 else if (info->dwDLType == DMUS_DOWNLOADINFO_WAVE)
151 FIXME("Download type DMUS_DOWNLOADINFO_WAVE not yet supported\n");
153 else if (info->dwDLType == DMUS_DOWNLOADINFO_INSTRUMENT2)
155 FIXME("Download type DMUS_DOWNLOADINFO_INSTRUMENT2 not yet supported\n");
157 else if (info->dwDLType == DMUS_DOWNLOADINFO_WAVEARTICULATION)
159 FIXME("Download type DMUS_DOWNLOADINFO_WAVEARTICULATION not yet supported\n");
161 else if (info->dwDLType == DMUS_DOWNLOADINFO_STREAMINGWAVE)
163 FIXME("Download type DMUS_DOWNLOADINFO_STREAMINGWAVE not yet supported\n");
165 else if (info->dwDLType == DMUS_DOWNLOADINFO_ONESHOTWAVE)
167 FIXME("Download type DMUS_DOWNLOADINFO_ONESHOTWAVE not yet supported\n");
171 WARN("Unknown download type %u\n", info->dwDLType);
172 return DMUS_E_UNKNOWNDOWNLOAD;
178 static HRESULT WINAPI IDirectMusicSynth8Impl_Unload(LPDIRECTMUSICSYNTH8 iface, HANDLE hDownload, HRESULT (CALLBACK* lpFreeHandle)(HANDLE,HANDLE), HANDLE hUserData)
180 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
182 FIXME("(%p)->(%p, %p, %p): stub\n", This, hDownload, lpFreeHandle, hUserData);
187 static HRESULT WINAPI IDirectMusicSynth8Impl_PlayBuffer(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME rt, LPBYTE buffer, DWORD size)
189 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
191 FIXME("(%p)->(0x%s, %p, %u): stub\n", This, wine_dbgstr_longlong(rt), buffer, size);
196 static HRESULT WINAPI IDirectMusicSynth8Impl_GetRunningStats(LPDIRECTMUSICSYNTH8 iface, LPDMUS_SYNTHSTATS stats)
198 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
200 FIXME("(%p)->(%p): stub\n", This, stats);
205 static HRESULT WINAPI IDirectMusicSynth8Impl_GetPortCaps(LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTCAPS caps)
207 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
209 TRACE("(%p)->(%p)\n", This, caps);
216 static HRESULT WINAPI IDirectMusicSynth8Impl_SetMasterClock(LPDIRECTMUSICSYNTH8 iface, IReferenceClock* clock)
218 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
220 FIXME("(%p)->(%p): stub\n", This, clock);
225 static HRESULT WINAPI IDirectMusicSynth8Impl_GetLatencyClock(LPDIRECTMUSICSYNTH8 iface, IReferenceClock** clock)
227 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
229 TRACE("(%p)->(%p)\n", iface, clock);
234 if (!This->pSynthSink)
235 return DMUS_E_NOSYNTHSINK;
237 *clock = This->pLatencyClock;
238 IReferenceClock_AddRef(This->pLatencyClock);
243 static HRESULT WINAPI IDirectMusicSynth8Impl_Activate(LPDIRECTMUSICSYNTH8 iface, BOOL enable)
245 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
247 TRACE("(%p)->(%d)\n", This, enable);
249 This->fActive = enable;
254 static HRESULT WINAPI IDirectMusicSynth8Impl_SetSynthSink(LPDIRECTMUSICSYNTH8 iface, IDirectMusicSynthSink* synth_sink)
256 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
258 TRACE("(%p)->(%p)\n", iface, synth_sink);
260 This->pSynthSink = (IDirectMusicSynthSinkImpl*)synth_sink;
263 return IDirectMusicSynthSink_GetLatencyClock(synth_sink, &This->pLatencyClock);
268 static HRESULT WINAPI IDirectMusicSynth8Impl_Render(LPDIRECTMUSICSYNTH8 iface, short* buffer, DWORD length, LONGLONG position)
270 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
272 FIXME("(%p)->(%p, %d, 0x%s): stub\n", This, buffer, length, wine_dbgstr_longlong(position));
277 static HRESULT WINAPI IDirectMusicSynth8Impl_SetChannelPriority(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, DWORD priority)
279 /* IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface); */
281 /* Silenced because of too many messages - 1000 groups * 16 channels ;=) */
282 /* FIXME("(%p)->(%ld, %ld, %ld): stub\n", This, channel_group, channel, priority); */
287 static HRESULT WINAPI IDirectMusicSynth8Impl_GetChannelPriority(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, LPDWORD priority)
289 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
291 FIXME("(%p)->(%d, %d, %p): stub\n", This, channel_group, channel, priority);
296 static HRESULT WINAPI IDirectMusicSynth8Impl_GetFormat(LPDIRECTMUSICSYNTH8 iface, LPWAVEFORMATEX wave_format, LPDWORD wave_format_size)
298 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
300 FIXME("(%p)->(%p, %p): stub\n", This, wave_format, wave_format_size);
305 static HRESULT WINAPI IDirectMusicSynth8Impl_GetAppend(LPDIRECTMUSICSYNTH8 iface, DWORD* append)
307 TRACE("(%p)->(%p)\n", iface, append);
309 /* We don't need extra space at the end of buffers passed to us for now */
315 /* IDirectMusicSynth8Impl IDirectMusicSynth8 part: */
316 static HRESULT WINAPI IDirectMusicSynth8Impl_PlayVoice(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME ref_time, DWORD voice_id, DWORD channel_group, DWORD channel,
317 DWORD dwDLId, LONG prPitch, LONG vrVolume, SAMPLE_TIME stVoiceStart, SAMPLE_TIME stLoopStart, SAMPLE_TIME stLoopEnd)
319 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
321 FIXME("(%p)->(0x%s, %d, %d, %d, %d, %i, %i,0x%s, 0x%s, 0x%s): stub\n",
322 This, wine_dbgstr_longlong(ref_time), voice_id, channel_group, channel, dwDLId, prPitch, vrVolume,
323 wine_dbgstr_longlong(stVoiceStart), wine_dbgstr_longlong(stLoopStart), wine_dbgstr_longlong(stLoopEnd));
328 static HRESULT WINAPI IDirectMusicSynth8Impl_StopVoice(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME ref_time, DWORD voice_id)
330 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
332 FIXME("(%p)->(0x%s, %d): stub\n", This, wine_dbgstr_longlong(ref_time), voice_id);
337 static HRESULT WINAPI IDirectMusicSynth8Impl_GetVoiceState(LPDIRECTMUSICSYNTH8 iface, DWORD dwVoice[], DWORD cbVoice, DMUS_VOICE_STATE dwVoiceState[])
339 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
341 FIXME("(%p)->(%p, %d, %p): stub\n", This, dwVoice, cbVoice, dwVoiceState);
346 static HRESULT WINAPI IDirectMusicSynth8Impl_Refresh(LPDIRECTMUSICSYNTH8 iface, DWORD download_id, DWORD flags)
348 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
350 FIXME("(%p)->(%d, %d): stub\n", This, download_id, flags);
355 static HRESULT WINAPI IDirectMusicSynth8Impl_AssignChannelToBuses(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, LPDWORD pdwBuses, DWORD cBuses)
357 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
359 FIXME("(%p)->(%d, %d, %p, %d): stub\n", This, channel_group, channel, pdwBuses, cBuses);
364 static const IDirectMusicSynth8Vtbl DirectMusicSynth8_Vtbl = {
365 IDirectMusicSynth8Impl_QueryInterface,
366 IDirectMusicSynth8Impl_AddRef,
367 IDirectMusicSynth8Impl_Release,
368 IDirectMusicSynth8Impl_Open,
369 IDirectMusicSynth8Impl_Close,
370 IDirectMusicSynth8Impl_SetNumChannelGroups,
371 IDirectMusicSynth8Impl_Download,
372 IDirectMusicSynth8Impl_Unload,
373 IDirectMusicSynth8Impl_PlayBuffer,
374 IDirectMusicSynth8Impl_GetRunningStats,
375 IDirectMusicSynth8Impl_GetPortCaps,
376 IDirectMusicSynth8Impl_SetMasterClock,
377 IDirectMusicSynth8Impl_GetLatencyClock,
378 IDirectMusicSynth8Impl_Activate,
379 IDirectMusicSynth8Impl_SetSynthSink,
380 IDirectMusicSynth8Impl_Render,
381 IDirectMusicSynth8Impl_SetChannelPriority,
382 IDirectMusicSynth8Impl_GetChannelPriority,
383 IDirectMusicSynth8Impl_GetFormat,
384 IDirectMusicSynth8Impl_GetAppend,
385 IDirectMusicSynth8Impl_PlayVoice,
386 IDirectMusicSynth8Impl_StopVoice,
387 IDirectMusicSynth8Impl_GetVoiceState,
388 IDirectMusicSynth8Impl_Refresh,
389 IDirectMusicSynth8Impl_AssignChannelToBuses
392 static inline IDirectMusicSynth8Impl *impl_from_IKsControl(IKsControl *iface)
394 return CONTAINING_RECORD(iface, IDirectMusicSynth8Impl, IKsControl_iface);
397 static HRESULT WINAPI DMSynthImpl_IKsControl_QueryInterface(IKsControl* iface, REFIID riid, LPVOID *ppobj)
399 IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
401 return IDirectMusicSynth8Impl_QueryInterface(&This->IDirectMusicSynth8_iface, riid, ppobj);
404 static ULONG WINAPI DMSynthImpl_IKsControl_AddRef(IKsControl* iface)
406 IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
408 return IDirectMusicSynth8Impl_AddRef(&This->IDirectMusicSynth8_iface);
411 static ULONG WINAPI DMSynthImpl_IKsControl_Release(IKsControl* iface)
413 IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
415 return IDirectMusicSynth8Impl_Release(&This->IDirectMusicSynth8_iface);
418 static HRESULT WINAPI DMSynthImpl_IKsControl_KsProperty(IKsControl* iface, PKSPROPERTY Property, ULONG PropertyLength, LPVOID PropertyData,
419 ULONG DataLength, ULONG* BytesReturned)
421 TRACE("(%p)->(%p, %u, %p, %u, %p)\n", iface, Property, PropertyLength, PropertyData, DataLength, BytesReturned);
423 TRACE("Property = %s - %u - %u\n", debugstr_guid(&Property->u.s.Set), Property->u.s.Id, Property->u.s.Flags);
425 if (Property->u.s.Flags != KSPROPERTY_TYPE_GET)
427 FIXME("Property flags %u not yet supported\n", Property->u.s.Flags);
431 if (DataLength < sizeof(DWORD))
432 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
434 if (IsEqualGUID(&Property->u.s.Set, &GUID_DMUS_PROP_INSTRUMENT2))
436 *(DWORD*)PropertyData = TRUE;
437 *BytesReturned = sizeof(DWORD);
439 else if (IsEqualGUID(&Property->u.s.Set, &GUID_DMUS_PROP_DLS2))
441 *(DWORD*)PropertyData = TRUE;
442 *BytesReturned = sizeof(DWORD);
444 else if (IsEqualGUID(&Property->u.s.Set, &GUID_DMUS_PROP_GM_Hardware))
446 *(DWORD*)PropertyData = FALSE;
447 *BytesReturned = sizeof(DWORD);
449 else if (IsEqualGUID(&Property->u.s.Set, &GUID_DMUS_PROP_GS_Hardware))
451 *(DWORD*)PropertyData = FALSE;
452 *BytesReturned = sizeof(DWORD);
454 else if (IsEqualGUID(&Property->u.s.Set, &GUID_DMUS_PROP_XG_Hardware))
456 *(DWORD*)PropertyData = FALSE;
457 *BytesReturned = sizeof(DWORD);
461 FIXME("Unknown property %s\n", debugstr_guid(&Property->u.s.Set));
462 *(DWORD*)PropertyData = FALSE;
463 *BytesReturned = sizeof(DWORD);
469 static HRESULT WINAPI DMSynthImpl_IKsControl_KsMethod(IKsControl* iface, PKSMETHOD Method, ULONG MethodLength, LPVOID MethodData,
470 ULONG DataLength, ULONG* BytesReturned)
472 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Method, MethodLength, MethodData, DataLength, BytesReturned);
477 static HRESULT WINAPI DMSynthImpl_IKsControl_KsEvent(IKsControl* iface, PKSEVENT Event, ULONG EventLength, LPVOID EventData,
478 ULONG DataLength, ULONG* BytesReturned)
480 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Event, EventLength, EventData, DataLength, BytesReturned);
486 static const IKsControlVtbl DMSynthImpl_IKsControl_Vtbl = {
487 DMSynthImpl_IKsControl_QueryInterface,
488 DMSynthImpl_IKsControl_AddRef,
489 DMSynthImpl_IKsControl_Release,
490 DMSynthImpl_IKsControl_KsProperty,
491 DMSynthImpl_IKsControl_KsMethod,
492 DMSynthImpl_IKsControl_KsEvent
495 /* for ClassFactory */
496 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter)
498 IDirectMusicSynth8Impl *obj;
500 TRACE("(%p,%p,%p)\n", lpcGUID, ppobj, pUnkOuter);
501 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynth8Impl));
504 return E_OUTOFMEMORY;
506 obj->IDirectMusicSynth8_iface.lpVtbl = &DirectMusicSynth8_Vtbl;
507 obj->IKsControl_iface.lpVtbl = &DMSynthImpl_IKsControl_Vtbl;
510 obj->pCaps.dwSize = sizeof(DMUS_PORTCAPS);
511 obj->pCaps.dwFlags = DMUS_PC_DLS | DMUS_PC_SOFTWARESYNTH | DMUS_PC_DIRECTSOUND | DMUS_PC_DLS2 | DMUS_PC_AUDIOPATH | DMUS_PC_WAVE;
512 obj->pCaps.guidPort = CLSID_DirectMusicSynth;
513 obj->pCaps.dwClass = DMUS_PC_OUTPUTCLASS;
514 obj->pCaps.dwType = DMUS_PORT_USER_MODE_SYNTH;
515 obj->pCaps.dwMemorySize = DMUS_PC_SYSTEMMEMORY;
516 obj->pCaps.dwMaxChannelGroups = 1000;
517 obj->pCaps.dwMaxVoices = 1000;
518 obj->pCaps.dwMaxAudioChannels = 2;
519 obj->pCaps.dwEffectFlags = DMUS_EFFECT_REVERB;
520 MultiByteToWideChar (CP_ACP, 0, "Microsoft Synthesizer", -1, obj->pCaps.wszDescription, sizeof(obj->pCaps.wszDescription)/sizeof(WCHAR));
522 return IDirectMusicSynth8Impl_QueryInterface ((LPDIRECTMUSICSYNTH8)obj, lpcGUID, ppobj);