1 /* IDirectMusicCollection 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 "dmusic_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
23 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
25 /*****************************************************************************
26 * IDirectMusicCollectionImpl implementation
28 /* IDirectMusicCollectionImpl IUnknown part: */
29 HRESULT WINAPI IDirectMusicCollectionImpl_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
30 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, UnknownVtbl, iface);
31 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
33 if (IsEqualIID (riid, &IID_IUnknown)) {
34 *ppobj = (LPVOID)&This->UnknownVtbl;
35 IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
37 } else if (IsEqualIID (riid, &IID_IDirectMusicCollection)) {
38 *ppobj = (LPVOID)&This->CollectionVtbl;
39 IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef ((LPDIRECTMUSICCOLLECTION)&This->CollectionVtbl);
41 } else if (IsEqualIID (riid, &IID_IDirectMusicObject)) {
42 *ppobj = (LPVOID)&This->ObjectVtbl;
43 IDirectMusicCollectionImpl_IDirectMusicObject_AddRef ((LPDIRECTMUSICOBJECT)&This->ObjectVtbl);
45 } else if (IsEqualIID (riid, &IID_IPersistStream)) {
46 *ppobj = (LPVOID)&This->PersistStreamVtbl;
47 IDirectMusicCollectionImpl_IPersistStream_AddRef ((LPPERSISTSTREAM)&This->PersistStreamVtbl);
51 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
55 ULONG WINAPI IDirectMusicCollectionImpl_IUnknown_AddRef (LPUNKNOWN iface) {
56 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, UnknownVtbl, iface);
57 ULONG refCount = InterlockedIncrement(&This->ref);
59 TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
64 ULONG WINAPI IDirectMusicCollectionImpl_IUnknown_Release (LPUNKNOWN iface) {
65 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, UnknownVtbl, iface);
66 ULONG refCount = InterlockedDecrement(&This->ref);
68 TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
71 HeapFree(GetProcessHeap(), 0, This);
76 IUnknownVtbl DirectMusicCollection_Unknown_Vtbl = {
77 IDirectMusicCollectionImpl_IUnknown_QueryInterface,
78 IDirectMusicCollectionImpl_IUnknown_AddRef,
79 IDirectMusicCollectionImpl_IUnknown_Release
82 /* IDirectMusicCollectionImpl IDirectMusicCollection part: */
83 HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicCollection_QueryInterface (LPDIRECTMUSICCOLLECTION iface, REFIID riid, LPVOID *ppobj) {
84 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, CollectionVtbl, iface);
85 return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
88 ULONG WINAPI IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef (LPDIRECTMUSICCOLLECTION iface) {
89 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, CollectionVtbl, iface);
90 return IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
93 ULONG WINAPI IDirectMusicCollectionImpl_IDirectMusicCollection_Release (LPDIRECTMUSICCOLLECTION iface) {
94 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, CollectionVtbl, iface);
95 return IDirectMusicCollectionImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
98 /* IDirectMusicCollection Interface follow: */
99 HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicCollection_GetInstrument (LPDIRECTMUSICCOLLECTION iface, DWORD dwPatch, IDirectMusicInstrument** ppInstrument) {
100 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, CollectionVtbl, iface);
101 DMUS_PRIVATE_INSTRUMENTENTRY *tmpEntry;
102 struct list *listEntry;
105 TRACE("(%p, %ld, %p)\n", This, dwPatch, ppInstrument);
107 LIST_FOR_EACH (listEntry, &This->Instruments) {
108 tmpEntry = LIST_ENTRY(listEntry, DMUS_PRIVATE_INSTRUMENTENTRY, entry);
109 IDirectMusicInstrument_GetPatch (tmpEntry->pInstrument, &dwInstPatch);
110 if (dwPatch == dwInstPatch) {
111 *ppInstrument = (LPDIRECTMUSICINSTRUMENT)tmpEntry->pInstrument;
112 IDirectMusicInstrument_AddRef (tmpEntry->pInstrument);
113 IDirectMusicInstrumentImpl_Custom_Load (tmpEntry->pInstrument, This->pStm); /* load instrument before returning it */
114 TRACE(": returning instrument %p\n", *ppInstrument);
119 TRACE(": instrument not found\n");
121 return DMUS_E_INVALIDPATCH;
124 HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicCollection_EnumInstrument (LPDIRECTMUSICCOLLECTION iface, DWORD dwIndex, DWORD* pdwPatch, LPWSTR pwszName, DWORD dwNameLen) {
125 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, CollectionVtbl, iface);
127 DMUS_PRIVATE_INSTRUMENTENTRY *tmpEntry;
128 struct list *listEntry;
130 TRACE("(%p, %ld, %p, %p, %ld)\n", This, dwIndex, pdwPatch, pwszName, dwNameLen);
131 LIST_FOR_EACH (listEntry, &This->Instruments) {
132 tmpEntry = LIST_ENTRY(listEntry, DMUS_PRIVATE_INSTRUMENTENTRY, entry);
134 ICOM_NAME_MULTI (IDirectMusicInstrumentImpl, InstrumentVtbl, tmpEntry->pInstrument, pInstrument);
135 IDirectMusicInstrument_GetPatch (tmpEntry->pInstrument, pdwPatch);
136 dwNameLen = strlenW (pInstrument->wszName);
137 strncpyW (pwszName, pInstrument->wszName, dwNameLen);
146 IDirectMusicCollectionVtbl DirectMusicCollection_Collection_Vtbl = {
147 IDirectMusicCollectionImpl_IDirectMusicCollection_QueryInterface,
148 IDirectMusicCollectionImpl_IDirectMusicCollection_AddRef,
149 IDirectMusicCollectionImpl_IDirectMusicCollection_Release,
150 IDirectMusicCollectionImpl_IDirectMusicCollection_GetInstrument,
151 IDirectMusicCollectionImpl_IDirectMusicCollection_EnumInstrument
154 /* IDirectMusicCollectionImpl IDirectMusicObject part: */
155 HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) {
156 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, ObjectVtbl, iface);
157 return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
160 ULONG WINAPI IDirectMusicCollectionImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) {
161 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, ObjectVtbl, iface);
162 return IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
165 ULONG WINAPI IDirectMusicCollectionImpl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) {
166 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, ObjectVtbl, iface);
167 return IDirectMusicCollectionImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
170 HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
171 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, ObjectVtbl, iface);
172 TRACE("(%p, %p)\n", This, pDesc);
173 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
174 memcpy (pDesc, This->pDesc, This->pDesc->dwSize);
178 HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
179 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, ObjectVtbl, iface);
180 TRACE("(%p, %p): setting descriptor:\n%s\n", This, pDesc, debugstr_DMUS_OBJECTDESC (pDesc));
182 /* According to MSDN, we should copy only given values, not whole struct */
183 if (pDesc->dwValidData & DMUS_OBJ_OBJECT)
184 memcpy (&This->pDesc->guidObject, &pDesc->guidObject, sizeof (pDesc->guidObject));
185 if (pDesc->dwValidData & DMUS_OBJ_CLASS)
186 memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass));
187 if (pDesc->dwValidData & DMUS_OBJ_NAME)
188 strncpyW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
189 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
190 strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
191 if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
192 strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
193 if (pDesc->dwValidData & DMUS_OBJ_VERSION)
194 memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));
195 if (pDesc->dwValidData & DMUS_OBJ_DATE)
196 memcpy (&This->pDesc->ftDate, &pDesc->ftDate, sizeof (pDesc->ftDate));
197 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
198 memcpy (&This->pDesc->llMemLength, &pDesc->llMemLength, sizeof (pDesc->llMemLength));
199 memcpy (This->pDesc->pbMemData, pDesc->pbMemData, sizeof (pDesc->pbMemData));
201 if (pDesc->dwValidData & DMUS_OBJ_STREAM) {
202 /* according to MSDN, we copy the stream */
203 IStream_Clone (pDesc->pStream, &This->pDesc->pStream);
207 This->pDesc->dwValidData |= pDesc->dwValidData;
212 HRESULT WINAPI IDirectMusicCollectionImpl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc) {
213 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, ObjectVtbl, iface);
214 DMUS_PRIVATE_CHUNK Chunk;
215 DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
216 LARGE_INTEGER liMove; /* used when skipping chunks */
218 TRACE("(%p, %p, %p)\n", This, pStream, pDesc);
220 /* FIXME: should this be determined from stream? */
221 pDesc->dwValidData |= DMUS_OBJ_CLASS;
222 memcpy (&pDesc->guidClass, &CLSID_DirectMusicCollection, sizeof(CLSID));
224 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
225 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
226 switch (Chunk.fccID) {
228 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
229 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
230 StreamSize = Chunk.dwSize - sizeof(FOURCC);
232 if (Chunk.fccID == mmioFOURCC('D','L','S',' ')) {
233 TRACE_(dmfile)(": collection form\n");
235 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
236 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
237 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
238 switch (Chunk.fccID) {
240 TRACE_(dmfile)(": GUID chunk\n");
241 pDesc->dwValidData |= DMUS_OBJ_OBJECT;
242 IStream_Read (pStream, &pDesc->guidObject, Chunk.dwSize, NULL);
245 case DMUS_FOURCC_VERSION_CHUNK: {
246 TRACE_(dmfile)(": version chunk\n");
247 pDesc->dwValidData |= DMUS_OBJ_VERSION;
248 IStream_Read (pStream, &pDesc->vVersion, Chunk.dwSize, NULL);
251 case DMUS_FOURCC_CATEGORY_CHUNK: {
252 TRACE_(dmfile)(": category chunk\n");
253 pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
254 IStream_Read (pStream, pDesc->wszCategory, Chunk.dwSize, NULL);
258 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
259 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
260 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
262 switch (Chunk.fccID) {
263 /* pure INFO list, such can be found in dls collections */
264 case mmioFOURCC('I','N','F','O'): {
265 TRACE_(dmfile)(": INFO list\n");
267 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
268 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
269 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
270 switch (Chunk.fccID) {
271 case mmioFOURCC('I','N','A','M'):{
272 CHAR szName[DMUS_MAX_NAME];
273 TRACE_(dmfile)(": name chunk\n");
274 pDesc->dwValidData |= DMUS_OBJ_NAME;
275 IStream_Read (pStream, szName, Chunk.dwSize, NULL);
276 MultiByteToWideChar (CP_ACP, 0, szName, -1, pDesc->wszName, DMUS_MAX_NAME);
277 if (even_or_odd(Chunk.dwSize)) {
280 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
284 case mmioFOURCC('I','A','R','T'): {
285 TRACE_(dmfile)(": artist chunk (ignored)\n");
286 if (even_or_odd(Chunk.dwSize)) {
290 liMove.QuadPart = Chunk.dwSize;
291 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
294 case mmioFOURCC('I','C','O','P'): {
295 TRACE_(dmfile)(": copyright chunk (ignored)\n");
296 if (even_or_odd(Chunk.dwSize)) {
300 liMove.QuadPart = Chunk.dwSize;
301 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
304 case mmioFOURCC('I','S','B','J'): {
305 TRACE_(dmfile)(": subject chunk (ignored)\n");
306 if (even_or_odd(Chunk.dwSize)) {
310 liMove.QuadPart = Chunk.dwSize;
311 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
314 case mmioFOURCC('I','C','M','T'): {
315 TRACE_(dmfile)(": comment chunk (ignored)\n");
316 if (even_or_odd(Chunk.dwSize)) {
320 liMove.QuadPart = Chunk.dwSize;
321 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
325 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
326 if (even_or_odd(Chunk.dwSize)) {
330 liMove.QuadPart = Chunk.dwSize;
331 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
335 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
336 } while (ListCount[0] < ListSize[0]);
340 TRACE_(dmfile)(": unknown (skipping)\n");
341 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
342 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
349 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
350 liMove.QuadPart = Chunk.dwSize;
351 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
355 TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
356 } while (StreamCount < StreamSize);
358 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
359 liMove.QuadPart = StreamSize;
360 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
364 TRACE_(dmfile)(": reading finished\n");
368 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
369 liMove.QuadPart = Chunk.dwSize;
370 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
371 return DMUS_E_INVALIDFILE;
375 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc));
380 IDirectMusicObjectVtbl DirectMusicCollection_Object_Vtbl = {
381 IDirectMusicCollectionImpl_IDirectMusicObject_QueryInterface,
382 IDirectMusicCollectionImpl_IDirectMusicObject_AddRef,
383 IDirectMusicCollectionImpl_IDirectMusicObject_Release,
384 IDirectMusicCollectionImpl_IDirectMusicObject_GetDescriptor,
385 IDirectMusicCollectionImpl_IDirectMusicObject_SetDescriptor,
386 IDirectMusicCollectionImpl_IDirectMusicObject_ParseDescriptor
389 /* IDirectMusicCollectionImpl IPersistStream part: */
390 HRESULT WINAPI IDirectMusicCollectionImpl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
391 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, PersistStreamVtbl, iface);
392 return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
395 ULONG WINAPI IDirectMusicCollectionImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
396 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, PersistStreamVtbl, iface);
397 return IDirectMusicCollectionImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
400 ULONG WINAPI IDirectMusicCollectionImpl_IPersistStream_Release (LPPERSISTSTREAM iface) {
401 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, PersistStreamVtbl, iface);
402 return IDirectMusicCollectionImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
405 HRESULT WINAPI IDirectMusicCollectionImpl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
409 HRESULT WINAPI IDirectMusicCollectionImpl_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
413 HRESULT WINAPI IDirectMusicCollectionImpl_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
414 ICOM_THIS_MULTI(IDirectMusicCollectionImpl, PersistStreamVtbl, iface);
416 DMUS_PRIVATE_CHUNK Chunk;
417 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
418 LARGE_INTEGER liMove; /* used when skipping chunks */
419 ULARGE_INTEGER dlibCollectionPosition, dlibInstrumentPosition, dlibWavePoolPosition;
421 IStream_AddRef (pStm); /* add count for later references */
423 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, &dlibCollectionPosition); /* store offset, in case it'll be needed later */
424 This->liCollectionPosition.QuadPart = dlibCollectionPosition.QuadPart;
427 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
428 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
429 switch (Chunk.fccID) {
431 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
432 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
433 StreamSize = Chunk.dwSize - sizeof(FOURCC);
435 switch (Chunk.fccID) {
437 TRACE_(dmfile)(": collection form\n");
439 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
440 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
441 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
442 switch (Chunk.fccID) {
444 TRACE_(dmfile)(": collection header chunk\n");
445 This->pHeader = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize);
446 IStream_Read (pStm, This->pHeader, Chunk.dwSize, NULL);
450 TRACE_(dmfile)(": DLID (GUID) chunk\n");
451 This->pDesc->dwValidData |= DMUS_OBJ_OBJECT;
452 IStream_Read (pStm, &This->pDesc->guidObject, Chunk.dwSize, NULL);
456 TRACE_(dmfile)(": version chunk\n");
457 This->pDesc->dwValidData |= DMUS_OBJ_VERSION;
458 IStream_Read (pStm, &This->pDesc->vVersion, Chunk.dwSize, NULL);
462 TRACE_(dmfile)(": pool table chunk\n");
463 This->pPoolTable = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(POOLTABLE));
464 IStream_Read (pStm, This->pPoolTable, sizeof(POOLTABLE), NULL);
465 Chunk.dwSize -= sizeof(POOLTABLE);
466 This->pPoolCues = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, This->pPoolTable->cCues*sizeof(POOLCUE));
467 IStream_Read (pStm, This->pPoolCues, Chunk.dwSize, NULL);
471 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
472 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
473 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
475 switch (Chunk.fccID) {
476 case mmioFOURCC('I','N','F','O'): {
477 TRACE_(dmfile)(": INFO list\n");
479 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
480 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
481 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
482 switch (Chunk.fccID) {
483 case mmioFOURCC('I','N','A','M'): {
484 CHAR szName[DMUS_MAX_NAME];
485 TRACE_(dmfile)(": name chunk\n");
486 This->pDesc->dwValidData |= DMUS_OBJ_NAME;
487 IStream_Read (pStm, szName, Chunk.dwSize, NULL);
488 MultiByteToWideChar (CP_ACP, 0, szName, -1, This->pDesc->wszName, DMUS_MAX_NAME);
489 if (even_or_odd(Chunk.dwSize)) {
492 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
496 case mmioFOURCC('I','A','R','T'): {
497 TRACE_(dmfile)(": artist chunk (ignored)\n");
498 if (even_or_odd(Chunk.dwSize)) {
502 liMove.QuadPart = Chunk.dwSize;
503 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
506 case mmioFOURCC('I','C','O','P'): {
507 TRACE_(dmfile)(": copyright chunk\n");
508 This->szCopyright = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize);
509 IStream_Read (pStm, This->szCopyright, Chunk.dwSize, NULL);
510 if (even_or_odd(Chunk.dwSize)) {
513 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
517 case mmioFOURCC('I','S','B','J'): {
518 TRACE_(dmfile)(": subject chunk (ignored)\n");
519 if (even_or_odd(Chunk.dwSize)) {
523 liMove.QuadPart = Chunk.dwSize;
524 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
527 case mmioFOURCC('I','C','M','T'): {
528 TRACE_(dmfile)(": comment chunk (ignored)\n");
529 if (even_or_odd(Chunk.dwSize)) {
533 liMove.QuadPart = Chunk.dwSize;
534 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
538 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
539 if (even_or_odd(Chunk.dwSize)) {
543 liMove.QuadPart = Chunk.dwSize;
544 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
548 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
549 } while (ListCount[0] < ListSize[0]);
553 TRACE_(dmfile)(": wave pool list (mark & skip)\n");
555 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, &dlibWavePoolPosition); /* store position */
556 This->liWavePoolTablePosition.QuadPart = dlibWavePoolPosition.QuadPart;
557 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
558 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
562 TRACE_(dmfile)(": instruments list\n");
564 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
565 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
566 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
567 switch (Chunk.fccID) {
569 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
570 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
571 ListSize[1] = Chunk.dwSize - sizeof(FOURCC);
573 switch (Chunk.fccID) {
575 LPDMUS_PRIVATE_INSTRUMENTENTRY pNewInstrument = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_INSTRUMENTENTRY));
576 TRACE_(dmfile)(": instrument list\n");
577 DMUSIC_CreateDirectMusicInstrumentImpl (&IID_IDirectMusicInstrument, (LPVOID*)&pNewInstrument->pInstrument, NULL); /* only way to create this one... even M$ does it discretly */
579 ICOM_NAME_MULTI (IDirectMusicInstrumentImpl, InstrumentVtbl, pNewInstrument->pInstrument, pInstrument);
581 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, &dlibInstrumentPosition);
582 pInstrument->liInstrumentPosition.QuadPart = dlibInstrumentPosition.QuadPart - (2*sizeof(FOURCC) + sizeof(DWORD)); /* store offset, it'll be needed later */
585 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
586 ListCount[1] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
587 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
588 switch (Chunk.fccID) {
590 TRACE_(dmfile)(": instrument header chunk\n");
591 pInstrument->pHeader = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize);
592 IStream_Read (pStm, pInstrument->pHeader, Chunk.dwSize, NULL);
596 TRACE_(dmfile)(": DLID (GUID) chunk\n");
597 pInstrument->pInstrumentID = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, Chunk.dwSize);
598 IStream_Read (pStm, pInstrument->pInstrumentID, Chunk.dwSize, NULL);
602 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
603 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
604 ListSize[2] = Chunk.dwSize - sizeof(FOURCC);
606 switch (Chunk.fccID) {
608 TRACE_(dmfile)(": unknown (skipping)\n");
609 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
610 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
617 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
618 liMove.QuadPart = Chunk.dwSize;
619 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
623 TRACE_(dmfile)(": ListCount[1] = %ld < ListSize[1] = %ld\n", ListCount[1], ListSize[1]);
624 } while (ListCount[1] < ListSize[1]);
625 /* DEBUG: dumps whole instrument object tree: */
626 if (TRACE_ON(dmusic)) {
627 TRACE("*** IDirectMusicInstrument (%p) ***\n", pInstrument);
628 if (pInstrument->pInstrumentID)
629 TRACE(" - GUID = %s\n", debugstr_dmguid(pInstrument->pInstrumentID));
631 TRACE(" - Instrument header:\n");
632 TRACE(" - cRegions: %ld\n", pInstrument->pHeader->cRegions);
633 TRACE(" - Locale:\n");
634 TRACE(" - ulBank: %ld\n", pInstrument->pHeader->Locale.ulBank);
635 TRACE(" - ulInstrument: %ld\n", pInstrument->pHeader->Locale.ulInstrument);
636 TRACE(" => dwPatch: %ld\n", MIDILOCALE2Patch(&pInstrument->pHeader->Locale));
638 list_add_tail (&This->Instruments, &pNewInstrument->entry);
646 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
647 liMove.QuadPart = Chunk.dwSize;
648 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
652 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
653 } while (ListCount[0] < ListSize[0]);
657 TRACE_(dmfile)(": unknown (skipping)\n");
658 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
659 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
666 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
667 liMove.QuadPart = Chunk.dwSize;
668 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
672 TRACE_(dmfile)(": StreamCount = %ld < StreamSize = %ld\n", StreamCount, StreamSize);
673 } while (StreamCount < StreamSize);
677 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
678 liMove.QuadPart = StreamSize;
679 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
683 TRACE_(dmfile)(": reading finished\n");
687 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
688 liMove.QuadPart = Chunk.dwSize;
689 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
694 /* DEBUG: dumps whole collection object tree: */
695 if (TRACE_ON(dmusic)) {
697 DMUS_PRIVATE_INSTRUMENTENTRY *tmpEntry;
698 struct list *listEntry;
700 TRACE("*** IDirectMusicCollection (%p) ***\n", This->CollectionVtbl);
701 if (This->pDesc->dwValidData & DMUS_OBJ_OBJECT)
702 TRACE(" - GUID = %s\n", debugstr_dmguid(&This->pDesc->guidObject));
703 if (This->pDesc->dwValidData & DMUS_OBJ_VERSION)
704 TRACE(" - Version = %i,%i,%i,%i\n", (This->pDesc->vVersion.dwVersionMS >> 8) && 0x0000FFFF, This->pDesc->vVersion.dwVersionMS && 0x0000FFFF, \
705 (This->pDesc->vVersion.dwVersionLS >> 8) && 0x0000FFFF, This->pDesc->vVersion.dwVersionLS && 0x0000FFFF);
706 if (This->pDesc->dwValidData & DMUS_OBJ_NAME)
707 TRACE(" - Name = %s\n", debugstr_w(This->pDesc->wszName));
709 TRACE(" - Collection header:\n");
710 TRACE(" - cInstruments: %ld\n", This->pHeader->cInstruments);
711 TRACE(" - Instruments:\n");
713 LIST_FOR_EACH (listEntry, &This->Instruments) {
714 tmpEntry = LIST_ENTRY( listEntry, DMUS_PRIVATE_INSTRUMENTENTRY, entry );
715 TRACE(" - Instrument[%i]: %p\n", r, tmpEntry->pInstrument);
723 HRESULT WINAPI IDirectMusicCollectionImpl_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
727 HRESULT WINAPI IDirectMusicCollectionImpl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
731 IPersistStreamVtbl DirectMusicCollection_PersistStream_Vtbl = {
732 IDirectMusicCollectionImpl_IPersistStream_QueryInterface,
733 IDirectMusicCollectionImpl_IPersistStream_AddRef,
734 IDirectMusicCollectionImpl_IPersistStream_Release,
735 IDirectMusicCollectionImpl_IPersistStream_GetClassID,
736 IDirectMusicCollectionImpl_IPersistStream_IsDirty,
737 IDirectMusicCollectionImpl_IPersistStream_Load,
738 IDirectMusicCollectionImpl_IPersistStream_Save,
739 IDirectMusicCollectionImpl_IPersistStream_GetSizeMax
743 /* for ClassFactory */
744 HRESULT WINAPI DMUSIC_CreateDirectMusicCollectionImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
745 IDirectMusicCollectionImpl* obj;
747 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicCollectionImpl));
750 return E_OUTOFMEMORY;
752 obj->UnknownVtbl = &DirectMusicCollection_Unknown_Vtbl;
753 obj->CollectionVtbl = &DirectMusicCollection_Collection_Vtbl;
754 obj->ObjectVtbl = &DirectMusicCollection_Object_Vtbl;
755 obj->PersistStreamVtbl = &DirectMusicCollection_PersistStream_Vtbl;
756 obj->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
757 DM_STRUCT_INIT(obj->pDesc);
758 obj->pDesc->dwValidData |= DMUS_OBJ_CLASS;
759 memcpy (&obj->pDesc->guidClass, &CLSID_DirectMusicCollection, sizeof (CLSID));
760 obj->ref = 0; /* will be inited by QueryInterface */
761 list_init (&obj->Instruments);
763 return IDirectMusicCollectionImpl_IUnknown_QueryInterface ((LPUNKNOWN)&obj->UnknownVtbl, lpcGUID, ppobj);