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