2 * IDirectMusicCollection Implementation
4 * Copyright (C) 2003-2004 Rok Mandeljc
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "dmusic_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(dmusic
);
25 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
27 /*****************************************************************************
28 * IDirectMusicCollectionImpl implementation
30 typedef struct IDirectMusicCollectionImpl
{
31 IDirectMusicCollection IDirectMusicCollection_iface
;
32 struct dmobject dmobj
;
34 /* IDirectMusicCollectionImpl fields */
35 IStream
*pStm
; /* stream from which we load collection and later instruments */
36 LARGE_INTEGER liCollectionPosition
; /* offset in a stream where collection was loaded from */
37 LARGE_INTEGER liWavePoolTablePosition
; /* offset in a stream where wave pool table can be found */
38 CHAR
*szCopyright
; /* FIXME: should probably be placed somewhere else */
41 POOLTABLE
*pPoolTable
;
44 struct list Instruments
;
45 } IDirectMusicCollectionImpl
;
47 static inline IDirectMusicCollectionImpl
*impl_from_IDirectMusicCollection(IDirectMusicCollection
*iface
)
49 return CONTAINING_RECORD(iface
, IDirectMusicCollectionImpl
, IDirectMusicCollection_iface
);
52 static inline struct dmobject
*impl_from_IDirectMusicObject(IDirectMusicObject
*iface
)
54 return CONTAINING_RECORD(iface
, struct dmobject
, IDirectMusicObject_iface
);
57 static inline IDirectMusicCollectionImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
59 return CONTAINING_RECORD(iface
, IDirectMusicCollectionImpl
, dmobj
.IPersistStream_iface
);
62 /* IDirectMusicCollectionImpl IUnknown part: */
63 static HRESULT WINAPI
IDirectMusicCollectionImpl_QueryInterface(IDirectMusicCollection
*iface
,
64 REFIID riid
, void **ret_iface
)
66 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicCollection(iface
);
68 TRACE("(%p/%p)->(%s, %p)\n", iface
, This
, debugstr_dmguid(riid
), ret_iface
);
72 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDirectMusicCollection
))
74 else if (IsEqualIID(riid
, &IID_IDirectMusicObject
))
75 *ret_iface
= &This
->dmobj
.IDirectMusicObject_iface
;
76 else if (IsEqualIID(riid
, &IID_IPersistStream
))
77 *ret_iface
= &This
->dmobj
.IPersistStream_iface
;
80 WARN("(%p/%p)->(%s, %p): not found\n", iface
, This
, debugstr_dmguid(riid
), ret_iface
);
84 IUnknown_AddRef((IUnknown
*)*ret_iface
);
88 static ULONG WINAPI
IDirectMusicCollectionImpl_AddRef(IDirectMusicCollection
*iface
)
90 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicCollection(iface
);
91 ULONG ref
= InterlockedIncrement(&This
->ref
);
93 TRACE("(%p/%p)->(): new ref = %u\n", iface
, This
, ref
);
98 static ULONG WINAPI
IDirectMusicCollectionImpl_Release(IDirectMusicCollection
*iface
)
100 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicCollection(iface
);
101 ULONG ref
= InterlockedDecrement(&This
->ref
);
103 TRACE("(%p/%p)->(): new ref = %u\n", iface
, This
, ref
);
106 HeapFree(GetProcessHeap(), 0, This
);
107 DMUSIC_UnlockModule();
113 /* IDirectMusicCollection Interface follows: */
114 static HRESULT WINAPI
IDirectMusicCollectionImpl_GetInstrument(IDirectMusicCollection
*iface
,
115 DWORD patch
, IDirectMusicInstrument
**instrument
)
117 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicCollection(iface
);
118 DMUS_PRIVATE_INSTRUMENTENTRY
*inst_entry
;
119 struct list
*list_entry
;
122 TRACE("(%p/%p)->(%u, %p)\n", iface
, This
, patch
, instrument
);
124 LIST_FOR_EACH(list_entry
, &This
->Instruments
) {
125 inst_entry
= LIST_ENTRY(list_entry
, DMUS_PRIVATE_INSTRUMENTENTRY
, entry
);
126 IDirectMusicInstrument_GetPatch(inst_entry
->pInstrument
, &inst_patch
);
127 if (patch
== inst_patch
) {
128 *instrument
= inst_entry
->pInstrument
;
129 IDirectMusicInstrument_AddRef(inst_entry
->pInstrument
);
130 IDirectMusicInstrumentImpl_CustomLoad(inst_entry
->pInstrument
, This
->pStm
);
131 TRACE(": returning instrument %p\n", *instrument
);
136 TRACE(": instrument not found\n");
138 return DMUS_E_INVALIDPATCH
;
141 static HRESULT WINAPI
IDirectMusicCollectionImpl_EnumInstrument(IDirectMusicCollection
*iface
,
142 DWORD index
, DWORD
*patch
, LPWSTR name
, DWORD name_length
)
144 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicCollection(iface
);
146 DMUS_PRIVATE_INSTRUMENTENTRY
*inst_entry
;
147 struct list
*list_entry
;
150 TRACE("(%p/%p)->(%d, %p, %p, %d)\n", iface
, This
, index
, patch
, name
, name_length
);
152 LIST_FOR_EACH(list_entry
, &This
->Instruments
) {
153 inst_entry
= LIST_ENTRY(list_entry
, DMUS_PRIVATE_INSTRUMENTENTRY
, entry
);
155 IDirectMusicInstrumentImpl
*instrument
= impl_from_IDirectMusicInstrument(inst_entry
->pInstrument
);
156 IDirectMusicInstrument_GetPatch(inst_entry
->pInstrument
, patch
);
158 length
= min(strlenW(instrument
->wszName
), name_length
- 1);
159 memcpy(name
, instrument
->wszName
, length
* sizeof(WCHAR
));
170 static const IDirectMusicCollectionVtbl DirectMusicCollection_Collection_Vtbl
= {
171 IDirectMusicCollectionImpl_QueryInterface
,
172 IDirectMusicCollectionImpl_AddRef
,
173 IDirectMusicCollectionImpl_Release
,
174 IDirectMusicCollectionImpl_GetInstrument
,
175 IDirectMusicCollectionImpl_EnumInstrument
178 /* IDirectMusicCollectionImpl IDirectMusicObject part: */
179 static HRESULT
read_from_stream(IStream
*stream
, void *data
, ULONG size
)
184 hr
= IStream_Read(stream
, data
, size
, &read
);
186 TRACE("IStream_Read failed: %08x\n", hr
);
190 TRACE("Didn't read full chunk: %u < %u\n", read
, size
);
197 static HRESULT WINAPI
IDirectMusicObjectImpl_ParseDescriptor(IDirectMusicObject
*iface
,
198 IStream
*stream
, DMUS_OBJECTDESC
*desc
)
200 struct dmobject
*This
= impl_from_IDirectMusicObject(iface
);
201 DMUS_PRIVATE_CHUNK chunk
;
202 DWORD StreamSize
, StreamCount
, ListSize
[1], ListCount
[1];
203 LARGE_INTEGER liMove
; /* used when skipping chunks */
206 TRACE("(%p)->(%p, %p)\n", This
, stream
, desc
);
208 /* FIXME: should this be determined from stream? */
209 desc
->dwValidData
|= DMUS_OBJ_CLASS
;
210 desc
->guidClass
= This
->desc
.guidClass
;
212 hr
= read_from_stream(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
));
215 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
217 if (chunk
.fccID
!= FOURCC_RIFF
) {
218 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
219 liMove
.QuadPart
= chunk
.dwSize
;
220 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
221 return DMUS_E_INVALIDFILE
;
224 hr
= read_from_stream(stream
, &chunk
.fccID
, sizeof(FOURCC
));
227 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(chunk
.fccID
));
228 StreamSize
= chunk
.dwSize
- sizeof(FOURCC
);
230 if (chunk
.fccID
!= FOURCC_DLS
) {
231 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
232 liMove
.QuadPart
= StreamSize
;
233 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
238 TRACE_(dmfile
)(": collection form\n");
241 hr
= read_from_stream(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
));
244 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + chunk
.dwSize
;
245 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
246 switch (chunk
.fccID
) {
248 TRACE_(dmfile
)(": GUID chunk\n");
249 desc
->dwValidData
|= DMUS_OBJ_OBJECT
;
250 hr
= read_from_stream(stream
, &desc
->guidObject
, chunk
.dwSize
);
255 case DMUS_FOURCC_VERSION_CHUNK
:
256 TRACE_(dmfile
)(": version chunk\n");
257 desc
->dwValidData
|= DMUS_OBJ_VERSION
;
258 hr
= read_from_stream(stream
, &desc
->vVersion
, chunk
.dwSize
);
263 case DMUS_FOURCC_CATEGORY_CHUNK
:
264 TRACE_(dmfile
)(": category chunk\n");
265 desc
->dwValidData
|= DMUS_OBJ_CATEGORY
;
266 hr
= read_from_stream(stream
, desc
->wszCategory
, chunk
.dwSize
);
272 hr
= read_from_stream(stream
, &chunk
.fccID
, sizeof(FOURCC
));
275 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(chunk
.fccID
));
276 ListSize
[0] = chunk
.dwSize
- sizeof(FOURCC
);
278 switch (chunk
.fccID
) {
279 /* pure INFO list, such can be found in dls collections */
280 case DMUS_FOURCC_INFO_LIST
:
281 TRACE_(dmfile
)(": INFO list\n");
283 hr
= read_from_stream(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
));
286 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + chunk
.dwSize
;
287 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
288 switch (chunk
.fccID
) {
289 case mmioFOURCC('I','N','A','M'): {
290 CHAR szName
[DMUS_MAX_NAME
];
291 TRACE_(dmfile
)(": name chunk\n");
292 desc
->dwValidData
|= DMUS_OBJ_NAME
;
293 hr
= read_from_stream(stream
, szName
, chunk
.dwSize
);
296 MultiByteToWideChar (CP_ACP
, 0, szName
, -1, desc
->wszName
, DMUS_MAX_NAME
);
297 if (even_or_odd(chunk
.dwSize
)) {
300 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
305 case mmioFOURCC('I','A','R','T'):
306 TRACE_(dmfile
)(": artist chunk (ignored)\n");
307 if (even_or_odd(chunk
.dwSize
)) {
311 liMove
.QuadPart
= chunk
.dwSize
;
312 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
315 case mmioFOURCC('I','C','O','P'):
316 TRACE_(dmfile
)(": copyright chunk (ignored)\n");
317 if (even_or_odd(chunk
.dwSize
)) {
321 liMove
.QuadPart
= chunk
.dwSize
;
322 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
325 case mmioFOURCC('I','S','B','J'):
326 TRACE_(dmfile
)(": subject chunk (ignored)\n");
327 if (even_or_odd(chunk
.dwSize
)) {
331 liMove
.QuadPart
= chunk
.dwSize
;
332 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
335 case mmioFOURCC('I','C','M','T'):
336 TRACE_(dmfile
)(": comment chunk (ignored)\n");
337 if (even_or_odd(chunk
.dwSize
)) {
340 liMove
.QuadPart
= chunk
.dwSize
;
341 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
346 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
347 if (even_or_odd(chunk
.dwSize
)) {
351 liMove
.QuadPart
= chunk
.dwSize
;
352 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
355 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
356 } while (ListCount
[0] < ListSize
[0]);
360 TRACE_(dmfile
)(": unknown (skipping)\n");
361 liMove
.QuadPart
= chunk
.dwSize
- sizeof(FOURCC
);
362 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
368 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
369 liMove
.QuadPart
= chunk
.dwSize
;
370 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
373 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
374 } while (StreamCount
< StreamSize
);
376 TRACE_(dmfile
)(": reading finished\n");
378 if (TRACE_ON(dmusic
)) {
379 TRACE("Returning descriptor:\n");
380 dump_DMUS_OBJECTDESC(desc
);
386 static const IDirectMusicObjectVtbl dmobject_vtbl
= {
387 dmobj_IDirectMusicObject_QueryInterface
,
388 dmobj_IDirectMusicObject_AddRef
,
389 dmobj_IDirectMusicObject_Release
,
390 dmobj_IDirectMusicObject_GetDescriptor
,
391 dmobj_IDirectMusicObject_SetDescriptor
,
392 IDirectMusicObjectImpl_ParseDescriptor
395 /* IDirectMusicCollectionImpl IPersistStream part: */
396 static HRESULT WINAPI
IPersistStreamImpl_Load(IPersistStream
*iface
,
399 IDirectMusicCollectionImpl
*This
= impl_from_IPersistStream(iface
);
400 DMUS_PRIVATE_CHUNK chunk
;
401 DWORD StreamSize
, StreamCount
, ListSize
[2], ListCount
[2];
402 LARGE_INTEGER liMove
; /* used when skipping chunks */
403 ULARGE_INTEGER dlibCollectionPosition
, dlibInstrumentPosition
, dlibWavePoolPosition
;
405 IStream_AddRef(stream
); /* add count for later references */
407 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, &dlibCollectionPosition
); /* store offset, in case it'll be needed later */
408 This
->liCollectionPosition
.QuadPart
= dlibCollectionPosition
.QuadPart
;
411 IStream_Read(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
), NULL
);
412 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
414 if (chunk
.fccID
!= FOURCC_RIFF
) {
415 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
416 liMove
.QuadPart
= chunk
.dwSize
;
417 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
421 IStream_Read(stream
, &chunk
.fccID
, sizeof(FOURCC
), NULL
);
422 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(chunk
.fccID
));
423 StreamSize
= chunk
.dwSize
- sizeof(FOURCC
);
426 if (chunk
.fccID
!= FOURCC_DLS
) {
427 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
428 liMove
.QuadPart
= StreamSize
;
429 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
433 TRACE_(dmfile
)(": collection form\n");
435 IStream_Read(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
), NULL
);
436 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + chunk
.dwSize
;
437 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
438 switch (chunk
.fccID
) {
440 TRACE_(dmfile
)(": collection header chunk\n");
441 This
->pHeader
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, chunk
.dwSize
);
442 IStream_Read(stream
, This
->pHeader
, chunk
.dwSize
, NULL
);
446 TRACE_(dmfile
)(": DLID (GUID) chunk\n");
447 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_OBJECT
;
448 IStream_Read(stream
, &This
->dmobj
.desc
.guidObject
, chunk
.dwSize
, NULL
);
452 TRACE_(dmfile
)(": version chunk\n");
453 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_VERSION
;
454 IStream_Read(stream
, &This
->dmobj
.desc
.vVersion
, chunk
.dwSize
, NULL
);
458 TRACE_(dmfile
)(": pool table chunk\n");
459 This
->pPoolTable
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(POOLTABLE
));
460 IStream_Read(stream
, This
->pPoolTable
, sizeof(POOLTABLE
), NULL
);
461 chunk
.dwSize
-= sizeof(POOLTABLE
);
462 This
->pPoolCues
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, This
->pPoolTable
->cCues
* sizeof(POOLCUE
));
463 IStream_Read(stream
, This
->pPoolCues
, chunk
.dwSize
, NULL
);
467 IStream_Read(stream
, &chunk
.fccID
, sizeof(FOURCC
), NULL
);
468 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(chunk
.fccID
));
469 ListSize
[0] = chunk
.dwSize
- sizeof(FOURCC
);
471 switch (chunk
.fccID
) {
472 case DMUS_FOURCC_INFO_LIST
: {
473 TRACE_(dmfile
)(": INFO list\n");
475 IStream_Read(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
), NULL
);
476 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + chunk
.dwSize
;
477 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
478 switch (chunk
.fccID
) {
479 case mmioFOURCC('I','N','A','M'): {
480 CHAR szName
[DMUS_MAX_NAME
];
481 TRACE_(dmfile
)(": name chunk\n");
482 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_NAME
;
483 IStream_Read(stream
, szName
, chunk
.dwSize
, NULL
);
484 MultiByteToWideChar(CP_ACP
, 0, szName
, -1, This
->dmobj
.desc
.wszName
, DMUS_MAX_NAME
);
485 if (even_or_odd(chunk
.dwSize
)) {
488 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
492 case mmioFOURCC('I','A','R','T'): {
493 TRACE_(dmfile
)(": artist chunk (ignored)\n");
494 if (even_or_odd(chunk
.dwSize
)) {
498 liMove
.QuadPart
= chunk
.dwSize
;
499 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
502 case mmioFOURCC('I','C','O','P'): {
503 TRACE_(dmfile
)(": copyright chunk\n");
504 This
->szCopyright
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, chunk
.dwSize
);
505 IStream_Read(stream
, This
->szCopyright
, chunk
.dwSize
, NULL
);
506 if (even_or_odd(chunk
.dwSize
)) {
509 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
513 case mmioFOURCC('I','S','B','J'): {
514 TRACE_(dmfile
)(": subject chunk (ignored)\n");
515 if (even_or_odd(chunk
.dwSize
)) {
519 liMove
.QuadPart
= chunk
.dwSize
;
520 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
523 case mmioFOURCC('I','C','M','T'): {
524 TRACE_(dmfile
)(": comment chunk (ignored)\n");
525 if (even_or_odd(chunk
.dwSize
)) {
529 liMove
.QuadPart
= chunk
.dwSize
;
530 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
534 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
535 if (even_or_odd(chunk
.dwSize
)) {
539 liMove
.QuadPart
= chunk
.dwSize
;
540 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
544 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
545 } while (ListCount
[0] < ListSize
[0]);
549 TRACE_(dmfile
)(": wave pool list (mark & skip)\n");
551 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, &dlibWavePoolPosition
); /* store position */
552 This
->liWavePoolTablePosition
.QuadPart
= dlibWavePoolPosition
.QuadPart
;
553 liMove
.QuadPart
= chunk
.dwSize
- sizeof(FOURCC
);
554 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
558 TRACE_(dmfile
)(": instruments list\n");
560 IStream_Read(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
), NULL
);
561 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + chunk
.dwSize
;
562 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
563 switch (chunk
.fccID
) {
565 IStream_Read(stream
, &chunk
.fccID
, sizeof(FOURCC
), NULL
);
566 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(chunk
.fccID
));
567 ListSize
[1] = chunk
.dwSize
- sizeof(FOURCC
);
569 switch (chunk
.fccID
) {
571 LPDMUS_PRIVATE_INSTRUMENTENTRY new_instrument
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_INSTRUMENTENTRY
));
572 TRACE_(dmfile
)(": instrument list\n");
573 /* Only way to create this one... even M$ does it discretely */
574 DMUSIC_CreateDirectMusicInstrumentImpl(&IID_IDirectMusicInstrument
, (void**)&new_instrument
->pInstrument
, NULL
);
576 IDirectMusicInstrumentImpl
*instrument
= impl_from_IDirectMusicInstrument(new_instrument
->pInstrument
);
577 /* Store offset and length, they will be needed when loading the instrument */
579 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, &dlibInstrumentPosition
);
580 instrument
->liInstrumentPosition
.QuadPart
= dlibInstrumentPosition
.QuadPart
;
581 instrument
->length
= ListSize
[1];
583 IStream_Read(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
), NULL
);
584 ListCount
[1] += sizeof(FOURCC
) + sizeof(DWORD
) + chunk
.dwSize
;
585 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
586 switch (chunk
.fccID
) {
588 TRACE_(dmfile
)(": instrument header chunk\n");
589 IStream_Read(stream
, &instrument
->header
, chunk
.dwSize
, NULL
);
593 TRACE_(dmfile
)(": DLID (GUID) chunk\n");
594 IStream_Read(stream
, &instrument
->id
, chunk
.dwSize
, NULL
);
598 IStream_Read(stream
, &chunk
.fccID
, sizeof(FOURCC
), NULL
);
599 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(chunk
.fccID
));
600 switch (chunk
.fccID
) {
602 TRACE_(dmfile
)(": unknown (skipping)\n");
603 liMove
.QuadPart
= chunk
.dwSize
- sizeof(FOURCC
);
604 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
611 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
612 liMove
.QuadPart
= chunk
.dwSize
;
613 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
617 TRACE_(dmfile
)(": ListCount[1] = %d < ListSize[1] = %d\n", ListCount
[1], ListSize
[1]);
618 } while (ListCount
[1] < ListSize
[1]);
619 /* DEBUG: dumps whole instrument object tree: */
620 if (TRACE_ON(dmusic
)) {
621 TRACE("*** IDirectMusicInstrument (%p) ***\n", instrument
);
622 if (!IsEqualGUID(&instrument
->id
, &GUID_NULL
))
623 TRACE(" - GUID = %s\n", debugstr_dmguid(&instrument
->id
));
624 TRACE(" - Instrument header:\n");
625 TRACE(" - cRegions: %d\n", instrument
->header
.cRegions
);
626 TRACE(" - Locale:\n");
627 TRACE(" - ulBank: %d\n", instrument
->header
.Locale
.ulBank
);
628 TRACE(" - ulInstrument: %d\n", instrument
->header
.Locale
.ulInstrument
);
629 TRACE(" => dwPatch: %d\n", MIDILOCALE2Patch(&instrument
->header
.Locale
));
631 list_add_tail(&This
->Instruments
, &new_instrument
->entry
);
639 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
640 liMove
.QuadPart
= chunk
.dwSize
;
641 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
645 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
646 } while (ListCount
[0] < ListSize
[0]);
650 TRACE_(dmfile
)(": unknown (skipping)\n");
651 liMove
.QuadPart
= chunk
.dwSize
- sizeof(FOURCC
);
652 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
659 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
660 liMove
.QuadPart
= chunk
.dwSize
;
661 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
665 TRACE_(dmfile
)(": StreamCount = %d < StreamSize = %d\n", StreamCount
, StreamSize
);
666 } while (StreamCount
< StreamSize
);
668 TRACE_(dmfile
)(": reading finished\n");
671 /* DEBUG: dumps whole collection object tree: */
672 if (TRACE_ON(dmusic
)) {
674 DMUS_PRIVATE_INSTRUMENTENTRY
*tmpEntry
;
675 struct list
*listEntry
;
677 TRACE("*** IDirectMusicCollection (%p) ***\n", &This
->IDirectMusicCollection_iface
);
678 if (This
->dmobj
.desc
.dwValidData
& DMUS_OBJ_OBJECT
)
679 TRACE(" - GUID = %s\n", debugstr_dmguid(&This
->dmobj
.desc
.guidObject
));
680 if (This
->dmobj
.desc
.dwValidData
& DMUS_OBJ_VERSION
)
681 TRACE(" - Version = %i,%i,%i,%i\n", (This
->dmobj
.desc
.vVersion
.dwVersionMS
>> 8) & 0x0000FFFF, This
->dmobj
.desc
.vVersion
.dwVersionMS
& 0x0000FFFF,
682 (This
->dmobj
.desc
.vVersion
.dwVersionLS
>> 8) & 0x0000FFFF, This
->dmobj
.desc
.vVersion
.dwVersionLS
& 0x0000FFFF);
683 if (This
->dmobj
.desc
.dwValidData
& DMUS_OBJ_NAME
)
684 TRACE(" - Name = %s\n", debugstr_w(This
->dmobj
.desc
.wszName
));
686 TRACE(" - Collection header:\n");
687 TRACE(" - cInstruments: %d\n", This
->pHeader
->cInstruments
);
688 TRACE(" - Instruments:\n");
690 LIST_FOR_EACH(listEntry
, &This
->Instruments
) {
691 tmpEntry
= LIST_ENTRY( listEntry
, DMUS_PRIVATE_INSTRUMENTENTRY
, entry
);
692 TRACE(" - Instrument[%i]: %p\n", r
, tmpEntry
->pInstrument
);
700 static const IPersistStreamVtbl persiststream_vtbl
= {
701 dmobj_IPersistStream_QueryInterface
,
702 dmobj_IPersistStream_AddRef
,
703 dmobj_IPersistStream_Release
,
704 unimpl_IPersistStream_GetClassID
,
705 unimpl_IPersistStream_IsDirty
,
706 IPersistStreamImpl_Load
,
707 unimpl_IPersistStream_Save
,
708 unimpl_IPersistStream_GetSizeMax
712 HRESULT WINAPI
DMUSIC_CreateDirectMusicCollectionImpl(LPCGUID lpcGUID
, LPVOID
* ppobj
, LPUNKNOWN pUnkOuter
)
714 IDirectMusicCollectionImpl
* obj
;
719 return CLASS_E_NOAGGREGATION
;
721 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicCollectionImpl
));
723 return E_OUTOFMEMORY
;
725 obj
->IDirectMusicCollection_iface
.lpVtbl
= &DirectMusicCollection_Collection_Vtbl
;
727 dmobject_init(&obj
->dmobj
, &CLSID_DirectMusicCollection
,
728 (IUnknown
*)&obj
->IDirectMusicCollection_iface
);
729 obj
->dmobj
.IDirectMusicObject_iface
.lpVtbl
= &dmobject_vtbl
;
730 obj
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
732 list_init (&obj
->Instruments
);
735 hr
= IDirectMusicCollection_QueryInterface(&obj
->IDirectMusicCollection_iface
, lpcGUID
, ppobj
);
736 IDirectMusicCollection_Release(&obj
->IDirectMusicCollection_iface
);