1 /* IDirectMusicStyle8 Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
4 * Copyright (C) 2003-2004 Raphael Junqueira
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "dmstyle_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(dmstyle
);
25 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
27 /*****************************************************************************
28 * IDirectMusicStyleImpl implementation
30 typedef struct IDirectMusicStyle8Impl
{
31 IDirectMusicStyle8 IDirectMusicStyle8_iface
;
32 struct dmobject dmobj
;
37 } IDirectMusicStyle8Impl
;
39 static inline IDirectMusicStyle8Impl
*impl_from_IDirectMusicStyle8(IDirectMusicStyle8
*iface
)
41 return CONTAINING_RECORD(iface
, IDirectMusicStyle8Impl
, IDirectMusicStyle8_iface
);
44 /* DirectMusicStyle8Impl IDirectMusicStyle8 part: */
45 static HRESULT WINAPI
IDirectMusicStyle8Impl_QueryInterface(IDirectMusicStyle8
*iface
, REFIID riid
,
48 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicStyle8(iface
);
50 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ret_iface
);
54 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDirectMusicStyle
) ||
55 IsEqualIID(riid
, &IID_IDirectMusicStyle8
))
57 else if (IsEqualIID(riid
, &IID_IDirectMusicObject
))
58 *ret_iface
= &This
->dmobj
.IDirectMusicObject_iface
;
59 else if (IsEqualIID(riid
, &IID_IPersistStream
))
60 *ret_iface
= &This
->dmobj
.IPersistStream_iface
;
62 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ret_iface
);
66 IUnknown_AddRef((IUnknown
*)*ret_iface
);
70 static ULONG WINAPI
IDirectMusicStyle8Impl_AddRef(IDirectMusicStyle8
*iface
)
72 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicStyle8(iface
);
73 LONG ref
= InterlockedIncrement(&This
->ref
);
75 TRACE("(%p) ref=%d\n", This
, ref
);
80 static ULONG WINAPI
IDirectMusicStyle8Impl_Release(IDirectMusicStyle8
*iface
)
82 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicStyle8(iface
);
83 LONG ref
= InterlockedDecrement(&This
->ref
);
85 TRACE("(%p) ref=%d\n", This
, ref
);
88 HeapFree(GetProcessHeap(), 0, This
);
89 DMSTYLE_UnlockModule();
95 /* IDirectMusicStyle8Impl IDirectMusicStyle(8) part: */
96 static HRESULT WINAPI
IDirectMusicStyle8Impl_GetBand(IDirectMusicStyle8
*iface
, WCHAR
*pwszName
,
97 IDirectMusicBand
**ppBand
)
99 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicStyle8(iface
);
100 FIXME("(%p, %p, %p): stub\n", This
, pwszName
, ppBand
);
104 static HRESULT WINAPI
IDirectMusicStyle8Impl_EnumBand(IDirectMusicStyle8
*iface
, DWORD dwIndex
,
107 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicStyle8(iface
);
108 FIXME("(%p, %d, %p): stub\n", This
, dwIndex
, pwszName
);
112 static HRESULT WINAPI
IDirectMusicStyle8Impl_GetDefaultBand(IDirectMusicStyle8
*iface
,
113 IDirectMusicBand
**ppBand
)
115 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicStyle8(iface
);
116 FIXME("(%p, %p): stub\n", This
, ppBand
);
120 static HRESULT WINAPI
IDirectMusicStyle8Impl_EnumMotif(IDirectMusicStyle8
*iface
, DWORD dwIndex
,
123 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicStyle8(iface
);
124 FIXME("(%p, %d, %p): stub\n", This
, dwIndex
, pwszName
);
128 static HRESULT WINAPI
IDirectMusicStyle8Impl_GetMotif(IDirectMusicStyle8
*iface
, WCHAR
*pwszName
,
129 IDirectMusicSegment
**ppSegment
)
131 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicStyle8(iface
);
132 FIXME("(%p, %p, %p): stub\n", This
, pwszName
, ppSegment
);
136 static HRESULT WINAPI
IDirectMusicStyle8Impl_GetDefaultChordMap(IDirectMusicStyle8
*iface
,
137 IDirectMusicChordMap
**ppChordMap
)
139 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicStyle8(iface
);
140 FIXME("(%p, %p): stub\n", This
, ppChordMap
);
144 static HRESULT WINAPI
IDirectMusicStyle8Impl_EnumChordMap(IDirectMusicStyle8
*iface
, DWORD dwIndex
,
147 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicStyle8(iface
);
148 FIXME("(%p, %d, %p): stub\n", This
, dwIndex
, pwszName
);
152 static HRESULT WINAPI
IDirectMusicStyle8Impl_GetChordMap(IDirectMusicStyle8
*iface
, WCHAR
*pwszName
,
153 IDirectMusicChordMap
**ppChordMap
)
155 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicStyle8(iface
);
156 FIXME("(%p, %p, %p): stub\n", This
, pwszName
, ppChordMap
);
160 static HRESULT WINAPI
IDirectMusicStyle8Impl_GetTimeSignature(IDirectMusicStyle8
*iface
,
161 DMUS_TIMESIGNATURE
*pTimeSig
)
163 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicStyle8(iface
);
164 FIXME("(%p, %p): stub\n", This
, pTimeSig
);
168 static HRESULT WINAPI
IDirectMusicStyle8Impl_GetEmbellishmentLength(IDirectMusicStyle8
*iface
,
169 DWORD dwType
, DWORD dwLevel
, DWORD
*pdwMin
, DWORD
*pdwMax
)
171 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicStyle8(iface
);
172 FIXME("(%p, %d, %d, %p, %p): stub\n", This
, dwType
, dwLevel
, pdwMin
, pdwMax
);
176 static HRESULT WINAPI
IDirectMusicStyle8Impl_GetTempo(IDirectMusicStyle8
*iface
, double *pTempo
)
178 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicStyle8(iface
);
179 FIXME("(%p, %p): stub\n", This
, pTempo
);
183 static HRESULT WINAPI
IDirectMusicStyle8Impl_EnumPattern(IDirectMusicStyle8
*iface
, DWORD dwIndex
,
184 DWORD dwPatternType
, WCHAR
*pwszName
)
186 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicStyle8(iface
);
187 FIXME("(%p, %d, %d, %p): stub\n", This
, dwIndex
, dwPatternType
, pwszName
);
191 static const IDirectMusicStyle8Vtbl dmstyle8_vtbl
= {
192 IDirectMusicStyle8Impl_QueryInterface
,
193 IDirectMusicStyle8Impl_AddRef
,
194 IDirectMusicStyle8Impl_Release
,
195 IDirectMusicStyle8Impl_GetBand
,
196 IDirectMusicStyle8Impl_EnumBand
,
197 IDirectMusicStyle8Impl_GetDefaultBand
,
198 IDirectMusicStyle8Impl_EnumMotif
,
199 IDirectMusicStyle8Impl_GetMotif
,
200 IDirectMusicStyle8Impl_GetDefaultChordMap
,
201 IDirectMusicStyle8Impl_EnumChordMap
,
202 IDirectMusicStyle8Impl_GetChordMap
,
203 IDirectMusicStyle8Impl_GetTimeSignature
,
204 IDirectMusicStyle8Impl_GetEmbellishmentLength
,
205 IDirectMusicStyle8Impl_GetTempo
,
206 IDirectMusicStyle8Impl_EnumPattern
209 /* IDirectMusicStyle8Impl IDirectMusicObject part: */
210 static inline IDirectMusicStyle8Impl
*impl_from_IDirectMusicObject(IDirectMusicObject
*iface
)
212 return CONTAINING_RECORD(iface
, IDirectMusicStyle8Impl
, dmobj
.IDirectMusicObject_iface
);
215 static HRESULT WINAPI
IDirectMusicObjectImpl_ParseDescriptor(IDirectMusicObject
*iface
,
216 IStream
*pStream
, DMUS_OBJECTDESC
*pDesc
)
218 IDirectMusicStyle8Impl
*This
= impl_from_IDirectMusicObject(iface
);
219 DMUS_PRIVATE_CHUNK Chunk
;
220 DWORD StreamSize
, StreamCount
, ListSize
[1], ListCount
[1];
221 LARGE_INTEGER liMove
; /* used when skipping chunks */
223 TRACE("(%p, %p, %p)\n", This
, pStream
, pDesc
);
225 /* FIXME: should this be determined from stream? */
226 pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
227 pDesc
->guidClass
= CLSID_DirectMusicStyle
;
229 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
230 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
231 switch (Chunk
.fccID
) {
233 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
234 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
235 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
237 if (Chunk
.fccID
== DMUS_FOURCC_STYLE_FORM
) {
238 TRACE_(dmfile
)(": style form\n");
240 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
241 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
242 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
243 switch (Chunk
.fccID
) {
244 case DMUS_FOURCC_GUID_CHUNK
: {
245 TRACE_(dmfile
)(": GUID chunk\n");
246 pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
247 IStream_Read (pStream
, &pDesc
->guidObject
, Chunk
.dwSize
, NULL
);
250 case DMUS_FOURCC_VERSION_CHUNK
: {
251 TRACE_(dmfile
)(": version chunk\n");
252 pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
253 IStream_Read (pStream
, &pDesc
->vVersion
, Chunk
.dwSize
, NULL
);
256 case DMUS_FOURCC_CATEGORY_CHUNK
: {
257 TRACE_(dmfile
)(": category chunk\n");
258 pDesc
->dwValidData
|= DMUS_OBJ_CATEGORY
;
259 IStream_Read (pStream
, pDesc
->wszCategory
, Chunk
.dwSize
, NULL
);
263 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
264 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
265 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
267 switch (Chunk
.fccID
) {
268 /* evil M$ UNFO list, which can (!?) contain INFO elements */
269 case DMUS_FOURCC_UNFO_LIST
: {
270 TRACE_(dmfile
)(": UNFO list\n");
272 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
273 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
274 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
275 switch (Chunk
.fccID
) {
276 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
277 (though strings seem to be valid unicode) */
278 case mmioFOURCC('I','N','A','M'):
279 case DMUS_FOURCC_UNAM_CHUNK
: {
280 TRACE_(dmfile
)(": name chunk\n");
281 pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
282 IStream_Read (pStream
, pDesc
->wszName
, Chunk
.dwSize
, NULL
);
285 case mmioFOURCC('I','A','R','T'):
286 case DMUS_FOURCC_UART_CHUNK
: {
287 TRACE_(dmfile
)(": artist chunk (ignored)\n");
288 liMove
.QuadPart
= Chunk
.dwSize
;
289 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
292 case mmioFOURCC('I','C','O','P'):
293 case DMUS_FOURCC_UCOP_CHUNK
: {
294 TRACE_(dmfile
)(": copyright chunk (ignored)\n");
295 liMove
.QuadPart
= Chunk
.dwSize
;
296 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
299 case mmioFOURCC('I','S','B','J'):
300 case DMUS_FOURCC_USBJ_CHUNK
: {
301 TRACE_(dmfile
)(": subject chunk (ignored)\n");
302 liMove
.QuadPart
= Chunk
.dwSize
;
303 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
306 case mmioFOURCC('I','C','M','T'):
307 case DMUS_FOURCC_UCMT_CHUNK
: {
308 TRACE_(dmfile
)(": comment chunk (ignored)\n");
309 liMove
.QuadPart
= Chunk
.dwSize
;
310 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
314 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
315 liMove
.QuadPart
= Chunk
.dwSize
;
316 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
320 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
321 } while (ListCount
[0] < ListSize
[0]);
325 TRACE_(dmfile
)(": unknown (skipping)\n");
326 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
327 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
334 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
335 liMove
.QuadPart
= Chunk
.dwSize
;
336 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
340 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
341 } while (StreamCount
< StreamSize
);
343 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
344 liMove
.QuadPart
= StreamSize
;
345 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
349 TRACE_(dmfile
)(": reading finished\n");
353 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
354 liMove
.QuadPart
= Chunk
.dwSize
;
355 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
356 return DMUS_E_INVALIDFILE
;
360 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc
));
365 static const IDirectMusicObjectVtbl dmobject_vtbl
= {
366 dmobj_IDirectMusicObject_QueryInterface
,
367 dmobj_IDirectMusicObject_AddRef
,
368 dmobj_IDirectMusicObject_Release
,
369 dmobj_IDirectMusicObject_GetDescriptor
,
370 dmobj_IDirectMusicObject_SetDescriptor
,
371 IDirectMusicObjectImpl_ParseDescriptor
374 /* IDirectMusicStyle8Impl IPersistStream part: */
375 static inline IDirectMusicStyle8Impl
*impl_from_IPersistStream(IPersistStream
*iface
)
377 return CONTAINING_RECORD(iface
, IDirectMusicStyle8Impl
, dmobj
.IPersistStream_iface
);
380 static HRESULT
load_band(IStream
*pClonedStream
, IDirectMusicBand
**ppBand
)
383 IPersistStream
* pPersistStream
= NULL
;
385 hr
= CoCreateInstance (&CLSID_DirectMusicBand
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectMusicBand
, (LPVOID
*) ppBand
);
387 ERR(": could not create object\n");
390 /* acquire PersistStream interface */
391 hr
= IDirectMusicBand_QueryInterface (*ppBand
, &IID_IPersistStream
, (LPVOID
*) &pPersistStream
);
393 ERR(": could not acquire IPersistStream\n");
397 hr
= IPersistStream_Load (pPersistStream
, pClonedStream
);
399 ERR(": failed to load object\n");
403 /* release all loading-related stuff */
404 IPersistStream_Release (pPersistStream
);
409 static HRESULT
parse_part_ref_list(DMUS_PRIVATE_CHUNK
*pChunk
, IStream
*pStm
,
410 DMUS_PRIVATE_STYLE_MOTIF
*pNewMotif
)
413 DMUS_PRIVATE_CHUNK Chunk
;
414 DWORD ListSize
[3], ListCount
[3];
415 LARGE_INTEGER liMove
; /* used when skipping chunks */
417 LPDMUS_PRIVATE_STYLE_PARTREF_ITEM pNewItem
= NULL
;
420 if (pChunk
->fccID
!= DMUS_FOURCC_PARTREF_LIST
) {
421 ERR_(dmfile
)(": %s chunk should be a PARTREF list\n", debugstr_fourcc (pChunk
->fccID
));
425 ListSize
[0] = pChunk
->dwSize
- sizeof(FOURCC
);
429 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
430 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
431 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
432 switch (Chunk
.fccID
) {
433 case DMUS_FOURCC_PARTREF_CHUNK
: {
434 TRACE_(dmfile
)(": PartRef chunk\n");
435 pNewItem
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_STYLE_PARTREF_ITEM
));
437 ERR(": no more memory\n");
438 return E_OUTOFMEMORY
;
440 hr
= IStream_Read (pStm
, &pNewItem
->part_ref
, sizeof(DMUS_IO_PARTREF
), NULL
);
441 /*TRACE_(dmfile)(" - sizeof %lu\n", sizeof(DMUS_IO_PARTREF));*/
442 list_add_tail (&pNewMotif
->Items
, &pNewItem
->entry
);
443 pNewItem
->desc
.dwSize
= sizeof(pNewItem
->desc
);
447 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
448 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
449 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
451 switch (Chunk
.fccID
) {
452 case DMUS_FOURCC_UNFO_LIST
: {
453 TRACE_(dmfile
)(": UNFO list\n");
455 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
456 ListCount
[1] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
457 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
460 ERR(": pNewItem not yet allocated, chunk order bad?\n");
461 return E_OUTOFMEMORY
;
463 hr
= IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk
, pStm
, &pNewItem
->desc
);
464 if (FAILED(hr
)) return hr
;
467 switch (Chunk
.fccID
) {
469 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
470 liMove
.QuadPart
= Chunk
.dwSize
;
471 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
476 TRACE_(dmfile
)(": ListCount[1] = %d < ListSize[1] = %d\n", ListCount
[1], ListSize
[1]);
477 } while (ListCount
[1] < ListSize
[1]);
481 TRACE_(dmfile
)(": unknown chunk (skipping)\n");
482 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
483 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
490 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
491 liMove
.QuadPart
= Chunk
.dwSize
;
492 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
496 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
497 } while (ListCount
[0] < ListSize
[0]);
502 static HRESULT
parse_part_list(DMUS_PRIVATE_CHUNK
*pChunk
, IStream
*pStm
)
505 DMUS_PRIVATE_CHUNK Chunk
;
506 DWORD ListSize
[3], ListCount
[3];
507 LARGE_INTEGER liMove
; /* used when skipping chunks */
509 DMUS_OBJECTDESC desc
;
513 if (pChunk
->fccID
!= DMUS_FOURCC_PART_LIST
) {
514 ERR_(dmfile
)(": %s chunk should be a PART list\n", debugstr_fourcc (pChunk
->fccID
));
518 ListSize
[0] = pChunk
->dwSize
- sizeof(FOURCC
);
522 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
523 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
524 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
525 switch (Chunk
.fccID
) {
526 case DMUS_FOURCC_PART_CHUNK
: {
527 TRACE_(dmfile
)(": Part chunk (skipping for now)\n" );
528 liMove
.QuadPart
= Chunk
.dwSize
;
529 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
532 case DMUS_FOURCC_NOTE_CHUNK
: {
533 TRACE_(dmfile
)(": Note chunk (skipping for now)\n");
534 IStream_Read (pStm
, &dwSize
, sizeof(DWORD
), NULL
);
535 cnt
= (Chunk
.dwSize
- sizeof(DWORD
));
536 TRACE_(dmfile
)(" - dwSize: %u\n", dwSize
);
537 TRACE_(dmfile
)(" - cnt: %u (%u / %u)\n", cnt
/ dwSize
, (DWORD
)(Chunk
.dwSize
- sizeof(DWORD
)), dwSize
);
538 if (cnt
% dwSize
!= 0) {
539 ERR("Invalid Array Size\n");
544 liMove
.QuadPart
= cnt
* dwSize
;
545 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
548 case DMUS_FOURCC_CURVE_CHUNK
: {
549 TRACE_(dmfile
)(": Curve chunk (skipping for now)\n");
550 IStream_Read (pStm
, &dwSize
, sizeof(DWORD
), NULL
);
551 cnt
= (Chunk
.dwSize
- sizeof(DWORD
));
552 TRACE_(dmfile
)(" - dwSize: %u\n", dwSize
);
553 TRACE_(dmfile
)(" - cnt: %u (%u / %u)\n", cnt
/ dwSize
, (DWORD
)(Chunk
.dwSize
- sizeof(DWORD
)), dwSize
);
554 if (cnt
% dwSize
!= 0) {
555 ERR("Invalid Array Size\n");
560 liMove
.QuadPart
= cnt
* dwSize
;
561 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
564 case DMUS_FOURCC_MARKER_CHUNK
: {
565 TRACE_(dmfile
)(": Marker chunk (skipping for now)\n");
566 liMove
.QuadPart
= Chunk
.dwSize
;
567 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
570 case DMUS_FOURCC_RESOLUTION_CHUNK
: {
571 TRACE_(dmfile
)(": Resolution chunk (skipping for now)\n");
572 liMove
.QuadPart
= Chunk
.dwSize
;
573 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
576 case DMUS_FOURCC_ANTICIPATION_CHUNK
: {
577 TRACE_(dmfile
)(": Anticipation chunk (skipping for now)\n");
578 liMove
.QuadPart
= Chunk
.dwSize
;
579 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
583 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
584 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
585 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
587 switch (Chunk
.fccID
) {
588 case DMUS_FOURCC_UNFO_LIST
: {
589 TRACE_(dmfile
)(": UNFO list\n");
591 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
592 ListCount
[1] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
593 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
595 hr
= IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk
, pStm
, &desc
);
596 if (FAILED(hr
)) return hr
;
599 switch (Chunk
.fccID
) {
601 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
602 liMove
.QuadPart
= Chunk
.dwSize
;
603 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
608 TRACE_(dmfile
)(": ListCount[1] = %d < ListSize[1] = %d\n", ListCount
[1], ListSize
[1]);
609 } while (ListCount
[1] < ListSize
[1]);
613 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
614 liMove
.QuadPart
= Chunk
.dwSize
;
615 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
622 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
623 liMove
.QuadPart
= Chunk
.dwSize
;
624 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
628 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
629 } while (ListCount
[0] < ListSize
[0]);
634 static HRESULT
parse_pattern_list(IDirectMusicStyle8Impl
*This
, DMUS_PRIVATE_CHUNK
*pChunk
,
638 DMUS_PRIVATE_CHUNK Chunk
;
639 DWORD ListSize
[3], ListCount
[3];
640 LARGE_INTEGER liMove
; /* used when skipping chunks */
642 IDirectMusicBand
* pBand
= NULL
;
643 LPDMUS_PRIVATE_STYLE_MOTIF pNewMotif
= NULL
;
645 if (pChunk
->fccID
!= DMUS_FOURCC_PATTERN_LIST
) {
646 ERR_(dmfile
)(": %s chunk should be a PATTERN list\n", debugstr_fourcc (pChunk
->fccID
));
650 ListSize
[0] = pChunk
->dwSize
- sizeof(FOURCC
);
654 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
655 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
656 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
657 switch (Chunk
.fccID
) {
658 case DMUS_FOURCC_PATTERN_CHUNK
: {
659 TRACE_(dmfile
)(": Pattern chunk\n");
660 /** alloc new motif entry */
661 pNewMotif
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_STYLE_MOTIF
));
662 if (NULL
== pNewMotif
) {
663 ERR(": no more memory\n");
664 return E_OUTOFMEMORY
;
666 list_add_tail (&This
->Motifs
, &pNewMotif
->entry
);
668 IStream_Read (pStm
, &pNewMotif
->pattern
, Chunk
.dwSize
, NULL
);
669 /** TODO trace pattern */
671 /** reset all data, as a new pattern begin */
672 pNewMotif
->desc
.dwSize
= sizeof(pNewMotif
->desc
);
673 list_init (&pNewMotif
->Items
);
676 case DMUS_FOURCC_RHYTHM_CHUNK
: {
677 TRACE_(dmfile
)(": Rhythm chunk\n");
678 IStream_Read (pStm
, &pNewMotif
->dwRhythm
, sizeof(DWORD
), NULL
);
679 TRACE_(dmfile
)(" - dwRhythm: %u\n", pNewMotif
->dwRhythm
);
680 /** TODO understand why some Chunks have size > 4 */
681 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(DWORD
);
682 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
685 case DMUS_FOURCC_MOTIFSETTINGS_CHUNK
: {
686 TRACE_(dmfile
)(": MotifSettings chunk (skipping for now)\n");
687 IStream_Read (pStm
, &pNewMotif
->settings
, Chunk
.dwSize
, NULL
);
688 /** TODO trace settings */
693 * should be embedded Bands into pattern
695 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
696 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
697 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
699 switch (Chunk
.fccID
) {
700 case DMUS_FOURCC_BAND_FORM
: {
701 LPSTREAM pClonedStream
= NULL
;
703 TRACE_(dmfile
)(": BAND RIFF\n");
705 IStream_Clone (pStm
, &pClonedStream
);
708 liMove
.QuadPart
-= sizeof(FOURCC
) + (sizeof(FOURCC
)+sizeof(DWORD
));
709 IStream_Seek (pClonedStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
711 hr
= load_band(pClonedStream
, &pBand
);
713 ERR(": could not load track\n");
716 IStream_Release (pClonedStream
);
718 pNewMotif
->pBand
= pBand
;
719 IDirectMusicBand_AddRef(pBand
);
721 IDirectMusicTrack_Release(pBand
); pBand
= NULL
; /* now we can release it as it's inserted */
723 /** now safe move the cursor */
724 liMove
.QuadPart
= ListSize
[1];
725 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
730 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
731 liMove
.QuadPart
= ListSize
[1];
732 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
739 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
740 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
741 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
743 switch (Chunk
.fccID
) {
744 case DMUS_FOURCC_UNFO_LIST
: {
745 TRACE_(dmfile
)(": UNFO list\n");
747 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
748 ListCount
[1] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
749 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
751 hr
= IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk
, pStm
, &pNewMotif
->desc
);
752 if (FAILED(hr
)) return hr
;
755 switch (Chunk
.fccID
) {
757 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
758 liMove
.QuadPart
= Chunk
.dwSize
;
759 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
764 TRACE_(dmfile
)(": ListCount[1] = %d < ListSize[1] = %d\n", ListCount
[1], ListSize
[1]);
765 } while (ListCount
[1] < ListSize
[1]);
768 case DMUS_FOURCC_PARTREF_LIST
: {
769 TRACE_(dmfile
)(": PartRef list\n");
770 hr
= parse_part_ref_list(&Chunk
, pStm
, pNewMotif
);
771 if (FAILED(hr
)) return hr
;
775 TRACE_(dmfile
)(": unknown (skipping)\n");
776 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
777 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
784 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
785 liMove
.QuadPart
= Chunk
.dwSize
;
786 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
790 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
791 } while (ListCount
[0] < ListSize
[0]);
796 static HRESULT
parse_style_form(IDirectMusicStyle8Impl
*This
, DMUS_PRIVATE_CHUNK
*pChunk
,
800 DMUS_PRIVATE_CHUNK Chunk
;
801 DWORD StreamSize
, StreamCount
, ListSize
[3], ListCount
[3];
802 LARGE_INTEGER liMove
; /* used when skipping chunks */
804 IDirectMusicBand
* pBand
= NULL
;
806 if (pChunk
->fccID
!= DMUS_FOURCC_STYLE_FORM
) {
807 ERR_(dmfile
)(": %s chunk should be a STYLE form\n", debugstr_fourcc (pChunk
->fccID
));
811 StreamSize
= pChunk
->dwSize
- sizeof(FOURCC
);
815 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
816 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
817 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
819 hr
= IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk
, pStm
, &This
->dmobj
.desc
);
820 if (FAILED(hr
)) return hr
;
823 switch (Chunk
.fccID
) {
824 case DMUS_FOURCC_STYLE_CHUNK
: {
825 TRACE_(dmfile
)(": Style chunk\n");
826 IStream_Read (pStm
, &This
->style
, sizeof(DMUS_IO_STYLE
), NULL
);
827 /** TODO dump DMUS_IO_TIMESIG style.timeSig */
828 TRACE_(dmfile
)(" - dblTempo: %g\n", This
->style
.dblTempo
);
833 * should be embedded Bands into style
835 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
836 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
837 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
839 switch (Chunk
.fccID
) {
840 case DMUS_FOURCC_BAND_FORM
: {
841 LPSTREAM pClonedStream
= NULL
;
842 LPDMUS_PRIVATE_STYLE_BAND pNewBand
;
844 TRACE_(dmfile
)(": BAND RIFF\n");
846 IStream_Clone (pStm
, &pClonedStream
);
849 liMove
.QuadPart
-= sizeof(FOURCC
) + (sizeof(FOURCC
)+sizeof(DWORD
));
850 IStream_Seek (pClonedStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
852 hr
= load_band(pClonedStream
, &pBand
);
854 ERR(": could not load track\n");
857 IStream_Release (pClonedStream
);
859 pNewBand
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_STYLE_BAND
));
860 if (NULL
== pNewBand
) {
861 ERR(": no more memory\n");
862 return E_OUTOFMEMORY
;
864 pNewBand
->pBand
= pBand
;
865 IDirectMusicBand_AddRef(pBand
);
866 list_add_tail (&This
->Bands
, &pNewBand
->entry
);
868 IDirectMusicTrack_Release(pBand
); pBand
= NULL
; /* now we can release it as it's inserted */
870 /** now safely move the cursor */
871 liMove
.QuadPart
= ListSize
[0];
872 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
877 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
878 liMove
.QuadPart
= ListSize
[0];
879 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
886 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
887 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
888 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
890 switch (Chunk
.fccID
) {
891 case DMUS_FOURCC_UNFO_LIST
: {
892 TRACE_(dmfile
)(": UNFO list\n");
894 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
895 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
896 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
898 hr
= IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk
, pStm
, &This
->dmobj
.desc
);
899 if (FAILED(hr
)) return hr
;
902 switch (Chunk
.fccID
) {
904 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
905 liMove
.QuadPart
= Chunk
.dwSize
;
906 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
911 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
912 } while (ListCount
[0] < ListSize
[0]);
915 case DMUS_FOURCC_PART_LIST
: {
916 TRACE_(dmfile
)(": PART list\n");
917 hr
= parse_part_list(&Chunk
, pStm
);
918 if (FAILED(hr
)) return hr
;
921 case DMUS_FOURCC_PATTERN_LIST
: {
922 TRACE_(dmfile
)(": PATTERN list\n");
923 hr
= parse_pattern_list(This
, &Chunk
, pStm
);
924 if (FAILED(hr
)) return hr
;
928 TRACE_(dmfile
)(": unknown (skipping)\n");
929 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
930 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
937 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
938 liMove
.QuadPart
= Chunk
.dwSize
;
939 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
944 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
945 } while (StreamCount
< StreamSize
);
950 static HRESULT WINAPI
IPersistStreamImpl_Load(IPersistStream
*iface
, IStream
*pStm
)
952 IDirectMusicStyle8Impl
*This
= impl_from_IPersistStream(iface
);
953 DMUS_PRIVATE_CHUNK Chunk
;
954 LARGE_INTEGER liMove
; /* used when skipping chunks */
957 FIXME("(%p, %p): Loading\n", This
, pStm
);
959 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
960 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
961 switch (Chunk
.fccID
) {
963 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
964 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
965 switch (Chunk
.fccID
) {
966 case DMUS_FOURCC_STYLE_FORM
: {
967 TRACE_(dmfile
)(": Style form\n");
968 hr
= parse_style_form(This
, &Chunk
, pStm
);
969 if (FAILED(hr
)) return hr
;
973 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
974 liMove
.QuadPart
= Chunk
.dwSize
;
975 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
979 TRACE_(dmfile
)(": reading finished\n");
983 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
984 liMove
.QuadPart
= Chunk
.dwSize
;
985 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
993 static const IPersistStreamVtbl persiststream_vtbl
= {
994 dmobj_IPersistStream_QueryInterface
,
995 dmobj_IPersistStream_AddRef
,
996 dmobj_IPersistStream_Release
,
997 dmobj_IPersistStream_GetClassID
,
998 unimpl_IPersistStream_IsDirty
,
999 IPersistStreamImpl_Load
,
1000 unimpl_IPersistStream_Save
,
1001 unimpl_IPersistStream_GetSizeMax
1004 /* for ClassFactory */
1005 HRESULT WINAPI
create_dmstyle(REFIID lpcGUID
, void **ppobj
)
1007 IDirectMusicStyle8Impl
* obj
;
1010 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicStyle8Impl
));
1013 return E_OUTOFMEMORY
;
1015 obj
->IDirectMusicStyle8_iface
.lpVtbl
= &dmstyle8_vtbl
;
1017 dmobject_init(&obj
->dmobj
, &CLSID_DirectMusicStyle
, (IUnknown
*)&obj
->IDirectMusicStyle8_iface
);
1018 obj
->dmobj
.IDirectMusicObject_iface
.lpVtbl
= &dmobject_vtbl
;
1019 obj
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
1020 list_init (&obj
->Bands
);
1021 list_init (&obj
->Motifs
);
1023 DMSTYLE_LockModule();
1024 hr
= IDirectMusicStyle8_QueryInterface(&obj
->IDirectMusicStyle8_iface
, lpcGUID
, ppobj
);
1025 IDirectMusicStyle8_Release(&obj
->IDirectMusicStyle8_iface
);