dmsynth: Display new ref in trace for AddRef and Release.
[wine/multimedia.git] / dlls / dmsynth / synth.c
blob657f3bda1994dc989d1b834cbbb41ccedc0a0497
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 *ppobj)
39 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
41 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
43 if (IsEqualIID (riid, &IID_IUnknown) ||
44 IsEqualIID (riid, &IID_IDirectMusicSynth) ||
45 IsEqualIID (riid, &IID_IDirectMusicSynth8)) {
46 IUnknown_AddRef(iface);
47 *ppobj = This;
48 return S_OK;
50 else if (IsEqualIID(riid, &IID_IKsControl)) {
51 IUnknown_AddRef(iface);
52 *ppobj = &This->IKsControl_iface;
53 return S_OK;
56 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
57 return E_NOINTERFACE;
60 static ULONG WINAPI IDirectMusicSynth8Impl_AddRef(LPDIRECTMUSICSYNTH8 iface)
62 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
63 ULONG ref = InterlockedIncrement(&This->ref);
65 TRACE("(%p)->(): new ref = %u\n", This, ref);
67 DMSYNTH_LockModule();
69 return ref;
72 static ULONG WINAPI IDirectMusicSynth8Impl_Release(LPDIRECTMUSICSYNTH8 iface)
74 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
75 ULONG ref = InterlockedDecrement(&This->ref);
77 TRACE("(%p)->(): new ref = %u\n", This, ref);
79 if (!ref) {
80 if (This->pLatencyClock)
81 IReferenceClock_Release(This->pLatencyClock);
82 HeapFree(GetProcessHeap(), 0, This);
85 DMSYNTH_UnlockModule();
87 return ref;
90 /* IDirectMusicSynth8Impl IDirectMusicSynth part: */
91 static HRESULT WINAPI IDirectMusicSynth8Impl_Open(LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTPARAMS pPortParams)
93 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
95 FIXME("(%p)->(%p): stub\n", This, pPortParams);
97 return S_OK;
100 static HRESULT WINAPI IDirectMusicSynth8Impl_Close(LPDIRECTMUSICSYNTH8 iface)
102 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
104 FIXME("(%p)->(): stub\n", This);
106 return S_OK;
109 static HRESULT WINAPI IDirectMusicSynth8Impl_SetNumChannelGroups(LPDIRECTMUSICSYNTH8 iface, DWORD groups)
111 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
113 FIXME("(%p->(%d): stub\n", This, groups);
115 return S_OK;
118 static HRESULT WINAPI IDirectMusicSynth8Impl_Download(LPDIRECTMUSICSYNTH8 iface, LPHANDLE hDownload, LPVOID data, LPBOOL free)
120 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
122 FIXME("(%p)->(%p, %p, %p): stub\n", This, hDownload, data, free);
124 return S_OK;
127 static HRESULT WINAPI IDirectMusicSynth8Impl_Unload(LPDIRECTMUSICSYNTH8 iface, HANDLE hDownload, HRESULT (CALLBACK* lpFreeHandle)(HANDLE,HANDLE), HANDLE hUserData)
129 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
131 FIXME("(%p)->(%p, %p, %p): stub\n", This, hDownload, lpFreeHandle, hUserData);
133 return S_OK;
136 static HRESULT WINAPI IDirectMusicSynth8Impl_PlayBuffer(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME rt, LPBYTE buffer, DWORD size)
138 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
140 FIXME("(%p)->(0x%s, %p, %u): stub\n", This, wine_dbgstr_longlong(rt), buffer, size);
142 return S_OK;
145 static HRESULT WINAPI IDirectMusicSynth8Impl_GetRunningStats(LPDIRECTMUSICSYNTH8 iface, LPDMUS_SYNTHSTATS stats)
147 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
149 FIXME("(%p)->(%p): stub\n", This, stats);
151 return S_OK;
154 static HRESULT WINAPI IDirectMusicSynth8Impl_GetPortCaps(LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTCAPS caps)
156 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
158 TRACE("(%p)->(%p)\n", This, caps);
160 *caps = This->pCaps;
162 return S_OK;
165 static HRESULT WINAPI IDirectMusicSynth8Impl_SetMasterClock(LPDIRECTMUSICSYNTH8 iface, IReferenceClock* clock)
167 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
169 FIXME("(%p)->(%p): stub\n", This, clock);
171 return S_OK;
174 static HRESULT WINAPI IDirectMusicSynth8Impl_GetLatencyClock(LPDIRECTMUSICSYNTH8 iface, IReferenceClock** clock)
176 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
178 TRACE("(%p)->(%p)\n", iface, clock);
180 if (!clock)
181 return E_POINTER;
183 if (!This->pSynthSink)
184 return DMUS_E_NOSYNTHSINK;
186 *clock = This->pLatencyClock;
187 IReferenceClock_AddRef(This->pLatencyClock);
189 return S_OK;
192 static HRESULT WINAPI IDirectMusicSynth8Impl_Activate(LPDIRECTMUSICSYNTH8 iface, BOOL enable)
194 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
196 TRACE("(%p)->(%d)\n", This, enable);
198 This->fActive = enable;
200 return S_OK;
203 static HRESULT WINAPI IDirectMusicSynth8Impl_SetSynthSink(LPDIRECTMUSICSYNTH8 iface, IDirectMusicSynthSink* synth_sink)
205 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
207 TRACE("(%p)->(%p)\n", iface, synth_sink);
209 This->pSynthSink = (IDirectMusicSynthSinkImpl*)synth_sink;
211 if (synth_sink)
212 return IDirectMusicSynthSink_GetLatencyClock(synth_sink, &This->pLatencyClock);
214 return S_OK;
217 static HRESULT WINAPI IDirectMusicSynth8Impl_Render(LPDIRECTMUSICSYNTH8 iface, short* buffer, DWORD length, LONGLONG position)
219 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
221 FIXME("(%p)->(%p, %d, 0x%s): stub\n", This, buffer, length, wine_dbgstr_longlong(position));
223 return S_OK;
226 static HRESULT WINAPI IDirectMusicSynth8Impl_SetChannelPriority(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, DWORD priority)
228 /* IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface); */
230 /* Silenced because of too many messages - 1000 groups * 16 channels ;=) */
231 /* FIXME("(%p)->(%ld, %ld, %ld): stub\n", This, channel_group, channel, priority); */
233 return S_OK;
236 static HRESULT WINAPI IDirectMusicSynth8Impl_GetChannelPriority(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, LPDWORD priority)
238 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
240 FIXME("(%p)->(%d, %d, %p): stub\n", This, channel_group, channel, priority);
242 return S_OK;
245 static HRESULT WINAPI IDirectMusicSynth8Impl_GetFormat(LPDIRECTMUSICSYNTH8 iface, LPWAVEFORMATEX wave_format, LPDWORD wave_format_size)
247 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
249 FIXME("(%p)->(%p, %p): stub\n", This, wave_format, wave_format_size);
251 return S_OK;
254 static HRESULT WINAPI IDirectMusicSynth8Impl_GetAppend(LPDIRECTMUSICSYNTH8 iface, DWORD* append)
256 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
258 FIXME("(%p)->(%p): stub\n", This, append);
260 return S_OK;
263 /* IDirectMusicSynth8Impl IDirectMusicSynth8 part: */
264 static HRESULT WINAPI IDirectMusicSynth8Impl_PlayVoice(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME ref_time, DWORD voice_id, DWORD channel_group, DWORD channel,
265 DWORD dwDLId, LONG prPitch, LONG vrVolume, SAMPLE_TIME stVoiceStart, SAMPLE_TIME stLoopStart, SAMPLE_TIME stLoopEnd)
267 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
269 FIXME("(%p)->(0x%s, %d, %d, %d, %d, %i, %i,0x%s, 0x%s, 0x%s): stub\n",
270 This, wine_dbgstr_longlong(ref_time), voice_id, channel_group, channel, dwDLId, prPitch, vrVolume,
271 wine_dbgstr_longlong(stVoiceStart), wine_dbgstr_longlong(stLoopStart), wine_dbgstr_longlong(stLoopEnd));
273 return S_OK;
276 static HRESULT WINAPI IDirectMusicSynth8Impl_StopVoice(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME ref_time, DWORD voice_id)
278 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
280 FIXME("(%p)->(0x%s, %d): stub\n", This, wine_dbgstr_longlong(ref_time), voice_id);
282 return S_OK;
285 static HRESULT WINAPI IDirectMusicSynth8Impl_GetVoiceState(LPDIRECTMUSICSYNTH8 iface, DWORD dwVoice[], DWORD cbVoice, DMUS_VOICE_STATE dwVoiceState[])
287 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
289 FIXME("(%p)->(%p, %d, %p): stub\n", This, dwVoice, cbVoice, dwVoiceState);
291 return S_OK;
294 static HRESULT WINAPI IDirectMusicSynth8Impl_Refresh(LPDIRECTMUSICSYNTH8 iface, DWORD download_id, DWORD flags)
296 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
298 FIXME("(%p)->(%d, %d): stub\n", This, download_id, flags);
300 return S_OK;
303 static HRESULT WINAPI IDirectMusicSynth8Impl_AssignChannelToBuses(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, LPDWORD pdwBuses, DWORD cBuses)
305 IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
307 FIXME("(%p)->(%d, %d, %p, %d): stub\n", This, channel_group, channel, pdwBuses, cBuses);
309 return S_OK;
312 static const IDirectMusicSynth8Vtbl DirectMusicSynth8_Vtbl = {
313 IDirectMusicSynth8Impl_QueryInterface,
314 IDirectMusicSynth8Impl_AddRef,
315 IDirectMusicSynth8Impl_Release,
316 IDirectMusicSynth8Impl_Open,
317 IDirectMusicSynth8Impl_Close,
318 IDirectMusicSynth8Impl_SetNumChannelGroups,
319 IDirectMusicSynth8Impl_Download,
320 IDirectMusicSynth8Impl_Unload,
321 IDirectMusicSynth8Impl_PlayBuffer,
322 IDirectMusicSynth8Impl_GetRunningStats,
323 IDirectMusicSynth8Impl_GetPortCaps,
324 IDirectMusicSynth8Impl_SetMasterClock,
325 IDirectMusicSynth8Impl_GetLatencyClock,
326 IDirectMusicSynth8Impl_Activate,
327 IDirectMusicSynth8Impl_SetSynthSink,
328 IDirectMusicSynth8Impl_Render,
329 IDirectMusicSynth8Impl_SetChannelPriority,
330 IDirectMusicSynth8Impl_GetChannelPriority,
331 IDirectMusicSynth8Impl_GetFormat,
332 IDirectMusicSynth8Impl_GetAppend,
333 IDirectMusicSynth8Impl_PlayVoice,
334 IDirectMusicSynth8Impl_StopVoice,
335 IDirectMusicSynth8Impl_GetVoiceState,
336 IDirectMusicSynth8Impl_Refresh,
337 IDirectMusicSynth8Impl_AssignChannelToBuses
340 static inline IDirectMusicSynth8Impl *impl_from_IKsControl(IKsControl *iface)
342 return CONTAINING_RECORD(iface, IDirectMusicSynth8Impl, IKsControl_iface);
345 static HRESULT WINAPI DMSynthImpl_IKsControl_QueryInterface(IKsControl* iface, REFIID riid, LPVOID *ppobj)
347 IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
349 return IDirectMusicSynth8Impl_QueryInterface(&This->IDirectMusicSynth8_iface, riid, ppobj);
352 static ULONG WINAPI DMSynthImpl_IKsControl_AddRef(IKsControl* iface)
354 IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
356 return IDirectMusicSynth8Impl_AddRef(&This->IDirectMusicSynth8_iface);
359 static ULONG WINAPI DMSynthImpl_IKsControl_Release(IKsControl* iface)
361 IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
363 return IDirectMusicSynth8Impl_Release(&This->IDirectMusicSynth8_iface);
366 static HRESULT WINAPI DMSynthImpl_IKsControl_KsProperty(IKsControl* iface, PKSPROPERTY Property, ULONG PropertyLength, LPVOID PropertyData,
367 ULONG DataLength, ULONG* BytesReturned)
369 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Property, PropertyLength, PropertyData, DataLength, BytesReturned);
371 return E_NOTIMPL;
374 static HRESULT WINAPI DMSynthImpl_IKsControl_KsMethod(IKsControl* iface, PKSMETHOD Method, ULONG MethodLength, LPVOID MethodData,
375 ULONG DataLength, ULONG* BytesReturned)
377 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Method, MethodLength, MethodData, DataLength, BytesReturned);
379 return E_NOTIMPL;
382 static HRESULT WINAPI DMSynthImpl_IKsControl_KsEvent(IKsControl* iface, PKSEVENT Event, ULONG EventLength, LPVOID EventData,
383 ULONG DataLength, ULONG* BytesReturned)
385 FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Event, EventLength, EventData, DataLength, BytesReturned);
387 return E_NOTIMPL;
391 static const IKsControlVtbl DMSynthImpl_IKsControl_Vtbl = {
392 DMSynthImpl_IKsControl_QueryInterface,
393 DMSynthImpl_IKsControl_AddRef,
394 DMSynthImpl_IKsControl_Release,
395 DMSynthImpl_IKsControl_KsProperty,
396 DMSynthImpl_IKsControl_KsMethod,
397 DMSynthImpl_IKsControl_KsEvent
400 /* for ClassFactory */
401 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter)
403 IDirectMusicSynth8Impl *obj;
405 TRACE("(%p,%p,%p)\n", lpcGUID, ppobj, pUnkOuter);
406 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynth8Impl));
407 if (NULL == obj) {
408 *ppobj = NULL;
409 return E_OUTOFMEMORY;
411 obj->IDirectMusicSynth8_iface.lpVtbl = &DirectMusicSynth8_Vtbl;
412 obj->IKsControl_iface.lpVtbl = &DMSynthImpl_IKsControl_Vtbl;
413 obj->ref = 0;
414 /* fill in caps */
415 obj->pCaps.dwSize = sizeof(DMUS_PORTCAPS);
416 obj->pCaps.dwFlags = DMUS_PC_DLS | DMUS_PC_SOFTWARESYNTH | DMUS_PC_DIRECTSOUND | DMUS_PC_DLS2 | DMUS_PC_AUDIOPATH | DMUS_PC_WAVE;
417 obj->pCaps.guidPort = CLSID_DirectMusicSynth;
418 obj->pCaps.dwClass = DMUS_PC_OUTPUTCLASS;
419 obj->pCaps.dwType = DMUS_PORT_USER_MODE_SYNTH;
420 obj->pCaps.dwMemorySize = DMUS_PC_SYSTEMMEMORY;
421 obj->pCaps.dwMaxChannelGroups = 1000;
422 obj->pCaps.dwMaxVoices = 1000;
423 obj->pCaps.dwMaxAudioChannels = 2;
424 obj->pCaps.dwEffectFlags = DMUS_EFFECT_REVERB;
425 MultiByteToWideChar (CP_ACP, 0, "Microsoft Synthesizer", -1, obj->pCaps.wszDescription, sizeof(obj->pCaps.wszDescription)/sizeof(WCHAR));
427 return IDirectMusicSynth8Impl_QueryInterface ((LPDIRECTMUSICSYNTH8)obj, lpcGUID, ppobj);