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
28 #include "dmsynth_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(dmsynth);
32 static inline IDirectMusicSynth8Impl *impl_from_IDirectMusicSynth8(IDirectMusicSynth8 *iface)
34 return CONTAINING_RECORD(iface, IDirectMusicSynth8Impl, IDirectMusicSynth8_iface);
37 /* IDirectMusicSynth8Impl IUnknown part: */
38 static HRESULT WINAPI IDirectMusicSynth8Impl_QueryInterface(LPDIRECTMUSICSYNTH8 iface, REFIID riid, LPVOID *ret_iface)
40 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
42 TRACE("(%p)->(%s, %p)\n", iface, debugstr_dmguid(riid), ret_iface);
44 if (IsEqualIID (riid, &IID_IUnknown) ||
45 IsEqualIID (riid, &IID_IDirectMusicSynth) ||
46 IsEqualIID (riid, &IID_IDirectMusicSynth8))
48 IUnknown_AddRef(iface);
52 else if (IsEqualIID(riid, &IID_IKsControl))
54 IUnknown_AddRef(iface);
55 *ret_iface = &This->IKsControl_iface;
61 WARN("(%p)->(%s, %p): not found\n", iface, debugstr_dmguid(riid), ret_iface);
66 static ULONG WINAPI IDirectMusicSynth8Impl_AddRef(LPDIRECTMUSICSYNTH8 iface)
68 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
69 ULONG ref = InterlockedIncrement(&This->ref);
71 TRACE("(%p)->(): new ref = %u\n", This, ref);
78 static ULONG WINAPI IDirectMusicSynth8Impl_Release(LPDIRECTMUSICSYNTH8 iface)
80 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
81 ULONG ref = InterlockedDecrement(&This->ref);
83 TRACE("(%p)->(): new ref = %u\n", This, ref);
86 if (This->pLatencyClock)
87 IReferenceClock_Release(This->pLatencyClock);
88 HeapFree(GetProcessHeap(), 0, This);
91 DMSYNTH_UnlockModule();
96 /* IDirectMusicSynth8Impl IDirectMusicSynth part: */
97 static HRESULT WINAPI IDirectMusicSynth8Impl_Open(LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTPARAMS pPortParams)
99 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
101 FIXME("(%p)->(%p): stub\n", This, pPortParams);
106 static HRESULT WINAPI IDirectMusicSynth8Impl_Close(LPDIRECTMUSICSYNTH8 iface)
108 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
110 FIXME("(%p)->(): stub\n", This);
115 static HRESULT WINAPI IDirectMusicSynth8Impl_SetNumChannelGroups(LPDIRECTMUSICSYNTH8 iface, DWORD groups)
117 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
119 FIXME("(%p->(%d): stub\n", This, groups);
124 static HRESULT WINAPI IDirectMusicSynth8Impl_Download(LPDIRECTMUSICSYNTH8 iface, LPHANDLE hDownload, LPVOID data, LPBOOL free)
126 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
127 DMUS_DOWNLOADINFO* info = (DMUS_DOWNLOADINFO*)data;
129 FIXME("(%p)->(%p, %p, %p): stub\n", This, hDownload, data, free);
131 if (!hDownload || !data || !free)
134 if (TRACE_ON(dmsynth))
136 TRACE("Dump DMUS_DOWNLOADINFO struct:\n");
137 TRACE(" - dwDLType = %u\n", info->dwDLType);
138 TRACE(" - dwDLId = %u\n", info->dwDLId);
139 TRACE(" - dwNumOffsetTableEntries = %u\n", info->dwNumOffsetTableEntries);
140 TRACE(" - cbSize = %u\n", info->cbSize);
143 if (info->dwDLType == DMUS_DOWNLOADINFO_INSTRUMENT)
145 FIXME("Download type DMUS_DOWNLOADINFO_INSTRUMENT not yet supported\n");
147 else if (info->dwDLType == DMUS_DOWNLOADINFO_WAVE)
149 FIXME("Download type DMUS_DOWNLOADINFO_WAVE not yet supported\n");
151 else if (info->dwDLType == DMUS_DOWNLOADINFO_INSTRUMENT2)
153 FIXME("Download type DMUS_DOWNLOADINFO_INSTRUMENT2 not yet supported\n");
155 else if (info->dwDLType == DMUS_DOWNLOADINFO_WAVEARTICULATION)
157 FIXME("Download type DMUS_DOWNLOADINFO_WAVEARTICULATION not yet supported\n");
159 else if (info->dwDLType == DMUS_DOWNLOADINFO_STREAMINGWAVE)
161 FIXME("Download type DMUS_DOWNLOADINFO_STREAMINGWAVE not yet supported\n");
163 else if (info->dwDLType == DMUS_DOWNLOADINFO_ONESHOTWAVE)
165 FIXME("Download type DMUS_DOWNLOADINFO_ONESHOTWAVE not yet supported\n");
169 WARN("Unknown download type %u\n", info->dwDLType);
170 return DMUS_E_UNKNOWNDOWNLOAD;
176 static HRESULT WINAPI IDirectMusicSynth8Impl_Unload(LPDIRECTMUSICSYNTH8 iface, HANDLE hDownload, HRESULT (CALLBACK* lpFreeHandle)(HANDLE,HANDLE), HANDLE hUserData)
178 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
180 FIXME("(%p)->(%p, %p, %p): stub\n", This, hDownload, lpFreeHandle, hUserData);
185 static HRESULT WINAPI IDirectMusicSynth8Impl_PlayBuffer(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME rt, LPBYTE buffer, DWORD size)
187 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
189 FIXME("(%p)->(0x%s, %p, %u): stub\n", This, wine_dbgstr_longlong(rt), buffer, size);
194 static HRESULT WINAPI IDirectMusicSynth8Impl_GetRunningStats(LPDIRECTMUSICSYNTH8 iface, LPDMUS_SYNTHSTATS stats)
196 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
198 FIXME("(%p)->(%p): stub\n", This, stats);
203 static HRESULT WINAPI IDirectMusicSynth8Impl_GetPortCaps(LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTCAPS caps)
205 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
207 TRACE("(%p)->(%p)\n", This, caps);
214 static HRESULT WINAPI IDirectMusicSynth8Impl_SetMasterClock(LPDIRECTMUSICSYNTH8 iface, IReferenceClock* clock)
216 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
218 FIXME("(%p)->(%p): stub\n", This, clock);
223 static HRESULT WINAPI IDirectMusicSynth8Impl_GetLatencyClock(LPDIRECTMUSICSYNTH8 iface, IReferenceClock** clock)
225 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
227 TRACE("(%p)->(%p)\n", iface, clock);
232 if (!This->pSynthSink)
233 return DMUS_E_NOSYNTHSINK;
235 *clock = This->pLatencyClock;
236 IReferenceClock_AddRef(This->pLatencyClock);
241 static HRESULT WINAPI IDirectMusicSynth8Impl_Activate(LPDIRECTMUSICSYNTH8 iface, BOOL enable)
243 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
245 TRACE("(%p)->(%d)\n", This, enable);
247 This->fActive = enable;
252 static HRESULT WINAPI IDirectMusicSynth8Impl_SetSynthSink(LPDIRECTMUSICSYNTH8 iface, IDirectMusicSynthSink* synth_sink)
254 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
256 TRACE("(%p)->(%p)\n", iface, synth_sink);
258 This->pSynthSink = (IDirectMusicSynthSinkImpl*)synth_sink;
261 return IDirectMusicSynthSink_GetLatencyClock(synth_sink, &This->pLatencyClock);
266 static HRESULT WINAPI IDirectMusicSynth8Impl_Render(LPDIRECTMUSICSYNTH8 iface, short* buffer, DWORD length, LONGLONG position)
268 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
270 FIXME("(%p)->(%p, %d, 0x%s): stub\n", This, buffer, length, wine_dbgstr_longlong(position));
275 static HRESULT WINAPI IDirectMusicSynth8Impl_SetChannelPriority(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, DWORD priority)
277 /* IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface); */
279 /* Silenced because of too many messages - 1000 groups * 16 channels ;=) */
280 /* FIXME("(%p)->(%ld, %ld, %ld): stub\n", This, channel_group, channel, priority); */
285 static HRESULT WINAPI IDirectMusicSynth8Impl_GetChannelPriority(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, LPDWORD priority)
287 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
289 FIXME("(%p)->(%d, %d, %p): stub\n", This, channel_group, channel, priority);
294 static HRESULT WINAPI IDirectMusicSynth8Impl_GetFormat(LPDIRECTMUSICSYNTH8 iface, LPWAVEFORMATEX wave_format, LPDWORD wave_format_size)
296 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
298 FIXME("(%p)->(%p, %p): stub\n", This, wave_format, wave_format_size);
303 static HRESULT WINAPI IDirectMusicSynth8Impl_GetAppend(LPDIRECTMUSICSYNTH8 iface, DWORD* append)
305 TRACE("(%p)->(%p)\n", iface, append);
307 /* We don't need extra space at the end of buffers passed to us for now */
313 /* IDirectMusicSynth8Impl IDirectMusicSynth8 part: */
314 static HRESULT WINAPI IDirectMusicSynth8Impl_PlayVoice(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME ref_time, DWORD voice_id, DWORD channel_group, DWORD channel,
315 DWORD dwDLId, LONG prPitch, LONG vrVolume, SAMPLE_TIME stVoiceStart, SAMPLE_TIME stLoopStart, SAMPLE_TIME stLoopEnd)
317 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
319 FIXME("(%p)->(0x%s, %d, %d, %d, %d, %i, %i,0x%s, 0x%s, 0x%s): stub\n",
320 This, wine_dbgstr_longlong(ref_time), voice_id, channel_group, channel, dwDLId, prPitch, vrVolume,
321 wine_dbgstr_longlong(stVoiceStart), wine_dbgstr_longlong(stLoopStart), wine_dbgstr_longlong(stLoopEnd));
326 static HRESULT WINAPI IDirectMusicSynth8Impl_StopVoice(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME ref_time, DWORD voice_id)
328 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
330 FIXME("(%p)->(0x%s, %d): stub\n", This, wine_dbgstr_longlong(ref_time), voice_id);
335 static HRESULT WINAPI IDirectMusicSynth8Impl_GetVoiceState(LPDIRECTMUSICSYNTH8 iface, DWORD dwVoice[], DWORD cbVoice, DMUS_VOICE_STATE dwVoiceState[])
337 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
339 FIXME("(%p)->(%p, %d, %p): stub\n", This, dwVoice, cbVoice, dwVoiceState);
344 static HRESULT WINAPI IDirectMusicSynth8Impl_Refresh(LPDIRECTMUSICSYNTH8 iface, DWORD download_id, DWORD flags)
346 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
348 FIXME("(%p)->(%d, %d): stub\n", This, download_id, flags);
353 static HRESULT WINAPI IDirectMusicSynth8Impl_AssignChannelToBuses(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, LPDWORD pdwBuses, DWORD cBuses)
355 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
357 FIXME("(%p)->(%d, %d, %p, %d): stub\n", This, channel_group, channel, pdwBuses, cBuses);
362 static const IDirectMusicSynth8Vtbl DirectMusicSynth8_Vtbl = {
363 IDirectMusicSynth8Impl_QueryInterface,
364 IDirectMusicSynth8Impl_AddRef,
365 IDirectMusicSynth8Impl_Release,
366 IDirectMusicSynth8Impl_Open,
367 IDirectMusicSynth8Impl_Close,
368 IDirectMusicSynth8Impl_SetNumChannelGroups,
369 IDirectMusicSynth8Impl_Download,
370 IDirectMusicSynth8Impl_Unload,
371 IDirectMusicSynth8Impl_PlayBuffer,
372 IDirectMusicSynth8Impl_GetRunningStats,
373 IDirectMusicSynth8Impl_GetPortCaps,
374 IDirectMusicSynth8Impl_SetMasterClock,
375 IDirectMusicSynth8Impl_GetLatencyClock,
376 IDirectMusicSynth8Impl_Activate,
377 IDirectMusicSynth8Impl_SetSynthSink,
378 IDirectMusicSynth8Impl_Render,
379 IDirectMusicSynth8Impl_SetChannelPriority,
380 IDirectMusicSynth8Impl_GetChannelPriority,
381 IDirectMusicSynth8Impl_GetFormat,
382 IDirectMusicSynth8Impl_GetAppend,
383 IDirectMusicSynth8Impl_PlayVoice,
384 IDirectMusicSynth8Impl_StopVoice,
385 IDirectMusicSynth8Impl_GetVoiceState,
386 IDirectMusicSynth8Impl_Refresh,
387 IDirectMusicSynth8Impl_AssignChannelToBuses
390 static inline IDirectMusicSynth8Impl *impl_from_IKsControl(IKsControl *iface)
392 return CONTAINING_RECORD(iface, IDirectMusicSynth8Impl, IKsControl_iface);
395 static HRESULT WINAPI DMSynthImpl_IKsControl_QueryInterface(IKsControl* iface, REFIID riid, LPVOID *ppobj)
397 IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
399 return IDirectMusicSynth8Impl_QueryInterface(&This->IDirectMusicSynth8_iface, riid, ppobj);
402 static ULONG WINAPI DMSynthImpl_IKsControl_AddRef(IKsControl* iface)
404 IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
406 return IDirectMusicSynth8Impl_AddRef(&This->IDirectMusicSynth8_iface);
409 static ULONG WINAPI DMSynthImpl_IKsControl_Release(IKsControl* iface)
411 IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
413 return IDirectMusicSynth8Impl_Release(&This->IDirectMusicSynth8_iface);
416 static HRESULT WINAPI DMSynthImpl_IKsControl_KsProperty(IKsControl* iface, PKSPROPERTY Property, ULONG PropertyLength, LPVOID PropertyData,
417 ULONG DataLength, ULONG* BytesReturned)
419 TRACE("(%p)->(%p, %u, %p, %u, %p)\n", iface, Property, PropertyLength, PropertyData, DataLength, BytesReturned);
421 TRACE("Property = %s - %u - %u\n", debugstr_guid(&Property->Set), Property->Id, Property->Flags);
423 if (Property->Flags != KSPROPERTY_TYPE_GET)
425 FIXME("Property flags %u not yet supported\n", Property->Flags);
429 if (DataLength < sizeof(DWORD))
430 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
432 if (IsEqualGUID(&Property->Set, &GUID_DMUS_PROP_INSTRUMENT2))
434 *(DWORD*)PropertyData = TRUE;
435 *BytesReturned = sizeof(DWORD);
437 else if (IsEqualGUID(&Property->Set, &GUID_DMUS_PROP_DLS2))
439 *(DWORD*)PropertyData = TRUE;
440 *BytesReturned = sizeof(DWORD);
442 else if (IsEqualGUID(&Property->Set, &GUID_DMUS_PROP_GM_Hardware))
444 *(DWORD*)PropertyData = FALSE;
445 *BytesReturned = sizeof(DWORD);
447 else if (IsEqualGUID(&Property->Set, &GUID_DMUS_PROP_GS_Hardware))
449 *(DWORD*)PropertyData = FALSE;
450 *BytesReturned = sizeof(DWORD);
452 else if (IsEqualGUID(&Property->Set, &GUID_DMUS_PROP_XG_Hardware))
454 *(DWORD*)PropertyData = FALSE;
455 *BytesReturned = sizeof(DWORD);
459 FIXME("Unknown property %s\n", debugstr_guid(&Property->Set));
460 *(DWORD*)PropertyData = FALSE;
461 *BytesReturned = sizeof(DWORD);
467 static HRESULT WINAPI DMSynthImpl_IKsControl_KsMethod(IKsControl* iface, PKSMETHOD Method, ULONG MethodLength, LPVOID MethodData,
468 ULONG DataLength, ULONG* BytesReturned)
470 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Method, MethodLength, MethodData, DataLength, BytesReturned);
475 static HRESULT WINAPI DMSynthImpl_IKsControl_KsEvent(IKsControl* iface, PKSEVENT Event, ULONG EventLength, LPVOID EventData,
476 ULONG DataLength, ULONG* BytesReturned)
478 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Event, EventLength, EventData, DataLength, BytesReturned);
484 static const IKsControlVtbl DMSynthImpl_IKsControl_Vtbl = {
485 DMSynthImpl_IKsControl_QueryInterface,
486 DMSynthImpl_IKsControl_AddRef,
487 DMSynthImpl_IKsControl_Release,
488 DMSynthImpl_IKsControl_KsProperty,
489 DMSynthImpl_IKsControl_KsMethod,
490 DMSynthImpl_IKsControl_KsEvent
493 /* for ClassFactory */
494 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter)
496 IDirectMusicSynth8Impl *obj;
498 TRACE("(%p,%p,%p)\n", lpcGUID, ppobj, pUnkOuter);
499 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynth8Impl));
502 return E_OUTOFMEMORY;
504 obj->IDirectMusicSynth8_iface.lpVtbl = &DirectMusicSynth8_Vtbl;
505 obj->IKsControl_iface.lpVtbl = &DMSynthImpl_IKsControl_Vtbl;
508 obj->pCaps.dwSize = sizeof(DMUS_PORTCAPS);
509 obj->pCaps.dwFlags = DMUS_PC_DLS | DMUS_PC_SOFTWARESYNTH | DMUS_PC_DIRECTSOUND | DMUS_PC_DLS2 | DMUS_PC_AUDIOPATH | DMUS_PC_WAVE;
510 obj->pCaps.guidPort = CLSID_DirectMusicSynth;
511 obj->pCaps.dwClass = DMUS_PC_OUTPUTCLASS;
512 obj->pCaps.dwType = DMUS_PORT_USER_MODE_SYNTH;
513 obj->pCaps.dwMemorySize = DMUS_PC_SYSTEMMEMORY;
514 obj->pCaps.dwMaxChannelGroups = 1000;
515 obj->pCaps.dwMaxVoices = 1000;
516 obj->pCaps.dwMaxAudioChannels = 2;
517 obj->pCaps.dwEffectFlags = DMUS_EFFECT_REVERB;
518 MultiByteToWideChar (CP_ACP, 0, "Microsoft Synthesizer", -1, obj->pCaps.wszDescription, sizeof(obj->pCaps.wszDescription)/sizeof(WCHAR));
520 return IDirectMusicSynth8Impl_QueryInterface ((LPDIRECTMUSICSYNTH8)obj, lpcGUID, ppobj);