1 /* IDirectMusicCollection Implementation
3 * Copyright (C) 2003 Rok Mandeljc
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.
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.
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.
26 #include "wine/debug.h"
28 #include "dmusic_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(dmusic
);
32 /* IDirectMusicCollection IUnknown parts follow: */
33 HRESULT WINAPI
IDirectMusicCollectionImpl_QueryInterface (LPDIRECTMUSICCOLLECTION iface
, REFIID riid
, LPVOID
*ppobj
)
35 ICOM_THIS(IDirectMusicCollectionImpl
,iface
);
37 if (IsEqualIID (riid
, &IID_IUnknown
)
38 || IsEqualIID (riid
, &IID_IDirectMusicCollection
)) {
39 IDirectMusicCollectionImpl_AddRef(iface
);
44 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppobj
);
48 ULONG WINAPI
IDirectMusicCollectionImpl_AddRef (LPDIRECTMUSICCOLLECTION iface
)
50 ICOM_THIS(IDirectMusicCollectionImpl
,iface
);
51 TRACE("(%p) : AddRef from %ld\n", This
, This
->ref
);
55 ULONG WINAPI
IDirectMusicCollectionImpl_Release (LPDIRECTMUSICCOLLECTION iface
)
57 ICOM_THIS(IDirectMusicCollectionImpl
,iface
);
58 ULONG ref
= --This
->ref
;
59 TRACE("(%p) : ReleaseRef to %ld\n", This
, This
->ref
);
61 HeapFree(GetProcessHeap(), 0, This
);
66 /* IDirectMusicCollection Interface follow: */
67 HRESULT WINAPI
IDirectMusicCollectionImpl_GetInstrument (LPDIRECTMUSICCOLLECTION iface
, DWORD dwPatch
, IDirectMusicInstrument
** ppInstrument
)
69 ICOM_THIS(IDirectMusicCollectionImpl
,iface
);
72 TRACE("(%p, %ld, %p)\n", This
, dwPatch
, ppInstrument
);
73 for (i
= 0; i
< This
->nrofinstruments
; i
++) {
74 if (This
->ppInstruments
[i
]->dwPatch
== dwPatch
) {
75 *ppInstrument
= (LPDIRECTMUSICINSTRUMENT
)This
->ppInstruments
[i
];
80 return DMUS_E_INVALIDPATCH
;
83 HRESULT WINAPI
IDirectMusicCollectionImpl_EnumInstrument (LPDIRECTMUSICCOLLECTION iface
, DWORD dwIndex
, DWORD
* pdwPatch
, LPWSTR pwszName
, DWORD dwNameLen
)
85 ICOM_THIS(IDirectMusicCollectionImpl
,iface
);
87 TRACE("(%p, %ld, %p, %p, %ld)\n", This
, dwIndex
, pdwPatch
, pwszName
, dwNameLen
);
88 if (dwIndex
> This
->nrofinstruments
)
90 *pdwPatch
= This
->ppInstruments
[dwIndex
]->dwPatch
;
91 if (pwszName
!= NULL
) {
93 *pwszName = (LPWSTR)This->ppInstruments[dwIndex]->pwszName;
94 *dwNameLen = wcslen (This->ppInstruments[dwIndex]->pwszName);
101 ICOM_VTABLE(IDirectMusicCollection
) DirectMusicCollection_Vtbl
=
103 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
104 IDirectMusicCollectionImpl_QueryInterface
,
105 IDirectMusicCollectionImpl_AddRef
,
106 IDirectMusicCollectionImpl_Release
,
107 IDirectMusicCollectionImpl_GetInstrument
,
108 IDirectMusicCollectionImpl_EnumInstrument
111 /* for ClassFactory */
112 HRESULT WINAPI
DMUSIC_CreateDirectMusicCollection (LPCGUID lpcGUID
, LPDIRECTMUSICCOLLECTION
* ppDMColl
, LPUNKNOWN pUnkOuter
)
114 IDirectMusicCollectionImpl
*collection
;
116 TRACE("(%p,%p,%p)\n", lpcGUID
, ppDMColl
, pUnkOuter
);
117 if (IsEqualIID (lpcGUID
, &IID_IDirectMusicCollection
)) {
118 collection
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicCollectionImpl
));
119 if (NULL
== collection
) {
120 *ppDMColl
= (LPDIRECTMUSICCOLLECTION
) NULL
;
121 return E_OUTOFMEMORY
;
123 collection
->lpVtbl
= &DirectMusicCollection_Vtbl
;
125 *ppDMColl
= (LPDIRECTMUSICCOLLECTION
) collection
;
129 WARN("No interface found\n");
130 return E_NOINTERFACE
;
134 /*****************************************************************************
135 * IDirectMusicCollectionObject implementation
137 /* IDirectMusicCollectionObject IUnknown part: */
138 HRESULT WINAPI
IDirectMusicCollectionObject_QueryInterface (LPDIRECTMUSICOBJECT iface
, REFIID riid
, LPVOID
*ppobj
)
140 ICOM_THIS(IDirectMusicCollectionObject
,iface
);
142 if (IsEqualIID (riid
, &IID_IUnknown
)
143 || IsEqualIID (riid
, &IID_IDirectMusicObject
)) {
144 IDirectMusicCollectionObject_AddRef(iface
);
147 } else if (IsEqualIID (riid
, &IID_IPersistStream
)) {
148 IDirectMusicCollectionObjectStream_AddRef ((LPPERSISTSTREAM
)This
->pStream
);
149 *ppobj
= This
->pStream
;
151 } else if (IsEqualIID (riid
, &IID_IDirectMusicCollection
)) {
152 IDirectMusicCollectionImpl_AddRef ((LPDIRECTMUSICCOLLECTION
)This
->pCollection
);
153 *ppobj
= This
->pCollection
;
157 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppobj
);
158 return E_NOINTERFACE
;
161 ULONG WINAPI
IDirectMusicCollectionObject_AddRef (LPDIRECTMUSICOBJECT iface
)
163 ICOM_THIS(IDirectMusicCollectionObject
,iface
);
164 TRACE("(%p) : AddRef from %ld\n", This
, This
->ref
);
165 return ++(This
->ref
);
168 ULONG WINAPI
IDirectMusicCollectionObject_Release (LPDIRECTMUSICOBJECT iface
)
170 ICOM_THIS(IDirectMusicCollectionObject
,iface
);
171 ULONG ref
= --This
->ref
;
172 TRACE("(%p) : ReleaseRef to %ld\n", This
, This
->ref
);
174 HeapFree(GetProcessHeap(), 0, This
);
179 /* IDirectMusicCollectionObject IDirectMusicObject part: */
180 HRESULT WINAPI
IDirectMusicCollectionObject_GetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
)
182 ICOM_THIS(IDirectMusicCollectionObject
,iface
);
184 TRACE("(%p, %p)\n", This
, pDesc
);
190 HRESULT WINAPI
IDirectMusicCollectionObject_SetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
)
192 ICOM_THIS(IDirectMusicCollectionObject
,iface
);
194 TRACE("(%p, %p)\n", This
, pDesc
);
200 HRESULT WINAPI
IDirectMusicCollectionObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface
, LPSTREAM pStream
, LPDMUS_OBJECTDESC pDesc
)
202 ICOM_THIS(IDirectMusicCollectionObject
,iface
);
204 FIXME("(%p, %p, %p): stub\n", This
, pStream
, pDesc
);
209 ICOM_VTABLE(IDirectMusicObject
) DirectMusicCollectionObject_Vtbl
=
211 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
212 IDirectMusicCollectionObject_QueryInterface
,
213 IDirectMusicCollectionObject_AddRef
,
214 IDirectMusicCollectionObject_Release
,
215 IDirectMusicCollectionObject_GetDescriptor
,
216 IDirectMusicCollectionObject_SetDescriptor
,
217 IDirectMusicCollectionObject_ParseDescriptor
220 /* for ClassFactory */
221 HRESULT WINAPI
DMUSIC_CreateDirectMusicCollectionObject (LPCGUID lpcGUID
, LPDIRECTMUSICOBJECT
* ppObject
, LPUNKNOWN pUnkOuter
)
223 IDirectMusicCollectionObject
*obj
;
225 TRACE("(%p,%p,%p)\n", lpcGUID
, ppObject
, pUnkOuter
);
226 if (IsEqualIID (lpcGUID
, &IID_IDirectMusicObject
)) {
227 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicCollectionObject
));
229 *ppObject
= (LPDIRECTMUSICOBJECT
) NULL
;
230 return E_OUTOFMEMORY
;
232 obj
->lpVtbl
= &DirectMusicCollectionObject_Vtbl
;
234 /* prepare IPersistStream */
235 obj
->pStream
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicCollectionObjectStream
));
236 obj
->pStream
->lpVtbl
= &DirectMusicCollectionObjectStream_Vtbl
;
237 obj
->pStream
->ref
= 1;
238 obj
->pStream
->pParentObject
= obj
;
239 /* prepare IDirectMusicCollection */
240 DMUSIC_CreateDirectMusicCollection (&IID_IDirectMusicCollection
, (LPDIRECTMUSICCOLLECTION
*)&obj
->pCollection
, NULL
);
241 obj
->pCollection
->pObject
= obj
;
242 *ppObject
= (LPDIRECTMUSICOBJECT
) obj
;
245 WARN("No interface found\n");
247 return E_NOINTERFACE
;
250 /*****************************************************************************
251 * IDirectMusicCollectionObjectStream implementation
253 /* IDirectMusicCollectionObjectStream IUnknown part: */
254 HRESULT WINAPI
IDirectMusicCollectionObjectStream_QueryInterface (LPPERSISTSTREAM iface
, REFIID riid
, LPVOID
*ppobj
)
256 ICOM_THIS(IDirectMusicCollectionObjectStream
,iface
);
258 if (IsEqualIID (riid
, &IID_IUnknown
)
259 || IsEqualIID (riid
, &IID_IPersistStream
)) {
260 IDirectMusicCollectionObjectStream_AddRef (iface
);
265 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppobj
);
266 return E_NOINTERFACE
;
269 ULONG WINAPI
IDirectMusicCollectionObjectStream_AddRef (LPPERSISTSTREAM iface
)
271 ICOM_THIS(IDirectMusicCollectionObjectStream
,iface
);
272 TRACE("(%p) : AddRef from %ld\n", This
, This
->ref
);
273 return ++(This
->ref
);
276 ULONG WINAPI
IDirectMusicCollectionObjectStream_Release (LPPERSISTSTREAM iface
)
278 ICOM_THIS(IDirectMusicCollectionObjectStream
,iface
);
279 ULONG ref
= --This
->ref
;
280 TRACE("(%p) : ReleaseRef to %ld\n", This
, This
->ref
);
282 HeapFree(GetProcessHeap(), 0, This
);
287 /* IDirectMusicCollectionObjectStream IPersist part: */
288 HRESULT WINAPI
IDirectMusicCollectionObjectStream_GetClassID (LPPERSISTSTREAM iface
, CLSID
* pClassID
)
293 /* IDirectMusicCollectionObjectStream IPersistStream part: */
294 HRESULT WINAPI
IDirectMusicCollectionObjectStream_IsDirty (LPPERSISTSTREAM iface
)
299 HRESULT WINAPI
IDirectMusicCollectionObjectStream_Load (LPPERSISTSTREAM iface
, IStream
* pStm
)
304 IStream_Read (pStm
, &chunkID
, sizeof(FOURCC
), NULL
);
305 IStream_Read (pStm
, &chunkSize
, sizeof(FOURCC
), NULL
);
307 if (chunkID
== FOURCC_RIFF
) {
308 FIXME(": Loading not implemented yet\n");
310 WARN("Not a RIFF file\n");
317 HRESULT WINAPI
IDirectMusicCollectionObjectStream_Save (LPPERSISTSTREAM iface
, IStream
* pStm
, BOOL fClearDirty
)
322 HRESULT WINAPI
IDirectMusicCollectionObjectStream_GetSizeMax (LPPERSISTSTREAM iface
, ULARGE_INTEGER
* pcbSize
)
327 ICOM_VTABLE(IPersistStream
) DirectMusicCollectionObjectStream_Vtbl
=
329 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
330 IDirectMusicCollectionObjectStream_QueryInterface
,
331 IDirectMusicCollectionObjectStream_AddRef
,
332 IDirectMusicCollectionObjectStream_Release
,
333 IDirectMusicCollectionObjectStream_GetClassID
,
334 IDirectMusicCollectionObjectStream_IsDirty
,
335 IDirectMusicCollectionObjectStream_Load
,
336 IDirectMusicCollectionObjectStream_Save
,
337 IDirectMusicCollectionObjectStream_GetSizeMax