windowscodecs: Implement Commit for the PNG encoder.
[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 /* IDirectMusicSynth8Impl IUnknown part: */
25 static 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                 IUnknown_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 static ULONG WINAPI IDirectMusicSynth8Impl_AddRef (LPDIRECTMUSICSYNTH8 iface) {
41         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
42         ULONG refCount = InterlockedIncrement(&This->ref);
43
44         TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
45
46         DMSYNTH_LockModule();
47
48         return refCount;
49 }
50
51 static ULONG WINAPI IDirectMusicSynth8Impl_Release (LPDIRECTMUSICSYNTH8 iface) {
52         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
53         ULONG refCount = InterlockedDecrement(&This->ref);
54
55         TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
56
57         if (!refCount) {
58                 HeapFree(GetProcessHeap(), 0, This);
59         }
60
61         DMSYNTH_UnlockModule();
62         
63         return refCount;
64 }
65
66 /* IDirectMusicSynth8Impl IDirectMusicSynth part: */
67 static HRESULT WINAPI IDirectMusicSynth8Impl_Open (LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTPARAMS pPortParams) {
68         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
69         FIXME("(%p, %p): stub\n", This, pPortParams);
70         return S_OK;
71 }
72
73 static HRESULT WINAPI IDirectMusicSynth8Impl_Close (LPDIRECTMUSICSYNTH8 iface) {
74         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
75         FIXME("(%p): stub\n", This);
76         return S_OK;
77 }
78
79 static HRESULT WINAPI IDirectMusicSynth8Impl_SetNumChannelGroups (LPDIRECTMUSICSYNTH8 iface, DWORD dwGroups) {
80         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
81         FIXME("(%p, %d): stub\n", This, dwGroups);
82         return S_OK;
83 }
84
85 static HRESULT WINAPI IDirectMusicSynth8Impl_Download (LPDIRECTMUSICSYNTH8 iface, LPHANDLE phDownload, LPVOID pvData, LPBOOL pbFree) {
86         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
87         FIXME("(%p, %p, %p, %p): stub\n", This, phDownload, pvData, pbFree);
88         return S_OK;
89 }
90
91 static HRESULT WINAPI IDirectMusicSynth8Impl_Unload (LPDIRECTMUSICSYNTH8 iface, HANDLE hDownload, HRESULT (CALLBACK* lpFreeHandle)(HANDLE,HANDLE), HANDLE hUserData) {
92         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
93         FIXME("(%p, %p, %p): stub\n", This, hDownload, hUserData);
94         return S_OK;
95 }
96
97 static HRESULT WINAPI IDirectMusicSynth8Impl_PlayBuffer (LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME rt, LPBYTE pbBuffer, DWORD cbBuffer) {
98         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
99         FIXME("(%p, 0x%s, %p, %d): stub\n", This, wine_dbgstr_longlong(rt), pbBuffer, cbBuffer);
100         return S_OK;
101 }
102
103 static HRESULT WINAPI IDirectMusicSynth8Impl_GetRunningStats (LPDIRECTMUSICSYNTH8 iface, LPDMUS_SYNTHSTATS pStats) {
104         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
105         FIXME("(%p, %p): stub\n", This, pStats);
106         return S_OK;
107 }
108
109 static HRESULT WINAPI IDirectMusicSynth8Impl_GetPortCaps (LPDIRECTMUSICSYNTH8 iface, LPDMUS_PORTCAPS pCaps) {
110         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
111         TRACE("(%p, %p)\n", This, pCaps);
112         *pCaps = This->pCaps;
113         return S_OK;
114 }
115
116 static HRESULT WINAPI IDirectMusicSynth8Impl_SetMasterClock (LPDIRECTMUSICSYNTH8 iface, IReferenceClock* pClock) {
117         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
118         FIXME("(%p, %p): stub\n", This, pClock);
119         return S_OK;
120 }
121
122 static HRESULT WINAPI IDirectMusicSynth8Impl_GetLatencyClock (LPDIRECTMUSICSYNTH8 iface, IReferenceClock** ppClock) {
123         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
124         TRACE("(%p, %p)\n", This, ppClock);
125         *ppClock = This->pLatencyClock;
126         return S_OK;
127 }
128
129 static HRESULT WINAPI IDirectMusicSynth8Impl_Activate (LPDIRECTMUSICSYNTH8 iface, BOOL fEnable) {
130         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
131         TRACE("(%p, %d)\n", This, fEnable);
132         This->fActive = fEnable;
133         return S_OK;
134 }
135
136 static HRESULT WINAPI IDirectMusicSynth8Impl_SetSynthSink (LPDIRECTMUSICSYNTH8 iface, IDirectMusicSynthSink* pSynthSink) {
137         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
138         TRACE("(%p, %p)\n", This, pSynthSink);
139         This->pSynthSink = (IDirectMusicSynthSinkImpl*)pSynthSink;
140         return S_OK;
141 }
142
143 static HRESULT WINAPI IDirectMusicSynth8Impl_Render (LPDIRECTMUSICSYNTH8 iface, short* pBuffer, DWORD dwLength, LONGLONG llPosition) {
144         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
145         FIXME("(%p, %p, %d, 0x%s): stub\n", This, pBuffer, dwLength, wine_dbgstr_longlong(llPosition));
146         return S_OK;
147 }
148
149 static HRESULT WINAPI IDirectMusicSynth8Impl_SetChannelPriority (LPDIRECTMUSICSYNTH8 iface, DWORD dwChannelGroup, DWORD dwChannel, DWORD dwPriority) {
150         /*IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface; */
151         /* silenced because of too many messages - 1000 groups * 16 channels ;=) */
152         /*FIXME("(%p, %ld, %ld, %ld): stub\n", This, dwChannelGroup, dwChannel, dwPriority); */
153         return S_OK;
154 }
155
156 static HRESULT WINAPI IDirectMusicSynth8Impl_GetChannelPriority (LPDIRECTMUSICSYNTH8 iface, DWORD dwChannelGroup, DWORD dwChannel, LPDWORD pdwPriority) {
157         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
158         FIXME("(%p, %d, %d, %p): stub\n", This, dwChannelGroup, dwChannel, pdwPriority);
159         return S_OK;
160 }
161
162 static HRESULT WINAPI IDirectMusicSynth8Impl_GetFormat (LPDIRECTMUSICSYNTH8 iface, LPWAVEFORMATEX pWaveFormatEx, LPDWORD pdwWaveFormatExSiz) {
163         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
164         FIXME("(%p, %p, %p): stub\n", This, pWaveFormatEx, pdwWaveFormatExSiz);
165         return S_OK;
166 }
167
168 static HRESULT WINAPI IDirectMusicSynth8Impl_GetAppend (LPDIRECTMUSICSYNTH8 iface, DWORD* pdwAppend) {
169         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
170         FIXME("(%p, %p): stub\n", This, pdwAppend);
171         return S_OK;
172 }
173
174 /* IDirectMusicSynth8Impl IDirectMusicSynth8 part: */
175 static 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) {
176         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
177         FIXME("(%p, 0x%s, %d, %d, %d, %d, %i, %i,0x%s, 0x%s, 0x%s): stub\n",
178             This, wine_dbgstr_longlong(rt), dwVoiceId, dwChannelGroup, dwChannel, dwDLId, prPitch, vrVolume,
179             wine_dbgstr_longlong(stVoiceStart), wine_dbgstr_longlong(stLoopStart), wine_dbgstr_longlong(stLoopEnd));
180         return S_OK;
181 }
182
183 static HRESULT WINAPI IDirectMusicSynth8Impl_StopVoice (LPDIRECTMUSICSYNTH8 iface, REFERENCE_TIME rt, DWORD dwVoiceId) {
184         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
185         FIXME("(%p, 0x%s, %d): stub\n", This, wine_dbgstr_longlong(rt), dwVoiceId);
186         return S_OK;
187 }
188
189 static HRESULT WINAPI IDirectMusicSynth8Impl_GetVoiceState (LPDIRECTMUSICSYNTH8 iface, DWORD dwVoice[], DWORD cbVoice, DMUS_VOICE_STATE dwVoiceState[]) {
190         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
191         FIXME("(%p, %p, %d, %p): stub\n", This, dwVoice, cbVoice, dwVoiceState);
192         return S_OK;
193 }
194
195 static HRESULT WINAPI IDirectMusicSynth8Impl_Refresh (LPDIRECTMUSICSYNTH8 iface, DWORD dwDownloadID, DWORD dwFlags) {
196         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
197         FIXME("(%p, %d, %d): stub\n", This, dwDownloadID, dwFlags);
198         return S_OK;
199 }
200
201 static HRESULT WINAPI IDirectMusicSynth8Impl_AssignChannelToBuses (LPDIRECTMUSICSYNTH8 iface, DWORD dwChannelGroup, DWORD dwChannel, LPDWORD pdwBuses, DWORD cBuses) {
202         IDirectMusicSynth8Impl *This = (IDirectMusicSynth8Impl *)iface;
203         FIXME("(%p, %d, %d, %p, %d): stub\n", This, dwChannelGroup, dwChannel, pdwBuses, cBuses);
204         return S_OK;
205 }
206
207 static const IDirectMusicSynth8Vtbl DirectMusicSynth8_Vtbl = {
208         IDirectMusicSynth8Impl_QueryInterface,
209         IDirectMusicSynth8Impl_AddRef,
210         IDirectMusicSynth8Impl_Release,
211         IDirectMusicSynth8Impl_Open,
212         IDirectMusicSynth8Impl_Close,
213         IDirectMusicSynth8Impl_SetNumChannelGroups,
214         IDirectMusicSynth8Impl_Download,
215         IDirectMusicSynth8Impl_Unload,
216         IDirectMusicSynth8Impl_PlayBuffer,
217         IDirectMusicSynth8Impl_GetRunningStats,
218         IDirectMusicSynth8Impl_GetPortCaps,
219         IDirectMusicSynth8Impl_SetMasterClock,
220         IDirectMusicSynth8Impl_GetLatencyClock,
221         IDirectMusicSynth8Impl_Activate,
222         IDirectMusicSynth8Impl_SetSynthSink,
223         IDirectMusicSynth8Impl_Render,
224         IDirectMusicSynth8Impl_SetChannelPriority,
225         IDirectMusicSynth8Impl_GetChannelPriority,
226         IDirectMusicSynth8Impl_GetFormat,
227         IDirectMusicSynth8Impl_GetAppend,
228         IDirectMusicSynth8Impl_PlayVoice,
229         IDirectMusicSynth8Impl_StopVoice,
230         IDirectMusicSynth8Impl_GetVoiceState,
231         IDirectMusicSynth8Impl_Refresh,
232         IDirectMusicSynth8Impl_AssignChannelToBuses
233 };
234
235 /* for ClassFactory */
236 HRESULT WINAPI DMUSIC_CreateDirectMusicSynthImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
237         IDirectMusicSynth8Impl *obj;
238         
239         TRACE("(%p,%p,%p)\n", lpcGUID, ppobj, pUnkOuter);
240         obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSynth8Impl));
241         if (NULL == obj) {
242                 *ppobj = NULL;
243                 return E_OUTOFMEMORY;
244         }
245         obj->lpVtbl = &DirectMusicSynth8_Vtbl;
246         obj->ref = 0;
247         /* fill in caps */
248         obj->pCaps.dwSize = sizeof(DMUS_PORTCAPS);
249         obj->pCaps.dwFlags = DMUS_PC_DLS | DMUS_PC_SOFTWARESYNTH | DMUS_PC_DIRECTSOUND | DMUS_PC_DLS2 | DMUS_PC_AUDIOPATH | DMUS_PC_WAVE;
250         obj->pCaps.guidPort = CLSID_DirectMusicSynth;
251         obj->pCaps.dwClass = DMUS_PC_OUTPUTCLASS;
252         obj->pCaps.dwType = DMUS_PORT_WINMM_DRIVER;
253         obj->pCaps.dwMemorySize = DMUS_PC_SYSTEMMEMORY;
254         obj->pCaps.dwMaxChannelGroups = 1000;
255         obj->pCaps.dwMaxVoices = 1000;
256         obj->pCaps.dwMaxAudioChannels = -1;
257         obj->pCaps.dwEffectFlags = DMUS_EFFECT_REVERB | DMUS_EFFECT_CHORUS | DMUS_EFFECT_DELAY;
258         MultiByteToWideChar (CP_ACP, 0, "Microsoft Synthesizer", -1, obj->pCaps.wszDescription, sizeof(obj->pCaps.wszDescription)/sizeof(WCHAR));
259         /* assign latency clock */
260         /*DMUSIC_CreateReferenceClockImpl (&IID_IReferenceClock, (LPVOID*)&This->pLatencyClock, NULL); */
261
262         return IDirectMusicSynth8Impl_QueryInterface ((LPDIRECTMUSICSYNTH8)obj, lpcGUID, ppobj);
263 }