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., 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);
25 static const GUID IID_IDirectMusicBandPRIVATE = {0xda54db81,0x837d,0x11d1,{0x86,0xbc,0x00,0xc0,0x4f,0xbf,0x8f,0xef}};
27 /*****************************************************************************
28 * IDirectMusicBandImpl implementation
30 /* IDirectMusicBandImpl IUnknown part: */
31 static 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 IUnknown_AddRef (iface);
39 } else if (IsEqualIID (riid, &IID_IDirectMusicBand)) {
40 *ppobj = (LPVOID)&This->BandVtbl;
41 IUnknown_AddRef (iface);
43 } else if (IsEqualIID (riid, &IID_IDirectMusicObject)) {
44 *ppobj = (LPVOID)&This->ObjectVtbl;
45 IUnknown_AddRef (iface);
47 } else if (IsEqualIID (riid, &IID_IPersistStream)) {
48 *ppobj = (LPVOID)&This->PersistStreamVtbl;
49 IUnknown_AddRef (iface);
53 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
57 static ULONG WINAPI IDirectMusicBandImpl_IUnknown_AddRef (LPUNKNOWN iface) {
58 ICOM_THIS_MULTI(IDirectMusicBandImpl, UnknownVtbl, iface);
59 ULONG ref = InterlockedIncrement(&This->ref);
61 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
68 static ULONG WINAPI IDirectMusicBandImpl_IUnknown_Release (LPUNKNOWN iface) {
69 ICOM_THIS_MULTI(IDirectMusicBandImpl, UnknownVtbl, iface);
70 ULONG ref = InterlockedDecrement(&This->ref);
72 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
75 HeapFree(GetProcessHeap(), 0, This);
78 DMBAND_UnlockModule();
83 static const IUnknownVtbl DirectMusicBand_Unknown_Vtbl = {
84 IDirectMusicBandImpl_IUnknown_QueryInterface,
85 IDirectMusicBandImpl_IUnknown_AddRef,
86 IDirectMusicBandImpl_IUnknown_Release
89 /* IDirectMusicBandImpl IDirectMusicBand part: */
90 static HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicBand_QueryInterface (LPDIRECTMUSICBAND iface, REFIID riid, LPVOID *ppobj) {
91 ICOM_THIS_MULTI(IDirectMusicBandImpl, BandVtbl, iface);
92 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
95 static ULONG WINAPI IDirectMusicBandImpl_IDirectMusicBand_AddRef (LPDIRECTMUSICBAND iface) {
96 ICOM_THIS_MULTI(IDirectMusicBandImpl, BandVtbl, iface);
97 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
100 static ULONG WINAPI IDirectMusicBandImpl_IDirectMusicBand_Release (LPDIRECTMUSICBAND iface) {
101 ICOM_THIS_MULTI(IDirectMusicBandImpl, BandVtbl, iface);
102 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
105 static HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicBand_CreateSegment (LPDIRECTMUSICBAND iface, IDirectMusicSegment** ppSegment) {
106 ICOM_THIS_MULTI(IDirectMusicBandImpl, BandVtbl, iface);
107 FIXME("(%p, %p): stub\n", This, ppSegment);
111 static HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicBand_Download (LPDIRECTMUSICBAND iface, IDirectMusicPerformance* pPerformance) {
112 ICOM_THIS_MULTI(IDirectMusicBandImpl, BandVtbl, iface);
113 FIXME("(%p, %p): stub\n", This, pPerformance);
117 static HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicBand_Unload (LPDIRECTMUSICBAND iface, IDirectMusicPerformance* pPerformance) {
118 ICOM_THIS_MULTI(IDirectMusicBandImpl, BandVtbl, iface);
119 FIXME("(%p, %p): stub\n", This, pPerformance);
123 static const IDirectMusicBandVtbl DirectMusicBand_Band_Vtbl = {
124 IDirectMusicBandImpl_IDirectMusicBand_QueryInterface,
125 IDirectMusicBandImpl_IDirectMusicBand_AddRef,
126 IDirectMusicBandImpl_IDirectMusicBand_Release,
127 IDirectMusicBandImpl_IDirectMusicBand_CreateSegment,
128 IDirectMusicBandImpl_IDirectMusicBand_Download,
129 IDirectMusicBandImpl_IDirectMusicBand_Unload
132 /* IDirectMusicBandImpl IDirectMusicObject part: */
133 static HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) {
134 ICOM_THIS_MULTI(IDirectMusicBandImpl, ObjectVtbl, iface);
135 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
138 static ULONG WINAPI IDirectMusicBandImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) {
139 ICOM_THIS_MULTI(IDirectMusicBandImpl, ObjectVtbl, iface);
140 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
143 static ULONG WINAPI IDirectMusicBandImpl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) {
144 ICOM_THIS_MULTI(IDirectMusicBandImpl, ObjectVtbl, iface);
145 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
148 static HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
149 ICOM_THIS_MULTI(IDirectMusicBandImpl, ObjectVtbl, iface);
150 TRACE("(%p, %p)\n", This, pDesc);
151 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
152 memcpy (pDesc, This->pDesc, This->pDesc->dwSize);
156 static HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
157 ICOM_THIS_MULTI(IDirectMusicBandImpl, ObjectVtbl, iface);
158 TRACE("(%p, %p): setting descriptor:\n", This, pDesc); debug_DMUS_OBJECTDESC (pDesc);
160 /* According to MSDN, we should copy only given values, not whole struct */
161 if (pDesc->dwValidData & DMUS_OBJ_OBJECT)
162 memcpy (&This->pDesc->guidObject, &pDesc->guidObject, sizeof (pDesc->guidObject));
163 if (pDesc->dwValidData & DMUS_OBJ_CLASS)
164 memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass));
165 if (pDesc->dwValidData & DMUS_OBJ_NAME)
166 lstrcpynW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
167 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
168 lstrcpynW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
169 if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
170 lstrcpynW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
171 if (pDesc->dwValidData & DMUS_OBJ_VERSION)
172 memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));
173 if (pDesc->dwValidData & DMUS_OBJ_DATE)
174 memcpy (&This->pDesc->ftDate, &pDesc->ftDate, sizeof (pDesc->ftDate));
175 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
176 memcpy (&This->pDesc->llMemLength, &pDesc->llMemLength, sizeof (pDesc->llMemLength));
177 memcpy (This->pDesc->pbMemData, pDesc->pbMemData, sizeof (pDesc->pbMemData));
179 if (pDesc->dwValidData & DMUS_OBJ_STREAM) {
180 /* according to MSDN, we copy the stream */
181 IStream_Clone (pDesc->pStream, &This->pDesc->pStream);
185 This->pDesc->dwValidData |= pDesc->dwValidData;
190 static HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc) {
191 DMUS_PRIVATE_CHUNK Chunk;
192 DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
193 LARGE_INTEGER liMove; /* used when skipping chunks */
195 TRACE("(%p, %p)\n", pStream, pDesc);
197 /* FIXME: should this be determined from stream? */
198 pDesc->dwValidData |= DMUS_OBJ_CLASS;
199 memcpy (&pDesc->guidClass, &CLSID_DirectMusicBand, sizeof(CLSID));
201 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
202 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
203 switch (Chunk.fccID) {
205 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
206 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
207 StreamSize = Chunk.dwSize - sizeof(FOURCC);
209 if (Chunk.fccID == DMUS_FOURCC_BAND_FORM) {
210 TRACE_(dmfile)(": band form\n");
212 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
213 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
214 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
215 switch (Chunk.fccID) {
216 case DMUS_FOURCC_GUID_CHUNK: {
217 TRACE_(dmfile)(": GUID chunk\n");
218 pDesc->dwValidData |= DMUS_OBJ_OBJECT;
219 IStream_Read (pStream, &pDesc->guidObject, Chunk.dwSize, NULL);
222 case DMUS_FOURCC_VERSION_CHUNK: {
223 TRACE_(dmfile)(": version chunk\n");
224 pDesc->dwValidData |= DMUS_OBJ_VERSION;
225 IStream_Read (pStream, &pDesc->vVersion, Chunk.dwSize, NULL);
228 case DMUS_FOURCC_CATEGORY_CHUNK: {
229 TRACE_(dmfile)(": category chunk\n");
230 pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
231 IStream_Read (pStream, pDesc->wszCategory, Chunk.dwSize, NULL);
235 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
236 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
237 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
239 switch (Chunk.fccID) {
240 /* evil M$ UNFO list, which can (!?) contain INFO elements */
241 case DMUS_FOURCC_UNFO_LIST: {
242 TRACE_(dmfile)(": UNFO list\n");
244 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
245 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
246 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
247 switch (Chunk.fccID) {
248 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
249 (though strings seem to be valid unicode) */
250 case mmioFOURCC('I','N','A','M'):
251 case DMUS_FOURCC_UNAM_CHUNK: {
252 TRACE_(dmfile)(": name chunk\n");
253 pDesc->dwValidData |= DMUS_OBJ_NAME;
254 IStream_Read (pStream, pDesc->wszName, Chunk.dwSize, NULL);
257 case mmioFOURCC('I','A','R','T'):
258 case DMUS_FOURCC_UART_CHUNK: {
259 TRACE_(dmfile)(": artist chunk (ignored)\n");
260 liMove.QuadPart = Chunk.dwSize;
261 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
264 case mmioFOURCC('I','C','O','P'):
265 case DMUS_FOURCC_UCOP_CHUNK: {
266 TRACE_(dmfile)(": copyright chunk (ignored)\n");
267 liMove.QuadPart = Chunk.dwSize;
268 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
271 case mmioFOURCC('I','S','B','J'):
272 case DMUS_FOURCC_USBJ_CHUNK: {
273 TRACE_(dmfile)(": subject chunk (ignored)\n");
274 liMove.QuadPart = Chunk.dwSize;
275 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
278 case mmioFOURCC('I','C','M','T'):
279 case DMUS_FOURCC_UCMT_CHUNK: {
280 TRACE_(dmfile)(": comment chunk (ignored)\n");
281 liMove.QuadPart = Chunk.dwSize;
282 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
286 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
287 liMove.QuadPart = Chunk.dwSize;
288 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
292 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
293 } while (ListCount[0] < ListSize[0]);
297 TRACE_(dmfile)(": unknown (skipping)\n");
298 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
299 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
306 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
307 liMove.QuadPart = Chunk.dwSize;
308 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
312 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
313 } while (StreamCount < StreamSize);
315 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
316 liMove.QuadPart = StreamSize;
317 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
321 TRACE_(dmfile)(": reading finished\n");
325 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
326 liMove.QuadPart = Chunk.dwSize;
327 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
328 return DMUS_E_INVALIDFILE;
332 TRACE(": returning descriptor:\n"); debug_DMUS_OBJECTDESC (pDesc);
337 static const IDirectMusicObjectVtbl DirectMusicBand_Object_Vtbl = {
338 IDirectMusicBandImpl_IDirectMusicObject_QueryInterface,
339 IDirectMusicBandImpl_IDirectMusicObject_AddRef,
340 IDirectMusicBandImpl_IDirectMusicObject_Release,
341 IDirectMusicBandImpl_IDirectMusicObject_GetDescriptor,
342 IDirectMusicBandImpl_IDirectMusicObject_SetDescriptor,
343 IDirectMusicBandImpl_IDirectMusicObject_ParseDescriptor
346 /* IDirectMusicBandImpl IPersistStream part: */
347 static HRESULT WINAPI IDirectMusicBandImpl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
348 ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);
349 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
352 static ULONG WINAPI IDirectMusicBandImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
353 ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);
354 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
357 static ULONG WINAPI IDirectMusicBandImpl_IPersistStream_Release (LPPERSISTSTREAM iface) {
358 ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);
359 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
362 static HRESULT WINAPI IDirectMusicBandImpl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
363 ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);
364 TRACE("(%p, %p)\n", This, pClassID);
365 memcpy(pClassID, &CLSID_DirectMusicBand, sizeof(CLSID));
369 static HRESULT WINAPI IDirectMusicBandImpl_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
370 ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);
371 FIXME("(%p): stub, always S_FALSE\n", This);
375 static HRESULT IDirectMusicBandImpl_IPersistStream_ParseInstrument (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
376 ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);
377 DMUS_PRIVATE_CHUNK Chunk;
378 DWORD ListSize[3], ListCount[3];
379 LARGE_INTEGER liMove; /* used when skipping chunks */
382 DMUS_IO_INSTRUMENT inst;
383 LPDMUS_PRIVATE_INSTRUMENT pNewInstrument;
384 IDirectMusicObject* pObject = NULL;
386 if (pChunk->fccID != DMUS_FOURCC_INSTRUMENT_LIST) {
387 ERR_(dmfile)(": %s chunk should be an INSTRUMENT list\n", debugstr_fourcc (pChunk->fccID));
391 ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
395 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
396 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
397 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
398 switch (Chunk.fccID) {
399 case DMUS_FOURCC_INSTRUMENT_CHUNK: {
400 TRACE_(dmfile)(": Instrument chunk\n");
401 if (Chunk.dwSize != sizeof(DMUS_IO_INSTRUMENT)) return E_FAIL;
402 IStream_Read (pStm, &inst, sizeof(DMUS_IO_INSTRUMENT), NULL);
403 TRACE_(dmfile)(" - dwPatch: %u\n", inst.dwPatch);
404 TRACE_(dmfile)(" - dwAssignPatch: %u\n", inst.dwAssignPatch);
405 TRACE_(dmfile)(" - dwNoteRanges[0]: %u\n", inst.dwNoteRanges[0]);
406 TRACE_(dmfile)(" - dwNoteRanges[1]: %u\n", inst.dwNoteRanges[1]);
407 TRACE_(dmfile)(" - dwNoteRanges[2]: %u\n", inst.dwNoteRanges[2]);
408 TRACE_(dmfile)(" - dwNoteRanges[3]: %u\n", inst.dwNoteRanges[3]);
409 TRACE_(dmfile)(" - dwPChannel: %u\n", inst.dwPChannel);
410 TRACE_(dmfile)(" - dwFlags: %u\n", inst.dwFlags);
411 TRACE_(dmfile)(" - bPan: %u\n", inst.bPan);
412 TRACE_(dmfile)(" - bVolume: %u\n", inst.bVolume);
413 TRACE_(dmfile)(" - nTranspose: %d\n", inst.nTranspose);
414 TRACE_(dmfile)(" - dwChannelPriority: %u\n", inst.dwChannelPriority);
415 TRACE_(dmfile)(" - nPitchBendRange: %d\n", inst.nPitchBendRange);
419 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
420 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
421 ListSize[1] = Chunk.dwSize - sizeof(FOURCC);
423 switch (Chunk.fccID) {
424 case DMUS_FOURCC_REF_LIST: {
425 FIXME_(dmfile)(": DMRF (DM References) list\n");
426 hr = IDirectMusicUtils_IPersistStream_ParseReference (iface, &Chunk, pStm, &pObject);
428 ERR(": could not load Reference\n");
434 TRACE_(dmfile)(": unknown (skipping)\n");
435 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
436 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
443 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
444 liMove.QuadPart = Chunk.dwSize;
445 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
449 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
450 } while (ListCount[0] < ListSize[0]);
453 * @TODO insert pNewInstrument into This
455 pNewInstrument = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_INSTRUMENT));
456 if (NULL == pNewInstrument) {
457 ERR(": no more memory\n");
458 return E_OUTOFMEMORY;
460 memcpy(&pNewInstrument->pInstrument, &inst, sizeof(DMUS_IO_INSTRUMENT));
461 pNewInstrument->ppReferenceCollection = NULL;
462 if (NULL != pObject) {
463 IDirectMusicCollection* pCol = NULL;
464 hr = IDirectMusicObject_QueryInterface (pObject, &IID_IDirectMusicCollection, (void**) &pCol);
466 ERR(": failed to get IDirectMusicCollection Interface from DMObject\n");
469 pNewInstrument->ppReferenceCollection = pCol;
470 IDirectMusicObject_Release(pObject);
472 list_add_tail (&This->Instruments, &pNewInstrument->entry);
477 static HRESULT IDirectMusicBandImpl_IPersistStream_ParseInstrumentsList (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
478 /*ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);*/
480 DMUS_PRIVATE_CHUNK Chunk;
481 DWORD ListSize[3], ListCount[3];
482 LARGE_INTEGER liMove; /* used when skipping chunks */
484 if (pChunk->fccID != DMUS_FOURCC_INSTRUMENTS_LIST) {
485 ERR_(dmfile)(": %s chunk should be an INSTRUMENTS list\n", debugstr_fourcc (pChunk->fccID));
489 ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
493 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
494 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
495 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
496 switch (Chunk.fccID) {
498 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
499 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
500 ListSize[1] = Chunk.dwSize - sizeof(FOURCC);
502 switch (Chunk.fccID) {
503 case DMUS_FOURCC_INSTRUMENT_LIST: {
504 TRACE_(dmfile)(": Instrument list\n");
505 hr = IDirectMusicBandImpl_IPersistStream_ParseInstrument (iface, &Chunk, pStm);
506 if (FAILED(hr)) return hr;
510 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
511 liMove.QuadPart = ListSize[1];
512 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
519 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
520 liMove.QuadPart = Chunk.dwSize;
521 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
525 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
526 } while (ListCount[0] < ListSize[0]);
531 static HRESULT IDirectMusicBandImpl_IPersistStream_ParseBandForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
533 ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);
535 DMUS_PRIVATE_CHUNK Chunk;
536 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
537 LARGE_INTEGER liMove; /* used when skipping chunks */
541 if (pChunk->fccID != DMUS_FOURCC_BAND_FORM) {
542 ERR_(dmfile)(": %s chunk should be a BAND form\n", debugstr_fourcc (pChunk->fccID));
546 StreamSize = pChunk->dwSize - sizeof(FOURCC);
550 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
551 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
552 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
554 hr = IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk, pStm, This->pDesc);
555 if (FAILED(hr)) return hr;
558 switch (Chunk.fccID) {
559 case DMUS_FOURCC_GUID_CHUNK: {
560 TRACE_(dmfile)(": GUID\n");
561 IStream_Read (pStm, &tmp_guid, sizeof(GUID), NULL);
562 TRACE_(dmfile)(" - guid: %s\n", debugstr_dmguid(&tmp_guid));
566 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
567 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
568 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
570 switch (Chunk.fccID) {
571 case DMUS_FOURCC_UNFO_LIST: {
572 TRACE_(dmfile)(": UNFO list\n");
574 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
575 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
576 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
578 hr = IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk, pStm, This->pDesc);
579 if (FAILED(hr)) return hr;
582 switch (Chunk.fccID) {
584 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
585 liMove.QuadPart = Chunk.dwSize;
586 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
591 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
592 } while (ListCount[0] < ListSize[0]);
595 case DMUS_FOURCC_INSTRUMENTS_LIST: {
596 TRACE_(dmfile)(": INSTRUMENTS list\n");
597 hr = IDirectMusicBandImpl_IPersistStream_ParseInstrumentsList (iface, &Chunk, pStm);
598 if (FAILED(hr)) return hr;
602 TRACE_(dmfile)(": unknown (skipping)\n");
603 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
604 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
611 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
612 liMove.QuadPart = Chunk.dwSize;
613 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
618 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
619 } while (StreamCount < StreamSize);
624 static HRESULT WINAPI IDirectMusicBandImpl_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
625 ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);
627 DMUS_PRIVATE_CHUNK Chunk;
628 LARGE_INTEGER liMove;
631 TRACE("(%p,%p): loading\n", This, pStm);
633 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
634 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
635 switch (Chunk.fccID) {
637 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
638 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
639 switch (Chunk.fccID) {
640 case DMUS_FOURCC_BAND_FORM: {
641 TRACE_(dmfile)(": Band form\n");
642 hr = IDirectMusicBandImpl_IPersistStream_ParseBandForm (iface, &Chunk, pStm);
643 if (FAILED(hr)) return hr;
647 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
648 liMove.QuadPart = Chunk.dwSize;
649 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
653 TRACE_(dmfile)(": reading finished\n");
657 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
658 liMove.QuadPart = Chunk.dwSize;
659 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
667 static HRESULT WINAPI IDirectMusicBandImpl_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
668 ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);
669 FIXME("(%p): Saving not implemented yet\n", This);
673 static HRESULT WINAPI IDirectMusicBandImpl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
677 static const IPersistStreamVtbl DirectMusicBand_PersistStream_Vtbl = {
678 IDirectMusicBandImpl_IPersistStream_QueryInterface,
679 IDirectMusicBandImpl_IPersistStream_AddRef,
680 IDirectMusicBandImpl_IPersistStream_Release,
681 IDirectMusicBandImpl_IPersistStream_GetClassID,
682 IDirectMusicBandImpl_IPersistStream_IsDirty,
683 IDirectMusicBandImpl_IPersistStream_Load,
684 IDirectMusicBandImpl_IPersistStream_Save,
685 IDirectMusicBandImpl_IPersistStream_GetSizeMax
688 /* for ClassFactory */
689 HRESULT WINAPI DMUSIC_CreateDirectMusicBandImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
690 IDirectMusicBandImpl* obj;
692 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicBandImpl));
695 return E_OUTOFMEMORY;
697 obj->UnknownVtbl = &DirectMusicBand_Unknown_Vtbl;
698 obj->BandVtbl = &DirectMusicBand_Band_Vtbl;
699 obj->ObjectVtbl = &DirectMusicBand_Object_Vtbl;
700 obj->PersistStreamVtbl = &DirectMusicBand_PersistStream_Vtbl;
701 obj->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
702 DM_STRUCT_INIT(obj->pDesc);
703 obj->pDesc->dwValidData |= DMUS_OBJ_CLASS;
704 memcpy (&obj->pDesc->guidClass, &CLSID_DirectMusicBand, sizeof (CLSID));
705 obj->ref = 0; /* will be inited by QueryInterface */
706 list_init (&obj->Instruments);
708 return IDirectMusicBandImpl_IUnknown_QueryInterface ((LPUNKNOWN)&obj->UnknownVtbl, lpcGUID, ppobj);