1 /* IDirectMusicBand 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 "dmband_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(dmband
);
23 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
26 /*****************************************************************************
27 * IDirectMusicBandImpl implementation
29 static inline IDirectMusicBandImpl
*impl_from_IDirectMusicBand(IDirectMusicBand
*iface
)
31 return CONTAINING_RECORD(iface
, IDirectMusicBandImpl
, IDirectMusicBand_iface
);
34 /* DirectMusicBandImpl IDirectMusicBand part: */
35 static HRESULT WINAPI
IDirectMusicBandImpl_QueryInterface(IDirectMusicBand
*iface
, REFIID riid
,
38 IDirectMusicBandImpl
*This
= impl_from_IDirectMusicBand(iface
);
40 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ret_iface
);
44 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDirectMusicBand
))
46 else if (IsEqualIID(riid
, &IID_IDirectMusicObject
))
47 *ret_iface
= &This
->ObjectVtbl
;
48 else if (IsEqualIID(riid
, &IID_IPersistStream
))
49 *ret_iface
= &This
->PersistStreamVtbl
;
51 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ret_iface
);
55 IDirectMusicBand_AddRef((IUnknown
*)*ret_iface
);
59 static ULONG WINAPI
IDirectMusicBandImpl_AddRef(IDirectMusicBand
*iface
)
61 IDirectMusicBandImpl
*This
= impl_from_IDirectMusicBand(iface
);
62 LONG ref
= InterlockedIncrement(&This
->ref
);
64 TRACE("(%p) ref=%d\n", This
, ref
);
69 static ULONG WINAPI
IDirectMusicBandImpl_Release(IDirectMusicBand
*iface
)
71 IDirectMusicBandImpl
*This
= impl_from_IDirectMusicBand(iface
);
72 LONG ref
= InterlockedDecrement(&This
->ref
);
74 TRACE("(%p) ref=%d\n", This
, ref
);
77 HeapFree(GetProcessHeap(), 0, This
->pDesc
);
78 HeapFree(GetProcessHeap(), 0, This
);
79 DMBAND_UnlockModule();
85 static HRESULT WINAPI
IDirectMusicBandImpl_CreateSegment(IDirectMusicBand
*iface
,
86 IDirectMusicSegment
**ppSegment
)
88 IDirectMusicBandImpl
*This
= impl_from_IDirectMusicBand(iface
);
89 FIXME("(%p, %p): stub\n", This
, ppSegment
);
93 static HRESULT WINAPI
IDirectMusicBandImpl_Download(IDirectMusicBand
*iface
,
94 IDirectMusicPerformance
*pPerformance
)
96 IDirectMusicBandImpl
*This
= impl_from_IDirectMusicBand(iface
);
97 FIXME("(%p, %p): stub\n", This
, pPerformance
);
101 static HRESULT WINAPI
IDirectMusicBandImpl_Unload(IDirectMusicBand
*iface
,
102 IDirectMusicPerformance
*pPerformance
)
104 IDirectMusicBandImpl
*This
= impl_from_IDirectMusicBand(iface
);
105 FIXME("(%p, %p): stub\n", This
, pPerformance
);
109 static const IDirectMusicBandVtbl dmband_vtbl
= {
110 IDirectMusicBandImpl_QueryInterface
,
111 IDirectMusicBandImpl_AddRef
,
112 IDirectMusicBandImpl_Release
,
113 IDirectMusicBandImpl_CreateSegment
,
114 IDirectMusicBandImpl_Download
,
115 IDirectMusicBandImpl_Unload
118 /* IDirectMusicBandImpl IDirectMusicObject part: */
119 static HRESULT WINAPI
IDirectMusicBandImpl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface
, REFIID riid
, LPVOID
*ppobj
) {
120 ICOM_THIS_MULTI(IDirectMusicBandImpl
, ObjectVtbl
, iface
);
121 return IDirectMusicBand_QueryInterface(&This
->IDirectMusicBand_iface
, riid
, ppobj
);
124 static ULONG WINAPI
IDirectMusicBandImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface
) {
125 ICOM_THIS_MULTI(IDirectMusicBandImpl
, ObjectVtbl
, iface
);
126 return IDirectMusicBand_AddRef(&This
->IDirectMusicBand_iface
);
129 static ULONG WINAPI
IDirectMusicBandImpl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface
) {
130 ICOM_THIS_MULTI(IDirectMusicBandImpl
, ObjectVtbl
, iface
);
131 return IDirectMusicBand_Release(&This
->IDirectMusicBand_iface
);
134 static HRESULT WINAPI
IDirectMusicBandImpl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
) {
135 ICOM_THIS_MULTI(IDirectMusicBandImpl
, ObjectVtbl
, iface
);
136 TRACE("(%p, %p)\n", This
, pDesc
);
137 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
138 memcpy (pDesc
, This
->pDesc
, This
->pDesc
->dwSize
);
142 static HRESULT WINAPI
IDirectMusicBandImpl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
) {
143 ICOM_THIS_MULTI(IDirectMusicBandImpl
, ObjectVtbl
, iface
);
144 TRACE("(%p, %p): setting descriptor:\n", This
, pDesc
); debug_DMUS_OBJECTDESC (pDesc
);
146 /* According to MSDN, we should copy only given values, not whole struct */
147 if (pDesc
->dwValidData
& DMUS_OBJ_OBJECT
)
148 This
->pDesc
->guidObject
= pDesc
->guidObject
;
149 if (pDesc
->dwValidData
& DMUS_OBJ_CLASS
)
150 This
->pDesc
->guidClass
= pDesc
->guidClass
;
151 if (pDesc
->dwValidData
& DMUS_OBJ_NAME
)
152 lstrcpynW (This
->pDesc
->wszName
, pDesc
->wszName
, DMUS_MAX_NAME
);
153 if (pDesc
->dwValidData
& DMUS_OBJ_CATEGORY
)
154 lstrcpynW (This
->pDesc
->wszCategory
, pDesc
->wszCategory
, DMUS_MAX_CATEGORY
);
155 if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
)
156 lstrcpynW (This
->pDesc
->wszFileName
, pDesc
->wszFileName
, DMUS_MAX_FILENAME
);
157 if (pDesc
->dwValidData
& DMUS_OBJ_VERSION
)
158 This
->pDesc
->vVersion
= pDesc
->vVersion
;
159 if (pDesc
->dwValidData
& DMUS_OBJ_DATE
)
160 This
->pDesc
->ftDate
= pDesc
->ftDate
;
161 if (pDesc
->dwValidData
& DMUS_OBJ_MEMORY
) {
162 This
->pDesc
->llMemLength
= pDesc
->llMemLength
;
163 memcpy (This
->pDesc
->pbMemData
, pDesc
->pbMemData
, pDesc
->llMemLength
);
165 if (pDesc
->dwValidData
& DMUS_OBJ_STREAM
) {
166 /* according to MSDN, we copy the stream */
167 IStream_Clone (pDesc
->pStream
, &This
->pDesc
->pStream
);
171 This
->pDesc
->dwValidData
|= pDesc
->dwValidData
;
176 static HRESULT WINAPI
IDirectMusicBandImpl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface
, LPSTREAM pStream
, LPDMUS_OBJECTDESC pDesc
) {
177 DMUS_PRIVATE_CHUNK Chunk
;
178 DWORD StreamSize
, StreamCount
, ListSize
[1], ListCount
[1];
179 LARGE_INTEGER liMove
; /* used when skipping chunks */
181 TRACE("(%p, %p)\n", pStream
, pDesc
);
183 /* FIXME: should this be determined from stream? */
184 pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
185 pDesc
->guidClass
= CLSID_DirectMusicBand
;
187 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
188 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
189 switch (Chunk
.fccID
) {
191 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
192 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
193 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
195 if (Chunk
.fccID
== DMUS_FOURCC_BAND_FORM
) {
196 TRACE_(dmfile
)(": band form\n");
198 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
199 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
200 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
201 switch (Chunk
.fccID
) {
202 case DMUS_FOURCC_GUID_CHUNK
: {
203 TRACE_(dmfile
)(": GUID chunk\n");
204 pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
205 IStream_Read (pStream
, &pDesc
->guidObject
, Chunk
.dwSize
, NULL
);
208 case DMUS_FOURCC_VERSION_CHUNK
: {
209 TRACE_(dmfile
)(": version chunk\n");
210 pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
211 IStream_Read (pStream
, &pDesc
->vVersion
, Chunk
.dwSize
, NULL
);
214 case DMUS_FOURCC_CATEGORY_CHUNK
: {
215 TRACE_(dmfile
)(": category chunk\n");
216 pDesc
->dwValidData
|= DMUS_OBJ_CATEGORY
;
217 IStream_Read (pStream
, pDesc
->wszCategory
, Chunk
.dwSize
, NULL
);
221 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
222 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
223 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
225 switch (Chunk
.fccID
) {
226 /* evil M$ UNFO list, which can (!?) contain INFO elements */
227 case DMUS_FOURCC_UNFO_LIST
: {
228 TRACE_(dmfile
)(": UNFO list\n");
230 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
231 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
232 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
233 switch (Chunk
.fccID
) {
234 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
235 (though strings seem to be valid unicode) */
236 case mmioFOURCC('I','N','A','M'):
237 case DMUS_FOURCC_UNAM_CHUNK
: {
238 TRACE_(dmfile
)(": name chunk\n");
239 pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
240 IStream_Read (pStream
, pDesc
->wszName
, Chunk
.dwSize
, NULL
);
243 case mmioFOURCC('I','A','R','T'):
244 case DMUS_FOURCC_UART_CHUNK
: {
245 TRACE_(dmfile
)(": artist chunk (ignored)\n");
246 liMove
.QuadPart
= Chunk
.dwSize
;
247 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
250 case mmioFOURCC('I','C','O','P'):
251 case DMUS_FOURCC_UCOP_CHUNK
: {
252 TRACE_(dmfile
)(": copyright chunk (ignored)\n");
253 liMove
.QuadPart
= Chunk
.dwSize
;
254 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
257 case mmioFOURCC('I','S','B','J'):
258 case DMUS_FOURCC_USBJ_CHUNK
: {
259 TRACE_(dmfile
)(": subject chunk (ignored)\n");
260 liMove
.QuadPart
= Chunk
.dwSize
;
261 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
264 case mmioFOURCC('I','C','M','T'):
265 case DMUS_FOURCC_UCMT_CHUNK
: {
266 TRACE_(dmfile
)(": comment chunk (ignored)\n");
267 liMove
.QuadPart
= Chunk
.dwSize
;
268 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
272 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
273 liMove
.QuadPart
= Chunk
.dwSize
;
274 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
278 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
279 } while (ListCount
[0] < ListSize
[0]);
283 TRACE_(dmfile
)(": unknown (skipping)\n");
284 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
285 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
292 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
293 liMove
.QuadPart
= Chunk
.dwSize
;
294 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
298 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
299 } while (StreamCount
< StreamSize
);
301 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
302 liMove
.QuadPart
= StreamSize
;
303 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
307 TRACE_(dmfile
)(": reading finished\n");
311 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
312 liMove
.QuadPart
= Chunk
.dwSize
;
313 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
314 return DMUS_E_INVALIDFILE
;
318 TRACE(": returning descriptor:\n"); debug_DMUS_OBJECTDESC (pDesc
);
323 static const IDirectMusicObjectVtbl DirectMusicBand_Object_Vtbl
= {
324 IDirectMusicBandImpl_IDirectMusicObject_QueryInterface
,
325 IDirectMusicBandImpl_IDirectMusicObject_AddRef
,
326 IDirectMusicBandImpl_IDirectMusicObject_Release
,
327 IDirectMusicBandImpl_IDirectMusicObject_GetDescriptor
,
328 IDirectMusicBandImpl_IDirectMusicObject_SetDescriptor
,
329 IDirectMusicBandImpl_IDirectMusicObject_ParseDescriptor
332 /* IDirectMusicBandImpl IPersistStream part: */
333 static HRESULT WINAPI
IDirectMusicBandImpl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface
, REFIID riid
, LPVOID
*ppobj
) {
334 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
335 return IDirectMusicBand_QueryInterface(&This
->IDirectMusicBand_iface
, riid
, ppobj
);
338 static ULONG WINAPI
IDirectMusicBandImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface
) {
339 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
340 return IDirectMusicBand_AddRef(&This
->IDirectMusicBand_iface
);
343 static ULONG WINAPI
IDirectMusicBandImpl_IPersistStream_Release (LPPERSISTSTREAM iface
) {
344 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
345 return IDirectMusicBand_Release(&This
->IDirectMusicBand_iface
);
348 static HRESULT WINAPI
IDirectMusicBandImpl_IPersistStream_GetClassID (LPPERSISTSTREAM iface
, CLSID
* pClassID
) {
349 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
350 TRACE("(%p, %p)\n", This
, pClassID
);
351 *pClassID
= CLSID_DirectMusicBand
;
355 static HRESULT WINAPI
IDirectMusicBandImpl_IPersistStream_IsDirty (LPPERSISTSTREAM iface
) {
356 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
357 FIXME("(%p): stub, always S_FALSE\n", This
);
361 static HRESULT
IDirectMusicBandImpl_IPersistStream_ParseInstrument (LPPERSISTSTREAM iface
, DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
) {
362 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
363 DMUS_PRIVATE_CHUNK Chunk
;
364 DWORD ListSize
[3], ListCount
[3];
365 LARGE_INTEGER liMove
; /* used when skipping chunks */
368 DMUS_IO_INSTRUMENT inst
;
369 LPDMUS_PRIVATE_INSTRUMENT pNewInstrument
;
370 IDirectMusicObject
* pObject
= NULL
;
372 if (pChunk
->fccID
!= DMUS_FOURCC_INSTRUMENT_LIST
) {
373 ERR_(dmfile
)(": %s chunk should be an INSTRUMENT list\n", debugstr_fourcc (pChunk
->fccID
));
377 ListSize
[0] = pChunk
->dwSize
- sizeof(FOURCC
);
381 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
382 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
383 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
384 switch (Chunk
.fccID
) {
385 case DMUS_FOURCC_INSTRUMENT_CHUNK
: {
386 TRACE_(dmfile
)(": Instrument chunk\n");
387 if (Chunk
.dwSize
!= sizeof(DMUS_IO_INSTRUMENT
)) return E_FAIL
;
388 IStream_Read (pStm
, &inst
, sizeof(DMUS_IO_INSTRUMENT
), NULL
);
389 TRACE_(dmfile
)(" - dwPatch: %u\n", inst
.dwPatch
);
390 TRACE_(dmfile
)(" - dwAssignPatch: %u\n", inst
.dwAssignPatch
);
391 TRACE_(dmfile
)(" - dwNoteRanges[0]: %u\n", inst
.dwNoteRanges
[0]);
392 TRACE_(dmfile
)(" - dwNoteRanges[1]: %u\n", inst
.dwNoteRanges
[1]);
393 TRACE_(dmfile
)(" - dwNoteRanges[2]: %u\n", inst
.dwNoteRanges
[2]);
394 TRACE_(dmfile
)(" - dwNoteRanges[3]: %u\n", inst
.dwNoteRanges
[3]);
395 TRACE_(dmfile
)(" - dwPChannel: %u\n", inst
.dwPChannel
);
396 TRACE_(dmfile
)(" - dwFlags: %x\n", inst
.dwFlags
);
397 TRACE_(dmfile
)(" - bPan: %u\n", inst
.bPan
);
398 TRACE_(dmfile
)(" - bVolume: %u\n", inst
.bVolume
);
399 TRACE_(dmfile
)(" - nTranspose: %d\n", inst
.nTranspose
);
400 TRACE_(dmfile
)(" - dwChannelPriority: %u\n", inst
.dwChannelPriority
);
401 TRACE_(dmfile
)(" - nPitchBendRange: %d\n", inst
.nPitchBendRange
);
405 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
406 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
407 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
409 switch (Chunk
.fccID
) {
410 case DMUS_FOURCC_REF_LIST
: {
411 FIXME_(dmfile
)(": DMRF (DM References) list\n");
412 hr
= IDirectMusicUtils_IPersistStream_ParseReference (iface
, &Chunk
, pStm
, &pObject
);
414 ERR(": could not load Reference\n");
420 TRACE_(dmfile
)(": unknown (skipping)\n");
421 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
422 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
429 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
430 liMove
.QuadPart
= Chunk
.dwSize
;
431 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
435 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
436 } while (ListCount
[0] < ListSize
[0]);
439 * @TODO insert pNewInstrument into This
441 pNewInstrument
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_INSTRUMENT
));
442 if (NULL
== pNewInstrument
) {
443 ERR(": no more memory\n");
444 return E_OUTOFMEMORY
;
446 memcpy(&pNewInstrument
->pInstrument
, &inst
, sizeof(DMUS_IO_INSTRUMENT
));
447 pNewInstrument
->ppReferenceCollection
= NULL
;
448 if (NULL
!= pObject
) {
449 IDirectMusicCollection
* pCol
= NULL
;
450 hr
= IDirectMusicObject_QueryInterface (pObject
, &IID_IDirectMusicCollection
, (void**) &pCol
);
452 ERR(": failed to get IDirectMusicCollection Interface from DMObject\n");
453 HeapFree(GetProcessHeap(), 0, pNewInstrument
);
457 pNewInstrument
->ppReferenceCollection
= pCol
;
458 IDirectMusicObject_Release(pObject
);
460 list_add_tail (&This
->Instruments
, &pNewInstrument
->entry
);
465 static HRESULT
IDirectMusicBandImpl_IPersistStream_ParseInstrumentsList (LPPERSISTSTREAM iface
, DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
) {
466 /*ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);*/
468 DMUS_PRIVATE_CHUNK Chunk
;
469 DWORD ListSize
[3], ListCount
[3];
470 LARGE_INTEGER liMove
; /* used when skipping chunks */
472 if (pChunk
->fccID
!= DMUS_FOURCC_INSTRUMENTS_LIST
) {
473 ERR_(dmfile
)(": %s chunk should be an INSTRUMENTS list\n", debugstr_fourcc (pChunk
->fccID
));
477 ListSize
[0] = pChunk
->dwSize
- sizeof(FOURCC
);
481 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
482 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
483 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
484 switch (Chunk
.fccID
) {
486 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
487 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
488 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
490 switch (Chunk
.fccID
) {
491 case DMUS_FOURCC_INSTRUMENT_LIST
: {
492 TRACE_(dmfile
)(": Instrument list\n");
493 hr
= IDirectMusicBandImpl_IPersistStream_ParseInstrument (iface
, &Chunk
, pStm
);
494 if (FAILED(hr
)) return hr
;
498 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
499 liMove
.QuadPart
= ListSize
[1];
500 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
507 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
508 liMove
.QuadPart
= Chunk
.dwSize
;
509 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
513 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
514 } while (ListCount
[0] < ListSize
[0]);
519 static HRESULT
IDirectMusicBandImpl_IPersistStream_ParseBandForm (LPPERSISTSTREAM iface
, DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
) {
521 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
523 DMUS_PRIVATE_CHUNK Chunk
;
524 DWORD StreamSize
, StreamCount
, ListSize
[3], ListCount
[3];
525 LARGE_INTEGER liMove
; /* used when skipping chunks */
529 if (pChunk
->fccID
!= DMUS_FOURCC_BAND_FORM
) {
530 ERR_(dmfile
)(": %s chunk should be a BAND form\n", debugstr_fourcc (pChunk
->fccID
));
534 StreamSize
= pChunk
->dwSize
- sizeof(FOURCC
);
538 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
539 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
540 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
542 hr
= IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk
, pStm
, This
->pDesc
);
543 if (FAILED(hr
)) return hr
;
546 switch (Chunk
.fccID
) {
547 case DMUS_FOURCC_GUID_CHUNK
: {
548 TRACE_(dmfile
)(": GUID\n");
549 IStream_Read (pStm
, &tmp_guid
, sizeof(GUID
), NULL
);
550 TRACE_(dmfile
)(" - guid: %s\n", debugstr_dmguid(&tmp_guid
));
554 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
555 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
556 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
558 switch (Chunk
.fccID
) {
559 case DMUS_FOURCC_UNFO_LIST
: {
560 TRACE_(dmfile
)(": UNFO list\n");
562 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
563 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
564 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
566 hr
= IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk
, pStm
, This
->pDesc
);
567 if (FAILED(hr
)) return hr
;
570 switch (Chunk
.fccID
) {
572 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
573 liMove
.QuadPart
= Chunk
.dwSize
;
574 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
579 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
580 } while (ListCount
[0] < ListSize
[0]);
583 case DMUS_FOURCC_INSTRUMENTS_LIST
: {
584 TRACE_(dmfile
)(": INSTRUMENTS list\n");
585 hr
= IDirectMusicBandImpl_IPersistStream_ParseInstrumentsList (iface
, &Chunk
, pStm
);
586 if (FAILED(hr
)) return hr
;
590 TRACE_(dmfile
)(": unknown (skipping)\n");
591 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
592 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
599 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
600 liMove
.QuadPart
= Chunk
.dwSize
;
601 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
606 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
607 } while (StreamCount
< StreamSize
);
612 static HRESULT WINAPI
IDirectMusicBandImpl_IPersistStream_Load (LPPERSISTSTREAM iface
, IStream
* pStm
) {
613 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
615 DMUS_PRIVATE_CHUNK Chunk
;
616 LARGE_INTEGER liMove
;
619 TRACE("(%p,%p): loading\n", This
, pStm
);
621 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
622 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
623 switch (Chunk
.fccID
) {
625 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
626 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
627 switch (Chunk
.fccID
) {
628 case DMUS_FOURCC_BAND_FORM
: {
629 TRACE_(dmfile
)(": Band form\n");
630 hr
= IDirectMusicBandImpl_IPersistStream_ParseBandForm (iface
, &Chunk
, pStm
);
631 if (FAILED(hr
)) return hr
;
635 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
636 liMove
.QuadPart
= Chunk
.dwSize
;
637 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
641 TRACE_(dmfile
)(": reading finished\n");
645 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
646 liMove
.QuadPart
= Chunk
.dwSize
;
647 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
655 static HRESULT WINAPI
IDirectMusicBandImpl_IPersistStream_Save (LPPERSISTSTREAM iface
, IStream
* pStm
, BOOL fClearDirty
) {
656 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
657 FIXME("(%p): Saving not implemented yet\n", This
);
661 static HRESULT WINAPI
IDirectMusicBandImpl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface
, ULARGE_INTEGER
* pcbSize
) {
665 static const IPersistStreamVtbl DirectMusicBand_PersistStream_Vtbl
= {
666 IDirectMusicBandImpl_IPersistStream_QueryInterface
,
667 IDirectMusicBandImpl_IPersistStream_AddRef
,
668 IDirectMusicBandImpl_IPersistStream_Release
,
669 IDirectMusicBandImpl_IPersistStream_GetClassID
,
670 IDirectMusicBandImpl_IPersistStream_IsDirty
,
671 IDirectMusicBandImpl_IPersistStream_Load
,
672 IDirectMusicBandImpl_IPersistStream_Save
,
673 IDirectMusicBandImpl_IPersistStream_GetSizeMax
676 /* for ClassFactory */
677 HRESULT WINAPI
create_dmband(REFIID lpcGUID
, void **ppobj
)
679 IDirectMusicBandImpl
* obj
;
682 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicBandImpl
));
685 return E_OUTOFMEMORY
;
687 obj
->IDirectMusicBand_iface
.lpVtbl
= &dmband_vtbl
;
688 obj
->ObjectVtbl
= &DirectMusicBand_Object_Vtbl
;
689 obj
->PersistStreamVtbl
= &DirectMusicBand_PersistStream_Vtbl
;
690 obj
->pDesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DMUS_OBJECTDESC
));
691 DM_STRUCT_INIT(obj
->pDesc
);
692 obj
->pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
693 obj
->pDesc
->guidClass
= CLSID_DirectMusicBand
;
695 list_init (&obj
->Instruments
);
698 hr
= IDirectMusicBand_QueryInterface(&obj
->IDirectMusicBand_iface
, lpcGUID
, ppobj
);
699 IDirectMusicBand_Release(&obj
->IDirectMusicBand_iface
);