1 /* IDirectMusicCollection Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
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.
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.
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
20 #include "dmusic_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(dmusic
);
23 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
25 static ULONG WINAPI
IDirectMusicCollectionImpl_IUnknown_AddRef (LPUNKNOWN iface
);
26 static ULONG WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef (LPDIRECTMUSICCOLLECTION iface
);
27 static ULONG WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface
);
28 static ULONG WINAPI
IDirectMusicCollectionImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface
);
30 /*****************************************************************************
31 * IDirectMusicCollectionImpl implementation
33 /* IDirectMusicCollectionImpl IUnknown part: */
34 static HRESULT WINAPI
IDirectMusicCollectionImpl_IUnknown_QueryInterface (LPUNKNOWN iface
, REFIID riid
, LPVOID
*ppobj
) {
35 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, UnknownVtbl
, iface
);
36 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ppobj
);
38 if (IsEqualIID (riid
, &IID_IUnknown
)) {
39 *ppobj
= &This
->UnknownVtbl
;
40 IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
42 } else if (IsEqualIID (riid
, &IID_IDirectMusicCollection
)) {
43 *ppobj
= &This
->CollectionVtbl
;
44 IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef ((LPDIRECTMUSICCOLLECTION
)&This
->CollectionVtbl
);
46 } else if (IsEqualIID (riid
, &IID_IDirectMusicObject
)) {
47 *ppobj
= &This
->ObjectVtbl
;
48 IDirectMusicCollectionImpl_IDirectMusicObject_AddRef ((LPDIRECTMUSICOBJECT
)&This
->ObjectVtbl
);
50 } else if (IsEqualIID (riid
, &IID_IPersistStream
)) {
51 *ppobj
= &This
->PersistStreamVtbl
;
52 IDirectMusicCollectionImpl_IPersistStream_AddRef ((LPPERSISTSTREAM
)&This
->PersistStreamVtbl
);
56 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ppobj
);
60 static ULONG WINAPI
IDirectMusicCollectionImpl_IUnknown_AddRef (LPUNKNOWN iface
) {
61 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, UnknownVtbl
, iface
);
62 ULONG refCount
= InterlockedIncrement(&This
->ref
);
64 TRACE("(%p)->(ref before=%u)\n", This
, refCount
- 1);
71 static ULONG WINAPI
IDirectMusicCollectionImpl_IUnknown_Release (LPUNKNOWN iface
) {
72 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, UnknownVtbl
, iface
);
73 ULONG refCount
= InterlockedDecrement(&This
->ref
);
75 TRACE("(%p)->(ref before=%u)\n", This
, refCount
+ 1);
78 HeapFree(GetProcessHeap(), 0, This
);
81 DMUSIC_UnlockModule();
86 static const IUnknownVtbl DirectMusicCollection_Unknown_Vtbl
= {
87 IDirectMusicCollectionImpl_IUnknown_QueryInterface
,
88 IDirectMusicCollectionImpl_IUnknown_AddRef
,
89 IDirectMusicCollectionImpl_IUnknown_Release
92 /* IDirectMusicCollectionImpl IDirectMusicCollection part: */
93 static HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_QueryInterface (LPDIRECTMUSICCOLLECTION iface
, REFIID riid
, LPVOID
*ppobj
) {
94 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, CollectionVtbl
, iface
);
95 return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
98 static ULONG WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef (LPDIRECTMUSICCOLLECTION iface
) {
99 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, CollectionVtbl
, iface
);
100 return IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
103 static ULONG WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_Release (LPDIRECTMUSICCOLLECTION iface
) {
104 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, CollectionVtbl
, iface
);
105 return IDirectMusicCollectionImpl_IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
108 /* IDirectMusicCollection Interface follow: */
109 static HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_GetInstrument (LPDIRECTMUSICCOLLECTION iface
, DWORD dwPatch
, IDirectMusicInstrument
** ppInstrument
) {
110 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, CollectionVtbl
, iface
);
111 DMUS_PRIVATE_INSTRUMENTENTRY
*tmpEntry
;
112 struct list
*listEntry
;
115 TRACE("(%p, %d, %p)\n", This
, dwPatch
, ppInstrument
);
117 LIST_FOR_EACH (listEntry
, &This
->Instruments
) {
118 tmpEntry
= LIST_ENTRY(listEntry
, DMUS_PRIVATE_INSTRUMENTENTRY
, entry
);
119 IDirectMusicInstrument_GetPatch (tmpEntry
->pInstrument
, &dwInstPatch
);
120 if (dwPatch
== dwInstPatch
) {
121 *ppInstrument
= tmpEntry
->pInstrument
;
122 IDirectMusicInstrument_AddRef (tmpEntry
->pInstrument
);
123 IDirectMusicInstrumentImpl_Custom_Load (tmpEntry
->pInstrument
, This
->pStm
); /* load instrument before returning it */
124 TRACE(": returning instrument %p\n", *ppInstrument
);
129 TRACE(": instrument not found\n");
131 return DMUS_E_INVALIDPATCH
;
134 static HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_EnumInstrument (LPDIRECTMUSICCOLLECTION iface
, DWORD dwIndex
, DWORD
* pdwPatch
, LPWSTR pwszName
, DWORD dwNameLen
) {
135 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, CollectionVtbl
, iface
);
137 DMUS_PRIVATE_INSTRUMENTENTRY
*tmpEntry
;
138 struct list
*listEntry
;
141 TRACE("(%p, %d, %p, %p, %d)\n", This
, dwIndex
, pdwPatch
, pwszName
, dwNameLen
);
142 LIST_FOR_EACH (listEntry
, &This
->Instruments
) {
143 tmpEntry
= LIST_ENTRY(listEntry
, DMUS_PRIVATE_INSTRUMENTENTRY
, entry
);
145 ICOM_NAME_MULTI (IDirectMusicInstrumentImpl
, InstrumentVtbl
, tmpEntry
->pInstrument
, pInstrument
);
146 IDirectMusicInstrument_GetPatch (tmpEntry
->pInstrument
, pdwPatch
);
148 dwLen
= min(strlenW(pInstrument
->wszName
),dwNameLen
-1);
149 memcpy (pwszName
, pInstrument
->wszName
, dwLen
* sizeof(WCHAR
));
150 pwszName
[dwLen
] = '\0';
160 static const IDirectMusicCollectionVtbl DirectMusicCollection_Collection_Vtbl
= {
161 IDirectMusicCollectionImpl_IDirectMusicCollection_QueryInterface
,
162 IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef
,
163 IDirectMusicCollectionImpl_IDirectMusicCollection_Release
,
164 IDirectMusicCollectionImpl_IDirectMusicCollection_GetInstrument
,
165 IDirectMusicCollectionImpl_IDirectMusicCollection_EnumInstrument
168 /* IDirectMusicCollectionImpl IDirectMusicObject part: */
169 static HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface
, REFIID riid
, LPVOID
*ppobj
) {
170 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, ObjectVtbl
, iface
);
171 return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
174 static ULONG WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface
) {
175 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, ObjectVtbl
, iface
);
176 return IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
179 static ULONG WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface
) {
180 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, ObjectVtbl
, iface
);
181 return IDirectMusicCollectionImpl_IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
184 static HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
) {
185 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, ObjectVtbl
, iface
);
186 TRACE("(%p, %p)\n", This
, pDesc
);
187 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
188 memcpy (pDesc
, This
->pDesc
, This
->pDesc
->dwSize
);
192 static HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
) {
193 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, ObjectVtbl
, iface
);
194 TRACE("(%p, %p): setting descriptor:\n%s\n", This
, pDesc
, debugstr_DMUS_OBJECTDESC (pDesc
));
196 /* According to MSDN, we should copy only given values, not whole struct */
197 if (pDesc
->dwValidData
& DMUS_OBJ_OBJECT
)
198 This
->pDesc
->guidObject
= pDesc
->guidObject
;
199 if (pDesc
->dwValidData
& DMUS_OBJ_CLASS
)
200 This
->pDesc
->guidClass
= pDesc
->guidClass
;
201 if (pDesc
->dwValidData
& DMUS_OBJ_NAME
)
202 lstrcpynW(This
->pDesc
->wszName
, pDesc
->wszName
, DMUS_MAX_NAME
);
203 if (pDesc
->dwValidData
& DMUS_OBJ_CATEGORY
)
204 lstrcpynW(This
->pDesc
->wszCategory
, pDesc
->wszCategory
, DMUS_MAX_CATEGORY
);
205 if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
)
206 lstrcpynW(This
->pDesc
->wszFileName
, pDesc
->wszFileName
, DMUS_MAX_FILENAME
);
207 if (pDesc
->dwValidData
& DMUS_OBJ_VERSION
)
208 This
->pDesc
->vVersion
= pDesc
->vVersion
;
209 if (pDesc
->dwValidData
& DMUS_OBJ_DATE
)
210 This
->pDesc
->ftDate
= pDesc
->ftDate
;
211 if (pDesc
->dwValidData
& DMUS_OBJ_MEMORY
) {
212 memcpy (&This
->pDesc
->llMemLength
, &pDesc
->llMemLength
, sizeof (pDesc
->llMemLength
));
213 memcpy (This
->pDesc
->pbMemData
, pDesc
->pbMemData
, sizeof (pDesc
->pbMemData
));
215 if (pDesc
->dwValidData
& DMUS_OBJ_STREAM
) {
216 /* according to MSDN, we copy the stream */
217 IStream_Clone (pDesc
->pStream
, &This
->pDesc
->pStream
);
221 This
->pDesc
->dwValidData
|= pDesc
->dwValidData
;
226 static HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface
, LPSTREAM pStream
, LPDMUS_OBJECTDESC pDesc
) {
227 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, ObjectVtbl
, iface
);
228 DMUS_PRIVATE_CHUNK Chunk
;
229 DWORD StreamSize
, StreamCount
, ListSize
[1], ListCount
[1];
230 LARGE_INTEGER liMove
; /* used when skipping chunks */
232 TRACE("(%p, %p, %p)\n", This
, pStream
, pDesc
);
234 /* FIXME: should this be determined from stream? */
235 pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
236 pDesc
->guidClass
= CLSID_DirectMusicCollection
;
238 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
239 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
240 switch (Chunk
.fccID
) {
242 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
243 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
244 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
246 if (Chunk
.fccID
== mmioFOURCC('D','L','S',' ')) {
247 TRACE_(dmfile
)(": collection form\n");
249 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
250 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
251 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
252 switch (Chunk
.fccID
) {
254 TRACE_(dmfile
)(": GUID chunk\n");
255 pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
256 IStream_Read (pStream
, &pDesc
->guidObject
, Chunk
.dwSize
, NULL
);
259 case DMUS_FOURCC_VERSION_CHUNK
: {
260 TRACE_(dmfile
)(": version chunk\n");
261 pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
262 IStream_Read (pStream
, &pDesc
->vVersion
, Chunk
.dwSize
, NULL
);
265 case DMUS_FOURCC_CATEGORY_CHUNK
: {
266 TRACE_(dmfile
)(": category chunk\n");
267 pDesc
->dwValidData
|= DMUS_OBJ_CATEGORY
;
268 IStream_Read (pStream
, pDesc
->wszCategory
, Chunk
.dwSize
, NULL
);
272 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
273 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
274 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
276 switch (Chunk
.fccID
) {
277 /* pure INFO list, such can be found in dls collections */
278 case mmioFOURCC('I','N','F','O'): {
279 TRACE_(dmfile
)(": INFO list\n");
281 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
282 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
283 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
284 switch (Chunk
.fccID
) {
285 case mmioFOURCC('I','N','A','M'):{
286 CHAR szName
[DMUS_MAX_NAME
];
287 TRACE_(dmfile
)(": name chunk\n");
288 pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
289 IStream_Read (pStream
, szName
, Chunk
.dwSize
, NULL
);
290 MultiByteToWideChar (CP_ACP
, 0, szName
, -1, pDesc
->wszName
, DMUS_MAX_NAME
);
291 if (even_or_odd(Chunk
.dwSize
)) {
294 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
298 case mmioFOURCC('I','A','R','T'): {
299 TRACE_(dmfile
)(": artist chunk (ignored)\n");
300 if (even_or_odd(Chunk
.dwSize
)) {
304 liMove
.QuadPart
= Chunk
.dwSize
;
305 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
308 case mmioFOURCC('I','C','O','P'): {
309 TRACE_(dmfile
)(": copyright chunk (ignored)\n");
310 if (even_or_odd(Chunk
.dwSize
)) {
314 liMove
.QuadPart
= Chunk
.dwSize
;
315 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
318 case mmioFOURCC('I','S','B','J'): {
319 TRACE_(dmfile
)(": subject chunk (ignored)\n");
320 if (even_or_odd(Chunk
.dwSize
)) {
324 liMove
.QuadPart
= Chunk
.dwSize
;
325 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
328 case mmioFOURCC('I','C','M','T'): {
329 TRACE_(dmfile
)(": comment chunk (ignored)\n");
330 if (even_or_odd(Chunk
.dwSize
)) {
334 liMove
.QuadPart
= Chunk
.dwSize
;
335 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
339 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
340 if (even_or_odd(Chunk
.dwSize
)) {
344 liMove
.QuadPart
= Chunk
.dwSize
;
345 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
349 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
350 } while (ListCount
[0] < ListSize
[0]);
354 TRACE_(dmfile
)(": unknown (skipping)\n");
355 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
356 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
363 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
364 liMove
.QuadPart
= Chunk
.dwSize
;
365 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
369 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
370 } while (StreamCount
< StreamSize
);
372 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
373 liMove
.QuadPart
= StreamSize
;
374 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
378 TRACE_(dmfile
)(": reading finished\n");
382 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
383 liMove
.QuadPart
= Chunk
.dwSize
;
384 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
385 return DMUS_E_INVALIDFILE
;
389 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc
));
394 static const IDirectMusicObjectVtbl DirectMusicCollection_Object_Vtbl
= {
395 IDirectMusicCollectionImpl_IDirectMusicObject_QueryInterface
,
396 IDirectMusicCollectionImpl_IDirectMusicObject_AddRef
,
397 IDirectMusicCollectionImpl_IDirectMusicObject_Release
,
398 IDirectMusicCollectionImpl_IDirectMusicObject_GetDescriptor
,
399 IDirectMusicCollectionImpl_IDirectMusicObject_SetDescriptor
,
400 IDirectMusicCollectionImpl_IDirectMusicObject_ParseDescriptor
403 /* IDirectMusicCollectionImpl IPersistStream part: */
404 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface
, REFIID riid
, LPVOID
*ppobj
) {
405 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, PersistStreamVtbl
, iface
);
406 return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
409 static ULONG WINAPI
IDirectMusicCollectionImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface
) {
410 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, PersistStreamVtbl
, iface
);
411 return IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
414 static ULONG WINAPI
IDirectMusicCollectionImpl_IPersistStream_Release (LPPERSISTSTREAM iface
) {
415 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, PersistStreamVtbl
, iface
);
416 return IDirectMusicCollectionImpl_IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
419 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_GetClassID (LPPERSISTSTREAM iface
, CLSID
* pClassID
) {
423 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_IsDirty (LPPERSISTSTREAM iface
) {
427 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_Load (LPPERSISTSTREAM iface
, IStream
* pStm
) {
428 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, PersistStreamVtbl
, iface
);
430 DMUS_PRIVATE_CHUNK Chunk
;
431 DWORD StreamSize
, StreamCount
, ListSize
[3], ListCount
[3];
432 LARGE_INTEGER liMove
; /* used when skipping chunks */
433 ULARGE_INTEGER dlibCollectionPosition
, dlibInstrumentPosition
, dlibWavePoolPosition
;
435 IStream_AddRef (pStm
); /* add count for later references */
437 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, &dlibCollectionPosition
); /* store offset, in case it'll be needed later */
438 This
->liCollectionPosition
.QuadPart
= dlibCollectionPosition
.QuadPart
;
441 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
442 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
443 switch (Chunk
.fccID
) {
445 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
446 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
447 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
449 switch (Chunk
.fccID
) {
451 TRACE_(dmfile
)(": collection form\n");
453 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
454 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
455 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
456 switch (Chunk
.fccID
) {
458 TRACE_(dmfile
)(": collection header chunk\n");
459 This
->pHeader
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, Chunk
.dwSize
);
460 IStream_Read (pStm
, This
->pHeader
, Chunk
.dwSize
, NULL
);
464 TRACE_(dmfile
)(": DLID (GUID) chunk\n");
465 This
->pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
466 IStream_Read (pStm
, &This
->pDesc
->guidObject
, Chunk
.dwSize
, NULL
);
470 TRACE_(dmfile
)(": version chunk\n");
471 This
->pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
472 IStream_Read (pStm
, &This
->pDesc
->vVersion
, Chunk
.dwSize
, NULL
);
476 TRACE_(dmfile
)(": pool table chunk\n");
477 This
->pPoolTable
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(POOLTABLE
));
478 IStream_Read (pStm
, This
->pPoolTable
, sizeof(POOLTABLE
), NULL
);
479 Chunk
.dwSize
-= sizeof(POOLTABLE
);
480 This
->pPoolCues
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, This
->pPoolTable
->cCues
*sizeof(POOLCUE
));
481 IStream_Read (pStm
, This
->pPoolCues
, Chunk
.dwSize
, NULL
);
485 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
486 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
487 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
489 switch (Chunk
.fccID
) {
490 case mmioFOURCC('I','N','F','O'): {
491 TRACE_(dmfile
)(": INFO list\n");
493 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
494 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
495 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
496 switch (Chunk
.fccID
) {
497 case mmioFOURCC('I','N','A','M'): {
498 CHAR szName
[DMUS_MAX_NAME
];
499 TRACE_(dmfile
)(": name chunk\n");
500 This
->pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
501 IStream_Read (pStm
, szName
, Chunk
.dwSize
, NULL
);
502 MultiByteToWideChar (CP_ACP
, 0, szName
, -1, This
->pDesc
->wszName
, DMUS_MAX_NAME
);
503 if (even_or_odd(Chunk
.dwSize
)) {
506 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
510 case mmioFOURCC('I','A','R','T'): {
511 TRACE_(dmfile
)(": artist chunk (ignored)\n");
512 if (even_or_odd(Chunk
.dwSize
)) {
516 liMove
.QuadPart
= Chunk
.dwSize
;
517 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
520 case mmioFOURCC('I','C','O','P'): {
521 TRACE_(dmfile
)(": copyright chunk\n");
522 This
->szCopyright
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, Chunk
.dwSize
);
523 IStream_Read (pStm
, This
->szCopyright
, Chunk
.dwSize
, NULL
);
524 if (even_or_odd(Chunk
.dwSize
)) {
527 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
531 case mmioFOURCC('I','S','B','J'): {
532 TRACE_(dmfile
)(": subject chunk (ignored)\n");
533 if (even_or_odd(Chunk
.dwSize
)) {
537 liMove
.QuadPart
= Chunk
.dwSize
;
538 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
541 case mmioFOURCC('I','C','M','T'): {
542 TRACE_(dmfile
)(": comment chunk (ignored)\n");
543 if (even_or_odd(Chunk
.dwSize
)) {
547 liMove
.QuadPart
= Chunk
.dwSize
;
548 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
552 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
553 if (even_or_odd(Chunk
.dwSize
)) {
557 liMove
.QuadPart
= Chunk
.dwSize
;
558 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
562 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
563 } while (ListCount
[0] < ListSize
[0]);
567 TRACE_(dmfile
)(": wave pool list (mark & skip)\n");
569 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, &dlibWavePoolPosition
); /* store position */
570 This
->liWavePoolTablePosition
.QuadPart
= dlibWavePoolPosition
.QuadPart
;
571 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
572 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
576 TRACE_(dmfile
)(": instruments list\n");
578 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
579 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
580 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
581 switch (Chunk
.fccID
) {
583 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
584 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
585 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
587 switch (Chunk
.fccID
) {
589 LPDMUS_PRIVATE_INSTRUMENTENTRY pNewInstrument
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_INSTRUMENTENTRY
));
590 TRACE_(dmfile
)(": instrument list\n");
591 DMUSIC_CreateDirectMusicInstrumentImpl (&IID_IDirectMusicInstrument
, (LPVOID
*)&pNewInstrument
->pInstrument
, NULL
); /* only way to create this one... even M$ does it discretely */
593 ICOM_NAME_MULTI (IDirectMusicInstrumentImpl
, InstrumentVtbl
, pNewInstrument
->pInstrument
, pInstrument
);
595 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, &dlibInstrumentPosition
);
596 pInstrument
->liInstrumentPosition
.QuadPart
= dlibInstrumentPosition
.QuadPart
- (2*sizeof(FOURCC
) + sizeof(DWORD
)); /* store offset, it'll be needed later */
599 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
600 ListCount
[1] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
601 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
602 switch (Chunk
.fccID
) {
604 TRACE_(dmfile
)(": instrument header chunk\n");
605 pInstrument
->pHeader
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, Chunk
.dwSize
);
606 IStream_Read (pStm
, pInstrument
->pHeader
, Chunk
.dwSize
, NULL
);
610 TRACE_(dmfile
)(": DLID (GUID) chunk\n");
611 pInstrument
->pInstrumentID
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, Chunk
.dwSize
);
612 IStream_Read (pStm
, pInstrument
->pInstrumentID
, Chunk
.dwSize
, NULL
);
616 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
617 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
618 ListSize
[2] = Chunk
.dwSize
- sizeof(FOURCC
);
620 switch (Chunk
.fccID
) {
622 TRACE_(dmfile
)(": unknown (skipping)\n");
623 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
624 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
631 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
632 liMove
.QuadPart
= Chunk
.dwSize
;
633 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
637 TRACE_(dmfile
)(": ListCount[1] = %d < ListSize[1] = %d\n", ListCount
[1], ListSize
[1]);
638 } while (ListCount
[1] < ListSize
[1]);
639 /* DEBUG: dumps whole instrument object tree: */
640 if (TRACE_ON(dmusic
)) {
641 TRACE("*** IDirectMusicInstrument (%p) ***\n", pInstrument
);
642 if (pInstrument
->pInstrumentID
)
643 TRACE(" - GUID = %s\n", debugstr_dmguid(pInstrument
->pInstrumentID
));
645 TRACE(" - Instrument header:\n");
646 TRACE(" - cRegions: %d\n", pInstrument
->pHeader
->cRegions
);
647 TRACE(" - Locale:\n");
648 TRACE(" - ulBank: %d\n", pInstrument
->pHeader
->Locale
.ulBank
);
649 TRACE(" - ulInstrument: %d\n", pInstrument
->pHeader
->Locale
.ulInstrument
);
650 TRACE(" => dwPatch: %d\n", MIDILOCALE2Patch(&pInstrument
->pHeader
->Locale
));
652 list_add_tail (&This
->Instruments
, &pNewInstrument
->entry
);
660 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
661 liMove
.QuadPart
= Chunk
.dwSize
;
662 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
666 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
667 } while (ListCount
[0] < ListSize
[0]);
671 TRACE_(dmfile
)(": unknown (skipping)\n");
672 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
673 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
680 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
681 liMove
.QuadPart
= Chunk
.dwSize
;
682 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
686 TRACE_(dmfile
)(": StreamCount = %d < StreamSize = %d\n", StreamCount
, StreamSize
);
687 } while (StreamCount
< StreamSize
);
691 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
692 liMove
.QuadPart
= StreamSize
;
693 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
697 TRACE_(dmfile
)(": reading finished\n");
701 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
702 liMove
.QuadPart
= Chunk
.dwSize
;
703 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
708 /* DEBUG: dumps whole collection object tree: */
709 if (TRACE_ON(dmusic
)) {
711 DMUS_PRIVATE_INSTRUMENTENTRY
*tmpEntry
;
712 struct list
*listEntry
;
714 TRACE("*** IDirectMusicCollection (%p) ***\n", This
->CollectionVtbl
);
715 if (This
->pDesc
->dwValidData
& DMUS_OBJ_OBJECT
)
716 TRACE(" - GUID = %s\n", debugstr_dmguid(&This
->pDesc
->guidObject
));
717 if (This
->pDesc
->dwValidData
& DMUS_OBJ_VERSION
)
718 TRACE(" - Version = %i,%i,%i,%i\n", (This
->pDesc
->vVersion
.dwVersionMS
>> 8) & 0x0000FFFF, This
->pDesc
->vVersion
.dwVersionMS
& 0x0000FFFF,
719 (This
->pDesc
->vVersion
.dwVersionLS
>> 8) & 0x0000FFFF, This
->pDesc
->vVersion
.dwVersionLS
& 0x0000FFFF);
720 if (This
->pDesc
->dwValidData
& DMUS_OBJ_NAME
)
721 TRACE(" - Name = %s\n", debugstr_w(This
->pDesc
->wszName
));
723 TRACE(" - Collection header:\n");
724 TRACE(" - cInstruments: %d\n", This
->pHeader
->cInstruments
);
725 TRACE(" - Instruments:\n");
727 LIST_FOR_EACH (listEntry
, &This
->Instruments
) {
728 tmpEntry
= LIST_ENTRY( listEntry
, DMUS_PRIVATE_INSTRUMENTENTRY
, entry
);
729 TRACE(" - Instrument[%i]: %p\n", r
, tmpEntry
->pInstrument
);
737 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_Save (LPPERSISTSTREAM iface
, IStream
* pStm
, BOOL fClearDirty
) {
741 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface
, ULARGE_INTEGER
* pcbSize
) {
745 static const IPersistStreamVtbl DirectMusicCollection_PersistStream_Vtbl
= {
746 IDirectMusicCollectionImpl_IPersistStream_QueryInterface
,
747 IDirectMusicCollectionImpl_IPersistStream_AddRef
,
748 IDirectMusicCollectionImpl_IPersistStream_Release
,
749 IDirectMusicCollectionImpl_IPersistStream_GetClassID
,
750 IDirectMusicCollectionImpl_IPersistStream_IsDirty
,
751 IDirectMusicCollectionImpl_IPersistStream_Load
,
752 IDirectMusicCollectionImpl_IPersistStream_Save
,
753 IDirectMusicCollectionImpl_IPersistStream_GetSizeMax
757 /* for ClassFactory */
758 HRESULT WINAPI
DMUSIC_CreateDirectMusicCollectionImpl (LPCGUID lpcGUID
, LPVOID
* ppobj
, LPUNKNOWN pUnkOuter
) {
759 IDirectMusicCollectionImpl
* obj
;
761 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicCollectionImpl
));
764 return E_OUTOFMEMORY
;
766 obj
->UnknownVtbl
= &DirectMusicCollection_Unknown_Vtbl
;
767 obj
->CollectionVtbl
= &DirectMusicCollection_Collection_Vtbl
;
768 obj
->ObjectVtbl
= &DirectMusicCollection_Object_Vtbl
;
769 obj
->PersistStreamVtbl
= &DirectMusicCollection_PersistStream_Vtbl
;
770 obj
->pDesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DMUS_OBJECTDESC
));
771 DM_STRUCT_INIT(obj
->pDesc
);
772 obj
->pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
773 obj
->pDesc
->guidClass
= CLSID_DirectMusicCollection
;
774 obj
->ref
= 0; /* will be inited by QueryInterface */
775 list_init (&obj
->Instruments
);
777 return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN
)&obj
->UnknownVtbl
, lpcGUID
, ppobj
);