winmm: Avoid TRUE FALSE conditional expressions.
[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     DMUS_DOWNLOADINFO* info = (DMUS_DOWNLOADINFO*)data;
127
128     FIXME("(%p)->(%p, %p, %p): stub\n", This, hDownload, data, free);
129
130     if (!hDownload || !data || !free)
131         return E_POINTER;
132
133     if (TRACE_ON(dmsynth))
134     {
135         TRACE("Dump DMUS_DOWNLOADINFO struct:\n");
136         TRACE(" - dwDLType                = %u\n", info->dwDLType);
137         TRACE(" - dwDLId                  = %u\n", info->dwDLId);
138         TRACE(" - dwNumOffsetTableEntries = %u\n", info->dwNumOffsetTableEntries);
139         TRACE(" - cbSize                  = %u\n", info->cbSize);
140     }
141
142     if (info->dwDLType == DMUS_DOWNLOADINFO_INSTRUMENT)
143     {
144         FIXME("Download type DMUS_DOWNLOADINFO_INSTRUMENT not yet supported\n");
145     }
146     else if (info->dwDLType == DMUS_DOWNLOADINFO_WAVE)
147     {
148         FIXME("Download type DMUS_DOWNLOADINFO_WAVE not yet supported\n");
149     }
150     else if (info->dwDLType == DMUS_DOWNLOADINFO_INSTRUMENT2)
151     {
152         FIXME("Download type DMUS_DOWNLOADINFO_INSTRUMENT2 not yet supported\n");
153     }
154     else if (info->dwDLType == DMUS_DOWNLOADINFO_WAVEARTICULATION)
155     {
156         FIXME("Download type DMUS_DOWNLOADINFO_WAVEARTICULATION not yet supported\n");
157     }
158     else if (info->dwDLType == DMUS_DOWNLOADINFO_STREAMINGWAVE)
159     {
160         FIXME("Download type DMUS_DOWNLOADINFO_STREAMINGWAVE not yet supported\n");
161     }
162     else if (info->dwDLType == DMUS_DOWNLOADINFO_ONESHOTWAVE)
163     {
164         FIXME("Download type DMUS_DOWNLOADINFO_ONESHOTWAVE not yet supported\n");
165     }
166     else
167     {
168         WARN("Unknown download type %u\n", info->dwDLType);
169         return DMUS_E_UNKNOWNDOWNLOAD;
170     }
171
172     return S_OK;
173 }
174
175 static HRESULT WINAPI IDirectMusicSynth8Impl_Unload(LPDIRECTMUSICSYNTH8 iface, HANDLE hDownload, HRESULT (CALLBACK* lpFreeHandle)(HANDLE,HANDLE), HANDLE hUserData)
176 {
177     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
178
179     FIXME("(%p)->(%p, %p, %p): stub\n", This, hDownload, lpFreeHandle, hUserData);
180
181     return S_OK;
182 }
183
184 static HRESULT WINAPI IDirectMusicSynth8Impl_PlayBuffer(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME rt, LPBYTE buffer, DWORD size)
185 {
186     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
187
188     FIXME("(%p)->(0x%s, %p, %u): stub\n", This, wine_dbgstr_longlong(rt), buffer, size);
189
190     return S_OK;
191 }
192
193 static HRESULT WINAPI IDirectMusicSynth8Impl_GetRunningStats(LPDIRECTMUSICSYNTH8 iface, LPDMUS_SYNTHSTATS stats)
194 {
195     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
196
197     FIXME("(%p)->(%p): stub\n", This, stats);
198
199     return S_OK;
200 }
201
202 static HRESULT WINAPI IDirectMusicSynth8Impl_GetPortCaps(LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTCAPS caps)
203 {
204     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
205
206     TRACE("(%p)->(%p)\n", This, caps);
207
208     *caps = This->pCaps;
209
210     return S_OK;
211 }
212
213 static HRESULT WINAPI IDirectMusicSynth8Impl_SetMasterClock(LPDIRECTMUSICSYNTH8 iface, IReferenceClock* clock)
214 {
215     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
216
217     FIXME("(%p)->(%p): stub\n", This, clock);
218
219     return S_OK;
220 }
221
222 static HRESULT WINAPI IDirectMusicSynth8Impl_GetLatencyClock(LPDIRECTMUSICSYNTH8 iface, IReferenceClock** clock)
223 {
224     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
225
226     TRACE("(%p)->(%p)\n", iface, clock);
227
228     if (!clock)
229         return E_POINTER;
230
231     if (!This->pSynthSink)
232         return DMUS_E_NOSYNTHSINK;
233
234     *clock = This->pLatencyClock;
235     IReferenceClock_AddRef(This->pLatencyClock);
236
237     return S_OK;
238 }
239
240 static HRESULT WINAPI IDirectMusicSynth8Impl_Activate(LPDIRECTMUSICSYNTH8 iface, BOOL enable)
241 {
242     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
243
244     TRACE("(%p)->(%d)\n", This, enable);
245
246     This->fActive = enable;
247
248     return S_OK;
249 }
250
251 static HRESULT WINAPI IDirectMusicSynth8Impl_SetSynthSink(LPDIRECTMUSICSYNTH8 iface, IDirectMusicSynthSink* synth_sink)
252 {
253     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
254
255     TRACE("(%p)->(%p)\n", iface, synth_sink);
256
257     This->pSynthSink = (IDirectMusicSynthSinkImpl*)synth_sink;
258
259     if (synth_sink)
260         return IDirectMusicSynthSink_GetLatencyClock(synth_sink, &This->pLatencyClock);
261
262     return S_OK;
263 }
264
265 static HRESULT WINAPI IDirectMusicSynth8Impl_Render(LPDIRECTMUSICSYNTH8 iface, short* buffer, DWORD length, LONGLONG position)
266 {
267     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
268
269     FIXME("(%p)->(%p, %d, 0x%s): stub\n", This, buffer, length, wine_dbgstr_longlong(position));
270
271     return S_OK;
272 }
273
274 static HRESULT WINAPI IDirectMusicSynth8Impl_SetChannelPriority(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, DWORD priority)
275 {
276     /* IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface); */
277
278     /* Silenced because of too many messages - 1000 groups * 16 channels ;=) */
279     /* FIXME("(%p)->(%ld, %ld, %ld): stub\n", This, channel_group, channel, priority); */
280
281     return S_OK;
282 }
283
284 static HRESULT WINAPI IDirectMusicSynth8Impl_GetChannelPriority(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, LPDWORD priority)
285 {
286     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
287
288     FIXME("(%p)->(%d, %d, %p): stub\n", This, channel_group, channel, priority);
289
290     return S_OK;
291 }
292
293 static HRESULT WINAPI IDirectMusicSynth8Impl_GetFormat(LPDIRECTMUSICSYNTH8 iface, LPWAVEFORMATEX wave_format, LPDWORD wave_format_size)
294 {
295     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
296
297     FIXME("(%p)->(%p, %p): stub\n", This, wave_format, wave_format_size);
298
299     return S_OK;
300 }
301
302 static HRESULT WINAPI IDirectMusicSynth8Impl_GetAppend(LPDIRECTMUSICSYNTH8 iface, DWORD* append)
303 {
304     TRACE("(%p)->(%p)\n", iface, append);
305
306     /* We don't need extra space at the end of buffers passed to us for now */
307     *append = 0;
308
309     return S_OK;
310 }
311
312 /* IDirectMusicSynth8Impl IDirectMusicSynth8 part: */
313 static HRESULT WINAPI IDirectMusicSynth8Impl_PlayVoice(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME ref_time, DWORD voice_id, DWORD channel_group, DWORD channel,
314                                                        DWORD dwDLId, LONG prPitch, LONG vrVolume, SAMPLE_TIME stVoiceStart, SAMPLE_TIME stLoopStart, SAMPLE_TIME stLoopEnd)
315 {
316     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
317
318     FIXME("(%p)->(0x%s, %d, %d, %d, %d, %i, %i,0x%s, 0x%s, 0x%s): stub\n",
319           This, wine_dbgstr_longlong(ref_time), voice_id, channel_group, channel, dwDLId, prPitch, vrVolume,
320           wine_dbgstr_longlong(stVoiceStart), wine_dbgstr_longlong(stLoopStart), wine_dbgstr_longlong(stLoopEnd));
321
322     return S_OK;
323 }
324
325 static HRESULT WINAPI IDirectMusicSynth8Impl_StopVoice(LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME ref_time, DWORD voice_id)
326 {
327     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
328
329     FIXME("(%p)->(0x%s, %d): stub\n", This, wine_dbgstr_longlong(ref_time), voice_id);
330
331     return S_OK;
332 }
333
334 static HRESULT WINAPI IDirectMusicSynth8Impl_GetVoiceState(LPDIRECTMUSICSYNTH8 iface, DWORD dwVoice[], DWORD cbVoice, DMUS_VOICE_STATE dwVoiceState[])
335 {
336     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
337
338     FIXME("(%p)->(%p, %d, %p): stub\n", This, dwVoice, cbVoice, dwVoiceState);
339
340     return S_OK;
341 }
342
343 static HRESULT WINAPI IDirectMusicSynth8Impl_Refresh(LPDIRECTMUSICSYNTH8 iface, DWORD download_id, DWORD flags)
344 {
345     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
346
347     FIXME("(%p)->(%d, %d): stub\n", This, download_id, flags);
348
349     return S_OK;
350 }
351
352 static HRESULT WINAPI IDirectMusicSynth8Impl_AssignChannelToBuses(LPDIRECTMUSICSYNTH8 iface, DWORD channel_group, DWORD channel, LPDWORD pdwBuses, DWORD cBuses)
353 {
354     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
355
356     FIXME("(%p)->(%d, %d, %p, %d): stub\n", This, channel_group, channel, pdwBuses, cBuses);
357
358     return S_OK;
359 }
360
361 static const IDirectMusicSynth8Vtbl DirectMusicSynth8_Vtbl = {
362         IDirectMusicSynth8Impl_QueryInterface,
363         IDirectMusicSynth8Impl_AddRef,
364         IDirectMusicSynth8Impl_Release,
365         IDirectMusicSynth8Impl_Open,
366         IDirectMusicSynth8Impl_Close,
367         IDirectMusicSynth8Impl_SetNumChannelGroups,
368         IDirectMusicSynth8Impl_Download,
369         IDirectMusicSynth8Impl_Unload,
370         IDirectMusicSynth8Impl_PlayBuffer,
371         IDirectMusicSynth8Impl_GetRunningStats,
372         IDirectMusicSynth8Impl_GetPortCaps,
373         IDirectMusicSynth8Impl_SetMasterClock,
374         IDirectMusicSynth8Impl_GetLatencyClock,
375         IDirectMusicSynth8Impl_Activate,
376         IDirectMusicSynth8Impl_SetSynthSink,
377         IDirectMusicSynth8Impl_Render,
378         IDirectMusicSynth8Impl_SetChannelPriority,
379         IDirectMusicSynth8Impl_GetChannelPriority,
380         IDirectMusicSynth8Impl_GetFormat,
381         IDirectMusicSynth8Impl_GetAppend,
382         IDirectMusicSynth8Impl_PlayVoice,
383         IDirectMusicSynth8Impl_StopVoice,
384         IDirectMusicSynth8Impl_GetVoiceState,
385         IDirectMusicSynth8Impl_Refresh,
386         IDirectMusicSynth8Impl_AssignChannelToBuses
387 };
388
389 static inline IDirectMusicSynth8Impl *impl_from_IKsControl(IKsControl *iface)
390 {
391     return CONTAINING_RECORD(iface, IDirectMusicSynth8Impl, IKsControl_iface);
392 }
393
394 static HRESULT WINAPI DMSynthImpl_IKsControl_QueryInterface(IKsControl* iface, REFIID riid, LPVOID *ppobj)
395 {
396     IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
397
398     return IDirectMusicSynth8Impl_QueryInterface(&This->IDirectMusicSynth8_iface, riid, ppobj);
399 }
400
401 static ULONG WINAPI DMSynthImpl_IKsControl_AddRef(IKsControl* iface)
402 {
403     IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
404
405     return IDirectMusicSynth8Impl_AddRef(&This->IDirectMusicSynth8_iface);
406 }
407
408 static ULONG WINAPI DMSynthImpl_IKsControl_Release(IKsControl* iface)
409 {
410     IDirectMusicSynth8Impl *This = impl_from_IKsControl(iface);
411
412     return IDirectMusicSynth8Impl_Release(&This->IDirectMusicSynth8_iface);
413 }
414
415 static HRESULT WINAPI DMSynthImpl_IKsControl_KsProperty(IKsControl* iface, PKSPROPERTY Property, ULONG PropertyLength, LPVOID PropertyData,
416                                                         ULONG DataLength, ULONG* BytesReturned)
417 {
418     FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Property, PropertyLength, PropertyData, DataLength, BytesReturned);
419
420     return E_NOTIMPL;
421 }
422
423 static HRESULT WINAPI DMSynthImpl_IKsControl_KsMethod(IKsControl* iface, PKSMETHOD Method, ULONG MethodLength, LPVOID MethodData,
424                                                       ULONG DataLength, ULONG* BytesReturned)
425 {
426     FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Method, MethodLength, MethodData, DataLength, BytesReturned);
427
428     return E_NOTIMPL;
429 }
430
431 static HRESULT WINAPI DMSynthImpl_IKsControl_KsEvent(IKsControl* iface, PKSEVENT Event, ULONG EventLength, LPVOID EventData,
432                                                      ULONG DataLength, ULONG* BytesReturned)
433 {
434     FIXME("(%p)->(%p, %u, %p, %u, %p): stub\n", iface, Event, EventLength, EventData, DataLength, BytesReturned);
435
436     return E_NOTIMPL;
437 }
438
439
440 static const IKsControlVtbl DMSynthImpl_IKsControl_Vtbl = {
441     DMSynthImpl_IKsControl_QueryInterface,
442     DMSynthImpl_IKsControl_AddRef,
443     DMSynthImpl_IKsControl_Release,
444     DMSynthImpl_IKsControl_KsProperty,
445     DMSynthImpl_IKsControl_KsMethod,
446     DMSynthImpl_IKsControl_KsEvent
447 };
448
449 /* for ClassFactory */
450 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter)
451 {
452         IDirectMusicSynth8Impl *obj;
453         
454         TRACE("(%p,%p,%p)\n", lpcGUID, ppobj, pUnkOuter);
455         obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynth8Impl));
456         if (NULL == obj) {
457                 *ppobj = NULL;
458                 return E_OUTOFMEMORY;
459         }
460         obj->IDirectMusicSynth8_iface.lpVtbl = &DirectMusicSynth8_Vtbl;
461         obj->IKsControl_iface.lpVtbl = &DMSynthImpl_IKsControl_Vtbl;
462         obj->ref = 0;
463         /* fill in caps */
464         obj->pCaps.dwSize = sizeof(DMUS_PORTCAPS);
465         obj->pCaps.dwFlags = DMUS_PC_DLS | DMUS_PC_SOFTWARESYNTH | DMUS_PC_DIRECTSOUND | DMUS_PC_DLS2 | DMUS_PC_AUDIOPATH | DMUS_PC_WAVE;
466         obj->pCaps.guidPort = CLSID_DirectMusicSynth;
467         obj->pCaps.dwClass = DMUS_PC_OUTPUTCLASS;
468         obj->pCaps.dwType = DMUS_PORT_USER_MODE_SYNTH;
469         obj->pCaps.dwMemorySize = DMUS_PC_SYSTEMMEMORY;
470         obj->pCaps.dwMaxChannelGroups = 1000;
471         obj->pCaps.dwMaxVoices = 1000;
472         obj->pCaps.dwMaxAudioChannels = 2;
473         obj->pCaps.dwEffectFlags = DMUS_EFFECT_REVERB;
474         MultiByteToWideChar (CP_ACP, 0, "Microsoft Synthesizer", -1, obj->pCaps.wszDescription, sizeof(obj->pCaps.wszDescription)/sizeof(WCHAR));
475
476         return IDirectMusicSynth8Impl_QueryInterface ((LPDIRECTMUSICSYNTH8)obj, lpcGUID, ppobj);
477 }