If using the default values, also set dwType to REG_SZ as our default
[wine] / dlls / dmime / audiopath.c
1 /* IDirectMusicAudioPath 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
28 #include "dmime_private.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
31
32 /* IDirectMusicAudioPath IUnknown part: */
33 HRESULT WINAPI IDirectMusicAudioPathImpl_QueryInterface (LPDIRECTMUSICAUDIOPATH iface, REFIID riid, LPVOID *ppobj)
34 {
35         ICOM_THIS(IDirectMusicAudioPathImpl,iface);
36
37         if (IsEqualIID (riid, &IID_IUnknown) || 
38             IsEqualIID (riid, &IID_IDirectMusicAudioPath)) {
39                 IDirectMusicAudioPathImpl_AddRef(iface);
40                 *ppobj = This;
41                 return S_OK;
42         }
43         
44         WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
45         return E_NOINTERFACE;
46 }
47
48 ULONG WINAPI IDirectMusicAudioPathImpl_AddRef (LPDIRECTMUSICAUDIOPATH iface)
49 {
50         ICOM_THIS(IDirectMusicAudioPathImpl,iface);
51         TRACE("(%p) : AddRef from %ld\n", This, This->ref);
52         return ++(This->ref);
53 }
54
55 ULONG WINAPI IDirectMusicAudioPathImpl_Release (LPDIRECTMUSICAUDIOPATH iface)
56 {
57         ICOM_THIS(IDirectMusicAudioPathImpl,iface);
58         ULONG ref = --This->ref;
59         TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
60         if (ref == 0) {
61                 HeapFree(GetProcessHeap(), 0, This);
62         }
63         return ref;
64 }
65
66 /* IDirectMusicAudioPath IDirectMusicAudioPath part: */
67 HRESULT WINAPI IDirectMusicAudioPathImpl_GetObjectInPath (LPDIRECTMUSICAUDIOPATH iface, DWORD dwPChannel, DWORD dwStage, DWORD dwBuffer, REFGUID guidObject, WORD dwIndex, REFGUID iidInterface, void** ppObject)
68 {
69         ICOM_THIS(IDirectMusicAudioPathImpl,iface);
70
71         FIXME("(%p, %ld, %ld, %ld, %s, %d, %s, %p): stub\n", This, dwPChannel, dwStage, dwBuffer, debugstr_guid(guidObject), dwIndex, debugstr_guid(iidInterface), ppObject);
72
73         switch (dwStage) {
74         case DMUS_PATH_BUFFER:
75           {
76             if (IsEqualIID (iidInterface, &IID_IDirectSoundBuffer8)) {
77               IDirectSoundBuffer8_QueryInterface (This->pDSBuffer, &IID_IDirectSoundBuffer8, ppObject);
78               TRACE("returning %p\n",*ppObject);
79               return S_OK;
80             } else if (IsEqualIID (iidInterface, &IID_IDirectSound3DBuffer)) {
81               IDirectSoundBuffer8_QueryInterface (This->pDSBuffer, &IID_IDirectSound3DBuffer, ppObject);
82               TRACE("returning %p\n",*ppObject);
83               return S_OK;
84             } else {
85               FIXME("Bad iid\n");
86             }
87           }
88           break;
89
90         case DMUS_PATH_PRIMARY_BUFFER: {
91           if (IsEqualIID (iidInterface, &IID_IDirectSound3DListener)) {
92             IDirectSoundBuffer8_QueryInterface (This->pPrimary, &IID_IDirectSound3DListener, ppObject);
93             return S_OK;
94           } else {
95             FIXME("bad iid...\n");
96           }
97         }
98         break;
99
100         case DMUS_PATH_AUDIOPATH_GRAPH:
101           {
102             if (IsEqualIID (iidInterface, &IID_IDirectMusicGraph)) {
103               if (NULL == This->pToolGraph) {
104                 IDirectMusicGraphImpl* pGraph;
105                 pGraph = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicGraphImpl));          
106                 pGraph->lpVtbl = &DirectMusicGraph_Vtbl;
107                 pGraph->ref = 1;
108                 This->pToolGraph = (IDirectMusicGraph*) pGraph;
109               }
110               *ppObject = (LPDIRECTMUSICGRAPH) This->pToolGraph; 
111               IDirectMusicGraphImpl_AddRef((LPDIRECTMUSICGRAPH) *ppObject);
112               return S_OK;
113             }
114           }
115           break;
116
117         case DMUS_PATH_AUDIOPATH_TOOL:
118           {
119             /* TODO */
120           }
121           break;
122
123         case DMUS_PATH_PERFORMANCE:
124           {
125             /* TODO check wanted GUID */
126             *ppObject = (LPDIRECTMUSICPERFORMANCE8) This->pPerf; 
127             IDirectMusicPerformance8Impl_AddRef((LPDIRECTMUSICPERFORMANCE8) *ppObject);
128             return S_OK;
129           }
130           break;
131
132         case DMUS_PATH_PERFORMANCE_GRAPH:
133           {
134             IDirectMusicGraph* pPerfoGraph = NULL; 
135             IDirectMusicPerformance8Impl_GetGraph((LPDIRECTMUSICPERFORMANCE8) This->pPerf, &pPerfoGraph);
136             if (NULL == pPerfoGraph) {
137               IDirectMusicGraphImpl* pGraph = NULL; 
138               pGraph = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicGraphImpl));            
139               pGraph->lpVtbl = &DirectMusicGraph_Vtbl;
140               pGraph->ref = 1;
141               IDirectMusicPerformance8Impl_SetGraph((LPDIRECTMUSICPERFORMANCE8) This->pPerf, (IDirectMusicGraph*) pGraph);
142               /* we need release as SetGraph do an AddRef */
143               IDirectMusicGraphImpl_Release((LPDIRECTMUSICGRAPH) pGraph);
144               pPerfoGraph = (LPDIRECTMUSICGRAPH) pGraph;
145             }
146             *ppObject = (LPDIRECTMUSICGRAPH) pPerfoGraph; 
147             return S_OK;
148           }
149           break;
150
151         case DMUS_PATH_PERFORMANCE_TOOL:
152         default:
153           break;
154         }
155
156         *ppObject = NULL;
157         return E_INVALIDARG;
158 }
159
160 HRESULT WINAPI IDirectMusicAudioPathImpl_Activate (LPDIRECTMUSICAUDIOPATH iface, BOOL fActivate)
161 {
162         ICOM_THIS(IDirectMusicAudioPathImpl,iface);
163
164         FIXME("(%p, %d): stub\n", This, fActivate);
165
166         return S_OK;
167 }
168
169 HRESULT WINAPI IDirectMusicAudioPathImpl_SetVolume (LPDIRECTMUSICAUDIOPATH iface, long lVolume, DWORD dwDuration)
170 {
171         ICOM_THIS(IDirectMusicAudioPathImpl,iface);
172
173         FIXME("(%p, %li, %ld): stub\n", This, lVolume, dwDuration);
174
175         return S_OK;
176 }
177
178 HRESULT WINAPI IDirectMusicAudioPathImpl_ConvertPChannel (LPDIRECTMUSICAUDIOPATH iface, DWORD dwPChannelIn, DWORD* pdwPChannelOut)
179 {
180         ICOM_THIS(IDirectMusicAudioPathImpl,iface);
181
182         FIXME("(%p, %ld, %p): stub\n", This, dwPChannelIn, pdwPChannelOut);
183
184         return S_OK;
185 }
186
187 ICOM_VTABLE(IDirectMusicAudioPath) DirectMusicAudioPath_Vtbl =
188 {
189     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
190         IDirectMusicAudioPathImpl_QueryInterface,
191         IDirectMusicAudioPathImpl_AddRef,
192         IDirectMusicAudioPathImpl_Release,
193         IDirectMusicAudioPathImpl_GetObjectInPath,
194         IDirectMusicAudioPathImpl_Activate,
195         IDirectMusicAudioPathImpl_SetVolume,
196         IDirectMusicAudioPathImpl_ConvertPChannel
197 };
198
199 /* for ClassFactory */
200 HRESULT WINAPI DMUSIC_CreateDirectMusicAudioPath (LPCGUID lpcGUID, LPDIRECTMUSICAUDIOPATH* ppDMCAPath, LPUNKNOWN pUnkOuter)
201 {
202         IDirectMusicAudioPathImpl* path;
203         
204         if (IsEqualIID (lpcGUID, &IID_IDirectMusicAudioPath)) {
205                 path = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicAudioPathImpl));
206                 if (NULL == path) {
207                         *ppDMCAPath = (LPDIRECTMUSICAUDIOPATH) NULL;
208                         return E_OUTOFMEMORY;
209                 }
210                 path->lpVtbl = &DirectMusicAudioPath_Vtbl;
211                 path->ref = 1;
212                 *ppDMCAPath = (LPDIRECTMUSICAUDIOPATH) path;
213                 return S_OK;
214         }
215         
216         WARN("No interface found\n");
217         return E_NOINTERFACE;
218 }
219
220 /*****************************************************************************
221  * IDirectMusicAudioPathObject implementation
222  */
223 /* IDirectMusicAudioPathObject IUnknown part: */
224 HRESULT WINAPI IDirectMusicAudioPathObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj)
225 {
226         ICOM_THIS(IDirectMusicAudioPathObject,iface);
227
228         if (IsEqualIID (riid, &IID_IUnknown) 
229                 || IsEqualIID (riid, &IID_IDirectMusicObject)) {
230                 IDirectMusicAudioPathObject_AddRef(iface);
231                 *ppobj = This;
232                 return S_OK;
233         } else if (IsEqualIID (riid, &IID_IPersistStream)) {
234                 IPersistStream_AddRef ((LPPERSISTSTREAM)This->pStream);
235                 *ppobj = (LPPERSISTSTREAM)This->pStream;
236                 return S_OK;
237         } else if (IsEqualIID (riid, &IID_IDirectMusicAudioPath)) {
238                 IDirectMusicAudioPath_AddRef ((LPDIRECTMUSICAUDIOPATH)This->pAudioPath);
239                 *ppobj = (LPDIRECTMUSICAUDIOPATH)This->pAudioPath;
240                 return S_OK;
241         }
242         
243         WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
244         return E_NOINTERFACE;
245 }
246
247 ULONG WINAPI IDirectMusicAudioPathObject_AddRef (LPDIRECTMUSICOBJECT iface)
248 {
249         ICOM_THIS(IDirectMusicAudioPathObject,iface);
250         TRACE("(%p) : AddRef from %ld\n", This, This->ref);
251         return ++(This->ref);
252 }
253
254 ULONG WINAPI IDirectMusicAudioPathObject_Release (LPDIRECTMUSICOBJECT iface)
255 {
256         ICOM_THIS(IDirectMusicAudioPathObject,iface);
257         ULONG ref = --This->ref;
258         TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
259         if (ref == 0) {
260                 HeapFree(GetProcessHeap(), 0, This);
261         }
262         return ref;
263 }
264
265 /* IDirectMusicAudioPathObject IDirectMusicObject part: */
266 HRESULT WINAPI IDirectMusicAudioPathObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc)
267 {
268         ICOM_THIS(IDirectMusicAudioPathObject,iface);
269
270         TRACE("(%p, %p)\n", This, pDesc);
271         pDesc = This->pDesc;
272         
273         return S_OK;
274 }
275
276 HRESULT WINAPI IDirectMusicAudioPathObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc)
277 {
278         ICOM_THIS(IDirectMusicAudioPathObject,iface);
279
280         TRACE("(%p, %p)\n", This, pDesc);
281         This->pDesc = pDesc;
282
283         return S_OK;
284 }
285
286 HRESULT WINAPI IDirectMusicAudioPathObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc)
287 {
288         ICOM_THIS(IDirectMusicAudioPathObject,iface);
289
290         FIXME("(%p, %p, %p): stub\n", This, pStream, pDesc);
291
292         return S_OK;
293 }
294
295 ICOM_VTABLE(IDirectMusicObject) DirectMusicAudioPathObject_Vtbl =
296 {
297     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
298         IDirectMusicAudioPathObject_QueryInterface,
299         IDirectMusicAudioPathObject_AddRef,
300         IDirectMusicAudioPathObject_Release,
301         IDirectMusicAudioPathObject_GetDescriptor,
302         IDirectMusicAudioPathObject_SetDescriptor,
303         IDirectMusicAudioPathObject_ParseDescriptor
304 };
305
306 /* for ClassFactory */
307 HRESULT WINAPI DMUSIC_CreateDirectMusicAudioPathObject (LPCGUID lpcGUID, LPDIRECTMUSICOBJECT* ppObject, LPUNKNOWN pUnkOuter)
308 {
309         IDirectMusicAudioPathObject *obj;
310         
311         TRACE("(%p,%p,%p)\n", lpcGUID, ppObject, pUnkOuter);
312         if (IsEqualIID (lpcGUID, &IID_IDirectMusicObject)) {
313                 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicAudioPathObject));
314                 if (NULL == obj) {
315                         *ppObject = (LPDIRECTMUSICOBJECT) NULL;
316                         return E_OUTOFMEMORY;
317                 }
318                 obj->lpVtbl = &DirectMusicAudioPathObject_Vtbl;
319                 obj->ref = 1;
320                 /* prepare IPersistStream */
321                 obj->pStream = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(IDirectMusicAudioPathObjectStream));
322                 obj->pStream->lpVtbl = &DirectMusicAudioPathObjectStream_Vtbl;
323                 obj->pStream->ref = 1;  
324                 obj->pStream->pParentObject = obj;
325                 /* prepare IDirectMusicAudioPath */
326                 DMUSIC_CreateDirectMusicAudioPath (&IID_IDirectMusicAudioPath, (LPDIRECTMUSICAUDIOPATH*)&obj->pAudioPath, NULL);
327                 obj->pAudioPath->pObject = obj;
328                 *ppObject = (LPDIRECTMUSICOBJECT) obj;
329                 return S_OK;
330         }
331         WARN("No interface found\n");
332         
333         return E_NOINTERFACE;
334 }
335         
336 /*****************************************************************************
337  * IDirectMusicAudioPathObjectStream implementation
338  */
339 /* IDirectMusicAudioPathObjectStream IUnknown part: */
340 HRESULT WINAPI IDirectMusicAudioPathObjectStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj)
341 {
342         ICOM_THIS(IDirectMusicAudioPathObjectStream,iface);
343
344         if (IsEqualIID (riid, &IID_IUnknown)
345                 || IsEqualIID (riid, &IID_IPersistStream)) {
346                 IDirectMusicAudioPathObjectStream_AddRef(iface);
347                 *ppobj = This;
348                 return S_OK;
349         }
350         
351         WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
352         return E_NOINTERFACE;
353 }
354
355 ULONG WINAPI IDirectMusicAudioPathObjectStream_AddRef (LPPERSISTSTREAM iface)
356 {
357         ICOM_THIS(IDirectMusicAudioPathObjectStream,iface);
358         TRACE("(%p) : AddRef from %ld\n", This, This->ref);
359         return ++(This->ref);
360 }
361
362 ULONG WINAPI IDirectMusicAudioPathObjectStream_Release (LPPERSISTSTREAM iface)
363 {
364         ICOM_THIS(IDirectMusicAudioPathObjectStream,iface);
365         ULONG ref = --This->ref;
366         TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
367         if (ref == 0) {
368                 HeapFree(GetProcessHeap(), 0, This);
369         }
370         return ref;
371 }
372
373 /* IDirectMusicAudioPathObjectStream IPersist part: */
374 HRESULT WINAPI IDirectMusicAudioPathObjectStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID)
375 {
376         return E_NOTIMPL;
377 }
378
379 /* IDirectMusicAudioPathObjectStream IPersistStream part: */
380 HRESULT WINAPI IDirectMusicAudioPathObjectStream_IsDirty (LPPERSISTSTREAM iface)
381 {
382         return E_NOTIMPL;
383 }
384
385 HRESULT WINAPI IDirectMusicAudioPathObjectStream_Load (LPPERSISTSTREAM iface, IStream* pStm)
386 {
387         FIXME(": Loading not implemented yet\n");
388         return S_OK;
389 }
390
391 HRESULT WINAPI IDirectMusicAudioPathObjectStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty)
392 {
393         return E_NOTIMPL;
394 }
395
396 HRESULT WINAPI IDirectMusicAudioPathObjectStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize)
397 {
398         return E_NOTIMPL;
399 }
400
401 ICOM_VTABLE(IPersistStream) DirectMusicAudioPathObjectStream_Vtbl =
402 {
403     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
404         IDirectMusicAudioPathObjectStream_QueryInterface,
405         IDirectMusicAudioPathObjectStream_AddRef,
406         IDirectMusicAudioPathObjectStream_Release,
407         IDirectMusicAudioPathObjectStream_GetClassID,
408         IDirectMusicAudioPathObjectStream_IsDirty,
409         IDirectMusicAudioPathObjectStream_Load,
410         IDirectMusicAudioPathObjectStream_Save,
411         IDirectMusicAudioPathObjectStream_GetSizeMax
412 };