dmusic: COM cleanup of IDirectMusic8.
[wine] / dlls / dmsynth / synthsink.c
1 /*
2  * IDirectMusicSynthSink Implementation
3  *
4  * Copyright (C) 2003-2004 Rok Mandeljc
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "dmsynth_private.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(dmsynth);
24
25 static inline IDirectMusicSynthSinkImpl *impl_from_IDirectMusicSynthSink(IDirectMusicSynthSink *iface)
26 {
27     return CONTAINING_RECORD(iface, IDirectMusicSynthSinkImpl, IDirectMusicSynthSink_iface);
28 }
29
30 /* IDirectMusicSynthSinkImpl IUnknown part: */
31 static HRESULT WINAPI IDirectMusicSynthSinkImpl_QueryInterface(LPDIRECTMUSICSYNTHSINK iface, REFIID riid, LPVOID *ppobj)
32 {
33         IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
34         TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
35
36         if (IsEqualIID (riid, &IID_IUnknown) || 
37             IsEqualIID (riid, &IID_IDirectMusicSynthSink)) {
38                 IUnknown_AddRef(iface);
39                 *ppobj = This;
40                 return S_OK;
41         }
42         WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
43         return E_NOINTERFACE;
44 }
45
46 static ULONG WINAPI IDirectMusicSynthSinkImpl_AddRef(LPDIRECTMUSICSYNTHSINK iface)
47 {
48         IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
49         ULONG refCount = InterlockedIncrement(&This->ref);
50
51         TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
52
53         DMSYNTH_LockModule();
54
55         return refCount;
56 }
57
58 static ULONG WINAPI IDirectMusicSynthSinkImpl_Release(LPDIRECTMUSICSYNTHSINK iface)
59 {
60         IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
61         ULONG refCount = InterlockedDecrement(&This->ref);
62
63         TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
64
65         if (!refCount) {
66                 HeapFree(GetProcessHeap(), 0, This);
67         }
68
69         DMSYNTH_UnlockModule();
70
71         return refCount;
72 }
73
74 /* IDirectMusicSynthSinkImpl IDirectMusicSynthSink part: */
75 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Init(LPDIRECTMUSICSYNTHSINK iface, IDirectMusicSynth* synth)
76 {
77     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
78
79     FIXME("(%p)->(%p): stub\n", This, synth);
80
81     return S_OK;
82 }
83
84 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetMasterClock(LPDIRECTMUSICSYNTHSINK iface, IReferenceClock* clock)
85 {
86     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
87
88     FIXME("(%p)->(%p): stub\n", This, clock);
89
90     return S_OK;
91 }
92
93 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetLatencyClock(LPDIRECTMUSICSYNTHSINK iface, IReferenceClock** clock)
94 {
95     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
96
97     FIXME("(%p)->(%p): stub\n", This, clock);
98
99     return S_OK;
100 }
101
102 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Activate(LPDIRECTMUSICSYNTHSINK iface, BOOL enable)
103 {
104     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
105
106     FIXME("(%p)->(%d): stub\n", This, enable);
107
108     return S_OK;
109 }
110
111 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SampleToRefTime(LPDIRECTMUSICSYNTHSINK iface, LONGLONG sample_time, REFERENCE_TIME* ref_time)
112 {
113     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
114
115     FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(sample_time), ref_time);
116
117     return S_OK;
118 }
119
120 static HRESULT WINAPI IDirectMusicSynthSinkImpl_RefTimeToSample(LPDIRECTMUSICSYNTHSINK iface, REFERENCE_TIME ref_time, LONGLONG* sample_time)
121 {
122     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
123
124     FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(ref_time), sample_time);
125
126     return S_OK;
127 }
128
129 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetDirectSound(LPDIRECTMUSICSYNTHSINK iface, LPDIRECTSOUND dsound, LPDIRECTSOUNDBUFFER dsound_buffer)
130 {
131     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
132
133     FIXME("(%p)->(%p, %p): stub\n", This, dsound, dsound_buffer);
134
135     return S_OK;
136 }
137
138 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetDesiredBufferSize(LPDIRECTMUSICSYNTHSINK iface, LPDWORD buffer_size_in_samples)
139 {
140     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
141
142     FIXME("(%p)->(%p): stub\n", This, buffer_size_in_samples);
143
144     return S_OK;
145 }
146
147 static const IDirectMusicSynthSinkVtbl DirectMusicSynthSink_Vtbl = {
148         IDirectMusicSynthSinkImpl_QueryInterface,
149         IDirectMusicSynthSinkImpl_AddRef,
150         IDirectMusicSynthSinkImpl_Release,
151         IDirectMusicSynthSinkImpl_Init,
152         IDirectMusicSynthSinkImpl_SetMasterClock,
153         IDirectMusicSynthSinkImpl_GetLatencyClock,
154         IDirectMusicSynthSinkImpl_Activate,
155         IDirectMusicSynthSinkImpl_SampleToRefTime,
156         IDirectMusicSynthSinkImpl_RefTimeToSample,
157         IDirectMusicSynthSinkImpl_SetDirectSound,
158         IDirectMusicSynthSinkImpl_GetDesiredBufferSize
159 };
160
161 /* for ClassFactory */
162 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthSinkImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
163         IDirectMusicSynthSinkImpl *obj;
164         
165         TRACE("(%p,%p,%p)\n", lpcGUID, ppobj, pUnkOuter);
166         obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynthSinkImpl));
167         if (NULL == obj) {
168                 *ppobj = NULL;
169                 return E_OUTOFMEMORY;
170         }
171         obj->IDirectMusicSynthSink_iface.lpVtbl = &DirectMusicSynthSink_Vtbl;
172         obj->ref = 0;
173         
174         return IDirectMusicSynthSinkImpl_QueryInterface((LPDIRECTMUSICSYNTHSINK)obj, lpcGUID, ppobj);
175 }