Authors: Mike McCormack <mike@codeweavers.com>, Aric Stewart <aric@codeweavers.com...
[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 modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (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
13  * GNU Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #include "dmsynth_private.h"
21
22 WINE_DEFAULT_DEBUG_CHANNEL(dmsynth);
23
24 /* IDirectMusicSynth8Impl IUnknown part: */
25 HRESULT WINAPI IDirectMusicSynth8Impl_QueryInterface (LPDIRECTMUSICSYNTH8 iface, REFIID riid, LPVOID *ppobj) {
26         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
27         TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
28
29         if (IsEqualIID (riid, &IID_IUnknown) || 
30             IsEqualIID (riid, &IID_IDirectMusicSynth) ||
31             IsEqualIID (riid, &IID_IDirectMusicSynth8)) {
32                 IDirectMusicSynth8Impl_AddRef(iface);
33                 *ppobj = This;
34                 return S_OK;
35         }
36         WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
37         return E_NOINTERFACE;
38 }
39
40 ULONG WINAPI IDirectMusicSynth8Impl_AddRef (LPDIRECTMUSICSYNTH8 iface) {
41         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
42         ULONG refCount = InterlockedIncrement(&This->ref);
43
44         TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
45
46         return refCount;
47 }
48
49 ULONG WINAPI IDirectMusicSynth8Impl_Release (LPDIRECTMUSICSYNTH8 iface) {
50         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
51         ULONG refCount = InterlockedDecrement(&This->ref);
52
53         TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
54
55         if (!refCount) {
56                 HeapFree(GetProcessHeap(), 0, This);
57         }
58         return refCount;
59 }
60
61 /* IDirectMusicSynth8Impl IDirectMusicSynth part: */
62 HRESULT WINAPI IDirectMusicSynth8Impl_Open (LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTPARAMS pPortParams) {
63         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
64         FIXME("(%p, %p): stub\n", This, pPortParams);
65         return S_OK;
66 }
67
68 HRESULT WINAPI IDirectMusicSynth8Impl_Close (LPDIRECTMUSICSYNTH8 iface) {
69         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
70         FIXME("(%p): stub\n", This);
71         return S_OK;
72 }
73
74 HRESULT WINAPI IDirectMusicSynth8Impl_SetNumChannelGroups (LPDIRECTMUSICSYNTH8 iface, DWORD dwGroups) {
75         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
76         FIXME("(%p, %ld): stub\n", This, dwGroups);
77         return S_OK;
78 }
79
80 HRESULT WINAPI IDirectMusicSynth8Impl_Download (LPDIRECTMUSICSYNTH8 iface, LPHANDLE phDownload, LPVOID pvData, LPBOOL pbFree) {
81         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
82         FIXME("(%p, %p, %p, %p): stub\n", This, phDownload, pvData, pbFree);
83         return S_OK;
84 }
85
86 HRESULT WINAPI IDirectMusicSynth8Impl_Unload (LPDIRECTMUSICSYNTH8 iface, HANDLE hDownload, HRESULT (CALLBACK* lpFreeHandle)(HANDLE,HANDLE), HANDLE hUserData) {
87         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
88         FIXME("(%p, %p, %p): stub\n", This, hDownload, hUserData);
89         return S_OK;
90 }
91
92 HRESULT WINAPI IDirectMusicSynth8Impl_PlayBuffer (LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME rt, LPBYTE pbBuffer, DWORD cbBuffer) {
93         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
94         FIXME("(%p, %lli, %p, %ld): stub\n", This, rt, pbBuffer, cbBuffer);
95         return S_OK;
96 }
97
98 HRESULT WINAPI IDirectMusicSynth8Impl_GetRunningStats (LPDIRECTMUSICSYNTH8 iface, LPDMUS_SYNTHSTATS pStats) {
99         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
100         FIXME("(%p, %p): stub\n", This, pStats);
101         return S_OK;
102 }
103
104 HRESULT WINAPI IDirectMusicSynth8Impl_GetPortCaps (LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTCAPS pCaps) {
105         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
106         TRACE("(%p, %p)\n", This, pCaps);
107         *pCaps = This->pCaps;
108         return S_OK;
109 }
110
111 HRESULT WINAPI IDirectMusicSynth8Impl_SetMasterClock (LPDIRECTMUSICSYNTH8 iface, IReferenceClock* pClock) {
112         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
113         FIXME("(%p, %p): stub\n", This, pClock);
114         return S_OK;
115 }
116
117 HRESULT WINAPI IDirectMusicSynth8Impl_GetLatencyClock (LPDIRECTMUSICSYNTH8 iface, IReferenceClock** ppClock) {
118         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
119         TRACE("(%p, %p)\n", This, ppClock);
120         *ppClock = This->pLatencyClock;
121         return S_OK;
122 }
123
124 HRESULT WINAPI IDirectMusicSynth8Impl_Activate (LPDIRECTMUSICSYNTH8 iface, BOOL fEnable) {
125         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
126         TRACE("(%p, %d)\n", This, fEnable);
127         This->fActive = fEnable;
128         return S_OK;
129 }
130
131 HRESULT WINAPI IDirectMusicSynth8Impl_SetSynthSink (LPDIRECTMUSICSYNTH8 iface, IDirectMusicSynthSink* pSynthSink) {
132         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
133         TRACE("(%p, %p)\n", This, pSynthSink);
134         This->pSynthSink = (IDirectMusicSynthSinkImpl*)pSynthSink;
135         return S_OK;
136 }
137
138 HRESULT WINAPI IDirectMusicSynth8Impl_Render (LPDIRECTMUSICSYNTH8 iface, short* pBuffer, DWORD dwLength, LONGLONG llPosition) {
139         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
140         FIXME("(%p, %p, %ld, %lli): stub\n", This, pBuffer, dwLength, llPosition);
141         return S_OK;
142 }
143
144 HRESULT WINAPI IDirectMusicSynth8Impl_SetChannelPriority (LPDIRECTMUSICSYNTH8 iface, DWORD dwChannelGroup, DWORD dwChannel, DWORD dwPriority) {
145         /*IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface; */
146         /* silenced because of too many messages - 1000 groups * 16 channels ;=) */
147         /*FIXME("(%p, %ld, %ld, %ld): stub\n", This, dwChannelGroup, dwChannel, dwPriority); */
148         return S_OK;
149 }
150
151 HRESULT WINAPI IDirectMusicSynth8Impl_GetChannelPriority (LPDIRECTMUSICSYNTH8 iface, DWORD dwChannelGroup, DWORD dwChannel, LPDWORD pdwPriority) {
152         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
153         FIXME("(%p, %ld, %ld, %p): stub\n", This, dwChannelGroup, dwChannel, pdwPriority);
154         return S_OK;
155 }
156
157 HRESULT WINAPI IDirectMusicSynth8Impl_GetFormat (LPDIRECTMUSICSYNTH8 iface, LPWAVEFORMATEX pWaveFormatEx, LPDWORD pdwWaveFormatExSiz) {
158         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
159         FIXME("(%p, %p, %p): stub\n", This, pWaveFormatEx, pdwWaveFormatExSiz);
160         return S_OK;
161 }
162
163 HRESULT WINAPI IDirectMusicSynth8Impl_GetAppend (LPDIRECTMUSICSYNTH8 iface, DWORD* pdwAppend) {
164         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
165         FIXME("(%p, %p): stub\n", This, pdwAppend);
166         return S_OK;
167 }
168
169 /* IDirectMusicSynth8Impl IDirectMusicSynth8 part: */
170 HRESULT WINAPI IDirectMusicSynth8Impl_PlayVoice (LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME rt, DWORD dwVoiceId, DWORD dwChannelGroup, DWORD dwChannel, DWORD dwDLId, long prPitch, long vrVolume, SAMPLE_TIME stVoiceStart, SAMPLE_TIME stLoopStart, SAMPLE_TIME stLoopEnd) {
171         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
172         FIXME("(%p, %lli, %ld, %ld, %ld, %ld, %li, %li,%lli, %lli, %lli): stub\n", This, rt, dwVoiceId, dwChannelGroup, dwChannel, dwDLId, prPitch, vrVolume, stVoiceStart, stLoopStart, stLoopEnd);
173         return S_OK;
174 }
175
176 HRESULT WINAPI IDirectMusicSynth8Impl_StopVoice (LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME rt, DWORD dwVoiceId) {
177         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
178         FIXME("(%p, %lli, %ld): stub\n", This, rt, dwVoiceId);
179         return S_OK;
180 }
181
182 HRESULT WINAPI IDirectMusicSynth8Impl_GetVoiceState (LPDIRECTMUSICSYNTH8 iface, DWORD dwVoice[], DWORD cbVoice, DMUS_VOICE_STATE dwVoiceState[]) {
183         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
184         FIXME("(%p, %p, %ld, %p): stub\n", This, dwVoice, cbVoice, dwVoiceState);
185         return S_OK;
186 }
187
188 HRESULT WINAPI IDirectMusicSynth8Impl_Refresh (LPDIRECTMUSICSYNTH8 iface, DWORD dwDownloadID, DWORD dwFlags) {
189         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
190         FIXME("(%p, %ld, %ld): stub\n", This, dwDownloadID, dwFlags);
191         return S_OK;
192 }
193
194 HRESULT WINAPI IDirectMusicSynth8Impl_AssignChannelToBuses (LPDIRECTMUSICSYNTH8 iface, DWORD dwChannelGroup, DWORD dwChannel, LPDWORD pdwBuses, DWORD cBuses) {
195         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
196         FIXME("(%p, %ld, %ld, %p, %ld): stub\n", This, dwChannelGroup, dwChannel, pdwBuses, cBuses);
197         return S_OK;
198 }
199
200 IDirectMusicSynth8Vtbl DirectMusicSynth8_Vtbl = {
201         IDirectMusicSynth8Impl_QueryInterface,
202         IDirectMusicSynth8Impl_AddRef,
203         IDirectMusicSynth8Impl_Release,
204         IDirectMusicSynth8Impl_Open,
205         IDirectMusicSynth8Impl_Close,
206         IDirectMusicSynth8Impl_SetNumChannelGroups,
207         IDirectMusicSynth8Impl_Download,
208         IDirectMusicSynth8Impl_Unload,
209         IDirectMusicSynth8Impl_PlayBuffer,
210         IDirectMusicSynth8Impl_GetRunningStats,
211         IDirectMusicSynth8Impl_GetPortCaps,
212         IDirectMusicSynth8Impl_SetMasterClock,
213         IDirectMusicSynth8Impl_GetLatencyClock,
214         IDirectMusicSynth8Impl_Activate,
215         IDirectMusicSynth8Impl_SetSynthSink,
216         IDirectMusicSynth8Impl_Render,
217         IDirectMusicSynth8Impl_SetChannelPriority,
218         IDirectMusicSynth8Impl_GetChannelPriority,
219         IDirectMusicSynth8Impl_GetFormat,
220         IDirectMusicSynth8Impl_GetAppend,
221         IDirectMusicSynth8Impl_PlayVoice,
222         IDirectMusicSynth8Impl_StopVoice,
223         IDirectMusicSynth8Impl_GetVoiceState,
224         IDirectMusicSynth8Impl_Refresh,
225         IDirectMusicSynth8Impl_AssignChannelToBuses
226 };
227
228 /* for ClassFactory */
229 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
230         IDirectMusicSynth8Impl *obj;
231         
232         TRACE("(%p,%p,%p)\n", lpcGUID, ppobj, pUnkOuter);
233         obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynth8Impl));
234         if (NULL == obj) {
235                 *ppobj = (LPDIRECTMUSICSYNTH8) NULL;
236                 return E_OUTOFMEMORY;
237         }
238         obj->lpVtbl = &DirectMusicSynth8_Vtbl;
239         obj->ref = 0;
240         /* fill in caps */
241         obj->pCaps.dwSize = sizeof(DMUS_PORTCAPS);
242         obj->pCaps.dwFlags = DMUS_PC_DLS | DMUS_PC_SOFTWARESYNTH | DMUS_PC_DIRECTSOUND | DMUS_PC_DLS2 | DMUS_PC_AUDIOPATH | DMUS_PC_WAVE;
243         obj->pCaps.guidPort = CLSID_DirectMusicSynth;
244         obj->pCaps.dwClass = DMUS_PC_OUTPUTCLASS;
245         obj->pCaps.dwType = DMUS_PORT_WINMM_DRIVER;
246         obj->pCaps.dwMemorySize = DMUS_PC_SYSTEMMEMORY;
247         obj->pCaps.dwMaxChannelGroups = 1000;
248         obj->pCaps.dwMaxVoices = 1000;
249         obj->pCaps.dwMaxAudioChannels = -1;
250         obj->pCaps.dwEffectFlags = DMUS_EFFECT_REVERB | DMUS_EFFECT_CHORUS | DMUS_EFFECT_DELAY;
251         MultiByteToWideChar (CP_ACP, 0, "Microsotf Synthesizer", -1, obj->pCaps.wszDescription, sizeof(obj->pCaps.wszDescription)/sizeof(WCHAR));
252         /* assign latency clock */
253         /*DMUSIC_CreateReferenceClockImpl (&IID_IReferenceClock, (LPVOID*)&This->pLatencyClock, NULL); */
254
255         return IDirectMusicSynth8Impl_QueryInterface ((LPDIRECTMUSICSYNTH8)obj, lpcGUID, ppobj);
256 }