kernel32/nls: Added LOCALE_SNAN entries.
[wine.git] / dlls / dmband / band.c
blobb35d94f2d8b245942c79442a6f074e08a78e6626
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"
21 #include "dmobject.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;
33 LONG ref;
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,
44 void **ret_iface)
46 IDirectMusicBandImpl *This = impl_from_IDirectMusicBand(iface);
48 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ret_iface);
50 *ret_iface = NULL;
52 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDirectMusicBand))
53 *ret_iface = iface;
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;
58 else {
59 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ret_iface);
60 return E_NOINTERFACE;
63 IDirectMusicBand_AddRef((IUnknown*)*ret_iface);
64 return S_OK;
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);
74 return 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);
84 if (!ref) {
85 HeapFree(GetProcessHeap(), 0, This);
86 DMBAND_UnlockModule();
89 return ref;
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);
97 return S_OK;
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);
105 return S_OK;
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);
113 return S_OK;
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) {
142 case FOURCC_RIFF: {
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);
146 StreamCount = 0;
147 if (Chunk.fccID == DMUS_FOURCC_BAND_FORM) {
148 TRACE_(dmfile)(": band form\n");
149 do {
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);
158 break;
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);
164 break;
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);
170 break;
172 case FOURCC_LIST: {
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);
176 ListCount[0] = 0;
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");
181 do {
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);
193 break;
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);
200 break;
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);
207 break;
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);
214 break;
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);
221 break;
223 default: {
224 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
225 liMove.QuadPart = Chunk.dwSize;
226 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
227 break;
230 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
231 } while (ListCount[0] < ListSize[0]);
232 break;
234 default: {
235 TRACE_(dmfile)(": unknown (skipping)\n");
236 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
237 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
238 break;
241 break;
243 default: {
244 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
245 liMove.QuadPart = Chunk.dwSize;
246 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
247 break;
250 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
251 } while (StreamCount < StreamSize);
252 } else {
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 */
256 return E_FAIL;
259 TRACE_(dmfile)(": reading finished\n");
260 break;
262 default: {
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);
272 return S_OK;
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,
286 IStream *pStm)
288 DMUS_PRIVATE_CHUNK Chunk;
289 DWORD ListSize[3], ListCount[3];
290 LARGE_INTEGER liMove; /* used when skipping chunks */
291 HRESULT hr;
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));
299 return E_FAIL;
302 ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
303 ListCount[0] = 0;
305 do {
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);
327 break;
329 case FOURCC_LIST: {
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);
333 ListCount[1] = 0;
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);
339 if (FAILED(hr)) {
340 ERR(": could not load Reference\n");
341 return hr;
343 break;
345 default: {
346 TRACE_(dmfile)(": unknown (skipping)\n");
347 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
348 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
349 break;
352 break;
354 default: {
355 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
356 liMove.QuadPart = Chunk.dwSize;
357 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
358 break;
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);
377 if (FAILED(hr)) {
378 ERR(": failed to get IDirectMusicCollection Interface from DMObject\n");
379 HeapFree(GetProcessHeap(), 0, pNewInstrument);
381 return hr;
383 pNewInstrument->ppReferenceCollection = pCol;
384 IDirectMusicObject_Release(pObject);
386 list_add_tail (&This->Instruments, &pNewInstrument->entry);
388 return S_OK;
391 static HRESULT parse_instruments_list(IDirectMusicBandImpl *This, DMUS_PRIVATE_CHUNK *pChunk,
392 IStream *pStm)
394 HRESULT hr;
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));
401 return E_FAIL;
404 ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
405 ListCount[0] = 0;
407 do {
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) {
412 case FOURCC_LIST: {
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);
416 ListCount[1] = 0;
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;
422 break;
424 default: {
425 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
426 liMove.QuadPart = ListSize[1];
427 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
428 break;
431 break;
433 default: {
434 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
435 liMove.QuadPart = Chunk.dwSize;
436 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
437 break;
440 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
441 } while (ListCount[0] < ListSize[0]);
443 return S_OK;
446 static HRESULT parse_band_form(IDirectMusicBandImpl *This, DMUS_PRIVATE_CHUNK *pChunk,
447 IStream *pStm)
449 HRESULT hr = E_FAIL;
450 DMUS_PRIVATE_CHUNK Chunk;
451 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
452 LARGE_INTEGER liMove; /* used when skipping chunks */
454 GUID tmp_guid;
456 if (pChunk->fccID != DMUS_FOURCC_BAND_FORM) {
457 ERR_(dmfile)(": %s chunk should be a BAND form\n", debugstr_fourcc (pChunk->fccID));
458 return E_FAIL;
461 StreamSize = pChunk->dwSize - sizeof(FOURCC);
462 StreamCount = 0;
464 do {
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;
472 if (hr == S_FALSE) {
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));
478 break;
480 case FOURCC_LIST: {
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);
484 ListCount[0] = 0;
485 switch (Chunk.fccID) {
486 case DMUS_FOURCC_UNFO_LIST: {
487 TRACE_(dmfile)(": UNFO list\n");
488 do {
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;
496 if (hr == S_FALSE) {
497 switch (Chunk.fccID) {
498 default: {
499 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
500 liMove.QuadPart = Chunk.dwSize;
501 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
502 break;
506 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
507 } while (ListCount[0] < ListSize[0]);
508 break;
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;
514 break;
516 default: {
517 TRACE_(dmfile)(": unknown (skipping)\n");
518 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
519 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
520 break;
523 break;
525 default: {
526 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
527 liMove.QuadPart = Chunk.dwSize;
528 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
529 break;
533 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
534 } while (StreamCount < StreamSize);
536 return S_OK;
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;
549 HRESULT hr;
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) {
556 case FOURCC_RIFF: {
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;
564 break;
566 default: {
567 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
568 liMove.QuadPart = Chunk.dwSize;
569 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
570 return E_FAIL;
573 TRACE_(dmfile)(": reading finished\n");
574 break;
576 default: {
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 */
580 return E_FAIL;
584 return S_OK;
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;
602 HRESULT hr;
604 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicBandImpl));
605 if (NULL == obj) {
606 *ppobj = NULL;
607 return E_OUTOFMEMORY;
609 obj->IDirectMusicBand_iface.lpVtbl = &dmband_vtbl;
610 obj->ref = 1;
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);
616 DMBAND_LockModule();
617 hr = IDirectMusicBand_QueryInterface(&obj->IDirectMusicBand_iface, lpcGUID, ppobj);
618 IDirectMusicBand_Release(&obj->IDirectMusicBand_iface);
620 return hr;