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"
23 WINE_DEFAULT_DEBUG_CHANNEL(dmband
);
24 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
27 /*****************************************************************************
28 * IDirectMusicBandImpl implementation
30 typedef struct IDirectMusicBandImpl
{
31 IDirectMusicBand IDirectMusicBand_iface
;
32 struct dmobject dmobj
;
34 struct list Instruments
;
35 } IDirectMusicBandImpl
;
37 static inline IDirectMusicBandImpl
*impl_from_IDirectMusicBand(IDirectMusicBand
*iface
)
39 return CONTAINING_RECORD(iface
, IDirectMusicBandImpl
, IDirectMusicBand_iface
);
42 /* DirectMusicBandImpl IDirectMusicBand part: */
43 static HRESULT WINAPI
IDirectMusicBandImpl_QueryInterface(IDirectMusicBand
*iface
, REFIID riid
,
46 IDirectMusicBandImpl
*This
= impl_from_IDirectMusicBand(iface
);
48 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ret_iface
);
52 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDirectMusicBand
))
54 else if (IsEqualIID(riid
, &IID_IDirectMusicObject
))
55 *ret_iface
= &This
->dmobj
.IDirectMusicObject_iface
;
56 else if (IsEqualIID(riid
, &IID_IPersistStream
))
57 *ret_iface
= &This
->dmobj
.IPersistStream_iface
;
59 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ret_iface
);
63 IDirectMusicBand_AddRef((IUnknown
*)*ret_iface
);
67 static ULONG WINAPI
IDirectMusicBandImpl_AddRef(IDirectMusicBand
*iface
)
69 IDirectMusicBandImpl
*This
= impl_from_IDirectMusicBand(iface
);
70 LONG ref
= InterlockedIncrement(&This
->ref
);
72 TRACE("(%p) ref=%d\n", This
, ref
);
77 static ULONG WINAPI
IDirectMusicBandImpl_Release(IDirectMusicBand
*iface
)
79 IDirectMusicBandImpl
*This
= impl_from_IDirectMusicBand(iface
);
80 LONG ref
= InterlockedDecrement(&This
->ref
);
82 TRACE("(%p) ref=%d\n", This
, ref
);
85 HeapFree(GetProcessHeap(), 0, This
);
86 DMBAND_UnlockModule();
92 static HRESULT WINAPI
IDirectMusicBandImpl_CreateSegment(IDirectMusicBand
*iface
,
93 IDirectMusicSegment
**ppSegment
)
95 IDirectMusicBandImpl
*This
= impl_from_IDirectMusicBand(iface
);
96 FIXME("(%p, %p): stub\n", This
, ppSegment
);
100 static HRESULT WINAPI
IDirectMusicBandImpl_Download(IDirectMusicBand
*iface
,
101 IDirectMusicPerformance
*pPerformance
)
103 IDirectMusicBandImpl
*This
= impl_from_IDirectMusicBand(iface
);
104 FIXME("(%p, %p): stub\n", This
, pPerformance
);
108 static HRESULT WINAPI
IDirectMusicBandImpl_Unload(IDirectMusicBand
*iface
,
109 IDirectMusicPerformance
*pPerformance
)
111 IDirectMusicBandImpl
*This
= impl_from_IDirectMusicBand(iface
);
112 FIXME("(%p, %p): stub\n", This
, pPerformance
);
116 static const IDirectMusicBandVtbl dmband_vtbl
= {
117 IDirectMusicBandImpl_QueryInterface
,
118 IDirectMusicBandImpl_AddRef
,
119 IDirectMusicBandImpl_Release
,
120 IDirectMusicBandImpl_CreateSegment
,
121 IDirectMusicBandImpl_Download
,
122 IDirectMusicBandImpl_Unload
125 /* IDirectMusicBandImpl IDirectMusicObject part: */
126 static HRESULT WINAPI
IDirectMusicObjectImpl_ParseDescriptor(IDirectMusicObject
*iface
,
127 IStream
*pStream
, DMUS_OBJECTDESC
*pDesc
)
129 DMUS_PRIVATE_CHUNK Chunk
;
130 DWORD StreamSize
, StreamCount
, ListSize
[1], ListCount
[1];
131 LARGE_INTEGER liMove
; /* used when skipping chunks */
133 TRACE("(%p, %p)\n", pStream
, pDesc
);
135 /* FIXME: should this be determined from stream? */
136 pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
137 pDesc
->guidClass
= CLSID_DirectMusicBand
;
139 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
140 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
141 switch (Chunk
.fccID
) {
143 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
144 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
145 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
147 if (Chunk
.fccID
== DMUS_FOURCC_BAND_FORM
) {
148 TRACE_(dmfile
)(": band form\n");
150 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
151 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
152 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
153 switch (Chunk
.fccID
) {
154 case DMUS_FOURCC_GUID_CHUNK
: {
155 TRACE_(dmfile
)(": GUID chunk\n");
156 pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
157 IStream_Read (pStream
, &pDesc
->guidObject
, Chunk
.dwSize
, NULL
);
160 case DMUS_FOURCC_VERSION_CHUNK
: {
161 TRACE_(dmfile
)(": version chunk\n");
162 pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
163 IStream_Read (pStream
, &pDesc
->vVersion
, Chunk
.dwSize
, NULL
);
166 case DMUS_FOURCC_CATEGORY_CHUNK
: {
167 TRACE_(dmfile
)(": category chunk\n");
168 pDesc
->dwValidData
|= DMUS_OBJ_CATEGORY
;
169 IStream_Read (pStream
, pDesc
->wszCategory
, Chunk
.dwSize
, NULL
);
173 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
174 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
175 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
177 switch (Chunk
.fccID
) {
178 /* evil M$ UNFO list, which can (!?) contain INFO elements */
179 case DMUS_FOURCC_UNFO_LIST
: {
180 TRACE_(dmfile
)(": UNFO list\n");
182 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
183 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
184 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
185 switch (Chunk
.fccID
) {
186 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
187 (though strings seem to be valid unicode) */
188 case mmioFOURCC('I','N','A','M'):
189 case DMUS_FOURCC_UNAM_CHUNK
: {
190 TRACE_(dmfile
)(": name chunk\n");
191 pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
192 IStream_Read (pStream
, pDesc
->wszName
, Chunk
.dwSize
, NULL
);
195 case mmioFOURCC('I','A','R','T'):
196 case DMUS_FOURCC_UART_CHUNK
: {
197 TRACE_(dmfile
)(": artist chunk (ignored)\n");
198 liMove
.QuadPart
= Chunk
.dwSize
;
199 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
202 case mmioFOURCC('I','C','O','P'):
203 case DMUS_FOURCC_UCOP_CHUNK
: {
204 TRACE_(dmfile
)(": copyright chunk (ignored)\n");
205 liMove
.QuadPart
= Chunk
.dwSize
;
206 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
209 case mmioFOURCC('I','S','B','J'):
210 case DMUS_FOURCC_USBJ_CHUNK
: {
211 TRACE_(dmfile
)(": subject chunk (ignored)\n");
212 liMove
.QuadPart
= Chunk
.dwSize
;
213 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
216 case mmioFOURCC('I','C','M','T'):
217 case DMUS_FOURCC_UCMT_CHUNK
: {
218 TRACE_(dmfile
)(": comment chunk (ignored)\n");
219 liMove
.QuadPart
= Chunk
.dwSize
;
220 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
224 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
225 liMove
.QuadPart
= Chunk
.dwSize
;
226 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
230 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
231 } while (ListCount
[0] < ListSize
[0]);
235 TRACE_(dmfile
)(": unknown (skipping)\n");
236 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
237 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
244 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
245 liMove
.QuadPart
= Chunk
.dwSize
;
246 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
250 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
251 } while (StreamCount
< StreamSize
);
253 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
254 liMove
.QuadPart
= StreamSize
;
255 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
259 TRACE_(dmfile
)(": reading finished\n");
263 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
264 liMove
.QuadPart
= Chunk
.dwSize
;
265 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
266 return DMUS_E_INVALIDFILE
;
270 TRACE(": returning descriptor:\n"); debug_DMUS_OBJECTDESC (pDesc
);
275 static const IDirectMusicObjectVtbl dmobject_vtbl
= {
276 dmobj_IDirectMusicObject_QueryInterface
,
277 dmobj_IDirectMusicObject_AddRef
,
278 dmobj_IDirectMusicObject_Release
,
279 dmobj_IDirectMusicObject_GetDescriptor
,
280 dmobj_IDirectMusicObject_SetDescriptor
,
281 IDirectMusicObjectImpl_ParseDescriptor
284 /* IDirectMusicBandImpl IPersistStream part: */
285 static HRESULT
parse_instrument(IDirectMusicBandImpl
*This
, DMUS_PRIVATE_CHUNK
*pChunk
,
288 DMUS_PRIVATE_CHUNK Chunk
;
289 DWORD ListSize
[3], ListCount
[3];
290 LARGE_INTEGER liMove
; /* used when skipping chunks */
293 DMUS_IO_INSTRUMENT inst
;
294 LPDMUS_PRIVATE_INSTRUMENT pNewInstrument
;
295 IDirectMusicObject
* pObject
= NULL
;
297 if (pChunk
->fccID
!= DMUS_FOURCC_INSTRUMENT_LIST
) {
298 ERR_(dmfile
)(": %s chunk should be an INSTRUMENT list\n", debugstr_fourcc (pChunk
->fccID
));
302 ListSize
[0] = pChunk
->dwSize
- sizeof(FOURCC
);
306 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
307 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
308 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
309 switch (Chunk
.fccID
) {
310 case DMUS_FOURCC_INSTRUMENT_CHUNK
: {
311 TRACE_(dmfile
)(": Instrument chunk\n");
312 if (Chunk
.dwSize
!= sizeof(DMUS_IO_INSTRUMENT
)) return E_FAIL
;
313 IStream_Read (pStm
, &inst
, sizeof(DMUS_IO_INSTRUMENT
), NULL
);
314 TRACE_(dmfile
)(" - dwPatch: %u\n", inst
.dwPatch
);
315 TRACE_(dmfile
)(" - dwAssignPatch: %u\n", inst
.dwAssignPatch
);
316 TRACE_(dmfile
)(" - dwNoteRanges[0]: %u\n", inst
.dwNoteRanges
[0]);
317 TRACE_(dmfile
)(" - dwNoteRanges[1]: %u\n", inst
.dwNoteRanges
[1]);
318 TRACE_(dmfile
)(" - dwNoteRanges[2]: %u\n", inst
.dwNoteRanges
[2]);
319 TRACE_(dmfile
)(" - dwNoteRanges[3]: %u\n", inst
.dwNoteRanges
[3]);
320 TRACE_(dmfile
)(" - dwPChannel: %u\n", inst
.dwPChannel
);
321 TRACE_(dmfile
)(" - dwFlags: %x\n", inst
.dwFlags
);
322 TRACE_(dmfile
)(" - bPan: %u\n", inst
.bPan
);
323 TRACE_(dmfile
)(" - bVolume: %u\n", inst
.bVolume
);
324 TRACE_(dmfile
)(" - nTranspose: %d\n", inst
.nTranspose
);
325 TRACE_(dmfile
)(" - dwChannelPriority: %u\n", inst
.dwChannelPriority
);
326 TRACE_(dmfile
)(" - nPitchBendRange: %d\n", inst
.nPitchBendRange
);
330 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
331 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
332 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
334 switch (Chunk
.fccID
) {
335 case DMUS_FOURCC_REF_LIST
: {
336 FIXME_(dmfile
)(": DMRF (DM References) list\n");
337 hr
= IDirectMusicUtils_IPersistStream_ParseReference(&This
->dmobj
.IPersistStream_iface
,
338 &Chunk
, pStm
, &pObject
);
340 ERR(": could not load Reference\n");
346 TRACE_(dmfile
)(": unknown (skipping)\n");
347 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
348 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
355 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
356 liMove
.QuadPart
= Chunk
.dwSize
;
357 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
361 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
362 } while (ListCount
[0] < ListSize
[0]);
365 * @TODO insert pNewInstrument into This
367 pNewInstrument
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_INSTRUMENT
));
368 if (NULL
== pNewInstrument
) {
369 ERR(": no more memory\n");
370 return E_OUTOFMEMORY
;
372 memcpy(&pNewInstrument
->pInstrument
, &inst
, sizeof(DMUS_IO_INSTRUMENT
));
373 pNewInstrument
->ppReferenceCollection
= NULL
;
374 if (NULL
!= pObject
) {
375 IDirectMusicCollection
* pCol
= NULL
;
376 hr
= IDirectMusicObject_QueryInterface (pObject
, &IID_IDirectMusicCollection
, (void**) &pCol
);
378 ERR(": failed to get IDirectMusicCollection Interface from DMObject\n");
379 HeapFree(GetProcessHeap(), 0, pNewInstrument
);
383 pNewInstrument
->ppReferenceCollection
= pCol
;
384 IDirectMusicObject_Release(pObject
);
386 list_add_tail (&This
->Instruments
, &pNewInstrument
->entry
);
391 static HRESULT
parse_instruments_list(IDirectMusicBandImpl
*This
, DMUS_PRIVATE_CHUNK
*pChunk
,
395 DMUS_PRIVATE_CHUNK Chunk
;
396 DWORD ListSize
[3], ListCount
[3];
397 LARGE_INTEGER liMove
; /* used when skipping chunks */
399 if (pChunk
->fccID
!= DMUS_FOURCC_INSTRUMENTS_LIST
) {
400 ERR_(dmfile
)(": %s chunk should be an INSTRUMENTS list\n", debugstr_fourcc (pChunk
->fccID
));
404 ListSize
[0] = pChunk
->dwSize
- sizeof(FOURCC
);
408 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
409 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
410 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
411 switch (Chunk
.fccID
) {
413 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
414 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
415 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
417 switch (Chunk
.fccID
) {
418 case DMUS_FOURCC_INSTRUMENT_LIST
: {
419 TRACE_(dmfile
)(": Instrument list\n");
420 hr
= parse_instrument(This
, &Chunk
, pStm
);
421 if (FAILED(hr
)) return hr
;
425 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
426 liMove
.QuadPart
= ListSize
[1];
427 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
434 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
435 liMove
.QuadPart
= Chunk
.dwSize
;
436 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
440 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
441 } while (ListCount
[0] < ListSize
[0]);
446 static HRESULT
parse_band_form(IDirectMusicBandImpl
*This
, DMUS_PRIVATE_CHUNK
*pChunk
,
450 DMUS_PRIVATE_CHUNK Chunk
;
451 DWORD StreamSize
, StreamCount
, ListSize
[3], ListCount
[3];
452 LARGE_INTEGER liMove
; /* used when skipping chunks */
456 if (pChunk
->fccID
!= DMUS_FOURCC_BAND_FORM
) {
457 ERR_(dmfile
)(": %s chunk should be a BAND form\n", debugstr_fourcc (pChunk
->fccID
));
461 StreamSize
= pChunk
->dwSize
- sizeof(FOURCC
);
465 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
466 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
467 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
469 hr
= IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk
, pStm
, &This
->dmobj
.desc
);
470 if (FAILED(hr
)) return hr
;
473 switch (Chunk
.fccID
) {
474 case DMUS_FOURCC_GUID_CHUNK
: {
475 TRACE_(dmfile
)(": GUID\n");
476 IStream_Read (pStm
, &tmp_guid
, sizeof(GUID
), NULL
);
477 TRACE_(dmfile
)(" - guid: %s\n", debugstr_dmguid(&tmp_guid
));
481 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
482 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
483 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
485 switch (Chunk
.fccID
) {
486 case DMUS_FOURCC_UNFO_LIST
: {
487 TRACE_(dmfile
)(": UNFO list\n");
489 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
490 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
491 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
493 hr
= IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk
, pStm
, &This
->dmobj
.desc
);
494 if (FAILED(hr
)) return hr
;
497 switch (Chunk
.fccID
) {
499 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
500 liMove
.QuadPart
= Chunk
.dwSize
;
501 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
506 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
507 } while (ListCount
[0] < ListSize
[0]);
510 case DMUS_FOURCC_INSTRUMENTS_LIST
: {
511 TRACE_(dmfile
)(": INSTRUMENTS list\n");
512 hr
= parse_instruments_list(This
, &Chunk
, pStm
);
513 if (FAILED(hr
)) return hr
;
517 TRACE_(dmfile
)(": unknown (skipping)\n");
518 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
519 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
526 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
527 liMove
.QuadPart
= Chunk
.dwSize
;
528 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
533 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
534 } while (StreamCount
< StreamSize
);
539 static inline IDirectMusicBandImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
541 return CONTAINING_RECORD(iface
, IDirectMusicBandImpl
, dmobj
.IPersistStream_iface
);
544 static HRESULT WINAPI
IPersistStreamImpl_Load(IPersistStream
*iface
, IStream
*pStm
)
546 IDirectMusicBandImpl
*This
= impl_from_IPersistStream(iface
);
547 DMUS_PRIVATE_CHUNK Chunk
;
548 LARGE_INTEGER liMove
;
551 TRACE("(%p,%p): loading\n", This
, pStm
);
553 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
554 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
555 switch (Chunk
.fccID
) {
557 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
558 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
559 switch (Chunk
.fccID
) {
560 case DMUS_FOURCC_BAND_FORM
: {
561 TRACE_(dmfile
)(": Band form\n");
562 hr
= parse_band_form(This
, &Chunk
, pStm
);
563 if (FAILED(hr
)) return hr
;
567 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
568 liMove
.QuadPart
= Chunk
.dwSize
;
569 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
573 TRACE_(dmfile
)(": reading finished\n");
577 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
578 liMove
.QuadPart
= Chunk
.dwSize
;
579 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
587 static const IPersistStreamVtbl persiststream_vtbl
= {
588 dmobj_IPersistStream_QueryInterface
,
589 dmobj_IPersistStream_AddRef
,
590 dmobj_IPersistStream_Release
,
591 unimpl_IPersistStream_GetClassID
,
592 unimpl_IPersistStream_IsDirty
,
593 IPersistStreamImpl_Load
,
594 unimpl_IPersistStream_Save
,
595 unimpl_IPersistStream_GetSizeMax
598 /* for ClassFactory */
599 HRESULT WINAPI
create_dmband(REFIID lpcGUID
, void **ppobj
)
601 IDirectMusicBandImpl
* obj
;
604 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicBandImpl
));
607 return E_OUTOFMEMORY
;
609 obj
->IDirectMusicBand_iface
.lpVtbl
= &dmband_vtbl
;
611 dmobject_init(&obj
->dmobj
, &CLSID_DirectMusicBand
, (IUnknown
*)&obj
->IDirectMusicBand_iface
);
612 obj
->dmobj
.IDirectMusicObject_iface
.lpVtbl
= &dmobject_vtbl
;
613 obj
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
614 list_init (&obj
->Instruments
);
617 hr
= IDirectMusicBand_QueryInterface(&obj
->IDirectMusicBand_iface
, lpcGUID
, ppobj
);
618 IDirectMusicBand_Release(&obj
->IDirectMusicBand_iface
);