dmsynth: COM cleanup of IDirectMusicSynthSink and rename parameters.
[wine] / dlls / dmsynth / synth.c
1 /* IDirectMusicSynth8 Implementation
2  *
3  * Copyright (C) 2003-2004 Rok Mandeljc
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include "dmsynth_private.h"
21
22 WINE_DEFAULT_DEBUG_CHANNEL(dmsynth);
23
24 static inline IDirectMusicSynth8Impl *impl_from_IDirectMusicSynth8(IDirectMusicSynth8 *iface)
25 {
26     return CONTAINING_RECORD(iface, IDirectMusicSynth8Impl, IDirectMusicSynth8_iface);
27 }
28
29 /* IDirectMusicSynth8Impl IUnknown part: */
30 static HRESULT WINAPI IDirectMusicSynth8Impl_QueryInterface(LPDIRECTMUSICSYNTH8 iface, REFIID riid, LPVOID *ppobj)
31 {
32         IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
33
34         TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
35
36         if (IsEqualIID (riid, &IID_IUnknown) || 
37             IsEqualIID (riid, &IID_IDirectMusicSynth) ||
38             IsEqualIID (riid, &IID_IDirectMusicSynth8)) {
39                 IUnknown_AddRef(iface);
40                 *ppobj = This;
41                 return S_OK;
42         }
43         WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
44         return E_NOINTERFACE;
45 }
46
47 static ULONG WINAPI IDirectMusicSynth8Impl_AddRef(LPDIRECTMUSICSYNTH8 iface)
48 {
49         IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
50         ULONG refCount = InterlockedIncrement(&This->ref);
51
52         TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
53
54         DMSYNTH_LockModule();
55
56         return refCount;
57 }
58
59 static ULONG WINAPI IDirectMusicSynth8Impl_Release(LPDIRECTMUSICSYNTH8 iface)
60 {
61         IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
62         ULONG refCount = InterlockedDecrement(&This->ref);
63
64         TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
65
66         if (!refCount) {
67                 HeapFree(GetProcessHeap(), 0, This);
68         }
69
70         DMSYNTH_UnlockModule();
71         
72         return refCount;
73 }
74
75 /* IDirectMusicSynth8Impl IDirectMusicSynth part: */
76 static HRESULT WINAPI IDirectMusicSynth8Impl_Open(LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTPARAMS pPortParams)
77 {
78     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
79
80     FIXME("(%p)->(%p): stub\n", This, pPortParams);
81
82     return S_OK;
83 }
84
85 static HRESULT WINAPI IDirectMusicSynth8Impl_Close(LPDIRECTMUSICSYNTH8 iface)
86 {
87     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
88
89     FIXME("(%p)->(): stub\n", This);
90
91     return S_OK;
92 }
93
94 static HRESULT WINAPI IDirectMusicSynth8Impl_SetNumChannelGroups(LPDIRECTMUSICSYNTH8 iface, DWORD groups)
95 {
96     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
97
98     FIXME("(%p->(%d): stub\n", This, groups);
99
100     return S_OK;
101 }
102
103 static HRESULT WINAPI IDirectMusicSynth8Impl_Download(LPDIRECTMUSICSYNTH8 iface, LPHANDLE hDownload, LPVOID data, LPBOOL free)
104 {
105     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
106
107     FIXME("(%p)->(%p, %p, %p): stub\n", This, hDownload, data, free);
108
109     return S_OK;
110 }
111
112 static HRESULT WINAPI IDirectMusicSynth8Impl_Unload(LPDIRECTMUSICSYNTH8 iface, HANDLE hDownload, HRESULT (CALLBACK* lpFreeHandle)(HANDLE,HANDLE), HANDLE hUserData)
113 {
114     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
115
116     FIXME("(%p)->(%p, %p, %p): stub\n", This, hDownload, lpFreeHandle, hUserData);
117
118     return S_OK;
119 }
120
121 static HRESULT WINAPI IDirectMusicSynth8Impl_PlayBuffer(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME rt, LPBYTE buffer, DWORD size)
122 {
123     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
124
125     FIXME("(%p)->(0x%s, %p, %u): stub\n", This, wine_dbgstr_longlong(rt), buffer, size);
126
127     return S_OK;
128 }
129
130 static HRESULT WINAPI IDirectMusicSynth8Impl_GetRunningStats(LPDIRECTMUSICSYNTH8 iface, LPDMUS_SYNTHSTATS stats)
131 {
132     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
133
134     FIXME("(%p)->(%p): stub\n", This, stats);
135
136     return S_OK;
137 }
138
139 static HRESULT WINAPI IDirectMusicSynth8Impl_GetPortCaps(LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTCAPS caps)
140 {
141     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
142
143     TRACE("(%p)->(%p)\n", This, caps);
144
145     *caps = This->pCaps;
146
147     return S_OK;
148 }
149
150 static HRESULT WINAPI IDirectMusicSynth8Impl_SetMasterClock(LPDIRECTMUSICSYNTH8 iface, IReferenceClock* clock)
151 {
152     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
153
154     FIXME("(%p)->(%p): stub\n", This, clock);
155
156     return S_OK;
157 }
158
159 static HRESULT WINAPI IDirectMusicSynth8Impl_GetLatencyClock(LPDIRECTMUSICSYNTH8 iface, IReferenceClock** clock)
160 {
161     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
162
163     TRACE("(%p)->(%p)\n", This, clock);
164
165     *clock = This->pLatencyClock;
166
167     return S_OK;
168 }
169
170 static HRESULT WINAPI IDirectMusicSynth8Impl_Activate(LPDIRECTMUSICSYNTH8 iface, BOOL enable)
171 {
172     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
173
174     TRACE("(%p)->(%d)\n", This, enable);
175
176     This->fActive = enable;
177
178     return S_OK;
179 }
180
181 static HRESULT WINAPI IDirectMusicSynth8Impl_SetSynthSink(LPDIRECTMUSICSYNTH8 iface, IDirectMusicSynthSink* synth_sink)
182 {
183     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
184
185     TRACE("(%p)->(%p)\n", This, synth_sink);
186
187     This->pSynthSink = (IDirectMusicSynthSinkImpl*)synth_sink;
188
189     return S_OK;
190 }
191
192 static HRESULT WINAPI IDirectMusicSynth8Impl_Render(LPDIRECTMUSICSYNTH8 iface, short* buffer, DWORD length, LONGLONG position)
193 {
194     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
195
196     FIXME("(%p)->(%p, %d, 0x%s): stub\n", This, buffer, length, wine_dbgstr_longlong(position));
197
198     return S_OK;
199 }
200
201 static HRESULT WINAPI IDirectMusicSynth8Impl_SetChannelPriority(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, DWORD priority)
202 {
203     /* IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface); */
204
205     /* Silenced because of too many messages - 1000 groups * 16 channels ;=) */
206     /* FIXME("(%p)->(%ld, %ld, %ld): stub\n", This, channel_group, channel, priority); */
207
208     return S_OK;
209 }
210
211 static HRESULT WINAPI IDirectMusicSynth8Impl_GetChannelPriority(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, LPDWORD priority)
212 {
213     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
214
215     FIXME("(%p)->(%d, %d, %p): stub\n", This, channel_group, channel, priority);
216
217     return S_OK;
218 }
219
220 static HRESULT WINAPI IDirectMusicSynth8Impl_GetFormat(LPDIRECTMUSICSYNTH8 iface, LPWAVEFORMATEX wave_format, LPDWORD wave_format_size)
221 {
222     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
223
224     FIXME("(%p)->(%p, %p): stub\n", This, wave_format, wave_format_size);
225
226     return S_OK;
227 }
228
229 static HRESULT WINAPI IDirectMusicSynth8Impl_GetAppend(LPDIRECTMUSICSYNTH8 iface, DWORD* append)
230 {
231     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
232
233     FIXME("(%p)->(%p): stub\n", This, append);
234
235     return S_OK;
236 }
237
238 /* IDirectMusicSynth8Impl IDirectMusicSynth8 part: */
239 static HRESULT WINAPI IDirectMusicSynth8Impl_PlayVoice(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME ref_time, DWORD voice_id, DWORD channel_group, DWORD channel,
240                                                        DWORD dwDLId, LONG prPitch, LONG vrVolume, SAMPLE_TIME stVoiceStart, SAMPLE_TIME stLoopStart, SAMPLE_TIME stLoopEnd)
241 {
242     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
243
244     FIXME("(%p)->(0x%s, %d, %d, %d, %d, %i, %i,0x%s, 0x%s, 0x%s): stub\n",
245           This, wine_dbgstr_longlong(ref_time), voice_id, channel_group, channel, dwDLId, prPitch, vrVolume,
246           wine_dbgstr_longlong(stVoiceStart), wine_dbgstr_longlong(stLoopStart), wine_dbgstr_longlong(stLoopEnd));
247
248     return S_OK;
249 }
250
251 static HRESULT WINAPI IDirectMusicSynth8Impl_StopVoice(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME ref_time, DWORD voice_id)
252 {
253     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
254
255     FIXME("(%p)->(0x%s, %d): stub\n", This, wine_dbgstr_longlong(ref_time), voice_id);
256
257     return S_OK;
258 }
259
260 static HRESULT WINAPI IDirectMusicSynth8Impl_GetVoiceState(LPDIRECTMUSICSYNTH8 iface, DWORD dwVoice[], DWORD cbVoice, DMUS_VOICE_STATE dwVoiceState[])
261 {
262     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
263
264     FIXME("(%p)->(%p, %d, %p): stub\n", This, dwVoice, cbVoice, dwVoiceState);
265
266     return S_OK;
267 }
268
269 static HRESULT WINAPI IDirectMusicSynth8Impl_Refresh(LPDIRECTMUSICSYNTH8 iface, DWORD download_id, DWORD flags)
270 {
271     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
272
273     FIXME("(%p)->(%d, %d): stub\n", This, download_id, flags);
274
275     return S_OK;
276 }
277
278 static HRESULT WINAPI IDirectMusicSynth8Impl_AssignChannelToBuses(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, LPDWORD pdwBuses, DWORD cBuses)
279 {
280     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
281
282     FIXME("(%p)->(%d, %d, %p, %d): stub\n", This, channel_group, channel, pdwBuses, cBuses);
283
284     return S_OK;
285 }
286
287 static const IDirectMusicSynth8Vtbl DirectMusicSynth8_Vtbl = {
288         IDirectMusicSynth8Impl_QueryInterface,
289         IDirectMusicSynth8Impl_AddRef,
290         IDirectMusicSynth8Impl_Release,
291         IDirectMusicSynth8Impl_Open,
292         IDirectMusicSynth8Impl_Close,
293         IDirectMusicSynth8Impl_SetNumChannelGroups,
294         IDirectMusicSynth8Impl_Download,
295         IDirectMusicSynth8Impl_Unload,
296         IDirectMusicSynth8Impl_PlayBuffer,
297         IDirectMusicSynth8Impl_GetRunningStats,
298         IDirectMusicSynth8Impl_GetPortCaps,
299         IDirectMusicSynth8Impl_SetMasterClock,
300         IDirectMusicSynth8Impl_GetLatencyClock,
301         IDirectMusicSynth8Impl_Activate,
302         IDirectMusicSynth8Impl_SetSynthSink,
303         IDirectMusicSynth8Impl_Render,
304         IDirectMusicSynth8Impl_SetChannelPriority,
305         IDirectMusicSynth8Impl_GetChannelPriority,
306         IDirectMusicSynth8Impl_GetFormat,
307         IDirectMusicSynth8Impl_GetAppend,
308         IDirectMusicSynth8Impl_PlayVoice,
309         IDirectMusicSynth8Impl_StopVoice,
310         IDirectMusicSynth8Impl_GetVoiceState,
311         IDirectMusicSynth8Impl_Refresh,
312         IDirectMusicSynth8Impl_AssignChannelToBuses
313 };
314
315 /* for ClassFactory */
316 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter)
317 {
318         IDirectMusicSynth8Impl *obj;
319         
320         TRACE("(%p,%p,%p)\n", lpcGUID, ppobj, pUnkOuter);
321         obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynth8Impl));
322         if (NULL == obj) {
323                 *ppobj = NULL;
324                 return E_OUTOFMEMORY;
325         }
326         obj->IDirectMusicSynth8_iface.lpVtbl = &DirectMusicSynth8_Vtbl;
327         obj->ref = 0;
328         /* fill in caps */
329         obj->pCaps.dwSize = sizeof(DMUS_PORTCAPS);
330         obj->pCaps.dwFlags = DMUS_PC_DLS | DMUS_PC_SOFTWARESYNTH | DMUS_PC_DIRECTSOUND | DMUS_PC_DLS2 | DMUS_PC_AUDIOPATH | DMUS_PC_WAVE;
331         obj->pCaps.guidPort = CLSID_DirectMusicSynth;
332         obj->pCaps.dwClass = DMUS_PC_OUTPUTCLASS;
333         obj->pCaps.dwType = DMUS_PORT_USER_MODE_SYNTH;
334         obj->pCaps.dwMemorySize = DMUS_PC_SYSTEMMEMORY;
335         obj->pCaps.dwMaxChannelGroups = 1000;
336         obj->pCaps.dwMaxVoices = 1000;
337         obj->pCaps.dwMaxAudioChannels = 2;
338         obj->pCaps.dwEffectFlags = DMUS_EFFECT_REVERB;
339         MultiByteToWideChar (CP_ACP, 0, "Microsoft Synthesizer", -1, obj->pCaps.wszDescription, sizeof(obj->pCaps.wszDescription)/sizeof(WCHAR));
340         /* assign latency clock */
341         /*DMUSIC_CreateReferenceClockImpl (&IID_IReferenceClock, (LPVOID*)&This->pLatencyClock, NULL); */
342
343         return IDirectMusicSynth8Impl_QueryInterface ((LPDIRECTMUSICSYNTH8)obj, lpcGUID, ppobj);
344 }