Print exe name when initialization fails.
[wine] / dlls / dmsynth / synth.c
1 /* IDirectMusicSynth8 Implementation
2  *
3  * Copyright (C) 2003 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 <stdarg.h>
21
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winuser.h"
25 #include "wingdi.h"
26 #include "wine/debug.h"
27 #include "winnls.h"
28
29 #include "dmsynth_private.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(dmsynth);
32
33 /* IDirectMusicSynth8 IUnknown part: */
34 HRESULT WINAPI IDirectMusicSynth8Impl_QueryInterface (LPDIRECTMUSICSYNTH8 iface, REFIID riid, LPVOID *ppobj)
35 {
36         ICOM_THIS(IDirectMusicSynth8Impl,iface);
37
38         if (IsEqualIID (riid, &IID_IUnknown) || 
39             IsEqualIID (riid, &IID_IDirectMusicSynth) ||
40             IsEqualIID (riid, &IID_IDirectMusicSynth8)) {
41                 IDirectMusicSynth8Impl_AddRef(iface);
42                 *ppobj = This;
43                 return S_OK;
44         }
45
46         WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
47         return E_NOINTERFACE;
48 }
49
50 ULONG WINAPI IDirectMusicSynth8Impl_AddRef (LPDIRECTMUSICSYNTH8 iface)
51 {
52         ICOM_THIS(IDirectMusicSynth8Impl,iface);
53         TRACE("(%p) : AddRef from %ld\n", This, This->ref);
54         return ++(This->ref);
55 }
56
57 ULONG WINAPI IDirectMusicSynth8Impl_Release (LPDIRECTMUSICSYNTH8 iface)
58 {
59         ICOM_THIS(IDirectMusicSynth8Impl,iface);
60         ULONG ref = --This->ref;
61         TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
62         if (ref == 0) {
63                 HeapFree(GetProcessHeap(), 0, This);
64         }
65         return ref;
66 }
67
68 /* IDirectMusicSynth8 IDirectMusicSynth part: */
69 HRESULT WINAPI IDirectMusicSynth8Impl_Open (LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTPARAMS pPortParams)
70 {
71         ICOM_THIS(IDirectMusicSynth8Impl,iface);
72
73         FIXME("(%p, %p): stub\n", This, pPortParams);
74
75         return S_OK;
76 }
77
78 HRESULT WINAPI IDirectMusicSynth8Impl_Close (LPDIRECTMUSICSYNTH8 iface)
79 {
80         ICOM_THIS(IDirectMusicSynth8Impl,iface);
81
82         FIXME("(%p): stub\n", This);
83
84         return S_OK;
85 }
86
87 HRESULT WINAPI IDirectMusicSynth8Impl_SetNumChannelGroups (LPDIRECTMUSICSYNTH8 iface, DWORD dwGroups)
88 {
89         ICOM_THIS(IDirectMusicSynth8Impl,iface);
90
91         FIXME("(%p, %ld): stub\n", This, dwGroups);
92
93         return S_OK;
94 }
95
96 HRESULT WINAPI IDirectMusicSynth8Impl_Download (LPDIRECTMUSICSYNTH8 iface, LPHANDLE phDownload, LPVOID pvData, LPBOOL pbFree)
97 {
98         ICOM_THIS(IDirectMusicSynth8Impl,iface);
99
100         FIXME("(%p, %p, %p, %p): stub\n", This, phDownload, pvData, pbFree);
101
102         return S_OK;
103 }
104
105 HRESULT WINAPI IDirectMusicSynth8Impl_Unload (LPDIRECTMUSICSYNTH8 iface, HANDLE hDownload, HRESULT (CALLBACK* lpFreeHandle)(HANDLE,HANDLE), HANDLE hUserData)
106 {
107         ICOM_THIS(IDirectMusicSynth8Impl,iface);
108
109         FIXME("(%p, %p, %p): stub\n", This, hDownload, hUserData);
110
111         return S_OK;
112 }
113
114 HRESULT WINAPI IDirectMusicSynth8Impl_PlayBuffer (LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME rt, LPBYTE pbBuffer, DWORD cbBuffer)
115 {
116         ICOM_THIS(IDirectMusicSynth8Impl,iface);
117
118         FIXME("(%p, %lli, %p, %ld): stub\n", This, rt, pbBuffer, cbBuffer);
119
120         return S_OK;
121 }
122
123 HRESULT WINAPI IDirectMusicSynth8Impl_GetRunningStats (LPDIRECTMUSICSYNTH8 iface, LPDMUS_SYNTHSTATS pStats)
124 {
125         ICOM_THIS(IDirectMusicSynth8Impl,iface);
126
127         FIXME("(%p, %p): stub\n", This, pStats);
128
129         return S_OK;
130 }
131
132 HRESULT WINAPI IDirectMusicSynth8Impl_GetPortCaps (LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTCAPS pCaps)
133 {
134         ICOM_THIS(IDirectMusicSynth8Impl,iface);
135
136         TRACE("(%p, %p)\n", This, pCaps);
137         *pCaps = This->pCaps;
138         
139         return S_OK;
140 }
141
142 HRESULT WINAPI IDirectMusicSynth8Impl_SetMasterClock (LPDIRECTMUSICSYNTH8 iface, IReferenceClock* pClock)
143 {
144         ICOM_THIS(IDirectMusicSynth8Impl,iface);
145
146         FIXME("(%p, %p): stub\n", This, pClock);
147
148         return S_OK;
149 }
150
151 HRESULT WINAPI IDirectMusicSynth8Impl_GetLatencyClock (LPDIRECTMUSICSYNTH8 iface, IReferenceClock** ppClock)
152 {
153         ICOM_THIS(IDirectMusicSynth8Impl,iface);
154
155         TRACE("(%p, %p)\n", This, ppClock);
156         *ppClock = This->pLatencyClock;
157
158         return S_OK;
159 }
160
161 HRESULT WINAPI IDirectMusicSynth8Impl_Activate (LPDIRECTMUSICSYNTH8 iface, BOOL fEnable)
162 {
163         ICOM_THIS(IDirectMusicSynth8Impl,iface);
164
165         TRACE("(%p, %d)\n", This, fEnable);
166         This->fActive = fEnable;
167
168         return S_OK;
169 }
170
171 HRESULT WINAPI IDirectMusicSynth8Impl_SetSynthSink (LPDIRECTMUSICSYNTH8 iface, IDirectMusicSynthSink* pSynthSink)
172 {
173         ICOM_THIS(IDirectMusicSynth8Impl,iface);
174
175         TRACE("(%p, %p)\n", This, pSynthSink);
176         This->pSynthSink = (IDirectMusicSynthSinkImpl*)pSynthSink;
177
178         return S_OK;
179 }
180
181 HRESULT WINAPI IDirectMusicSynth8Impl_Render (LPDIRECTMUSICSYNTH8 iface, short* pBuffer, DWORD dwLength, LONGLONG llPosition)
182 {
183         ICOM_THIS(IDirectMusicSynth8Impl,iface);
184
185         FIXME("(%p, %p, %ld, %lli): stub\n", This, pBuffer, dwLength, llPosition);
186
187         return S_OK;
188 }
189
190 HRESULT WINAPI IDirectMusicSynth8Impl_SetChannelPriority (LPDIRECTMUSICSYNTH8 iface, DWORD dwChannelGroup, DWORD dwChannel, DWORD dwPriority)
191 {
192         /*ICOM_THIS(IDirectMusicSynth8Impl,iface); */
193         
194         /* silenced because of too many messages - 1000 groups * 16 channels ;=) */
195         /*FIXME("(%p, %ld, %ld, %ld): stub\n", This, dwChannelGroup, dwChannel, dwPriority); */
196
197         return S_OK;
198 }
199
200 HRESULT WINAPI IDirectMusicSynth8Impl_GetChannelPriority (LPDIRECTMUSICSYNTH8 iface, DWORD dwChannelGroup, DWORD dwChannel, LPDWORD pdwPriority)
201 {
202         ICOM_THIS(IDirectMusicSynth8Impl,iface);
203
204         FIXME("(%p, %ld, %ld, %p): stub\n", This, dwChannelGroup, dwChannel, pdwPriority);
205
206         return S_OK;
207 }
208
209 HRESULT WINAPI IDirectMusicSynth8Impl_GetFormat (LPDIRECTMUSICSYNTH8 iface, LPWAVEFORMATEX pWaveFormatEx, LPDWORD pdwWaveFormatExSiz)
210 {
211         ICOM_THIS(IDirectMusicSynth8Impl,iface);
212
213         FIXME("(%p, %p, %p): stub\n", This, pWaveFormatEx, pdwWaveFormatExSiz);
214
215         return S_OK;
216 }
217
218 HRESULT WINAPI IDirectMusicSynth8Impl_GetAppend (LPDIRECTMUSICSYNTH8 iface, DWORD* pdwAppend)
219 {
220         ICOM_THIS(IDirectMusicSynth8Impl,iface);
221
222         FIXME("(%p, %p): stub\n", This, pdwAppend);
223
224         return S_OK;
225 }
226
227 /* IDirectMusicSynth8 IDirectMusicSynth8 part: */
228 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)
229 {
230         ICOM_THIS(IDirectMusicSynth8Impl,iface);
231
232         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);
233
234         return S_OK;
235 }
236
237 HRESULT WINAPI IDirectMusicSynth8Impl_StopVoice (LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME rt, DWORD dwVoiceId)
238 {
239         ICOM_THIS(IDirectMusicSynth8Impl,iface);
240
241         FIXME("(%p, %lli, %ld): stub\n", This, rt, dwVoiceId);
242
243         return S_OK;
244 }
245
246 HRESULT WINAPI IDirectMusicSynth8Impl_GetVoiceState (LPDIRECTMUSICSYNTH8 iface, DWORD dwVoice[], DWORD cbVoice, DMUS_VOICE_STATE dwVoiceState[])
247 {
248         ICOM_THIS(IDirectMusicSynth8Impl,iface);
249
250         FIXME("(%p, %p, %ld, %p): stub\n", This, dwVoice, cbVoice, dwVoiceState);
251
252         return S_OK;
253 }
254
255 HRESULT WINAPI IDirectMusicSynth8Impl_Refresh (LPDIRECTMUSICSYNTH8 iface, DWORD dwDownloadID, DWORD dwFlags)
256 {
257         ICOM_THIS(IDirectMusicSynth8Impl,iface);
258
259         FIXME("(%p, %ld, %ld): stub\n", This, dwDownloadID, dwFlags);
260
261         return S_OK;
262 }
263
264 HRESULT WINAPI IDirectMusicSynth8Impl_AssignChannelToBuses (LPDIRECTMUSICSYNTH8 iface, DWORD dwChannelGroup, DWORD dwChannel, LPDWORD pdwBuses, DWORD cBuses)
265 {
266         ICOM_THIS(IDirectMusicSynth8Impl,iface);
267
268         FIXME("(%p, %ld, %ld, %p, %ld): stub\n", This, dwChannelGroup, dwChannel, pdwBuses, cBuses);
269
270         return S_OK;
271 }
272
273 ICOM_VTABLE(IDirectMusicSynth8) DirectMusicSynth8_Vtbl =
274 {
275     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
276         IDirectMusicSynth8Impl_QueryInterface,
277         IDirectMusicSynth8Impl_AddRef,
278         IDirectMusicSynth8Impl_Release,
279         IDirectMusicSynth8Impl_Open,
280         IDirectMusicSynth8Impl_Close,
281         IDirectMusicSynth8Impl_SetNumChannelGroups,
282         IDirectMusicSynth8Impl_Download,
283         IDirectMusicSynth8Impl_Unload,
284         IDirectMusicSynth8Impl_PlayBuffer,
285         IDirectMusicSynth8Impl_GetRunningStats,
286         IDirectMusicSynth8Impl_GetPortCaps,
287         IDirectMusicSynth8Impl_SetMasterClock,
288         IDirectMusicSynth8Impl_GetLatencyClock,
289         IDirectMusicSynth8Impl_Activate,
290         IDirectMusicSynth8Impl_SetSynthSink,
291         IDirectMusicSynth8Impl_Render,
292         IDirectMusicSynth8Impl_SetChannelPriority,
293         IDirectMusicSynth8Impl_GetChannelPriority,
294         IDirectMusicSynth8Impl_GetFormat,
295         IDirectMusicSynth8Impl_GetAppend,
296         IDirectMusicSynth8Impl_PlayVoice,
297         IDirectMusicSynth8Impl_StopVoice,
298         IDirectMusicSynth8Impl_GetVoiceState,
299         IDirectMusicSynth8Impl_Refresh,
300         IDirectMusicSynth8Impl_AssignChannelToBuses
301 };
302
303 /* for ClassFactory */
304 HRESULT WINAPI DMUSIC_CreateDirectMusicSynth (LPCGUID lpcGUID, LPDIRECTMUSICSYNTH8* ppDMSynth, LPUNKNOWN pUnkOuter)
305 {
306         IDirectMusicSynth8Impl *dmsynth;
307         
308         TRACE("(%p,%p,%p)\n", lpcGUID, ppDMSynth, pUnkOuter);
309         if (IsEqualIID (lpcGUID, &IID_IDirectMusicSynth) ||
310                 IsEqualIID (lpcGUID, &IID_IDirectMusicSynth8))  {
311                 dmsynth = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynth8Impl));
312                 if (NULL == dmsynth) {
313                         *ppDMSynth = (LPDIRECTMUSICSYNTH8) NULL;
314                         return E_OUTOFMEMORY;
315                 }
316                 dmsynth->lpVtbl = &DirectMusicSynth8_Vtbl;
317                 dmsynth->ref = 1;
318                 /* fill in caps */
319                 dmsynth->pCaps.dwSize = sizeof(DMUS_PORTCAPS);
320                 dmsynth->pCaps.dwFlags = DMUS_PC_DLS | DMUS_PC_SOFTWARESYNTH | DMUS_PC_DIRECTSOUND | DMUS_PC_DLS2 | DMUS_PC_AUDIOPATH | DMUS_PC_WAVE;
321                 dmsynth->pCaps.guidPort = CLSID_DirectMusicSynth;
322                 dmsynth->pCaps.dwClass = DMUS_PC_OUTPUTCLASS;
323                 dmsynth->pCaps.dwType = DMUS_PORT_WINMM_DRIVER;
324                 dmsynth->pCaps.dwMemorySize = DMUS_PC_SYSTEMMEMORY;
325                 dmsynth->pCaps.dwMaxChannelGroups = 1000;
326                 dmsynth->pCaps.dwMaxVoices = 1000;
327                 dmsynth->pCaps.dwMaxAudioChannels = -1;
328                 dmsynth->pCaps.dwEffectFlags = DMUS_EFFECT_REVERB | DMUS_EFFECT_CHORUS | DMUS_EFFECT_DELAY;
329                 MultiByteToWideChar (CP_ACP, 0, "Microsotf Synthesizer", -1, dmsynth->pCaps.wszDescription, sizeof(dmsynth->pCaps.wszDescription)/sizeof(WCHAR));
330                 /* assign latency clock */
331                 /*DMUSIC_CreateReferenceClock (&IID_IReferenceClock, (LPREFERENCECLOCK*)&This->pLatencyClock, NULL); */
332
333                 *ppDMSynth = (LPDIRECTMUSICSYNTH8) dmsynth;
334                 return S_OK;
335         }
336         WARN("No interface found\n");
337         
338         return E_NOINTERFACE;
339 }