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"
25 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
27 static inline IDirectMusicCollectionImpl
*impl_from_IDirectMusicCollection(IDirectMusicCollection
*iface
)
29 return CONTAINING_RECORD(iface
, IDirectMusicCollectionImpl
, IDirectMusicCollection_iface
);
32 static inline IDirectMusicCollectionImpl
*impl_from_IDirectMusicObject(IDirectMusicObject
*iface
)
34 return CONTAINING_RECORD(iface
, IDirectMusicCollectionImpl
, IDirectMusicObject_iface
);
37 static inline IDirectMusicCollectionImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
39 return CONTAINING_RECORD(iface
, IDirectMusicCollectionImpl
, IPersistStream_iface
);
42 /*****************************************************************************
43 * IDirectMusicCollectionImpl implementation
45 /* IDirectMusicCollectionImpl IUnknown part: */
46 static HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_QueryInterface(LPDIRECTMUSICCOLLECTION iface
, REFIID riid
, LPVOID
*ret_iface
)
48 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicCollection(iface
);
50 TRACE("(%p/%p)->(%s, %p)\n", iface
, This
, debugstr_dmguid(riid
), ret_iface
);
54 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDirectMusicCollection
))
56 else if (IsEqualIID(riid
, &IID_IDirectMusicObject
))
57 *ret_iface
= &This
->IDirectMusicObject_iface
;
58 else if (IsEqualIID(riid
, &IID_IPersistStream
))
59 *ret_iface
= &This
->IPersistStream_iface
;
62 WARN("(%p/%p)->(%s, %p): not found\n", iface
, This
, debugstr_dmguid(riid
), ret_iface
);
66 IUnknown_AddRef((IUnknown
*)*ret_iface
);
70 static ULONG WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef(LPDIRECTMUSICCOLLECTION iface
)
72 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicCollection(iface
);
73 ULONG ref
= InterlockedIncrement(&This
->ref
);
75 TRACE("(%p/%p)->(): new ref = %u\n", iface
, This
, ref
);
82 static ULONG WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_Release(LPDIRECTMUSICCOLLECTION iface
)
84 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicCollection(iface
);
85 ULONG ref
= InterlockedDecrement(&This
->ref
);
87 TRACE("(%p/%p)->(): new ref = %u\n", iface
, This
, ref
);
90 HeapFree(GetProcessHeap(), 0, This
);
92 DMUSIC_UnlockModule();
97 /* IDirectMusicCollection Interface follows: */
98 static HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_GetInstrument(LPDIRECTMUSICCOLLECTION iface
, DWORD patch
, IDirectMusicInstrument
** instrument
)
100 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicCollection(iface
);
101 DMUS_PRIVATE_INSTRUMENTENTRY
*inst_entry
;
102 struct list
*list_entry
;
105 TRACE("(%p/%p)->(%u, %p)\n", iface
, This
, patch
, instrument
);
107 LIST_FOR_EACH(list_entry
, &This
->Instruments
) {
108 inst_entry
= LIST_ENTRY(list_entry
, DMUS_PRIVATE_INSTRUMENTENTRY
, entry
);
109 IDirectMusicInstrument_GetPatch(inst_entry
->pInstrument
, &inst_patch
);
110 if (patch
== inst_patch
) {
111 *instrument
= inst_entry
->pInstrument
;
112 IDirectMusicInstrument_AddRef(inst_entry
->pInstrument
);
113 IDirectMusicInstrumentImpl_CustomLoad(inst_entry
->pInstrument
, This
->pStm
);
114 TRACE(": returning instrument %p\n", *instrument
);
119 TRACE(": instrument not found\n");
121 return DMUS_E_INVALIDPATCH
;
124 static HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicCollection_EnumInstrument(LPDIRECTMUSICCOLLECTION iface
, DWORD index
, DWORD
* patch
, LPWSTR name
, DWORD name_length
)
126 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicCollection(iface
);
128 DMUS_PRIVATE_INSTRUMENTENTRY
*inst_entry
;
129 struct list
*list_entry
;
132 TRACE("(%p/%p)->(%d, %p, %p, %d)\n", iface
, This
, index
, patch
, name
, name_length
);
134 LIST_FOR_EACH(list_entry
, &This
->Instruments
) {
135 inst_entry
= LIST_ENTRY(list_entry
, DMUS_PRIVATE_INSTRUMENTENTRY
, entry
);
137 IDirectMusicInstrumentImpl
*instrument
= impl_from_IDirectMusicInstrument(inst_entry
->pInstrument
);
138 IDirectMusicInstrument_GetPatch(inst_entry
->pInstrument
, patch
);
140 length
= min(strlenW(instrument
->wszName
), name_length
- 1);
141 memcpy(name
, instrument
->wszName
, length
* sizeof(WCHAR
));
152 static const IDirectMusicCollectionVtbl DirectMusicCollection_Collection_Vtbl
= {
153 IDirectMusicCollectionImpl_IDirectMusicCollection_QueryInterface
,
154 IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef
,
155 IDirectMusicCollectionImpl_IDirectMusicCollection_Release
,
156 IDirectMusicCollectionImpl_IDirectMusicCollection_GetInstrument
,
157 IDirectMusicCollectionImpl_IDirectMusicCollection_EnumInstrument
160 /* IDirectMusicCollectionImpl IDirectMusicObject part: */
161 static HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_QueryInterface(LPDIRECTMUSICOBJECT iface
, REFIID riid
, LPVOID
*ret_iface
)
163 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicObject(iface
);
164 return IDirectMusicCollection_QueryInterface(&This
->IDirectMusicCollection_iface
, riid
, ret_iface
);
167 static ULONG WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_AddRef(LPDIRECTMUSICOBJECT iface
)
169 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicObject(iface
);
170 return IDirectMusicCollection_AddRef(&This
->IDirectMusicCollection_iface
);
173 static ULONG WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_Release(LPDIRECTMUSICOBJECT iface
)
175 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicObject(iface
);
176 return IDirectMusicCollection_Release(&This
->IDirectMusicCollection_iface
);
179 static HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_GetDescriptor(LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
)
181 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicObject(iface
);
183 TRACE("(%p/%p)->(%p)\n", iface
, This
, pDesc
);
188 memcpy (pDesc
, This
->pDesc
, This
->pDesc
->dwSize
);
193 static HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_SetDescriptor(LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
)
195 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicObject(iface
);
199 TRACE("(%p, %p)\n", iface
, pDesc
);
204 if (TRACE_ON(dmusic
))
206 TRACE("Setting descriptor:\n");
207 dump_DMUS_OBJECTDESC(pDesc
);
210 /* According to MSDN, we should copy only given values, not whole struct */
211 if (pDesc
->dwValidData
& DMUS_OBJ_OBJECT
)
212 This
->pDesc
->guidObject
= pDesc
->guidObject
;
213 if (pDesc
->dwValidData
& DMUS_OBJ_CLASS
)
215 pDesc
->dwValidData
&= ~DMUS_OBJ_CLASS
;
218 if (pDesc
->dwValidData
& DMUS_OBJ_NAME
)
219 lstrcpynW(This
->pDesc
->wszName
, pDesc
->wszName
, DMUS_MAX_NAME
);
220 if (pDesc
->dwValidData
& DMUS_OBJ_CATEGORY
)
221 lstrcpynW(This
->pDesc
->wszCategory
, pDesc
->wszCategory
, DMUS_MAX_CATEGORY
);
222 if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
)
223 lstrcpynW(This
->pDesc
->wszFileName
, pDesc
->wszFileName
, DMUS_MAX_FILENAME
);
224 if (pDesc
->dwValidData
& DMUS_OBJ_VERSION
)
225 This
->pDesc
->vVersion
= pDesc
->vVersion
;
226 if (pDesc
->dwValidData
& DMUS_OBJ_DATE
)
227 This
->pDesc
->ftDate
= pDesc
->ftDate
;
228 if (pDesc
->dwValidData
& DMUS_OBJ_MEMORY
) {
229 This
->pDesc
->llMemLength
= pDesc
->llMemLength
;
230 memcpy (This
->pDesc
->pbMemData
, pDesc
->pbMemData
, pDesc
->llMemLength
);
232 if (pDesc
->dwValidData
& DMUS_OBJ_STREAM
) {
233 /* according to MSDN, we copy the stream */
234 IStream_Clone (pDesc
->pStream
, &This
->pDesc
->pStream
);
238 This
->pDesc
->dwValidData
|= pDesc
->dwValidData
;
243 static HRESULT
read_from_stream(IStream
*stream
, void *data
, ULONG size
)
248 hr
= IStream_Read(stream
, data
, size
, &read
);
250 TRACE("IStream_Read failed: %08x\n", hr
);
254 TRACE("Didn't read full chunk: %u < %u\n", read
, size
);
261 static HRESULT WINAPI
IDirectMusicCollectionImpl_IDirectMusicObject_ParseDescriptor(LPDIRECTMUSICOBJECT iface
, LPSTREAM stream
, LPDMUS_OBJECTDESC desc
)
263 IDirectMusicCollectionImpl
*This
= impl_from_IDirectMusicObject(iface
);
264 DMUS_PRIVATE_CHUNK chunk
;
265 DWORD StreamSize
, StreamCount
, ListSize
[1], ListCount
[1];
266 LARGE_INTEGER liMove
; /* used when skipping chunks */
269 TRACE("(%p)->(%p, %p)\n", This
, stream
, desc
);
271 /* FIXME: should this be determined from stream? */
272 desc
->dwValidData
|= DMUS_OBJ_CLASS
;
273 desc
->guidClass
= This
->pDesc
->guidClass
;
275 hr
= read_from_stream(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
));
278 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
280 if (chunk
.fccID
!= FOURCC_RIFF
) {
281 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
282 liMove
.QuadPart
= chunk
.dwSize
;
283 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
284 return DMUS_E_INVALIDFILE
;
287 hr
= read_from_stream(stream
, &chunk
.fccID
, sizeof(FOURCC
));
290 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(chunk
.fccID
));
291 StreamSize
= chunk
.dwSize
- sizeof(FOURCC
);
293 if (chunk
.fccID
!= FOURCC_DLS
) {
294 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
295 liMove
.QuadPart
= StreamSize
;
296 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
301 TRACE_(dmfile
)(": collection form\n");
304 hr
= read_from_stream(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
));
307 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + chunk
.dwSize
;
308 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
309 switch (chunk
.fccID
) {
311 TRACE_(dmfile
)(": GUID chunk\n");
312 desc
->dwValidData
|= DMUS_OBJ_OBJECT
;
313 hr
= read_from_stream(stream
, &desc
->guidObject
, chunk
.dwSize
);
318 case DMUS_FOURCC_VERSION_CHUNK
:
319 TRACE_(dmfile
)(": version chunk\n");
320 desc
->dwValidData
|= DMUS_OBJ_VERSION
;
321 hr
= read_from_stream(stream
, &desc
->vVersion
, chunk
.dwSize
);
326 case DMUS_FOURCC_CATEGORY_CHUNK
:
327 TRACE_(dmfile
)(": category chunk\n");
328 desc
->dwValidData
|= DMUS_OBJ_CATEGORY
;
329 hr
= read_from_stream(stream
, desc
->wszCategory
, chunk
.dwSize
);
335 hr
= read_from_stream(stream
, &chunk
.fccID
, sizeof(FOURCC
));
338 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(chunk
.fccID
));
339 ListSize
[0] = chunk
.dwSize
- sizeof(FOURCC
);
341 switch (chunk
.fccID
) {
342 /* pure INFO list, such can be found in dls collections */
343 case DMUS_FOURCC_INFO_LIST
:
344 TRACE_(dmfile
)(": INFO list\n");
346 hr
= read_from_stream(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
));
349 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + chunk
.dwSize
;
350 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
351 switch (chunk
.fccID
) {
352 case mmioFOURCC('I','N','A','M'): {
353 CHAR szName
[DMUS_MAX_NAME
];
354 TRACE_(dmfile
)(": name chunk\n");
355 desc
->dwValidData
|= DMUS_OBJ_NAME
;
356 hr
= read_from_stream(stream
, szName
, chunk
.dwSize
);
359 MultiByteToWideChar (CP_ACP
, 0, szName
, -1, desc
->wszName
, DMUS_MAX_NAME
);
360 if (even_or_odd(chunk
.dwSize
)) {
363 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
368 case mmioFOURCC('I','A','R','T'):
369 TRACE_(dmfile
)(": artist chunk (ignored)\n");
370 if (even_or_odd(chunk
.dwSize
)) {
374 liMove
.QuadPart
= chunk
.dwSize
;
375 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
378 case mmioFOURCC('I','C','O','P'):
379 TRACE_(dmfile
)(": copyright chunk (ignored)\n");
380 if (even_or_odd(chunk
.dwSize
)) {
384 liMove
.QuadPart
= chunk
.dwSize
;
385 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
388 case mmioFOURCC('I','S','B','J'):
389 TRACE_(dmfile
)(": subject chunk (ignored)\n");
390 if (even_or_odd(chunk
.dwSize
)) {
394 liMove
.QuadPart
= chunk
.dwSize
;
395 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
398 case mmioFOURCC('I','C','M','T'):
399 TRACE_(dmfile
)(": comment chunk (ignored)\n");
400 if (even_or_odd(chunk
.dwSize
)) {
403 liMove
.QuadPart
= chunk
.dwSize
;
404 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
409 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
410 if (even_or_odd(chunk
.dwSize
)) {
414 liMove
.QuadPart
= chunk
.dwSize
;
415 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
418 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
419 } while (ListCount
[0] < ListSize
[0]);
423 TRACE_(dmfile
)(": unknown (skipping)\n");
424 liMove
.QuadPart
= chunk
.dwSize
- sizeof(FOURCC
);
425 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
431 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
432 liMove
.QuadPart
= chunk
.dwSize
;
433 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
436 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
437 } while (StreamCount
< StreamSize
);
439 TRACE_(dmfile
)(": reading finished\n");
441 if (TRACE_ON(dmusic
)) {
442 TRACE("Returning descriptor:\n");
443 dump_DMUS_OBJECTDESC(desc
);
449 static const IDirectMusicObjectVtbl DirectMusicCollection_Object_Vtbl
= {
450 IDirectMusicCollectionImpl_IDirectMusicObject_QueryInterface
,
451 IDirectMusicCollectionImpl_IDirectMusicObject_AddRef
,
452 IDirectMusicCollectionImpl_IDirectMusicObject_Release
,
453 IDirectMusicCollectionImpl_IDirectMusicObject_GetDescriptor
,
454 IDirectMusicCollectionImpl_IDirectMusicObject_SetDescriptor
,
455 IDirectMusicCollectionImpl_IDirectMusicObject_ParseDescriptor
458 /* IDirectMusicCollectionImpl IPersistStream part: */
459 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_QueryInterface(LPPERSISTSTREAM iface
, REFIID riid
, LPVOID
*ret_iface
)
461 IDirectMusicCollectionImpl
*This
= impl_from_IPersistStream(iface
);
462 return IDirectMusicCollection_QueryInterface(&This
->IDirectMusicCollection_iface
, riid
, ret_iface
);
465 static ULONG WINAPI
IDirectMusicCollectionImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface
)
467 IDirectMusicCollectionImpl
*This
= impl_from_IPersistStream(iface
);
468 return IDirectMusicCollection_AddRef(&This
->IDirectMusicCollection_iface
);
471 static ULONG WINAPI
IDirectMusicCollectionImpl_IPersistStream_Release (LPPERSISTSTREAM iface
)
473 IDirectMusicCollectionImpl
*This
= impl_from_IPersistStream(iface
);
474 return IDirectMusicCollection_Release(&This
->IDirectMusicCollection_iface
);
477 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_GetClassID(LPPERSISTSTREAM iface
, CLSID
* pClassID
)
482 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_IsDirty(LPPERSISTSTREAM iface
)
487 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_Load(LPPERSISTSTREAM iface
, IStream
* stream
)
489 IDirectMusicCollectionImpl
*This
= impl_from_IPersistStream(iface
);
490 DMUS_PRIVATE_CHUNK chunk
;
491 DWORD StreamSize
, StreamCount
, ListSize
[2], ListCount
[2];
492 LARGE_INTEGER liMove
; /* used when skipping chunks */
493 ULARGE_INTEGER dlibCollectionPosition
, dlibInstrumentPosition
, dlibWavePoolPosition
;
495 IStream_AddRef(stream
); /* add count for later references */
497 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, &dlibCollectionPosition
); /* store offset, in case it'll be needed later */
498 This
->liCollectionPosition
.QuadPart
= dlibCollectionPosition
.QuadPart
;
501 IStream_Read(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
), NULL
);
502 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
504 if (chunk
.fccID
!= FOURCC_RIFF
) {
505 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
506 liMove
.QuadPart
= chunk
.dwSize
;
507 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
511 IStream_Read(stream
, &chunk
.fccID
, sizeof(FOURCC
), NULL
);
512 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(chunk
.fccID
));
513 StreamSize
= chunk
.dwSize
- sizeof(FOURCC
);
516 if (chunk
.fccID
!= FOURCC_DLS
) {
517 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
518 liMove
.QuadPart
= StreamSize
;
519 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
523 TRACE_(dmfile
)(": collection form\n");
525 IStream_Read(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
), NULL
);
526 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + chunk
.dwSize
;
527 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
528 switch (chunk
.fccID
) {
530 TRACE_(dmfile
)(": collection header chunk\n");
531 This
->pHeader
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, chunk
.dwSize
);
532 IStream_Read(stream
, This
->pHeader
, chunk
.dwSize
, NULL
);
536 TRACE_(dmfile
)(": DLID (GUID) chunk\n");
537 This
->pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
538 IStream_Read(stream
, &This
->pDesc
->guidObject
, chunk
.dwSize
, NULL
);
542 TRACE_(dmfile
)(": version chunk\n");
543 This
->pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
544 IStream_Read(stream
, &This
->pDesc
->vVersion
, chunk
.dwSize
, NULL
);
548 TRACE_(dmfile
)(": pool table chunk\n");
549 This
->pPoolTable
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(POOLTABLE
));
550 IStream_Read(stream
, This
->pPoolTable
, sizeof(POOLTABLE
), NULL
);
551 chunk
.dwSize
-= sizeof(POOLTABLE
);
552 This
->pPoolCues
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, This
->pPoolTable
->cCues
* sizeof(POOLCUE
));
553 IStream_Read(stream
, This
->pPoolCues
, chunk
.dwSize
, NULL
);
557 IStream_Read(stream
, &chunk
.fccID
, sizeof(FOURCC
), NULL
);
558 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(chunk
.fccID
));
559 ListSize
[0] = chunk
.dwSize
- sizeof(FOURCC
);
561 switch (chunk
.fccID
) {
562 case DMUS_FOURCC_INFO_LIST
: {
563 TRACE_(dmfile
)(": INFO list\n");
565 IStream_Read(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
), NULL
);
566 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + chunk
.dwSize
;
567 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
568 switch (chunk
.fccID
) {
569 case mmioFOURCC('I','N','A','M'): {
570 CHAR szName
[DMUS_MAX_NAME
];
571 TRACE_(dmfile
)(": name chunk\n");
572 This
->pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
573 IStream_Read(stream
, szName
, chunk
.dwSize
, NULL
);
574 MultiByteToWideChar(CP_ACP
, 0, szName
, -1, This
->pDesc
->wszName
, DMUS_MAX_NAME
);
575 if (even_or_odd(chunk
.dwSize
)) {
578 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
582 case mmioFOURCC('I','A','R','T'): {
583 TRACE_(dmfile
)(": artist chunk (ignored)\n");
584 if (even_or_odd(chunk
.dwSize
)) {
588 liMove
.QuadPart
= chunk
.dwSize
;
589 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
592 case mmioFOURCC('I','C','O','P'): {
593 TRACE_(dmfile
)(": copyright chunk\n");
594 This
->szCopyright
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, chunk
.dwSize
);
595 IStream_Read(stream
, This
->szCopyright
, chunk
.dwSize
, NULL
);
596 if (even_or_odd(chunk
.dwSize
)) {
599 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
603 case mmioFOURCC('I','S','B','J'): {
604 TRACE_(dmfile
)(": subject chunk (ignored)\n");
605 if (even_or_odd(chunk
.dwSize
)) {
609 liMove
.QuadPart
= chunk
.dwSize
;
610 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
613 case mmioFOURCC('I','C','M','T'): {
614 TRACE_(dmfile
)(": comment chunk (ignored)\n");
615 if (even_or_odd(chunk
.dwSize
)) {
619 liMove
.QuadPart
= chunk
.dwSize
;
620 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
624 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
625 if (even_or_odd(chunk
.dwSize
)) {
629 liMove
.QuadPart
= chunk
.dwSize
;
630 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
634 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
635 } while (ListCount
[0] < ListSize
[0]);
639 TRACE_(dmfile
)(": wave pool list (mark & skip)\n");
641 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, &dlibWavePoolPosition
); /* store position */
642 This
->liWavePoolTablePosition
.QuadPart
= dlibWavePoolPosition
.QuadPart
;
643 liMove
.QuadPart
= chunk
.dwSize
- sizeof(FOURCC
);
644 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
648 TRACE_(dmfile
)(": instruments list\n");
650 IStream_Read(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
), NULL
);
651 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + chunk
.dwSize
;
652 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
653 switch (chunk
.fccID
) {
655 IStream_Read(stream
, &chunk
.fccID
, sizeof(FOURCC
), NULL
);
656 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(chunk
.fccID
));
657 ListSize
[1] = chunk
.dwSize
- sizeof(FOURCC
);
659 switch (chunk
.fccID
) {
661 LPDMUS_PRIVATE_INSTRUMENTENTRY new_instrument
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_INSTRUMENTENTRY
));
662 TRACE_(dmfile
)(": instrument list\n");
663 /* Only way to create this one... even M$ does it discretely */
664 DMUSIC_CreateDirectMusicInstrumentImpl(&IID_IDirectMusicInstrument
, (void**)&new_instrument
->pInstrument
, NULL
);
666 IDirectMusicInstrumentImpl
*instrument
= impl_from_IDirectMusicInstrument(new_instrument
->pInstrument
);
667 /* Store offset and length, they will be needed when loading the instrument */
669 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, &dlibInstrumentPosition
);
670 instrument
->liInstrumentPosition
.QuadPart
= dlibInstrumentPosition
.QuadPart
;
671 instrument
->length
= ListSize
[1];
673 IStream_Read(stream
, &chunk
, sizeof(FOURCC
) + sizeof(DWORD
), NULL
);
674 ListCount
[1] += sizeof(FOURCC
) + sizeof(DWORD
) + chunk
.dwSize
;
675 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc(chunk
.fccID
), chunk
.dwSize
);
676 switch (chunk
.fccID
) {
678 TRACE_(dmfile
)(": instrument header chunk\n");
679 IStream_Read(stream
, &instrument
->header
, chunk
.dwSize
, NULL
);
683 TRACE_(dmfile
)(": DLID (GUID) chunk\n");
684 IStream_Read(stream
, &instrument
->id
, chunk
.dwSize
, NULL
);
688 IStream_Read(stream
, &chunk
.fccID
, sizeof(FOURCC
), NULL
);
689 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(chunk
.fccID
));
690 switch (chunk
.fccID
) {
692 TRACE_(dmfile
)(": unknown (skipping)\n");
693 liMove
.QuadPart
= chunk
.dwSize
- sizeof(FOURCC
);
694 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
701 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
702 liMove
.QuadPart
= chunk
.dwSize
;
703 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
707 TRACE_(dmfile
)(": ListCount[1] = %d < ListSize[1] = %d\n", ListCount
[1], ListSize
[1]);
708 } while (ListCount
[1] < ListSize
[1]);
709 /* DEBUG: dumps whole instrument object tree: */
710 if (TRACE_ON(dmusic
)) {
711 TRACE("*** IDirectMusicInstrument (%p) ***\n", instrument
);
712 if (!IsEqualGUID(&instrument
->id
, &GUID_NULL
))
713 TRACE(" - GUID = %s\n", debugstr_dmguid(&instrument
->id
));
714 TRACE(" - Instrument header:\n");
715 TRACE(" - cRegions: %d\n", instrument
->header
.cRegions
);
716 TRACE(" - Locale:\n");
717 TRACE(" - ulBank: %d\n", instrument
->header
.Locale
.ulBank
);
718 TRACE(" - ulInstrument: %d\n", instrument
->header
.Locale
.ulInstrument
);
719 TRACE(" => dwPatch: %d\n", MIDILOCALE2Patch(&instrument
->header
.Locale
));
721 list_add_tail(&This
->Instruments
, &new_instrument
->entry
);
729 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
730 liMove
.QuadPart
= chunk
.dwSize
;
731 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
735 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
736 } while (ListCount
[0] < ListSize
[0]);
740 TRACE_(dmfile
)(": unknown (skipping)\n");
741 liMove
.QuadPart
= chunk
.dwSize
- sizeof(FOURCC
);
742 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
749 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
750 liMove
.QuadPart
= chunk
.dwSize
;
751 IStream_Seek(stream
, liMove
, STREAM_SEEK_CUR
, NULL
);
755 TRACE_(dmfile
)(": StreamCount = %d < StreamSize = %d\n", StreamCount
, StreamSize
);
756 } while (StreamCount
< StreamSize
);
758 TRACE_(dmfile
)(": reading finished\n");
761 /* DEBUG: dumps whole collection object tree: */
762 if (TRACE_ON(dmusic
)) {
764 DMUS_PRIVATE_INSTRUMENTENTRY
*tmpEntry
;
765 struct list
*listEntry
;
767 TRACE("*** IDirectMusicCollection (%p) ***\n", &This
->IDirectMusicCollection_iface
);
768 if (This
->pDesc
->dwValidData
& DMUS_OBJ_OBJECT
)
769 TRACE(" - GUID = %s\n", debugstr_dmguid(&This
->pDesc
->guidObject
));
770 if (This
->pDesc
->dwValidData
& DMUS_OBJ_VERSION
)
771 TRACE(" - Version = %i,%i,%i,%i\n", (This
->pDesc
->vVersion
.dwVersionMS
>> 8) & 0x0000FFFF, This
->pDesc
->vVersion
.dwVersionMS
& 0x0000FFFF,
772 (This
->pDesc
->vVersion
.dwVersionLS
>> 8) & 0x0000FFFF, This
->pDesc
->vVersion
.dwVersionLS
& 0x0000FFFF);
773 if (This
->pDesc
->dwValidData
& DMUS_OBJ_NAME
)
774 TRACE(" - Name = %s\n", debugstr_w(This
->pDesc
->wszName
));
776 TRACE(" - Collection header:\n");
777 TRACE(" - cInstruments: %d\n", This
->pHeader
->cInstruments
);
778 TRACE(" - Instruments:\n");
780 LIST_FOR_EACH(listEntry
, &This
->Instruments
) {
781 tmpEntry
= LIST_ENTRY( listEntry
, DMUS_PRIVATE_INSTRUMENTENTRY
, entry
);
782 TRACE(" - Instrument[%i]: %p\n", r
, tmpEntry
->pInstrument
);
790 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_Save(LPPERSISTSTREAM iface
, IStream
* pStm
, BOOL fClearDirty
)
795 static HRESULT WINAPI
IDirectMusicCollectionImpl_IPersistStream_GetSizeMax(LPPERSISTSTREAM iface
, ULARGE_INTEGER
* pcbSize
)
800 static const IPersistStreamVtbl DirectMusicCollection_PersistStream_Vtbl
= {
801 IDirectMusicCollectionImpl_IPersistStream_QueryInterface
,
802 IDirectMusicCollectionImpl_IPersistStream_AddRef
,
803 IDirectMusicCollectionImpl_IPersistStream_Release
,
804 IDirectMusicCollectionImpl_IPersistStream_GetClassID
,
805 IDirectMusicCollectionImpl_IPersistStream_IsDirty
,
806 IDirectMusicCollectionImpl_IPersistStream_Load
,
807 IDirectMusicCollectionImpl_IPersistStream_Save
,
808 IDirectMusicCollectionImpl_IPersistStream_GetSizeMax
812 /* for ClassFactory */
813 HRESULT WINAPI
DMUSIC_CreateDirectMusicCollectionImpl(LPCGUID lpcGUID
, LPVOID
* ppobj
, LPUNKNOWN pUnkOuter
)
815 IDirectMusicCollectionImpl
* obj
;
820 return CLASS_E_NOAGGREGATION
;
822 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicCollectionImpl
));
824 return E_OUTOFMEMORY
;
826 obj
->IDirectMusicCollection_iface
.lpVtbl
= &DirectMusicCollection_Collection_Vtbl
;
827 obj
->IDirectMusicObject_iface
.lpVtbl
= &DirectMusicCollection_Object_Vtbl
;
828 obj
->IPersistStream_iface
.lpVtbl
= &DirectMusicCollection_PersistStream_Vtbl
;
829 obj
->pDesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DMUS_OBJECTDESC
));
830 DM_STRUCT_INIT(obj
->pDesc
);
831 obj
->pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
832 obj
->pDesc
->guidClass
= CLSID_DirectMusicCollection
;
834 list_init (&obj
->Instruments
);
836 hr
= IDirectMusicCollection_QueryInterface(&obj
->IDirectMusicCollection_iface
, lpcGUID
, ppobj
);
837 IDirectMusicCollection_Release(&obj
->IDirectMusicCollection_iface
);