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 IDirectMusicInstrumentImpl
*pInstrument
= impl_from_IDirectMusicInstrument(tmpEntry
->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
)
194 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, ObjectVtbl
, iface
);
196 TRACE("(%p, %p)\n", iface
, pDesc
);
201 if (TRACE_ON(dmusic
))
203 TRACE("Setting descriptor:\n");
204 dump_DMUS_OBJECTDESC(pDesc
);
207 /* According to MSDN, we should copy only given values, not whole struct */
208 if (pDesc
->dwValidData
& DMUS_OBJ_OBJECT
)
209 This
->pDesc
->guidObject
= pDesc
->guidObject
;
210 if (pDesc
->dwValidData
& DMUS_OBJ_CLASS
)
211 This
->pDesc
->guidClass
= pDesc
->guidClass
;
212 if (pDesc
->dwValidData
& DMUS_OBJ_NAME
)
213 lstrcpynW(This
->pDesc
->wszName
, pDesc
->wszName
, DMUS_MAX_NAME
);
214 if (pDesc
->dwValidData
& DMUS_OBJ_CATEGORY
)
215 lstrcpynW(This
->pDesc
->wszCategory
, pDesc
->wszCategory
, DMUS_MAX_CATEGORY
);
216 if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
)
217 lstrcpynW(This
->pDesc
->wszFileName
, pDesc
->wszFileName
, DMUS_MAX_FILENAME
);
218 if (pDesc
->dwValidData
& DMUS_OBJ_VERSION
)
219 This
->pDesc
->vVersion
= pDesc
->vVersion
;
220 if (pDesc
->dwValidData
& DMUS_OBJ_DATE
)
221 This
->pDesc
->ftDate
= pDesc
->ftDate
;
222 if (pDesc
->dwValidData
& DMUS_OBJ_MEMORY
) {
223 This
->pDesc
->llMemLength
= pDesc
->llMemLength
;
224 memcpy (This
->pDesc
->pbMemData
, pDesc
->pbMemData
, pDesc
->llMemLength
);
226 if (pDesc
->dwValidData
& DMUS_OBJ_STREAM
) {
227 /* according to MSDN, we copy the stream */
228 IStream_Clone (pDesc
->pStream
, &This
->pDesc
->pStream
);
232 This
->pDesc
->dwValidData
|= pDesc
->dwValidData
;
237 static HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_ParseDescriptor(LPDIRECTMUSICOBJECT iface
, LPSTREAM pStream
, LPDMUS_OBJECTDESC pDesc
)
239 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, ObjectVtbl
, iface
);
240 DMUS_PRIVATE_CHUNK Chunk
;
241 DWORD StreamSize
, StreamCount
, ListSize
[1], ListCount
[1];
242 LARGE_INTEGER liMove
; /* used when skipping chunks */
244 TRACE("(%p, %p, %p)\n", This
, pStream
, pDesc
);
246 /* FIXME: should this be determined from stream? */
247 pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
248 pDesc
->guidClass
= CLSID_DirectMusicCollection
;
250 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
251 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
252 switch (Chunk
.fccID
) {
254 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
255 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
256 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
258 if (Chunk
.fccID
== mmioFOURCC('D','L','S',' ')) {
259 TRACE_(dmfile
)(": collection form\n");
261 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
262 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
263 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
264 switch (Chunk
.fccID
) {
266 TRACE_(dmfile
)(": GUID chunk\n");
267 pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
268 IStream_Read (pStream
, &pDesc
->guidObject
, Chunk
.dwSize
, NULL
);
271 case DMUS_FOURCC_VERSION_CHUNK
: {
272 TRACE_(dmfile
)(": version chunk\n");
273 pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
274 IStream_Read (pStream
, &pDesc
->vVersion
, Chunk
.dwSize
, NULL
);
277 case DMUS_FOURCC_CATEGORY_CHUNK
: {
278 TRACE_(dmfile
)(": category chunk\n");
279 pDesc
->dwValidData
|= DMUS_OBJ_CATEGORY
;
280 IStream_Read (pStream
, pDesc
->wszCategory
, Chunk
.dwSize
, NULL
);
284 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
285 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
286 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
288 switch (Chunk
.fccID
) {
289 /* pure INFO list, such can be found in dls collections */
290 case mmioFOURCC('I','N','F','O'): {
291 TRACE_(dmfile
)(": INFO list\n");
293 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
294 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
295 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
296 switch (Chunk
.fccID
) {
297 case mmioFOURCC('I','N','A','M'):{
298 CHAR szName
[DMUS_MAX_NAME
];
299 TRACE_(dmfile
)(": name chunk\n");
300 pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
301 IStream_Read (pStream
, szName
, Chunk
.dwSize
, NULL
);
302 MultiByteToWideChar (CP_ACP
, 0, szName
, -1, pDesc
->wszName
, DMUS_MAX_NAME
);
303 if (even_or_odd(Chunk
.dwSize
)) {
306 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
310 case mmioFOURCC('I','A','R','T'): {
311 TRACE_(dmfile
)(": artist chunk (ignored)\n");
312 if (even_or_odd(Chunk
.dwSize
)) {
316 liMove
.QuadPart
= Chunk
.dwSize
;
317 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
320 case mmioFOURCC('I','C','O','P'): {
321 TRACE_(dmfile
)(": copyright chunk (ignored)\n");
322 if (even_or_odd(Chunk
.dwSize
)) {
326 liMove
.QuadPart
= Chunk
.dwSize
;
327 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
330 case mmioFOURCC('I','S','B','J'): {
331 TRACE_(dmfile
)(": subject chunk (ignored)\n");
332 if (even_or_odd(Chunk
.dwSize
)) {
336 liMove
.QuadPart
= Chunk
.dwSize
;
337 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
340 case mmioFOURCC('I','C','M','T'): {
341 TRACE_(dmfile
)(": comment chunk (ignored)\n");
342 if (even_or_odd(Chunk
.dwSize
)) {
346 liMove
.QuadPart
= Chunk
.dwSize
;
347 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
351 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
352 if (even_or_odd(Chunk
.dwSize
)) {
356 liMove
.QuadPart
= Chunk
.dwSize
;
357 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
361 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
362 } while (ListCount
[0] < ListSize
[0]);
366 TRACE_(dmfile
)(": unknown (skipping)\n");
367 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
368 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
375 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
376 liMove
.QuadPart
= Chunk
.dwSize
;
377 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
381 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
382 } while (StreamCount
< StreamSize
);
384 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
385 liMove
.QuadPart
= StreamSize
;
386 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
390 TRACE_(dmfile
)(": reading finished\n");
394 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
395 liMove
.QuadPart
= Chunk
.dwSize
;
396 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
397 return DMUS_E_INVALIDFILE
;
401 if (TRACE_ON(dmusic
))
403 TRACE("Returning descriptor:\n");
404 dump_DMUS_OBJECTDESC(pDesc
);
410 static const IDirectMusicObjectVtbl DirectMusicCollection_Object_Vtbl
= {
411 IDirectMusicCollectionImpl_IDirectMusicObject_QueryInterface
,
412 IDirectMusicCollectionImpl_IDirectMusicObject_AddRef
,
413 IDirectMusicCollectionImpl_IDirectMusicObject_Release
,
414 IDirectMusicCollectionImpl_IDirectMusicObject_GetDescriptor
,
415 IDirectMusicCollectionImpl_IDirectMusicObject_SetDescriptor
,
416 IDirectMusicCollectionImpl_IDirectMusicObject_ParseDescriptor
419 /* IDirectMusicCollectionImpl IPersistStream part: */
420 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface
, REFIID riid
, LPVOID
*ppobj
) {
421 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, PersistStreamVtbl
, iface
);
422 return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
425 static ULONG WINAPI
IDirectMusicCollectionImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface
) {
426 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, PersistStreamVtbl
, iface
);
427 return IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
430 static ULONG WINAPI
IDirectMusicCollectionImpl_IPersistStream_Release (LPPERSISTSTREAM iface
) {
431 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, PersistStreamVtbl
, iface
);
432 return IDirectMusicCollectionImpl_IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
435 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_GetClassID (LPPERSISTSTREAM iface
, CLSID
* pClassID
) {
439 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_IsDirty (LPPERSISTSTREAM iface
) {
443 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_Load (LPPERSISTSTREAM iface
, IStream
* pStm
) {
444 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, PersistStreamVtbl
, iface
);
446 DMUS_PRIVATE_CHUNK Chunk
;
447 DWORD StreamSize
, StreamCount
, ListSize
[3], ListCount
[3];
448 LARGE_INTEGER liMove
; /* used when skipping chunks */
449 ULARGE_INTEGER dlibCollectionPosition
, dlibInstrumentPosition
, dlibWavePoolPosition
;
451 IStream_AddRef (pStm
); /* add count for later references */
453 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, &dlibCollectionPosition
); /* store offset, in case it'll be needed later */
454 This
->liCollectionPosition
.QuadPart
= dlibCollectionPosition
.QuadPart
;
457 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
458 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
459 switch (Chunk
.fccID
) {
461 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
462 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
463 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
465 switch (Chunk
.fccID
) {
467 TRACE_(dmfile
)(": collection form\n");
469 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
470 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
471 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
472 switch (Chunk
.fccID
) {
474 TRACE_(dmfile
)(": collection header chunk\n");
475 This
->pHeader
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, Chunk
.dwSize
);
476 IStream_Read (pStm
, This
->pHeader
, Chunk
.dwSize
, NULL
);
480 TRACE_(dmfile
)(": DLID (GUID) chunk\n");
481 This
->pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
482 IStream_Read (pStm
, &This
->pDesc
->guidObject
, Chunk
.dwSize
, NULL
);
486 TRACE_(dmfile
)(": version chunk\n");
487 This
->pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
488 IStream_Read (pStm
, &This
->pDesc
->vVersion
, Chunk
.dwSize
, NULL
);
492 TRACE_(dmfile
)(": pool table chunk\n");
493 This
->pPoolTable
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(POOLTABLE
));
494 IStream_Read (pStm
, This
->pPoolTable
, sizeof(POOLTABLE
), NULL
);
495 Chunk
.dwSize
-= sizeof(POOLTABLE
);
496 This
->pPoolCues
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, This
->pPoolTable
->cCues
*sizeof(POOLCUE
));
497 IStream_Read (pStm
, This
->pPoolCues
, Chunk
.dwSize
, NULL
);
501 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
502 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
503 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
505 switch (Chunk
.fccID
) {
506 case mmioFOURCC('I','N','F','O'): {
507 TRACE_(dmfile
)(": INFO list\n");
509 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
510 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
511 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
512 switch (Chunk
.fccID
) {
513 case mmioFOURCC('I','N','A','M'): {
514 CHAR szName
[DMUS_MAX_NAME
];
515 TRACE_(dmfile
)(": name chunk\n");
516 This
->pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
517 IStream_Read (pStm
, szName
, Chunk
.dwSize
, NULL
);
518 MultiByteToWideChar (CP_ACP
, 0, szName
, -1, This
->pDesc
->wszName
, DMUS_MAX_NAME
);
519 if (even_or_odd(Chunk
.dwSize
)) {
522 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
526 case mmioFOURCC('I','A','R','T'): {
527 TRACE_(dmfile
)(": artist chunk (ignored)\n");
528 if (even_or_odd(Chunk
.dwSize
)) {
532 liMove
.QuadPart
= Chunk
.dwSize
;
533 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
536 case mmioFOURCC('I','C','O','P'): {
537 TRACE_(dmfile
)(": copyright chunk\n");
538 This
->szCopyright
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, Chunk
.dwSize
);
539 IStream_Read (pStm
, This
->szCopyright
, Chunk
.dwSize
, NULL
);
540 if (even_or_odd(Chunk
.dwSize
)) {
543 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
547 case mmioFOURCC('I','S','B','J'): {
548 TRACE_(dmfile
)(": subject chunk (ignored)\n");
549 if (even_or_odd(Chunk
.dwSize
)) {
553 liMove
.QuadPart
= Chunk
.dwSize
;
554 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
557 case mmioFOURCC('I','C','M','T'): {
558 TRACE_(dmfile
)(": comment chunk (ignored)\n");
559 if (even_or_odd(Chunk
.dwSize
)) {
563 liMove
.QuadPart
= Chunk
.dwSize
;
564 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
568 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
569 if (even_or_odd(Chunk
.dwSize
)) {
573 liMove
.QuadPart
= Chunk
.dwSize
;
574 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
578 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
579 } while (ListCount
[0] < ListSize
[0]);
583 TRACE_(dmfile
)(": wave pool list (mark & skip)\n");
585 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, &dlibWavePoolPosition
); /* store position */
586 This
->liWavePoolTablePosition
.QuadPart
= dlibWavePoolPosition
.QuadPart
;
587 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
588 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
592 TRACE_(dmfile
)(": instruments list\n");
594 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
595 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
596 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
597 switch (Chunk
.fccID
) {
599 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
600 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
601 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
603 switch (Chunk
.fccID
) {
605 LPDMUS_PRIVATE_INSTRUMENTENTRY pNewInstrument
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_INSTRUMENTENTRY
));
606 TRACE_(dmfile
)(": instrument list\n");
607 DMUSIC_CreateDirectMusicInstrumentImpl (&IID_IDirectMusicInstrument
, (LPVOID
*)&pNewInstrument
->pInstrument
, NULL
); /* only way to create this one... even M$ does it discretely */
609 IDirectMusicInstrumentImpl
*pInstrument
= impl_from_IDirectMusicInstrument(pNewInstrument
->pInstrument
);
611 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, &dlibInstrumentPosition
);
612 pInstrument
->liInstrumentPosition
.QuadPart
= dlibInstrumentPosition
.QuadPart
- (2*sizeof(FOURCC
) + sizeof(DWORD
)); /* store offset, it'll be needed later */
615 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
616 ListCount
[1] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
617 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
618 switch (Chunk
.fccID
) {
620 TRACE_(dmfile
)(": instrument header chunk\n");
621 pInstrument
->pHeader
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, Chunk
.dwSize
);
622 IStream_Read (pStm
, pInstrument
->pHeader
, Chunk
.dwSize
, NULL
);
626 TRACE_(dmfile
)(": DLID (GUID) chunk\n");
627 pInstrument
->pInstrumentID
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, Chunk
.dwSize
);
628 IStream_Read (pStm
, pInstrument
->pInstrumentID
, Chunk
.dwSize
, NULL
);
632 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
633 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
634 ListSize
[2] = Chunk
.dwSize
- sizeof(FOURCC
);
636 switch (Chunk
.fccID
) {
638 TRACE_(dmfile
)(": unknown (skipping)\n");
639 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
640 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
647 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
648 liMove
.QuadPart
= Chunk
.dwSize
;
649 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
653 TRACE_(dmfile
)(": ListCount[1] = %d < ListSize[1] = %d\n", ListCount
[1], ListSize
[1]);
654 } while (ListCount
[1] < ListSize
[1]);
655 /* DEBUG: dumps whole instrument object tree: */
656 if (TRACE_ON(dmusic
)) {
657 TRACE("*** IDirectMusicInstrument (%p) ***\n", pInstrument
);
658 if (pInstrument
->pInstrumentID
)
659 TRACE(" - GUID = %s\n", debugstr_dmguid(pInstrument
->pInstrumentID
));
661 TRACE(" - Instrument header:\n");
662 TRACE(" - cRegions: %d\n", pInstrument
->pHeader
->cRegions
);
663 TRACE(" - Locale:\n");
664 TRACE(" - ulBank: %d\n", pInstrument
->pHeader
->Locale
.ulBank
);
665 TRACE(" - ulInstrument: %d\n", pInstrument
->pHeader
->Locale
.ulInstrument
);
666 TRACE(" => dwPatch: %d\n", MIDILOCALE2Patch(&pInstrument
->pHeader
->Locale
));
668 list_add_tail (&This
->Instruments
, &pNewInstrument
->entry
);
676 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
677 liMove
.QuadPart
= Chunk
.dwSize
;
678 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
682 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
683 } while (ListCount
[0] < ListSize
[0]);
687 TRACE_(dmfile
)(": unknown (skipping)\n");
688 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
689 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
696 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
697 liMove
.QuadPart
= Chunk
.dwSize
;
698 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
702 TRACE_(dmfile
)(": StreamCount = %d < StreamSize = %d\n", StreamCount
, StreamSize
);
703 } while (StreamCount
< StreamSize
);
707 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
708 liMove
.QuadPart
= StreamSize
;
709 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
713 TRACE_(dmfile
)(": reading finished\n");
717 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
718 liMove
.QuadPart
= Chunk
.dwSize
;
719 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
724 /* DEBUG: dumps whole collection object tree: */
725 if (TRACE_ON(dmusic
)) {
727 DMUS_PRIVATE_INSTRUMENTENTRY
*tmpEntry
;
728 struct list
*listEntry
;
730 TRACE("*** IDirectMusicCollection (%p) ***\n", This
->CollectionVtbl
);
731 if (This
->pDesc
->dwValidData
& DMUS_OBJ_OBJECT
)
732 TRACE(" - GUID = %s\n", debugstr_dmguid(&This
->pDesc
->guidObject
));
733 if (This
->pDesc
->dwValidData
& DMUS_OBJ_VERSION
)
734 TRACE(" - Version = %i,%i,%i,%i\n", (This
->pDesc
->vVersion
.dwVersionMS
>> 8) & 0x0000FFFF, This
->pDesc
->vVersion
.dwVersionMS
& 0x0000FFFF,
735 (This
->pDesc
->vVersion
.dwVersionLS
>> 8) & 0x0000FFFF, This
->pDesc
->vVersion
.dwVersionLS
& 0x0000FFFF);
736 if (This
->pDesc
->dwValidData
& DMUS_OBJ_NAME
)
737 TRACE(" - Name = %s\n", debugstr_w(This
->pDesc
->wszName
));
739 TRACE(" - Collection header:\n");
740 TRACE(" - cInstruments: %d\n", This
->pHeader
->cInstruments
);
741 TRACE(" - Instruments:\n");
743 LIST_FOR_EACH (listEntry
, &This
->Instruments
) {
744 tmpEntry
= LIST_ENTRY( listEntry
, DMUS_PRIVATE_INSTRUMENTENTRY
, entry
);
745 TRACE(" - Instrument[%i]: %p\n", r
, tmpEntry
->pInstrument
);
753 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_Save (LPPERSISTSTREAM iface
, IStream
* pStm
, BOOL fClearDirty
) {
757 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface
, ULARGE_INTEGER
* pcbSize
) {
761 static const IPersistStreamVtbl DirectMusicCollection_PersistStream_Vtbl
= {
762 IDirectMusicCollectionImpl_IPersistStream_QueryInterface
,
763 IDirectMusicCollectionImpl_IPersistStream_AddRef
,
764 IDirectMusicCollectionImpl_IPersistStream_Release
,
765 IDirectMusicCollectionImpl_IPersistStream_GetClassID
,
766 IDirectMusicCollectionImpl_IPersistStream_IsDirty
,
767 IDirectMusicCollectionImpl_IPersistStream_Load
,
768 IDirectMusicCollectionImpl_IPersistStream_Save
,
769 IDirectMusicCollectionImpl_IPersistStream_GetSizeMax
773 /* for ClassFactory */
774 HRESULT WINAPI
DMUSIC_CreateDirectMusicCollectionImpl (LPCGUID lpcGUID
, LPVOID
* ppobj
, LPUNKNOWN pUnkOuter
) {
775 IDirectMusicCollectionImpl
* obj
;
777 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicCollectionImpl
));
780 return E_OUTOFMEMORY
;
782 obj
->UnknownVtbl
= &DirectMusicCollection_Unknown_Vtbl
;
783 obj
->CollectionVtbl
= &DirectMusicCollection_Collection_Vtbl
;
784 obj
->ObjectVtbl
= &DirectMusicCollection_Object_Vtbl
;
785 obj
->PersistStreamVtbl
= &DirectMusicCollection_PersistStream_Vtbl
;
786 obj
->pDesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DMUS_OBJECTDESC
));
787 DM_STRUCT_INIT(obj
->pDesc
);
788 obj
->pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
789 obj
->pDesc
->guidClass
= CLSID_DirectMusicCollection
;
790 obj
->ref
= 0; /* will be inited by QueryInterface */
791 list_init (&obj
->Instruments
);
793 return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN
)&obj
->UnknownVtbl
, lpcGUID
, ppobj
);