1 /* IDirectMusicBand Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "dmband_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(dmband
);
23 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
25 const GUID IID_IDirectMusicBandPRIVATE
= {0xda54db81,0x837d,0x11d1,{0x86,0xbc,0x00,0xc0,0x4f,0xbf,0x8f,0xef}};
27 /*****************************************************************************
28 * IDirectMusicBandImpl implementation
30 /* IDirectMusicBandImpl IUnknown part: */
31 HRESULT WINAPI
IDirectMusicBandImpl_IUnknown_QueryInterface (LPUNKNOWN iface
, REFIID riid
, LPVOID
*ppobj
) {
32 ICOM_THIS_MULTI(IDirectMusicBandImpl
, UnknownVtbl
, iface
);
34 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ppobj
);
35 if (IsEqualIID (riid
, &IID_IUnknown
)) {
36 *ppobj
= (LPVOID
)&This
->UnknownVtbl
;
37 IDirectMusicBandImpl_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
39 } else if (IsEqualIID (riid
, &IID_IDirectMusicBand
)) {
40 *ppobj
= (LPVOID
)&This
->BandVtbl
;
41 IDirectMusicBandImpl_IDirectMusicBand_AddRef ((LPDIRECTMUSICBAND
)&This
->BandVtbl
);
43 } else if (IsEqualIID (riid
, &IID_IDirectMusicObject
)) {
44 *ppobj
= (LPVOID
)&This
->ObjectVtbl
;
45 IDirectMusicBandImpl_IDirectMusicObject_AddRef ((LPDIRECTMUSICOBJECT
)&This
->ObjectVtbl
);
47 } else if (IsEqualIID (riid
, &IID_IPersistStream
)) {
48 *ppobj
= (LPVOID
)&This
->PersistStreamVtbl
;
49 IDirectMusicBandImpl_IPersistStream_AddRef ((LPPERSISTSTREAM
)&This
->PersistStreamVtbl
);
53 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ppobj
);
57 ULONG WINAPI
IDirectMusicBandImpl_IUnknown_AddRef (LPUNKNOWN iface
) {
58 ICOM_THIS_MULTI(IDirectMusicBandImpl
, UnknownVtbl
, iface
);
59 TRACE("(%p) : AddRef from %ld\n", This
, This
->ref
);
63 ULONG WINAPI
IDirectMusicBandImpl_IUnknown_Release (LPUNKNOWN iface
) {
64 ICOM_THIS_MULTI(IDirectMusicBandImpl
, UnknownVtbl
, iface
);
65 ULONG ref
= --This
->ref
;
66 TRACE("(%p) : ReleaseRef to %ld\n", This
, This
->ref
);
68 HeapFree(GetProcessHeap(), 0, This
);
73 IUnknownVtbl DirectMusicBand_Unknown_Vtbl
= {
74 IDirectMusicBandImpl_IUnknown_QueryInterface
,
75 IDirectMusicBandImpl_IUnknown_AddRef
,
76 IDirectMusicBandImpl_IUnknown_Release
79 /* IDirectMusicBandImpl IDirectMusicBand part: */
80 HRESULT WINAPI
IDirectMusicBandImpl_IDirectMusicBand_QueryInterface (LPDIRECTMUSICBAND iface
, REFIID riid
, LPVOID
*ppobj
) {
81 ICOM_THIS_MULTI(IDirectMusicBandImpl
, BandVtbl
, iface
);
82 return IDirectMusicBandImpl_IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
85 ULONG WINAPI
IDirectMusicBandImpl_IDirectMusicBand_AddRef (LPDIRECTMUSICBAND iface
) {
86 ICOM_THIS_MULTI(IDirectMusicBandImpl
, BandVtbl
, iface
);
87 return IDirectMusicBandImpl_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
90 ULONG WINAPI
IDirectMusicBandImpl_IDirectMusicBand_Release (LPDIRECTMUSICBAND iface
) {
91 ICOM_THIS_MULTI(IDirectMusicBandImpl
, BandVtbl
, iface
);
92 return IDirectMusicBandImpl_IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
95 HRESULT WINAPI
IDirectMusicBandImpl_IDirectMusicBand_CreateSegment (LPDIRECTMUSICBAND iface
, IDirectMusicSegment
** ppSegment
) {
96 ICOM_THIS_MULTI(IDirectMusicBandImpl
, BandVtbl
, iface
);
97 FIXME("(%p, %p): stub\n", This
, ppSegment
);
101 HRESULT WINAPI
IDirectMusicBandImpl_IDirectMusicBand_Download (LPDIRECTMUSICBAND iface
, IDirectMusicPerformance
* pPerformance
) {
102 ICOM_THIS_MULTI(IDirectMusicBandImpl
, BandVtbl
, iface
);
103 FIXME("(%p, %p): stub\n", This
, pPerformance
);
107 HRESULT WINAPI
IDirectMusicBandImpl_IDirectMusicBand_Unload (LPDIRECTMUSICBAND iface
, IDirectMusicPerformance
* pPerformance
) {
108 ICOM_THIS_MULTI(IDirectMusicBandImpl
, BandVtbl
, iface
);
109 FIXME("(%p, %p): stub\n", This
, pPerformance
);
113 IDirectMusicBandVtbl DirectMusicBand_Band_Vtbl
= {
114 IDirectMusicBandImpl_IDirectMusicBand_QueryInterface
,
115 IDirectMusicBandImpl_IDirectMusicBand_AddRef
,
116 IDirectMusicBandImpl_IDirectMusicBand_Release
,
117 IDirectMusicBandImpl_IDirectMusicBand_CreateSegment
,
118 IDirectMusicBandImpl_IDirectMusicBand_Download
,
119 IDirectMusicBandImpl_IDirectMusicBand_Unload
122 /* IDirectMusicBandImpl IDirectMusicObject part: */
123 HRESULT WINAPI
IDirectMusicBandImpl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface
, REFIID riid
, LPVOID
*ppobj
) {
124 ICOM_THIS_MULTI(IDirectMusicBandImpl
, ObjectVtbl
, iface
);
125 return IDirectMusicBandImpl_IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
128 ULONG WINAPI
IDirectMusicBandImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface
) {
129 ICOM_THIS_MULTI(IDirectMusicBandImpl
, ObjectVtbl
, iface
);
130 return IDirectMusicBandImpl_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
133 ULONG WINAPI
IDirectMusicBandImpl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface
) {
134 ICOM_THIS_MULTI(IDirectMusicBandImpl
, ObjectVtbl
, iface
);
135 return IDirectMusicBandImpl_IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
138 HRESULT WINAPI
IDirectMusicBandImpl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
) {
139 ICOM_THIS_MULTI(IDirectMusicBandImpl
, ObjectVtbl
, iface
);
140 TRACE("(%p, %p)\n", This
, pDesc
);
141 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
142 memcpy (pDesc
, This
->pDesc
, This
->pDesc
->dwSize
);
146 HRESULT WINAPI
IDirectMusicBandImpl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
) {
147 ICOM_THIS_MULTI(IDirectMusicBandImpl
, ObjectVtbl
, iface
);
148 TRACE("(%p, %p): setting descriptor:\n", This
, pDesc
); debug_DMUS_OBJECTDESC (pDesc
);
150 /* According to MSDN, we should copy only given values, not whole struct */
151 if (pDesc
->dwValidData
& DMUS_OBJ_OBJECT
)
152 memcpy (&This
->pDesc
->guidObject
, &pDesc
->guidObject
, sizeof (pDesc
->guidObject
));
153 if (pDesc
->dwValidData
& DMUS_OBJ_CLASS
)
154 memcpy (&This
->pDesc
->guidClass
, &pDesc
->guidClass
, sizeof (pDesc
->guidClass
));
155 if (pDesc
->dwValidData
& DMUS_OBJ_NAME
)
156 strncpyW (This
->pDesc
->wszName
, pDesc
->wszName
, DMUS_MAX_NAME
);
157 if (pDesc
->dwValidData
& DMUS_OBJ_CATEGORY
)
158 strncpyW (This
->pDesc
->wszCategory
, pDesc
->wszCategory
, DMUS_MAX_CATEGORY
);
159 if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
)
160 strncpyW (This
->pDesc
->wszFileName
, pDesc
->wszFileName
, DMUS_MAX_FILENAME
);
161 if (pDesc
->dwValidData
& DMUS_OBJ_VERSION
)
162 memcpy (&This
->pDesc
->vVersion
, &pDesc
->vVersion
, sizeof (pDesc
->vVersion
));
163 if (pDesc
->dwValidData
& DMUS_OBJ_DATE
)
164 memcpy (&This
->pDesc
->ftDate
, &pDesc
->ftDate
, sizeof (pDesc
->ftDate
));
165 if (pDesc
->dwValidData
& DMUS_OBJ_MEMORY
) {
166 memcpy (&This
->pDesc
->llMemLength
, &pDesc
->llMemLength
, sizeof (pDesc
->llMemLength
));
167 memcpy (This
->pDesc
->pbMemData
, pDesc
->pbMemData
, sizeof (pDesc
->pbMemData
));
169 if (pDesc
->dwValidData
& DMUS_OBJ_STREAM
) {
170 /* according to MSDN, we copy the stream */
171 IStream_Clone (pDesc
->pStream
, &This
->pDesc
->pStream
);
175 This
->pDesc
->dwValidData
|= pDesc
->dwValidData
;
180 HRESULT WINAPI
IDirectMusicBandImpl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface
, LPSTREAM pStream
, LPDMUS_OBJECTDESC pDesc
) {
181 DMUS_PRIVATE_CHUNK Chunk
;
182 DWORD StreamSize
, StreamCount
, ListSize
[1], ListCount
[1];
183 LARGE_INTEGER liMove
; /* used when skipping chunks */
185 TRACE("(%p, %p)\n", pStream
, pDesc
);
187 /* FIXME: should this be determined from stream? */
188 pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
189 memcpy (&pDesc
->guidClass
, &CLSID_DirectMusicBand
, sizeof(CLSID
));
191 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
192 TRACE_(dmfile
)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
193 switch (Chunk
.fccID
) {
195 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
196 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
197 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
199 if (Chunk
.fccID
== DMUS_FOURCC_BAND_FORM
) {
200 TRACE_(dmfile
)(": band form\n");
202 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
203 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
204 TRACE_(dmfile
)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
205 switch (Chunk
.fccID
) {
206 case DMUS_FOURCC_GUID_CHUNK
: {
207 TRACE_(dmfile
)(": GUID chunk\n");
208 pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
209 IStream_Read (pStream
, &pDesc
->guidObject
, Chunk
.dwSize
, NULL
);
212 case DMUS_FOURCC_VERSION_CHUNK
: {
213 TRACE_(dmfile
)(": version chunk\n");
214 pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
215 IStream_Read (pStream
, &pDesc
->vVersion
, Chunk
.dwSize
, NULL
);
218 case DMUS_FOURCC_CATEGORY_CHUNK
: {
219 TRACE_(dmfile
)(": category chunk\n");
220 pDesc
->dwValidData
|= DMUS_OBJ_CATEGORY
;
221 IStream_Read (pStream
, pDesc
->wszCategory
, Chunk
.dwSize
, NULL
);
225 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
226 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
227 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
229 switch (Chunk
.fccID
) {
230 /* evil M$ UNFO list, which can (!?) contain INFO elements */
231 case DMUS_FOURCC_UNFO_LIST
: {
232 TRACE_(dmfile
)(": UNFO list\n");
234 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
235 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
236 TRACE_(dmfile
)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
237 switch (Chunk
.fccID
) {
238 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
239 (though strings seem to be valid unicode) */
240 case mmioFOURCC('I','N','A','M'):
241 case DMUS_FOURCC_UNAM_CHUNK
: {
242 TRACE_(dmfile
)(": name chunk\n");
243 pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
244 IStream_Read (pStream
, pDesc
->wszName
, Chunk
.dwSize
, NULL
);
247 case mmioFOURCC('I','A','R','T'):
248 case DMUS_FOURCC_UART_CHUNK
: {
249 TRACE_(dmfile
)(": artist chunk (ignored)\n");
250 liMove
.QuadPart
= Chunk
.dwSize
;
251 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
254 case mmioFOURCC('I','C','O','P'):
255 case DMUS_FOURCC_UCOP_CHUNK
: {
256 TRACE_(dmfile
)(": copyright chunk (ignored)\n");
257 liMove
.QuadPart
= Chunk
.dwSize
;
258 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
261 case mmioFOURCC('I','S','B','J'):
262 case DMUS_FOURCC_USBJ_CHUNK
: {
263 TRACE_(dmfile
)(": subject chunk (ignored)\n");
264 liMove
.QuadPart
= Chunk
.dwSize
;
265 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
268 case mmioFOURCC('I','C','M','T'):
269 case DMUS_FOURCC_UCMT_CHUNK
: {
270 TRACE_(dmfile
)(": comment chunk (ignored)\n");
271 liMove
.QuadPart
= Chunk
.dwSize
;
272 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
276 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
277 liMove
.QuadPart
= Chunk
.dwSize
;
278 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
282 TRACE_(dmfile
)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount
[0], ListSize
[0]);
283 } while (ListCount
[0] < ListSize
[0]);
287 TRACE_(dmfile
)(": unknown (skipping)\n");
288 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
289 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
296 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
297 liMove
.QuadPart
= Chunk
.dwSize
;
298 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
302 TRACE_(dmfile
)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount
, StreamSize
);
303 } while (StreamCount
< StreamSize
);
306 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
307 liMove
.QuadPart
= StreamSize
;
308 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
312 TRACE_(dmfile
)(": reading finished\n");
316 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
317 liMove
.QuadPart
= Chunk
.dwSize
;
318 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
319 return DMUS_E_INVALIDFILE
;
323 TRACE(": returning descriptor:\n"); debug_DMUS_OBJECTDESC (pDesc
);
328 IDirectMusicObjectVtbl DirectMusicBand_Object_Vtbl
= {
329 IDirectMusicBandImpl_IDirectMusicObject_QueryInterface
,
330 IDirectMusicBandImpl_IDirectMusicObject_AddRef
,
331 IDirectMusicBandImpl_IDirectMusicObject_Release
,
332 IDirectMusicBandImpl_IDirectMusicObject_GetDescriptor
,
333 IDirectMusicBandImpl_IDirectMusicObject_SetDescriptor
,
334 IDirectMusicBandImpl_IDirectMusicObject_ParseDescriptor
337 /* IDirectMusicBandImpl IPersistStream part: */
338 HRESULT WINAPI
IDirectMusicBandImpl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface
, REFIID riid
, LPVOID
*ppobj
) {
339 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
340 return IDirectMusicBandImpl_IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
343 ULONG WINAPI
IDirectMusicBandImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface
) {
344 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
345 return IDirectMusicBandImpl_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
348 ULONG WINAPI
IDirectMusicBandImpl_IPersistStream_Release (LPPERSISTSTREAM iface
) {
349 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
350 return IDirectMusicBandImpl_IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
353 HRESULT WINAPI
IDirectMusicBandImpl_IPersistStream_GetClassID (LPPERSISTSTREAM iface
, CLSID
* pClassID
) {
354 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
355 TRACE("(%p, %p)\n", This
, pClassID
);
356 memcpy(pClassID
, &CLSID_DirectMusicBand
, sizeof(CLSID
));
360 HRESULT WINAPI
IDirectMusicBandImpl_IPersistStream_IsDirty (LPPERSISTSTREAM iface
) {
361 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
362 FIXME("(%p): stub, always S_FALSE\n", This
);
366 static HRESULT
IDirectMusicBandImpl_IPersistStream_ParseInstrument (LPPERSISTSTREAM iface
, DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
) {
367 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
368 DMUS_PRIVATE_CHUNK Chunk
;
369 DWORD ListSize
[3], ListCount
[3];
370 LARGE_INTEGER liMove
; /* used when skipping chunks */
373 DMUS_IO_INSTRUMENT inst
;
374 LPDMUS_PRIVATE_INSTRUMENT pNewInstrument
;
375 IDirectMusicObject
* pObject
= NULL
;
377 if (pChunk
->fccID
!= DMUS_FOURCC_INSTRUMENT_LIST
) {
378 ERR_(dmfile
)(": %s chunk should be a INSTRUMENT list\n", debugstr_fourcc (pChunk
->fccID
));
382 ListSize
[0] = pChunk
->dwSize
- sizeof(FOURCC
);
386 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
387 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
388 TRACE_(dmfile
)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
389 switch (Chunk
.fccID
) {
390 case DMUS_FOURCC_INSTRUMENT_CHUNK
: {
391 TRACE_(dmfile
)(": Instrument chunk\n");
392 if (Chunk
.dwSize
!= sizeof(DMUS_IO_INSTRUMENT
)) return E_FAIL
;
393 IStream_Read (pStm
, &inst
, sizeof(DMUS_IO_INSTRUMENT
), NULL
);
394 TRACE_(dmfile
)(" - dwPatch: %lu\n", inst
.dwPatch
);
395 TRACE_(dmfile
)(" - dwAssignPatch: %lu\n", inst
.dwAssignPatch
);
396 TRACE_(dmfile
)(" - dwNoteRanges[0]: %lu\n", inst
.dwNoteRanges
[0]);
397 TRACE_(dmfile
)(" - dwNoteRanges[1]: %lu\n", inst
.dwNoteRanges
[1]);
398 TRACE_(dmfile
)(" - dwNoteRanges[2]: %lu\n", inst
.dwNoteRanges
[2]);
399 TRACE_(dmfile
)(" - dwNoteRanges[3]: %lu\n", inst
.dwNoteRanges
[3]);
400 TRACE_(dmfile
)(" - dwPChannel: %lu\n", inst
.dwPChannel
);
401 TRACE_(dmfile
)(" - dwFlags: %lu\n", inst
.dwFlags
);
402 TRACE_(dmfile
)(" - bPan: %u\n", inst
.bPan
);
403 TRACE_(dmfile
)(" - bVolume: %u\n", inst
.bVolume
);
404 TRACE_(dmfile
)(" - nTranspose: %d\n", inst
.nTranspose
);
405 TRACE_(dmfile
)(" - dwChannelPriority: %lu\n", inst
.dwChannelPriority
);
406 TRACE_(dmfile
)(" - nPitchBendRange: %d\n", inst
.nPitchBendRange
);
410 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
411 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
412 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
414 switch (Chunk
.fccID
) {
415 case DMUS_FOURCC_REF_LIST
: {
416 FIXME_(dmfile
)(": DMRF (DM References) list\n");
417 hr
= IDirectMusicUtils_IPersistStream_ParseReference (iface
, &Chunk
, pStm
, &pObject
);
419 ERR(": could not load Reference\n");
425 TRACE_(dmfile
)(": unknown (skipping)\n");
426 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
427 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
434 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
435 liMove
.QuadPart
= Chunk
.dwSize
;
436 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
440 TRACE_(dmfile
)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount
[0], ListSize
[0]);
441 } while (ListCount
[0] < ListSize
[0]);
444 * @TODO insert pNewInstrument into This
446 pNewInstrument
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_INSTRUMENT
));
447 if (NULL
== pNewInstrument
) {
448 ERR(": no more memory\n");
449 return E_OUTOFMEMORY
;
451 memcpy(&pNewInstrument
->pInstrument
, &inst
, sizeof(DMUS_IO_INSTRUMENT
));
452 pNewInstrument
->ppReferenceCollection
= NULL
;
453 if (NULL
!= pObject
) {
454 IDirectMusicCollection
* pCol
= NULL
;
455 hr
= IDirectMusicObject_QueryInterface (pObject
, &IID_IDirectMusicCollection
, (void**) &pCol
);
457 ERR(": failed to get IDirectMusicCollection Interface from DMObject\n");
460 pNewInstrument
->ppReferenceCollection
= pCol
;
461 IDirectMusicObject_Release(pObject
);
463 list_add_tail (&This
->Instruments
, &pNewInstrument
->entry
);
468 static HRESULT
IDirectMusicBandImpl_IPersistStream_ParseInstrumentsList (LPPERSISTSTREAM iface
, DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
) {
469 /*ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);*/
471 DMUS_PRIVATE_CHUNK Chunk
;
472 DWORD ListSize
[3], ListCount
[3];
473 LARGE_INTEGER liMove
; /* used when skipping chunks */
475 if (pChunk
->fccID
!= DMUS_FOURCC_INSTRUMENTS_LIST
) {
476 ERR_(dmfile
)(": %s chunk should be a INSTRUMENTS list\n", debugstr_fourcc (pChunk
->fccID
));
480 ListSize
[0] = pChunk
->dwSize
- sizeof(FOURCC
);
484 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
485 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
486 TRACE_(dmfile
)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
487 switch (Chunk
.fccID
) {
489 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
490 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
491 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
493 switch (Chunk
.fccID
) {
494 case DMUS_FOURCC_INSTRUMENT_LIST
: {
495 TRACE_(dmfile
)(": Instrument list\n");
496 hr
= IDirectMusicBandImpl_IPersistStream_ParseInstrument (iface
, &Chunk
, pStm
);
497 if (FAILED(hr
)) return hr
;
501 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
502 liMove
.QuadPart
= ListSize
[1];
503 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
510 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
511 liMove
.QuadPart
= Chunk
.dwSize
;
512 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
516 TRACE_(dmfile
)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount
[0], ListSize
[0]);
517 } while (ListCount
[0] < ListSize
[0]);
522 static HRESULT
IDirectMusicBandImpl_IPersistStream_ParseBandForm (LPPERSISTSTREAM iface
, DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
) {
524 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
526 DMUS_PRIVATE_CHUNK Chunk
;
527 DWORD StreamSize
, StreamCount
, ListSize
[3], ListCount
[3];
528 LARGE_INTEGER liMove
; /* used when skipping chunks */
532 if (pChunk
->fccID
!= DMUS_FOURCC_BAND_FORM
) {
533 ERR_(dmfile
)(": %s chunk should be a BAND form\n", debugstr_fourcc (pChunk
->fccID
));
537 StreamSize
= pChunk
->dwSize
- sizeof(FOURCC
);
541 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
542 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
543 TRACE_(dmfile
)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
545 hr
= IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk
, pStm
, This
->pDesc
);
546 if (FAILED(hr
)) return hr
;
549 switch (Chunk
.fccID
) {
550 case DMUS_FOURCC_GUID_CHUNK
: {
551 TRACE_(dmfile
)(": GUID\n");
552 IStream_Read (pStm
, &tmp_guid
, sizeof(GUID
), NULL
);
553 TRACE_(dmfile
)(" - guid: %s\n", debugstr_dmguid(&tmp_guid
));
557 IStream_Read (pStm
, &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_UNFO_LIST
: {
563 TRACE_(dmfile
)(": UNFO list\n");
565 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
566 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
567 TRACE_(dmfile
)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
569 hr
= IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk
, pStm
, This
->pDesc
);
570 if (FAILED(hr
)) return hr
;
573 switch (Chunk
.fccID
) {
575 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
576 liMove
.QuadPart
= Chunk
.dwSize
;
577 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
582 TRACE_(dmfile
)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount
[0], ListSize
[0]);
583 } while (ListCount
[0] < ListSize
[0]);
586 case DMUS_FOURCC_INSTRUMENTS_LIST
: {
587 TRACE_(dmfile
)(": INSTRUMENTS list\n");
588 hr
= IDirectMusicBandImpl_IPersistStream_ParseInstrumentsList (iface
, &Chunk
, pStm
);
589 if (FAILED(hr
)) return hr
;
593 TRACE_(dmfile
)(": unknown (skipping)\n");
594 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
595 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
602 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
603 liMove
.QuadPart
= Chunk
.dwSize
;
604 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
609 TRACE_(dmfile
)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount
, StreamSize
);
610 } while (StreamCount
< StreamSize
);
615 HRESULT WINAPI
IDirectMusicBandImpl_IPersistStream_Load (LPPERSISTSTREAM iface
, IStream
* pStm
) {
616 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
618 DMUS_PRIVATE_CHUNK Chunk
;
619 LARGE_INTEGER liMove
;
622 TRACE("(%p,%p): loading\n", This
, pStm
);
624 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
625 TRACE_(dmfile
)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
626 switch (Chunk
.fccID
) {
628 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
629 TRACE_(dmfile
)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
630 switch (Chunk
.fccID
) {
631 case DMUS_FOURCC_BAND_FORM
: {
632 TRACE_(dmfile
)(": Band form\n");
633 hr
= IDirectMusicBandImpl_IPersistStream_ParseBandForm (iface
, &Chunk
, pStm
);
634 if (FAILED(hr
)) return hr
;
638 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
639 liMove
.QuadPart
= Chunk
.dwSize
;
640 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
644 TRACE_(dmfile
)(": reading finished\n");
648 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
649 liMove
.QuadPart
= Chunk
.dwSize
;
650 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
658 HRESULT WINAPI
IDirectMusicBandImpl_IPersistStream_Save (LPPERSISTSTREAM iface
, IStream
* pStm
, BOOL fClearDirty
) {
659 ICOM_THIS_MULTI(IDirectMusicBandImpl
, PersistStreamVtbl
, iface
);
660 FIXME("(%p): Saving not implemented yet\n", This
);
664 HRESULT WINAPI
IDirectMusicBandImpl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface
, ULARGE_INTEGER
* pcbSize
) {
668 IPersistStreamVtbl DirectMusicBand_PersistStream_Vtbl
= {
669 IDirectMusicBandImpl_IPersistStream_QueryInterface
,
670 IDirectMusicBandImpl_IPersistStream_AddRef
,
671 IDirectMusicBandImpl_IPersistStream_Release
,
672 IDirectMusicBandImpl_IPersistStream_GetClassID
,
673 IDirectMusicBandImpl_IPersistStream_IsDirty
,
674 IDirectMusicBandImpl_IPersistStream_Load
,
675 IDirectMusicBandImpl_IPersistStream_Save
,
676 IDirectMusicBandImpl_IPersistStream_GetSizeMax
679 /* for ClassFactory */
680 HRESULT WINAPI
DMUSIC_CreateDirectMusicBandImpl (LPCGUID lpcGUID
, LPVOID
* ppobj
, LPUNKNOWN pUnkOuter
) {
681 IDirectMusicBandImpl
* obj
;
683 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicBandImpl
));
686 return E_OUTOFMEMORY
;
688 obj
->UnknownVtbl
= &DirectMusicBand_Unknown_Vtbl
;
689 obj
->BandVtbl
= &DirectMusicBand_Band_Vtbl
;
690 obj
->ObjectVtbl
= &DirectMusicBand_Object_Vtbl
;
691 obj
->PersistStreamVtbl
= &DirectMusicBand_PersistStream_Vtbl
;
692 obj
->pDesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DMUS_OBJECTDESC
));
693 DM_STRUCT_INIT(obj
->pDesc
);
694 obj
->pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
695 memcpy (&obj
->pDesc
->guidClass
, &CLSID_DirectMusicBand
, sizeof (CLSID
));
696 obj
->ref
= 0; /* will be inited by QueryInterface */
697 list_init (&obj
->Instruments
);
699 return IDirectMusicBandImpl_IUnknown_QueryInterface ((LPUNKNOWN
)&obj
->UnknownVtbl
, lpcGUID
, ppobj
);