dmsynth: Add stubbed IKsControl interface to DirectMusicSynthSink object.
[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 #include "initguid.h"
23 #include "uuids.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(dmsynth);
26
27 static inline IDirectMusicSynthSinkImpl *impl_from_IDirectMusicSynthSink(IDirectMusicSynthSink *iface)
28 {
29     return CONTAINING_RECORD(iface, IDirectMusicSynthSinkImpl, IDirectMusicSynthSink_iface);
30 }
31
32 /* IDirectMusicSynthSinkImpl IUnknown part: */
33 static HRESULT WINAPI IDirectMusicSynthSinkImpl_QueryInterface(LPDIRECTMUSICSYNTHSINK iface, REFIID riid, LPVOID *ppobj)
34 {
35         IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
36         TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
37
38         if (IsEqualIID (riid, &IID_IUnknown) || 
39             IsEqualIID (riid, &IID_IDirectMusicSynthSink)) {
40                 IUnknown_AddRef(iface);
41                 *ppobj = This;
42                 return S_OK;
43         }
44     else if (IsEqualIID(riid, &IID_IKsControl)) {
45                 IUnknown_AddRef(iface);
46                 *ppobj = &This->IKsControl_iface;
47                 return S_OK;
48     }
49
50         WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
51         return E_NOINTERFACE;
52 }
53
54 static ULONG WINAPI IDirectMusicSynthSinkImpl_AddRef(LPDIRECTMUSICSYNTHSINK iface)
55 {
56         IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
57         ULONG refCount = InterlockedIncrement(&This->ref);
58
59         TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
60
61         DMSYNTH_LockModule();
62
63         return refCount;
64 }
65
66 static ULONG WINAPI IDirectMusicSynthSinkImpl_Release(LPDIRECTMUSICSYNTHSINK iface)
67 {
68         IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
69         ULONG refCount = InterlockedDecrement(&This->ref);
70
71         TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
72
73         if (!refCount) {
74                 if (This->latency_clock)
75                         IReferenceClock_Release(This->latency_clock);
76                 HeapFree(GetProcessHeap(), 0, This);
77         }
78
79         DMSYNTH_UnlockModule();
80
81         return refCount;
82 }
83
84 /* IDirectMusicSynthSinkImpl IDirectMusicSynthSink part: */
85 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Init(LPDIRECTMUSICSYNTHSINK iface, IDirectMusicSynth* synth)
86 {
87     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
88
89     FIXME("(%p)->(%p): stub\n", This, synth);
90
91     return S_OK;
92 }
93
94 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetMasterClock(LPDIRECTMUSICSYNTHSINK iface, IReferenceClock* clock)
95 {
96     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
97
98     FIXME("(%p)->(%p): stub\n", This, clock);
99
100     return S_OK;
101 }
102
103 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetLatencyClock(LPDIRECTMUSICSYNTHSINK iface, IReferenceClock** clock)
104 {
105     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
106
107     TRACE("(%p)->(%p)\n", iface, clock);
108
109     if (!clock)
110         return E_POINTER;
111
112     *clock = This->latency_clock;
113     IReferenceClock_AddRef(This->latency_clock);
114
115     return S_OK;
116 }
117
118 static HRESULT WINAPI IDirectMusicSynthSinkImpl_Activate(LPDIRECTMUSICSYNTHSINK iface, BOOL enable)
119 {
120     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
121
122     FIXME("(%p)->(%d): stub\n", This, enable);
123
124     return S_OK;
125 }
126
127 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SampleToRefTime(LPDIRECTMUSICSYNTHSINK iface, LONGLONG sample_time, REFERENCE_TIME* ref_time)
128 {
129     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
130
131     FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(sample_time), ref_time);
132
133     return S_OK;
134 }
135
136 static HRESULT WINAPI IDirectMusicSynthSinkImpl_RefTimeToSample(LPDIRECTMUSICSYNTHSINK iface, REFERENCE_TIME ref_time, LONGLONG* sample_time)
137 {
138     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
139
140     FIXME("(%p)->(0x%s, %p): stub\n", This, wine_dbgstr_longlong(ref_time), sample_time);
141
142     return S_OK;
143 }
144
145 static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetDirectSound(LPDIRECTMUSICSYNTHSINK iface, LPDIRECTSOUND dsound, LPDIRECTSOUNDBUFFER dsound_buffer)
146 {
147     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
148
149     FIXME("(%p)->(%p, %p): stub\n", This, dsound, dsound_buffer);
150
151     return S_OK;
152 }
153
154 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetDesiredBufferSize(LPDIRECTMUSICSYNTHSINK iface, LPDWORD buffer_size_in_samples)
155 {
156     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
157
158     FIXME("(%p)->(%p): stub\n", This, buffer_size_in_samples);
159
160     return S_OK;
161 }
162
163 static const IDirectMusicSynthSinkVtbl DirectMusicSynthSink_Vtbl = {
164         IDirectMusicSynthSinkImpl_QueryInterface,
165         IDirectMusicSynthSinkImpl_AddRef,
166         IDirectMusicSynthSinkImpl_Release,
167         IDirectMusicSynthSinkImpl_Init,
168         IDirectMusicSynthSinkImpl_SetMasterClock,
169         IDirectMusicSynthSinkImpl_GetLatencyClock,
170         IDirectMusicSynthSinkImpl_Activate,
171         IDirectMusicSynthSinkImpl_SampleToRefTime,
172         IDirectMusicSynthSinkImpl_RefTimeToSample,
173         IDirectMusicSynthSinkImpl_SetDirectSound,
174         IDirectMusicSynthSinkImpl_GetDesiredBufferSize
175 };
176
177 static inline IDirectMusicSynthSinkImpl *impl_from_IKsControl(IKsControl *iface)
178 {
179     return CONTAINING_RECORD(iface, IDirectMusicSynthSinkImpl, IKsControl_iface);
180 }
181
182 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_QueryInterface(IKsControl* iface, REFIID riid, LPVOID *ppobj)
183 {
184     IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
185
186     return IDirectMusicSynthSinkImpl_QueryInterface(&This->IDirectMusicSynthSink_iface, riid, ppobj);
187 }
188
189 static ULONG WINAPI DMSynthSinkImpl_IKsControl_AddRef(IKsControl* iface)
190 {
191     IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
192
193     return IDirectMusicSynthSinkImpl_AddRef(&This->IDirectMusicSynthSink_iface);
194 }
195
196 static ULONG WINAPI DMSynthSinkImpl_IKsControl_Release(IKsControl* iface)
197 {
198     IDirectMusicSynthSinkImpl *This = impl_from_IKsControl(iface);
199
200     return IDirectMusicSynthSinkImpl_Release(&This->IDirectMusicSynthSink_iface);
201 }
202
203 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsProperty(IKsControl* iface, PKSPROPERTY Property, ULONG PropertyLength, LPVOID PropertyData,
204                                                             ULONG DataLength, ULONG* BytesReturned)
205 {
206     FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Property, PropertyLength, PropertyData, DataLength, BytesReturned);
207
208     return E_NOTIMPL;
209 }
210
211 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsMethod(IKsControl* iface, PKSMETHOD Method, ULONG MethodLength, LPVOID MethodData,
212                                                           ULONG DataLength, ULONG* BytesReturned)
213 {
214     FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Method, MethodLength, MethodData, DataLength, BytesReturned);
215
216     return E_NOTIMPL;
217 }
218
219 static HRESULT WINAPI DMSynthSinkImpl_IKsControl_KsEvent(IKsControl* iface, PKSEVENT Event, ULONG EventLength, LPVOID EventData,
220                                                          ULONG DataLength, ULONG* BytesReturned)
221 {
222     FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Event, EventLength, EventData, DataLength, BytesReturned);
223
224     return E_NOTIMPL;
225 }
226
227
228 static const IKsControlVtbl DMSynthSinkImpl_IKsControl_Vtbl = {
229     DMSynthSinkImpl_IKsControl_QueryInterface,
230     DMSynthSinkImpl_IKsControl_AddRef,
231     DMSynthSinkImpl_IKsControl_Release,
232     DMSynthSinkImpl_IKsControl_KsProperty,
233     DMSynthSinkImpl_IKsControl_KsMethod,
234     DMSynthSinkImpl_IKsControl_KsEvent
235 };
236
237 /* for ClassFactory */
238 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthSinkImpl(LPCGUID riid, LPVOID* ret_iface, LPUNKNOWN unkouter)
239 {
240     IDirectMusicSynthSinkImpl *obj;
241     HRESULT hr;
242
243     TRACE("(%p,%p,%p)\n", riid, ret_iface, unkouter);
244
245     *ret_iface = NULL;
246
247     obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynthSinkImpl));
248     if (!obj)
249         return E_OUTOFMEMORY;
250
251     obj->IDirectMusicSynthSink_iface.lpVtbl = &DirectMusicSynthSink_Vtbl;
252     obj->IKsControl_iface.lpVtbl = &DMSynthSinkImpl_IKsControl_Vtbl;
253     obj->ref = 0;
254
255     hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&obj->latency_clock);
256     if (FAILED(hr))
257     {
258         HeapFree(GetProcessHeap(), 0, obj);
259         return hr;
260     }
261
262     hr = IDirectMusicSynthSinkImpl_QueryInterface((LPDIRECTMUSICSYNTHSINK)obj, riid, ret_iface);
263     if (FAILED(hr))
264     {
265         IReferenceClock_Release(obj->latency_clock);
266         HeapFree(GetProcessHeap(), 0, obj);
267         return hr;
268     }
269
270     return S_OK;
271 }