strmbase: do not lock in BaseOutputPinImpl_GetDeliveryBuffer the MemInputPin will...
[wine] / dlls / dmsynth / synth.c
1 /*
2  * IDirectMusicSynth8 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 #define COBJMACROS
22
23 #include "objbase.h"
24 #include "initguid.h"
25 #include "dmksctrl.h"
26
27 #include "dmsynth_private.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(dmsynth);
30
31 static inline IDirectMusicSynth8Impl *impl_from_IDirectMusicSynth8(IDirectMusicSynth8 *iface)
32 {
33     return CONTAINING_RECORD(iface, IDirectMusicSynth8Impl, IDirectMusicSynth8_iface);
34 }
35
36 /* IDirectMusicSynth8Impl IUnknown part: */
37 static HRESULT WINAPI IDirectMusicSynth8Impl_QueryInterface(LPDIRECTMUSICSYNTH8 iface, REFIID riid, LPVOID *ret_iface)
38 {
39     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
40
41     TRACE("(%p)->(%s, %p)\n", iface, debugstr_dmguid(riid), ret_iface);
42
43     if (IsEqualIID (riid, &IID_IUnknown) ||
44         IsEqualIID (riid, &IID_IDirectMusicSynth) ||
45         IsEqualIID (riid, &IID_IDirectMusicSynth8))
46     {
47         IUnknown_AddRef(iface);
48         *ret_iface = iface;
49         return S_OK;
50     }
51     else if (IsEqualIID(riid, &IID_IKsControl))
52     {
53         IUnknown_AddRef(iface);
54         *ret_iface = &This->IKsControl_iface;
55         return S_OK;
56     }
57
58     *ret_iface = NULL;
59
60     WARN("(%p)->(%s, %p): not found\n", iface, debugstr_dmguid(riid), ret_iface);
61
62     return E_NOINTERFACE;
63 }
64
65 static ULONG WINAPI IDirectMusicSynth8Impl_AddRef(LPDIRECTMUSICSYNTH8 iface)
66 {
67     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
68     ULONG ref = InterlockedIncrement(&This->ref);
69
70     TRACE("(%p)->(): new ref = %u\n", This, ref);
71
72     DMSYNTH_LockModule();
73
74     return ref;
75 }
76
77 static ULONG WINAPI IDirectMusicSynth8Impl_Release(LPDIRECTMUSICSYNTH8 iface)
78 {
79     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
80     ULONG ref = InterlockedDecrement(&This->ref);
81
82     TRACE("(%p)->(): new ref = %u\n", This, ref);
83
84     if (!ref) {
85         if (This->pLatencyClock)
86             IReferenceClock_Release(This->pLatencyClock);
87         HeapFree(GetProcessHeap(), 0, This);
88     }
89
90     DMSYNTH_UnlockModule();
91
92     return ref;
93 }
94
95 /* IDirectMusicSynth8Impl IDirectMusicSynth part: */
96 static HRESULT WINAPI IDirectMusicSynth8Impl_Open(LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTPARAMS pPortParams)
97 {
98     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
99
100     FIXME("(%p)->(%p): stub\n", This, pPortParams);
101
102     return S_OK;
103 }
104
105 static HRESULT WINAPI IDirectMusicSynth8Impl_Close(LPDIRECTMUSICSYNTH8 iface)
106 {
107     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
108
109     FIXME("(%p)->(): stub\n", This);
110
111     return S_OK;
112 }
113
114 static HRESULT WINAPI IDirectMusicSynth8Impl_SetNumChannelGroups(LPDIRECTMUSICSYNTH8 iface, DWORD groups)
115 {
116     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
117
118     FIXME("(%p->(%d): stub\n", This, groups);
119
120     return S_OK;
121 }
122
123 static HRESULT WINAPI IDirectMusicSynth8Impl_Download(LPDIRECTMUSICSYNTH8 iface, LPHANDLE hDownload, LPVOID data, LPBOOL free)
124 {
125     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
126
127     FIXME("(%p)->(%p, %p, %p): stub\n", This, hDownload, data, free);
128
129     return S_OK;
130 }
131
132 static HRESULT WINAPI IDirectMusicSynth8Impl_Unload(LPDIRECTMUSICSYNTH8 iface, HANDLE hDownload, HRESULT (CALLBACK* lpFreeHandle)(HANDLE,HANDLE), HANDLE hUserData)
133 {
134     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
135
136     FIXME("(%p)->(%p, %p, %p): stub\n", This, hDownload, lpFreeHandle, hUserData);
137
138     return S_OK;
139 }
140
141 static HRESULT WINAPI IDirectMusicSynth8Impl_PlayBuffer(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME rt, LPBYTE buffer, DWORD size)
142 {
143     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
144
145     FIXME("(%p)->(0x%s, %p, %u): stub\n", This, wine_dbgstr_longlong(rt), buffer, size);
146
147     return S_OK;
148 }
149
150 static HRESULT WINAPI IDirectMusicSynth8Impl_GetRunningStats(LPDIRECTMUSICSYNTH8 iface, LPDMUS_SYNTHSTATS stats)
151 {
152     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
153
154     FIXME("(%p)->(%p): stub\n", This, stats);
155
156     return S_OK;
157 }
158
159 static HRESULT WINAPI IDirectMusicSynth8Impl_GetPortCaps(LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTCAPS caps)
160 {
161     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
162
163     TRACE("(%p)->(%p)\n", This, caps);
164
165     *caps = This->pCaps;
166
167     return S_OK;
168 }
169
170 static HRESULT WINAPI IDirectMusicSynth8Impl_SetMasterClock(LPDIRECTMUSICSYNTH8 iface, IReferenceClock* clock)
171 {
172     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
173
174     FIXME("(%p)->(%p): stub\n", This, clock);
175
176     return S_OK;
177 }
178
179 static HRESULT WINAPI IDirectMusicSynth8Impl_GetLatencyClock(LPDIRECTMUSICSYNTH8 iface, IReferenceClock** clock)
180 {
181     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
182
183     TRACE("(%p)->(%p)\n", iface, clock);
184
185     if (!clock)
186         return E_POINTER;
187
188     if (!This->pSynthSink)
189         return DMUS_E_NOSYNTHSINK;
190
191     *clock = This->pLatencyClock;
192     IReferenceClock_AddRef(This->pLatencyClock);
193
194     return S_OK;
195 }
196
197 static HRESULT WINAPI IDirectMusicSynth8Impl_Activate(LPDIRECTMUSICSYNTH8 iface, BOOL enable)
198 {
199     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
200
201     TRACE("(%p)->(%d)\n", This, enable);
202
203     This->fActive = enable;
204
205     return S_OK;
206 }
207
208 static HRESULT WINAPI IDirectMusicSynth8Impl_SetSynthSink(LPDIRECTMUSICSYNTH8 iface, IDirectMusicSynthSink* synth_sink)
209 {
210     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
211
212     TRACE("(%p)->(%p)\n", iface, synth_sink);
213
214     This->pSynthSink = (IDirectMusicSynthSinkImpl*)synth_sink;
215
216     if (synth_sink)
217         return IDirectMusicSynthSink_GetLatencyClock(synth_sink, &This->pLatencyClock);
218
219     return S_OK;
220 }
221
222 static HRESULT WINAPI IDirectMusicSynth8Impl_Render(LPDIRECTMUSICSYNTH8 iface, short* buffer, DWORD length, LONGLONG position)
223 {
224     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
225
226     FIXME("(%p)->(%p, %d, 0x%s): stub\n", This, buffer, length, wine_dbgstr_longlong(position));
227
228     return S_OK;
229 }
230
231 static HRESULT WINAPI IDirectMusicSynth8Impl_SetChannelPriority(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, DWORD priority)
232 {
233     /* IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface); */
234
235     /* Silenced because of too many messages - 1000 groups * 16 channels ;=) */
236     /* FIXME("(%p)->(%ld, %ld, %ld): stub\n", This, channel_group, channel, priority); */
237
238     return S_OK;
239 }
240
241 static HRESULT WINAPI IDirectMusicSynth8Impl_GetChannelPriority(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, LPDWORD priority)
242 {
243     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
244
245     FIXME("(%p)->(%d, %d, %p): stub\n", This, channel_group, channel, priority);
246
247     return S_OK;
248 }
249
250 static HRESULT WINAPI IDirectMusicSynth8Impl_GetFormat(LPDIRECTMUSICSYNTH8 iface, LPWAVEFORMATEX wave_format, LPDWORD wave_format_size)
251 {
252     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
253
254     FIXME("(%p)->(%p, %p): stub\n", This, wave_format, wave_format_size);
255
256     return S_OK;
257 }
258
259 static HRESULT WINAPI IDirectMusicSynth8Impl_GetAppend(LPDIRECTMUSICSYNTH8 iface, DWORD* append)
260 {
261     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
262
263     FIXME("(%p)->(%p): stub\n", This, append);
264
265     return S_OK;
266 }
267
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)
271 {
272     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
273
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));
277
278     return S_OK;
279 }
280
281 static HRESULT WINAPI IDirectMusicSynth8Impl_StopVoice(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME ref_time, DWORD voice_id)
282 {
283     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
284
285     FIXME("(%p)->(0x%s, %d): stub\n", This, wine_dbgstr_longlong(ref_time), voice_id);
286
287     return S_OK;
288 }
289
290 static HRESULT WINAPI IDirectMusicSynth8Impl_GetVoiceState(LPDIRECTMUSICSYNTH8 iface, DWORD dwVoice[], DWORD cbVoice, DMUS_VOICE_STATE dwVoiceState[])
291 {
292     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
293
294     FIXME("(%p)->(%p, %d, %p): stub\n", This, dwVoice, cbVoice, dwVoiceState);
295
296     return S_OK;
297 }
298
299 static HRESULT WINAPI IDirectMusicSynth8Impl_Refresh(LPDIRECTMUSICSYNTH8 iface, DWORD download_id, DWORD flags)
300 {
301     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
302
303     FIXME("(%p)->(%d, %d): stub\n", This, download_id, flags);
304
305     return S_OK;
306 }
307
308 static HRESULT WINAPI IDirectMusicSynth8Impl_AssignChannelToBuses(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, LPDWORD pdwBuses, DWORD cBuses)
309 {
310     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
311
312     FIXME("(%p)->(%d, %d, %p, %d): stub\n", This, channel_group, channel, pdwBuses, cBuses);
313
314     return S_OK;
315 }
316
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
343 };
344
345 static inline IDirectMusicSynth8Impl *impl_from_IKsControl(IKsControl *iface)
346 {
347     return CONTAINING_RECORD(iface, IDirectMusicSynth8Impl, IKsControl_iface);
348 }
349
350 static HRESULT WINAPI DMSynthImpl_IKsControl_QueryInterface(IKsControl* iface, REFIID riid, LPVOID *ppobj)
351 {
352     IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
353
354     return IDirectMusicSynth8Impl_QueryInterface(&This->IDirectMusicSynth8_iface, riid, ppobj);
355 }
356
357 static ULONG WINAPI DMSynthImpl_IKsControl_AddRef(IKsControl* iface)
358 {
359     IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
360
361     return IDirectMusicSynth8Impl_AddRef(&This->IDirectMusicSynth8_iface);
362 }
363
364 static ULONG WINAPI DMSynthImpl_IKsControl_Release(IKsControl* iface)
365 {
366     IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
367
368     return IDirectMusicSynth8Impl_Release(&This->IDirectMusicSynth8_iface);
369 }
370
371 static HRESULT WINAPI DMSynthImpl_IKsControl_KsProperty(IKsControl* iface, PKSPROPERTY Property, ULONG PropertyLength, LPVOID PropertyData,
372                                                         ULONG DataLength, ULONG* BytesReturned)
373 {
374     FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Property, PropertyLength, PropertyData, DataLength, BytesReturned);
375
376     return E_NOTIMPL;
377 }
378
379 static HRESULT WINAPI DMSynthImpl_IKsControl_KsMethod(IKsControl* iface, PKSMETHOD Method, ULONG MethodLength, LPVOID MethodData,
380                                                       ULONG DataLength, ULONG* BytesReturned)
381 {
382     FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Method, MethodLength, MethodData, DataLength, BytesReturned);
383
384     return E_NOTIMPL;
385 }
386
387 static HRESULT WINAPI DMSynthImpl_IKsControl_KsEvent(IKsControl* iface, PKSEVENT Event, ULONG EventLength, LPVOID EventData,
388                                                      ULONG DataLength, ULONG* BytesReturned)
389 {
390     FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Event, EventLength, EventData, DataLength, BytesReturned);
391
392     return E_NOTIMPL;
393 }
394
395
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
403 };
404
405 /* for ClassFactory */
406 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter)
407 {
408         IDirectMusicSynth8Impl *obj;
409         
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;
415         }
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));
431
432         return IDirectMusicSynth8Impl_QueryInterface ((LPDIRECTMUSICSYNTH8)obj, lpcGUID, ppobj);
433 }