1 /* IDirectMusicCollection Implementation
3 * Copyright (C) 2003-2004 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.
20 #include "dmusic_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(dmusic
);
23 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
25 /*****************************************************************************
26 * IDirectMusicCollectionImpl implementation
28 /* IDirectMusicCollectionImpl IUnknown part: */
29 HRESULT WINAPI
IDirectMusicCollectionImpl_IUnknown_QueryInterface (LPUNKNOWN iface
, REFIID riid
, LPVOID
*ppobj
) {
30 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, UnknownVtbl
, iface
);
31 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ppobj
);
33 if (IsEqualIID (riid
, &IID_IUnknown
)) {
34 *ppobj
= (LPVOID
)&This
->UnknownVtbl
;
35 IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
37 } else if (IsEqualIID (riid
, &IID_IDirectMusicCollection
)) {
38 *ppobj
= (LPVOID
)&This
->CollectionVtbl
;
39 IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef ((LPDIRECTMUSICCOLLECTION
)&This
->CollectionVtbl
);
41 } else if (IsEqualIID (riid
, &IID_IDirectMusicObject
)) {
42 *ppobj
= (LPVOID
)&This
->ObjectVtbl
;
43 IDirectMusicCollectionImpl_IDirectMusicObject_AddRef ((LPDIRECTMUSICOBJECT
)&This
->ObjectVtbl
);
45 } else if (IsEqualIID (riid
, &IID_IPersistStream
)) {
46 *ppobj
= (LPVOID
)&This
->PersistStreamVtbl
;
47 IDirectMusicCollectionImpl_IPersistStream_AddRef ((LPPERSISTSTREAM
)&This
->PersistStreamVtbl
);
51 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ppobj
);
55 ULONG WINAPI
IDirectMusicCollectionImpl_IUnknown_AddRef (LPUNKNOWN iface
) {
56 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, UnknownVtbl
, iface
);
57 ULONG refCount
= InterlockedIncrement(&This
->ref
);
59 TRACE("(%p)->(ref before=%lu)\n", This
, refCount
- 1);
66 ULONG WINAPI
IDirectMusicCollectionImpl_IUnknown_Release (LPUNKNOWN iface
) {
67 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, UnknownVtbl
, iface
);
68 ULONG refCount
= InterlockedDecrement(&This
->ref
);
70 TRACE("(%p)->(ref before=%lu)\n", This
, refCount
+ 1);
73 HeapFree(GetProcessHeap(), 0, This
);
76 DMUSIC_UnlockModule();
81 IUnknownVtbl DirectMusicCollection_Unknown_Vtbl
= {
82 IDirectMusicCollectionImpl_IUnknown_QueryInterface
,
83 IDirectMusicCollectionImpl_IUnknown_AddRef
,
84 IDirectMusicCollectionImpl_IUnknown_Release
87 /* IDirectMusicCollectionImpl IDirectMusicCollection part: */
88 HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_QueryInterface (LPDIRECTMUSICCOLLECTION iface
, REFIID riid
, LPVOID
*ppobj
) {
89 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, CollectionVtbl
, iface
);
90 return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
93 ULONG WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef (LPDIRECTMUSICCOLLECTION iface
) {
94 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, CollectionVtbl
, iface
);
95 return IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
98 ULONG WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_Release (LPDIRECTMUSICCOLLECTION iface
) {
99 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, CollectionVtbl
, iface
);
100 return IDirectMusicCollectionImpl_IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
103 /* IDirectMusicCollection Interface follow: */
104 HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_GetInstrument (LPDIRECTMUSICCOLLECTION iface
, DWORD dwPatch
, IDirectMusicInstrument
** ppInstrument
) {
105 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, CollectionVtbl
, iface
);
106 DMUS_PRIVATE_INSTRUMENTENTRY
*tmpEntry
;
107 struct list
*listEntry
;
110 TRACE("(%p, %ld, %p)\n", This
, dwPatch
, ppInstrument
);
112 LIST_FOR_EACH (listEntry
, &This
->Instruments
) {
113 tmpEntry
= LIST_ENTRY(listEntry
, DMUS_PRIVATE_INSTRUMENTENTRY
, entry
);
114 IDirectMusicInstrument_GetPatch (tmpEntry
->pInstrument
, &dwInstPatch
);
115 if (dwPatch
== dwInstPatch
) {
116 *ppInstrument
= (LPDIRECTMUSICINSTRUMENT
)tmpEntry
->pInstrument
;
117 IDirectMusicInstrument_AddRef (tmpEntry
->pInstrument
);
118 IDirectMusicInstrumentImpl_Custom_Load (tmpEntry
->pInstrument
, This
->pStm
); /* load instrument before returning it */
119 TRACE(": returning instrument %p\n", *ppInstrument
);
124 TRACE(": instrument not found\n");
126 return DMUS_E_INVALIDPATCH
;
129 HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_EnumInstrument (LPDIRECTMUSICCOLLECTION iface
, DWORD dwIndex
, DWORD
* pdwPatch
, LPWSTR pwszName
, DWORD dwNameLen
) {
130 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, CollectionVtbl
, iface
);
132 DMUS_PRIVATE_INSTRUMENTENTRY
*tmpEntry
;
133 struct list
*listEntry
;
136 TRACE("(%p, %ld, %p, %p, %ld)\n", This
, dwIndex
, pdwPatch
, pwszName
, dwNameLen
);
137 LIST_FOR_EACH (listEntry
, &This
->Instruments
) {
138 tmpEntry
= LIST_ENTRY(listEntry
, DMUS_PRIVATE_INSTRUMENTENTRY
, entry
);
140 ICOM_NAME_MULTI (IDirectMusicInstrumentImpl
, InstrumentVtbl
, tmpEntry
->pInstrument
, pInstrument
);
141 IDirectMusicInstrument_GetPatch (tmpEntry
->pInstrument
, pdwPatch
);
143 dwLen
= min(strlenW(pInstrument
->wszName
),dwNameLen
-1);
144 memcpy (pwszName
, pInstrument
->wszName
, dwLen
* sizeof(WCHAR
));
145 pwszName
[dwLen
] = '\0';
155 IDirectMusicCollectionVtbl DirectMusicCollection_Collection_Vtbl
= {
156 IDirectMusicCollectionImpl_IDirectMusicCollection_QueryInterface
,
157 IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef
,
158 IDirectMusicCollectionImpl_IDirectMusicCollection_Release
,
159 IDirectMusicCollectionImpl_IDirectMusicCollection_GetInstrument
,
160 IDirectMusicCollectionImpl_IDirectMusicCollection_EnumInstrument
163 /* IDirectMusicCollectionImpl IDirectMusicObject part: */
164 HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface
, REFIID riid
, LPVOID
*ppobj
) {
165 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, ObjectVtbl
, iface
);
166 return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
169 ULONG WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface
) {
170 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, ObjectVtbl
, iface
);
171 return IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
174 ULONG WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface
) {
175 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, ObjectVtbl
, iface
);
176 return IDirectMusicCollectionImpl_IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
179 HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
) {
180 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, ObjectVtbl
, iface
);
181 TRACE("(%p, %p)\n", This
, pDesc
);
182 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
183 memcpy (pDesc
, This
->pDesc
, This
->pDesc
->dwSize
);
187 HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
) {
188 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, ObjectVtbl
, iface
);
189 TRACE("(%p, %p): setting descriptor:\n%s\n", This
, pDesc
, debugstr_DMUS_OBJECTDESC (pDesc
));
191 /* According to MSDN, we should copy only given values, not whole struct */
192 if (pDesc
->dwValidData
& DMUS_OBJ_OBJECT
)
193 memcpy (&This
->pDesc
->guidObject
, &pDesc
->guidObject
, sizeof (pDesc
->guidObject
));
194 if (pDesc
->dwValidData
& DMUS_OBJ_CLASS
)
195 memcpy (&This
->pDesc
->guidClass
, &pDesc
->guidClass
, sizeof (pDesc
->guidClass
));
196 if (pDesc
->dwValidData
& DMUS_OBJ_NAME
)
197 lstrcpynW(This
->pDesc
->wszName
, pDesc
->wszName
, DMUS_MAX_NAME
);
198 if (pDesc
->dwValidData
& DMUS_OBJ_CATEGORY
)
199 lstrcpynW(This
->pDesc
->wszCategory
, pDesc
->wszCategory
, DMUS_MAX_CATEGORY
);
200 if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
)
201 lstrcpynW(This
->pDesc
->wszFileName
, pDesc
->wszFileName
, DMUS_MAX_FILENAME
);
202 if (pDesc
->dwValidData
& DMUS_OBJ_VERSION
)
203 memcpy (&This
->pDesc
->vVersion
, &pDesc
->vVersion
, sizeof (pDesc
->vVersion
));
204 if (pDesc
->dwValidData
& DMUS_OBJ_DATE
)
205 memcpy (&This
->pDesc
->ftDate
, &pDesc
->ftDate
, sizeof (pDesc
->ftDate
));
206 if (pDesc
->dwValidData
& DMUS_OBJ_MEMORY
) {
207 memcpy (&This
->pDesc
->llMemLength
, &pDesc
->llMemLength
, sizeof (pDesc
->llMemLength
));
208 memcpy (This
->pDesc
->pbMemData
, pDesc
->pbMemData
, sizeof (pDesc
->pbMemData
));
210 if (pDesc
->dwValidData
& DMUS_OBJ_STREAM
) {
211 /* according to MSDN, we copy the stream */
212 IStream_Clone (pDesc
->pStream
, &This
->pDesc
->pStream
);
216 This
->pDesc
->dwValidData
|= pDesc
->dwValidData
;
221 HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface
, LPSTREAM pStream
, LPDMUS_OBJECTDESC pDesc
) {
222 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, ObjectVtbl
, iface
);
223 DMUS_PRIVATE_CHUNK Chunk
;
224 DWORD StreamSize
, StreamCount
, ListSize
[1], ListCount
[1];
225 LARGE_INTEGER liMove
; /* used when skipping chunks */
227 TRACE("(%p, %p, %p)\n", This
, pStream
, pDesc
);
229 /* FIXME: should this be determined from stream? */
230 pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
231 memcpy (&pDesc
->guidClass
, &CLSID_DirectMusicCollection
, sizeof(CLSID
));
233 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
234 TRACE_(dmfile
)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
235 switch (Chunk
.fccID
) {
237 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
238 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
239 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
241 if (Chunk
.fccID
== mmioFOURCC('D','L','S',' ')) {
242 TRACE_(dmfile
)(": collection form\n");
244 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
245 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
246 TRACE_(dmfile
)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
247 switch (Chunk
.fccID
) {
249 TRACE_(dmfile
)(": GUID chunk\n");
250 pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
251 IStream_Read (pStream
, &pDesc
->guidObject
, Chunk
.dwSize
, NULL
);
254 case DMUS_FOURCC_VERSION_CHUNK
: {
255 TRACE_(dmfile
)(": version chunk\n");
256 pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
257 IStream_Read (pStream
, &pDesc
->vVersion
, Chunk
.dwSize
, NULL
);
260 case DMUS_FOURCC_CATEGORY_CHUNK
: {
261 TRACE_(dmfile
)(": category chunk\n");
262 pDesc
->dwValidData
|= DMUS_OBJ_CATEGORY
;
263 IStream_Read (pStream
, pDesc
->wszCategory
, Chunk
.dwSize
, NULL
);
267 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
268 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
269 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
271 switch (Chunk
.fccID
) {
272 /* pure INFO list, such can be found in dls collections */
273 case mmioFOURCC('I','N','F','O'): {
274 TRACE_(dmfile
)(": INFO list\n");
276 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
277 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
278 TRACE_(dmfile
)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
279 switch (Chunk
.fccID
) {
280 case mmioFOURCC('I','N','A','M'):{
281 CHAR szName
[DMUS_MAX_NAME
];
282 TRACE_(dmfile
)(": name chunk\n");
283 pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
284 IStream_Read (pStream
, szName
, Chunk
.dwSize
, NULL
);
285 MultiByteToWideChar (CP_ACP
, 0, szName
, -1, pDesc
->wszName
, DMUS_MAX_NAME
);
286 if (even_or_odd(Chunk
.dwSize
)) {
289 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
293 case mmioFOURCC('I','A','R','T'): {
294 TRACE_(dmfile
)(": artist chunk (ignored)\n");
295 if (even_or_odd(Chunk
.dwSize
)) {
299 liMove
.QuadPart
= Chunk
.dwSize
;
300 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
303 case mmioFOURCC('I','C','O','P'): {
304 TRACE_(dmfile
)(": copyright chunk (ignored)\n");
305 if (even_or_odd(Chunk
.dwSize
)) {
309 liMove
.QuadPart
= Chunk
.dwSize
;
310 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
313 case mmioFOURCC('I','S','B','J'): {
314 TRACE_(dmfile
)(": subject chunk (ignored)\n");
315 if (even_or_odd(Chunk
.dwSize
)) {
319 liMove
.QuadPart
= Chunk
.dwSize
;
320 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
323 case mmioFOURCC('I','C','M','T'): {
324 TRACE_(dmfile
)(": comment chunk (ignored)\n");
325 if (even_or_odd(Chunk
.dwSize
)) {
329 liMove
.QuadPart
= Chunk
.dwSize
;
330 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
334 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
335 if (even_or_odd(Chunk
.dwSize
)) {
339 liMove
.QuadPart
= Chunk
.dwSize
;
340 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
344 TRACE_(dmfile
)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount
[0], ListSize
[0]);
345 } while (ListCount
[0] < ListSize
[0]);
349 TRACE_(dmfile
)(": unknown (skipping)\n");
350 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
351 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
358 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
359 liMove
.QuadPart
= Chunk
.dwSize
;
360 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
364 TRACE_(dmfile
)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount
, StreamSize
);
365 } while (StreamCount
< StreamSize
);
367 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
368 liMove
.QuadPart
= StreamSize
;
369 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
373 TRACE_(dmfile
)(": reading finished\n");
377 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
378 liMove
.QuadPart
= Chunk
.dwSize
;
379 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
380 return DMUS_E_INVALIDFILE
;
384 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc
));
389 IDirectMusicObjectVtbl DirectMusicCollection_Object_Vtbl
= {
390 IDirectMusicCollectionImpl_IDirectMusicObject_QueryInterface
,
391 IDirectMusicCollectionImpl_IDirectMusicObject_AddRef
,
392 IDirectMusicCollectionImpl_IDirectMusicObject_Release
,
393 IDirectMusicCollectionImpl_IDirectMusicObject_GetDescriptor
,
394 IDirectMusicCollectionImpl_IDirectMusicObject_SetDescriptor
,
395 IDirectMusicCollectionImpl_IDirectMusicObject_ParseDescriptor
398 /* IDirectMusicCollectionImpl IPersistStream part: */
399 HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface
, REFIID riid
, LPVOID
*ppobj
) {
400 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, PersistStreamVtbl
, iface
);
401 return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
404 ULONG WINAPI
IDirectMusicCollectionImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface
) {
405 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, PersistStreamVtbl
, iface
);
406 return IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
409 ULONG WINAPI
IDirectMusicCollectionImpl_IPersistStream_Release (LPPERSISTSTREAM iface
) {
410 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, PersistStreamVtbl
, iface
);
411 return IDirectMusicCollectionImpl_IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
414 HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_GetClassID (LPPERSISTSTREAM iface
, CLSID
* pClassID
) {
418 HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_IsDirty (LPPERSISTSTREAM iface
) {
422 HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_Load (LPPERSISTSTREAM iface
, IStream
* pStm
) {
423 ICOM_THIS_MULTI(IDirectMusicCollectionImpl
, PersistStreamVtbl
, iface
);
425 DMUS_PRIVATE_CHUNK Chunk
;
426 DWORD StreamSize
, StreamCount
, ListSize
[3], ListCount
[3];
427 LARGE_INTEGER liMove
; /* used when skipping chunks */
428 ULARGE_INTEGER dlibCollectionPosition
, dlibInstrumentPosition
, dlibWavePoolPosition
;
430 IStream_AddRef (pStm
); /* add count for later references */
432 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, &dlibCollectionPosition
); /* store offset, in case it'll be needed later */
433 This
->liCollectionPosition
.QuadPart
= dlibCollectionPosition
.QuadPart
;
436 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
437 TRACE_(dmfile
)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
438 switch (Chunk
.fccID
) {
440 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
441 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
442 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
444 switch (Chunk
.fccID
) {
446 TRACE_(dmfile
)(": collection form\n");
448 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
449 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
450 TRACE_(dmfile
)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
451 switch (Chunk
.fccID
) {
453 TRACE_(dmfile
)(": collection header chunk\n");
454 This
->pHeader
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, Chunk
.dwSize
);
455 IStream_Read (pStm
, This
->pHeader
, Chunk
.dwSize
, NULL
);
459 TRACE_(dmfile
)(": DLID (GUID) chunk\n");
460 This
->pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
461 IStream_Read (pStm
, &This
->pDesc
->guidObject
, Chunk
.dwSize
, NULL
);
465 TRACE_(dmfile
)(": version chunk\n");
466 This
->pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
467 IStream_Read (pStm
, &This
->pDesc
->vVersion
, Chunk
.dwSize
, NULL
);
471 TRACE_(dmfile
)(": pool table chunk\n");
472 This
->pPoolTable
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(POOLTABLE
));
473 IStream_Read (pStm
, This
->pPoolTable
, sizeof(POOLTABLE
), NULL
);
474 Chunk
.dwSize
-= sizeof(POOLTABLE
);
475 This
->pPoolCues
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, This
->pPoolTable
->cCues
*sizeof(POOLCUE
));
476 IStream_Read (pStm
, This
->pPoolCues
, Chunk
.dwSize
, NULL
);
480 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
481 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
482 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
484 switch (Chunk
.fccID
) {
485 case mmioFOURCC('I','N','F','O'): {
486 TRACE_(dmfile
)(": INFO list\n");
488 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
489 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
490 TRACE_(dmfile
)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
491 switch (Chunk
.fccID
) {
492 case mmioFOURCC('I','N','A','M'): {
493 CHAR szName
[DMUS_MAX_NAME
];
494 TRACE_(dmfile
)(": name chunk\n");
495 This
->pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
496 IStream_Read (pStm
, szName
, Chunk
.dwSize
, NULL
);
497 MultiByteToWideChar (CP_ACP
, 0, szName
, -1, This
->pDesc
->wszName
, DMUS_MAX_NAME
);
498 if (even_or_odd(Chunk
.dwSize
)) {
501 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
505 case mmioFOURCC('I','A','R','T'): {
506 TRACE_(dmfile
)(": artist chunk (ignored)\n");
507 if (even_or_odd(Chunk
.dwSize
)) {
511 liMove
.QuadPart
= Chunk
.dwSize
;
512 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
515 case mmioFOURCC('I','C','O','P'): {
516 TRACE_(dmfile
)(": copyright chunk\n");
517 This
->szCopyright
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, Chunk
.dwSize
);
518 IStream_Read (pStm
, This
->szCopyright
, Chunk
.dwSize
, NULL
);
519 if (even_or_odd(Chunk
.dwSize
)) {
522 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
526 case mmioFOURCC('I','S','B','J'): {
527 TRACE_(dmfile
)(": subject 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','M','T'): {
537 TRACE_(dmfile
)(": comment chunk (ignored)\n");
538 if (even_or_odd(Chunk
.dwSize
)) {
542 liMove
.QuadPart
= Chunk
.dwSize
;
543 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
547 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
548 if (even_or_odd(Chunk
.dwSize
)) {
552 liMove
.QuadPart
= Chunk
.dwSize
;
553 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
557 TRACE_(dmfile
)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount
[0], ListSize
[0]);
558 } while (ListCount
[0] < ListSize
[0]);
562 TRACE_(dmfile
)(": wave pool list (mark & skip)\n");
564 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, &dlibWavePoolPosition
); /* store position */
565 This
->liWavePoolTablePosition
.QuadPart
= dlibWavePoolPosition
.QuadPart
;
566 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
567 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
571 TRACE_(dmfile
)(": instruments list\n");
573 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
574 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
575 TRACE_(dmfile
)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
576 switch (Chunk
.fccID
) {
578 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
579 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
580 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
582 switch (Chunk
.fccID
) {
584 LPDMUS_PRIVATE_INSTRUMENTENTRY pNewInstrument
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_INSTRUMENTENTRY
));
585 TRACE_(dmfile
)(": instrument list\n");
586 DMUSIC_CreateDirectMusicInstrumentImpl (&IID_IDirectMusicInstrument
, (LPVOID
*)&pNewInstrument
->pInstrument
, NULL
); /* only way to create this one... even M$ does it discretly */
588 ICOM_NAME_MULTI (IDirectMusicInstrumentImpl
, InstrumentVtbl
, pNewInstrument
->pInstrument
, pInstrument
);
590 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, &dlibInstrumentPosition
);
591 pInstrument
->liInstrumentPosition
.QuadPart
= dlibInstrumentPosition
.QuadPart
- (2*sizeof(FOURCC
) + sizeof(DWORD
)); /* store offset, it'll be needed later */
594 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
595 ListCount
[1] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
596 TRACE_(dmfile
)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
597 switch (Chunk
.fccID
) {
599 TRACE_(dmfile
)(": instrument header chunk\n");
600 pInstrument
->pHeader
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, Chunk
.dwSize
);
601 IStream_Read (pStm
, pInstrument
->pHeader
, Chunk
.dwSize
, NULL
);
605 TRACE_(dmfile
)(": DLID (GUID) chunk\n");
606 pInstrument
->pInstrumentID
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, Chunk
.dwSize
);
607 IStream_Read (pStm
, pInstrument
->pInstrumentID
, Chunk
.dwSize
, NULL
);
611 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
612 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
613 ListSize
[2] = Chunk
.dwSize
- sizeof(FOURCC
);
615 switch (Chunk
.fccID
) {
617 TRACE_(dmfile
)(": unknown (skipping)\n");
618 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
619 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
626 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
627 liMove
.QuadPart
= Chunk
.dwSize
;
628 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
632 TRACE_(dmfile
)(": ListCount[1] = %ld < ListSize[1] = %ld\n", ListCount
[1], ListSize
[1]);
633 } while (ListCount
[1] < ListSize
[1]);
634 /* DEBUG: dumps whole instrument object tree: */
635 if (TRACE_ON(dmusic
)) {
636 TRACE("*** IDirectMusicInstrument (%p) ***\n", pInstrument
);
637 if (pInstrument
->pInstrumentID
)
638 TRACE(" - GUID = %s\n", debugstr_dmguid(pInstrument
->pInstrumentID
));
640 TRACE(" - Instrument header:\n");
641 TRACE(" - cRegions: %ld\n", pInstrument
->pHeader
->cRegions
);
642 TRACE(" - Locale:\n");
643 TRACE(" - ulBank: %ld\n", pInstrument
->pHeader
->Locale
.ulBank
);
644 TRACE(" - ulInstrument: %ld\n", pInstrument
->pHeader
->Locale
.ulInstrument
);
645 TRACE(" => dwPatch: %ld\n", MIDILOCALE2Patch(&pInstrument
->pHeader
->Locale
));
647 list_add_tail (&This
->Instruments
, &pNewInstrument
->entry
);
655 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
656 liMove
.QuadPart
= Chunk
.dwSize
;
657 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
661 TRACE_(dmfile
)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount
[0], ListSize
[0]);
662 } while (ListCount
[0] < ListSize
[0]);
666 TRACE_(dmfile
)(": unknown (skipping)\n");
667 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
668 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
675 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
676 liMove
.QuadPart
= Chunk
.dwSize
;
677 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
681 TRACE_(dmfile
)(": StreamCount = %ld < StreamSize = %ld\n", StreamCount
, StreamSize
);
682 } while (StreamCount
< StreamSize
);
686 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
687 liMove
.QuadPart
= StreamSize
;
688 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
692 TRACE_(dmfile
)(": reading finished\n");
696 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
697 liMove
.QuadPart
= Chunk
.dwSize
;
698 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
703 /* DEBUG: dumps whole collection object tree: */
704 if (TRACE_ON(dmusic
)) {
706 DMUS_PRIVATE_INSTRUMENTENTRY
*tmpEntry
;
707 struct list
*listEntry
;
709 TRACE("*** IDirectMusicCollection (%p) ***\n", This
->CollectionVtbl
);
710 if (This
->pDesc
->dwValidData
& DMUS_OBJ_OBJECT
)
711 TRACE(" - GUID = %s\n", debugstr_dmguid(&This
->pDesc
->guidObject
));
712 if (This
->pDesc
->dwValidData
& DMUS_OBJ_VERSION
)
713 TRACE(" - Version = %i,%i,%i,%i\n", (This
->pDesc
->vVersion
.dwVersionMS
>> 8) && 0x0000FFFF, This
->pDesc
->vVersion
.dwVersionMS
&& 0x0000FFFF, \
714 (This
->pDesc
->vVersion
.dwVersionLS
>> 8) && 0x0000FFFF, This
->pDesc
->vVersion
.dwVersionLS
&& 0x0000FFFF);
715 if (This
->pDesc
->dwValidData
& DMUS_OBJ_NAME
)
716 TRACE(" - Name = %s\n", debugstr_w(This
->pDesc
->wszName
));
718 TRACE(" - Collection header:\n");
719 TRACE(" - cInstruments: %ld\n", This
->pHeader
->cInstruments
);
720 TRACE(" - Instruments:\n");
722 LIST_FOR_EACH (listEntry
, &This
->Instruments
) {
723 tmpEntry
= LIST_ENTRY( listEntry
, DMUS_PRIVATE_INSTRUMENTENTRY
, entry
);
724 TRACE(" - Instrument[%i]: %p\n", r
, tmpEntry
->pInstrument
);
732 HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_Save (LPPERSISTSTREAM iface
, IStream
* pStm
, BOOL fClearDirty
) {
736 HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface
, ULARGE_INTEGER
* pcbSize
) {
740 IPersistStreamVtbl DirectMusicCollection_PersistStream_Vtbl
= {
741 IDirectMusicCollectionImpl_IPersistStream_QueryInterface
,
742 IDirectMusicCollectionImpl_IPersistStream_AddRef
,
743 IDirectMusicCollectionImpl_IPersistStream_Release
,
744 IDirectMusicCollectionImpl_IPersistStream_GetClassID
,
745 IDirectMusicCollectionImpl_IPersistStream_IsDirty
,
746 IDirectMusicCollectionImpl_IPersistStream_Load
,
747 IDirectMusicCollectionImpl_IPersistStream_Save
,
748 IDirectMusicCollectionImpl_IPersistStream_GetSizeMax
752 /* for ClassFactory */
753 HRESULT WINAPI
DMUSIC_CreateDirectMusicCollectionImpl (LPCGUID lpcGUID
, LPVOID
* ppobj
, LPUNKNOWN pUnkOuter
) {
754 IDirectMusicCollectionImpl
* obj
;
756 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicCollectionImpl
));
759 return E_OUTOFMEMORY
;
761 obj
->UnknownVtbl
= &DirectMusicCollection_Unknown_Vtbl
;
762 obj
->CollectionVtbl
= &DirectMusicCollection_Collection_Vtbl
;
763 obj
->ObjectVtbl
= &DirectMusicCollection_Object_Vtbl
;
764 obj
->PersistStreamVtbl
= &DirectMusicCollection_PersistStream_Vtbl
;
765 obj
->pDesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DMUS_OBJECTDESC
));
766 DM_STRUCT_INIT(obj
->pDesc
);
767 obj
->pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
768 memcpy (&obj
->pDesc
->guidClass
, &CLSID_DirectMusicCollection
, sizeof (CLSID
));
769 obj
->ref
= 0; /* will be inited by QueryInterface */
770 list_init (&obj
->Instruments
);
772 return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN
)&obj
->UnknownVtbl
, lpcGUID
, ppobj
);