dmusic: Display new ref in trace for AddRef and Release for IDirectMusicInstrument.
[wine/multimedia.git] / dlls / dmsynth / synth.c
blobe5d5e1c89b95278fba25ccff34e92dc56aaaf474
1 /*
2 * IDirectMusicSynth8 Implementation
4 * Copyright (C) 2003-2004 Rok Mandeljc
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include "objbase.h"
24 #include "initguid.h"
25 #include "dmksctrl.h"
27 #include "dmsynth_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(dmsynth);
31 static inline IDirectMusicSynth8Impl *impl_from_IDirectMusicSynth8(IDirectMusicSynth8 *iface)
33 return CONTAINING_RECORD(iface, IDirectMusicSynth8Impl, IDirectMusicSynth8_iface);
36 /* IDirectMusicSynth8Impl IUnknown part: */
37 static HRESULT WINAPI IDirectMusicSynth8Impl_QueryInterface(LPDIRECTMUSICSYNTH8 iface, REFIID riid, LPVOID *ret_iface)
39 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
41 TRACE("(%p)->(%s, %p)\n", iface, debugstr_dmguid(riid), ret_iface);
43 if (IsEqualIID (riid, &IID_IUnknown) ||
44 IsEqualIID (riid, &IID_IDirectMusicSynth) ||
45 IsEqualIID (riid, &IID_IDirectMusicSynth8))
47 IUnknown_AddRef(iface);
48 *ret_iface = iface;
49 return S_OK;
51 else if (IsEqualIID(riid, &IID_IKsControl))
53 IUnknown_AddRef(iface);
54 *ret_iface = &This->IKsControl_iface;
55 return S_OK;
58 *ret_iface = NULL;
60 WARN("(%p)->(%s, %p): not found\n", iface, debugstr_dmguid(riid), ret_iface);
62 return E_NOINTERFACE;
65 static ULONG WINAPI IDirectMusicSynth8Impl_AddRef(LPDIRECTMUSICSYNTH8 iface)
67 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
68 ULONG ref = InterlockedIncrement(&This->ref);
70 TRACE("(%p)->(): new ref = %u\n", This, ref);
72 DMSYNTH_LockModule();
74 return ref;
77 static ULONG WINAPI IDirectMusicSynth8Impl_Release(LPDIRECTMUSICSYNTH8 iface)
79 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
80 ULONG ref = InterlockedDecrement(&This->ref);
82 TRACE("(%p)->(): new ref = %u\n", This, ref);
84 if (!ref) {
85 if (This->pLatencyClock)
86 IReferenceClock_Release(This->pLatencyClock);
87 HeapFree(GetProcessHeap(), 0, This);
90 DMSYNTH_UnlockModule();
92 return ref;
95 /* IDirectMusicSynth8Impl IDirectMusicSynth part: */
96 static HRESULT WINAPI IDirectMusicSynth8Impl_Open(LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTPARAMS pPortParams)
98 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
100 FIXME("(%p)->(%p): stub\n", This, pPortParams);
102 return S_OK;
105 static HRESULT WINAPI IDirectMusicSynth8Impl_Close(LPDIRECTMUSICSYNTH8 iface)
107 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
109 FIXME("(%p)->(): stub\n", This);
111 return S_OK;
114 static HRESULT WINAPI IDirectMusicSynth8Impl_SetNumChannelGroups(LPDIRECTMUSICSYNTH8 iface, DWORD groups)
116 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
118 FIXME("(%p->(%d): stub\n", This, groups);
120 return S_OK;
123 static HRESULT WINAPI IDirectMusicSynth8Impl_Download(LPDIRECTMUSICSYNTH8 iface, LPHANDLE hDownload, LPVOID data, LPBOOL free)
125 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
127 FIXME("(%p)->(%p, %p, %p): stub\n", This, hDownload, data, free);
129 return S_OK;
132 static HRESULT WINAPI IDirectMusicSynth8Impl_Unload(LPDIRECTMUSICSYNTH8 iface, HANDLE hDownload, HRESULT (CALLBACK* lpFreeHandle)(HANDLE,HANDLE), HANDLE hUserData)
134 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
136 FIXME("(%p)->(%p, %p, %p): stub\n", This, hDownload, lpFreeHandle, hUserData);
138 return S_OK;
141 static HRESULT WINAPI IDirectMusicSynth8Impl_PlayBuffer(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME rt, LPBYTE buffer, DWORD size)
143 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
145 FIXME("(%p)->(0x%s, %p, %u): stub\n", This, wine_dbgstr_longlong(rt), buffer, size);
147 return S_OK;
150 static HRESULT WINAPI IDirectMusicSynth8Impl_GetRunningStats(LPDIRECTMUSICSYNTH8 iface, LPDMUS_SYNTHSTATS stats)
152 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
154 FIXME("(%p)->(%p): stub\n", This, stats);
156 return S_OK;
159 static HRESULT WINAPI IDirectMusicSynth8Impl_GetPortCaps(LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTCAPS caps)
161 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
163 TRACE("(%p)->(%p)\n", This, caps);
165 *caps = This->pCaps;
167 return S_OK;
170 static HRESULT WINAPI IDirectMusicSynth8Impl_SetMasterClock(LPDIRECTMUSICSYNTH8 iface, IReferenceClock* clock)
172 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
174 FIXME("(%p)->(%p): stub\n", This, clock);
176 return S_OK;
179 static HRESULT WINAPI IDirectMusicSynth8Impl_GetLatencyClock(LPDIRECTMUSICSYNTH8 iface, IReferenceClock** clock)
181 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
183 TRACE("(%p)->(%p)\n", iface, clock);
185 if (!clock)
186 return E_POINTER;
188 if (!This->pSynthSink)
189 return DMUS_E_NOSYNTHSINK;
191 *clock = This->pLatencyClock;
192 IReferenceClock_AddRef(This->pLatencyClock);
194 return S_OK;
197 static HRESULT WINAPI IDirectMusicSynth8Impl_Activate(LPDIRECTMUSICSYNTH8 iface, BOOL enable)
199 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
201 TRACE("(%p)->(%d)\n", This, enable);
203 This->fActive = enable;
205 return S_OK;
208 static HRESULT WINAPI IDirectMusicSynth8Impl_SetSynthSink(LPDIRECTMUSICSYNTH8 iface, IDirectMusicSynthSink* synth_sink)
210 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
212 TRACE("(%p)->(%p)\n", iface, synth_sink);
214 This->pSynthSink = (IDirectMusicSynthSinkImpl*)synth_sink;
216 if (synth_sink)
217 return IDirectMusicSynthSink_GetLatencyClock(synth_sink, &This->pLatencyClock);
219 return S_OK;
222 static HRESULT WINAPI IDirectMusicSynth8Impl_Render(LPDIRECTMUSICSYNTH8 iface, short* buffer, DWORD length, LONGLONG position)
224 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
226 FIXME("(%p)->(%p, %d, 0x%s): stub\n", This, buffer, length, wine_dbgstr_longlong(position));
228 return S_OK;
231 static HRESULT WINAPI IDirectMusicSynth8Impl_SetChannelPriority(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, DWORD priority)
233 /* IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface); */
235 /* Silenced because of too many messages - 1000 groups * 16 channels ;=) */
236 /* FIXME("(%p)->(%ld, %ld, %ld): stub\n", This, channel_group, channel, priority); */
238 return S_OK;
241 static HRESULT WINAPI IDirectMusicSynth8Impl_GetChannelPriority(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, LPDWORD priority)
243 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
245 FIXME("(%p)->(%d, %d, %p): stub\n", This, channel_group, channel, priority);
247 return S_OK;
250 static HRESULT WINAPI IDirectMusicSynth8Impl_GetFormat(LPDIRECTMUSICSYNTH8 iface, LPWAVEFORMATEX wave_format, LPDWORD wave_format_size)
252 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
254 FIXME("(%p)->(%p, %p): stub\n", This, wave_format, wave_format_size);
256 return S_OK;
259 static HRESULT WINAPI IDirectMusicSynth8Impl_GetAppend(LPDIRECTMUSICSYNTH8 iface, DWORD* append)
261 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
263 FIXME("(%p)->(%p): stub\n", This, append);
265 return S_OK;
268 /* IDirectMusicSynth8Impl IDirectMusicSynth8 part: */
269 static HRESULT WINAPI IDirectMusicSynth8Impl_PlayVoice(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME ref_time, DWORD voice_id, DWORD channel_group, DWORD channel,
270 DWORD dwDLId, LONG prPitch, LONG vrVolume, SAMPLE_TIME stVoiceStart, SAMPLE_TIME stLoopStart, SAMPLE_TIME stLoopEnd)
272 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
274 FIXME("(%p)->(0x%s, %d, %d, %d, %d, %i, %i,0x%s, 0x%s, 0x%s): stub\n",
275 This, wine_dbgstr_longlong(ref_time), voice_id, channel_group, channel, dwDLId, prPitch, vrVolume,
276 wine_dbgstr_longlong(stVoiceStart), wine_dbgstr_longlong(stLoopStart), wine_dbgstr_longlong(stLoopEnd));
278 return S_OK;
281 static HRESULT WINAPI IDirectMusicSynth8Impl_StopVoice(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME ref_time, DWORD voice_id)
283 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
285 FIXME("(%p)->(0x%s, %d): stub\n", This, wine_dbgstr_longlong(ref_time), voice_id);
287 return S_OK;
290 static HRESULT WINAPI IDirectMusicSynth8Impl_GetVoiceState(LPDIRECTMUSICSYNTH8 iface, DWORD dwVoice[], DWORD cbVoice, DMUS_VOICE_STATE dwVoiceState[])
292 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
294 FIXME("(%p)->(%p, %d, %p): stub\n", This, dwVoice, cbVoice, dwVoiceState);
296 return S_OK;
299 static HRESULT WINAPI IDirectMusicSynth8Impl_Refresh(LPDIRECTMUSICSYNTH8 iface, DWORD download_id, DWORD flags)
301 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
303 FIXME("(%p)->(%d, %d): stub\n", This, download_id, flags);
305 return S_OK;
308 static HRESULT WINAPI IDirectMusicSynth8Impl_AssignChannelToBuses(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, LPDWORD pdwBuses, DWORD cBuses)
310 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
312 FIXME("(%p)->(%d, %d, %p, %d): stub\n", This, channel_group, channel, pdwBuses, cBuses);
314 return S_OK;
317 static const IDirectMusicSynth8Vtbl DirectMusicSynth8_Vtbl = {
318 IDirectMusicSynth8Impl_QueryInterface,
319 IDirectMusicSynth8Impl_AddRef,
320 IDirectMusicSynth8Impl_Release,
321 IDirectMusicSynth8Impl_Open,
322 IDirectMusicSynth8Impl_Close,
323 IDirectMusicSynth8Impl_SetNumChannelGroups,
324 IDirectMusicSynth8Impl_Download,
325 IDirectMusicSynth8Impl_Unload,
326 IDirectMusicSynth8Impl_PlayBuffer,
327 IDirectMusicSynth8Impl_GetRunningStats,
328 IDirectMusicSynth8Impl_GetPortCaps,
329 IDirectMusicSynth8Impl_SetMasterClock,
330 IDirectMusicSynth8Impl_GetLatencyClock,
331 IDirectMusicSynth8Impl_Activate,
332 IDirectMusicSynth8Impl_SetSynthSink,
333 IDirectMusicSynth8Impl_Render,
334 IDirectMusicSynth8Impl_SetChannelPriority,
335 IDirectMusicSynth8Impl_GetChannelPriority,
336 IDirectMusicSynth8Impl_GetFormat,
337 IDirectMusicSynth8Impl_GetAppend,
338 IDirectMusicSynth8Impl_PlayVoice,
339 IDirectMusicSynth8Impl_StopVoice,
340 IDirectMusicSynth8Impl_GetVoiceState,
341 IDirectMusicSynth8Impl_Refresh,
342 IDirectMusicSynth8Impl_AssignChannelToBuses
345 static inline IDirectMusicSynth8Impl *impl_from_IKsControl(IKsControl *iface)
347 return CONTAINING_RECORD(iface, IDirectMusicSynth8Impl, IKsControl_iface);
350 static HRESULT WINAPI DMSynthImpl_IKsControl_QueryInterface(IKsControl* iface, REFIID riid, LPVOID *ppobj)
352 IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
354 return IDirectMusicSynth8Impl_QueryInterface(&This->IDirectMusicSynth8_iface, riid, ppobj);
357 static ULONG WINAPI DMSynthImpl_IKsControl_AddRef(IKsControl* iface)
359 IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
361 return IDirectMusicSynth8Impl_AddRef(&This->IDirectMusicSynth8_iface);
364 static ULONG WINAPI DMSynthImpl_IKsControl_Release(IKsControl* iface)
366 IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
368 return IDirectMusicSynth8Impl_Release(&This->IDirectMusicSynth8_iface);
371 static HRESULT WINAPI DMSynthImpl_IKsControl_KsProperty(IKsControl* iface, PKSPROPERTY Property, ULONG PropertyLength, LPVOID PropertyData,
372 ULONG DataLength, ULONG* BytesReturned)
374 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Property, PropertyLength, PropertyData, DataLength, BytesReturned);
376 return E_NOTIMPL;
379 static HRESULT WINAPI DMSynthImpl_IKsControl_KsMethod(IKsControl* iface, PKSMETHOD Method, ULONG MethodLength, LPVOID MethodData,
380 ULONG DataLength, ULONG* BytesReturned)
382 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Method, MethodLength, MethodData, DataLength, BytesReturned);
384 return E_NOTIMPL;
387 static HRESULT WINAPI DMSynthImpl_IKsControl_KsEvent(IKsControl* iface, PKSEVENT Event, ULONG EventLength, LPVOID EventData,
388 ULONG DataLength, ULONG* BytesReturned)
390 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Event, EventLength, EventData, DataLength, BytesReturned);
392 return E_NOTIMPL;
396 static const IKsControlVtbl DMSynthImpl_IKsControl_Vtbl = {
397 DMSynthImpl_IKsControl_QueryInterface,
398 DMSynthImpl_IKsControl_AddRef,
399 DMSynthImpl_IKsControl_Release,
400 DMSynthImpl_IKsControl_KsProperty,
401 DMSynthImpl_IKsControl_KsMethod,
402 DMSynthImpl_IKsControl_KsEvent
405 /* for ClassFactory */
406 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter)
408 IDirectMusicSynth8Impl *obj;
410 TRACE("(%p,%p,%p)\n", lpcGUID, ppobj, pUnkOuter);
411 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynth8Impl));
412 if (NULL == obj) {
413 *ppobj = NULL;
414 return E_OUTOFMEMORY;
416 obj->IDirectMusicSynth8_iface.lpVtbl = &DirectMusicSynth8_Vtbl;
417 obj->IKsControl_iface.lpVtbl = &DMSynthImpl_IKsControl_Vtbl;
418 obj->ref = 0;
419 /* fill in caps */
420 obj->pCaps.dwSize = sizeof(DMUS_PORTCAPS);
421 obj->pCaps.dwFlags = DMUS_PC_DLS | DMUS_PC_SOFTWARESYNTH | DMUS_PC_DIRECTSOUND | DMUS_PC_DLS2 | DMUS_PC_AUDIOPATH | DMUS_PC_WAVE;
422 obj->pCaps.guidPort = CLSID_DirectMusicSynth;
423 obj->pCaps.dwClass = DMUS_PC_OUTPUTCLASS;
424 obj->pCaps.dwType = DMUS_PORT_USER_MODE_SYNTH;
425 obj->pCaps.dwMemorySize = DMUS_PC_SYSTEMMEMORY;
426 obj->pCaps.dwMaxChannelGroups = 1000;
427 obj->pCaps.dwMaxVoices = 1000;
428 obj->pCaps.dwMaxAudioChannels = 2;
429 obj->pCaps.dwEffectFlags = DMUS_EFFECT_REVERB;
430 MultiByteToWideChar (CP_ACP, 0, "Microsoft Synthesizer", -1, obj->pCaps.wszDescription, sizeof(obj->pCaps.wszDescription)/sizeof(WCHAR));
432 return IDirectMusicSynth8Impl_QueryInterface ((LPDIRECTMUSICSYNTH8)obj, lpcGUID, ppobj);