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 DM_STRUCT_INIT(&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 DMUS_OBJECTDESC desc
;
643 IDirectMusicBand
* pBand
= NULL
;
644 LPDMUS_PRIVATE_STYLE_MOTIF pNewMotif
= NULL
;
646 DM_STRUCT_INIT(&desc
);
648 if (pChunk
->fccID
!= DMUS_FOURCC_PATTERN_LIST
) {
649 ERR_(dmfile
)(": %s chunk should be a PATTERN list\n", debugstr_fourcc (pChunk
->fccID
));
653 ListSize
[0] = pChunk
->dwSize
- sizeof(FOURCC
);
657 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
658 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
659 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
660 switch (Chunk
.fccID
) {
661 case DMUS_FOURCC_PATTERN_CHUNK
: {
662 TRACE_(dmfile
)(": Pattern chunk\n");
663 /** alloc new motif entry */
664 pNewMotif
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_STYLE_MOTIF
));
665 if (NULL
== pNewMotif
) {
666 ERR(": no more memory\n");
667 return E_OUTOFMEMORY
;
669 list_add_tail (&This
->Motifs
, &pNewMotif
->entry
);
671 IStream_Read (pStm
, &pNewMotif
->pattern
, Chunk
.dwSize
, NULL
);
672 /** TODO trace pattern */
674 /** reset all data, as a new pattern begin */
675 DM_STRUCT_INIT(&pNewMotif
->desc
);
676 list_init (&pNewMotif
->Items
);
679 case DMUS_FOURCC_RHYTHM_CHUNK
: {
680 TRACE_(dmfile
)(": Rhythm chunk\n");
681 IStream_Read (pStm
, &pNewMotif
->dwRhythm
, sizeof(DWORD
), NULL
);
682 TRACE_(dmfile
)(" - dwRhythm: %u\n", pNewMotif
->dwRhythm
);
683 /** TODO understand why some Chunks have size > 4 */
684 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(DWORD
);
685 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
688 case DMUS_FOURCC_MOTIFSETTINGS_CHUNK
: {
689 TRACE_(dmfile
)(": MotifSettings chunk (skipping for now)\n");
690 IStream_Read (pStm
, &pNewMotif
->settings
, Chunk
.dwSize
, NULL
);
691 /** TODO trace settings */
696 * should be embedded Bands into pattern
698 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
699 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
700 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
702 switch (Chunk
.fccID
) {
703 case DMUS_FOURCC_BAND_FORM
: {
704 LPSTREAM pClonedStream
= NULL
;
706 TRACE_(dmfile
)(": BAND RIFF\n");
708 IStream_Clone (pStm
, &pClonedStream
);
711 liMove
.QuadPart
-= sizeof(FOURCC
) + (sizeof(FOURCC
)+sizeof(DWORD
));
712 IStream_Seek (pClonedStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
714 hr
= load_band(pClonedStream
, &pBand
);
716 ERR(": could not load track\n");
719 IStream_Release (pClonedStream
);
721 pNewMotif
->pBand
= pBand
;
722 IDirectMusicBand_AddRef(pBand
);
724 IDirectMusicTrack_Release(pBand
); pBand
= NULL
; /* now we can release it as it's inserted */
726 /** now safe move the cursor */
727 liMove
.QuadPart
= ListSize
[1];
728 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
733 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
734 liMove
.QuadPart
= ListSize
[1];
735 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
742 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
743 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
744 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
746 switch (Chunk
.fccID
) {
747 case DMUS_FOURCC_UNFO_LIST
: {
748 TRACE_(dmfile
)(": UNFO list\n");
750 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
751 ListCount
[1] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
752 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
754 hr
= IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk
, pStm
, &pNewMotif
->desc
);
755 if (FAILED(hr
)) return hr
;
758 switch (Chunk
.fccID
) {
760 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
761 liMove
.QuadPart
= Chunk
.dwSize
;
762 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
767 TRACE_(dmfile
)(": ListCount[1] = %d < ListSize[1] = %d\n", ListCount
[1], ListSize
[1]);
768 } while (ListCount
[1] < ListSize
[1]);
771 case DMUS_FOURCC_PARTREF_LIST
: {
772 TRACE_(dmfile
)(": PartRef list\n");
773 hr
= parse_part_ref_list(&Chunk
, pStm
, pNewMotif
);
774 if (FAILED(hr
)) return hr
;
778 TRACE_(dmfile
)(": unknown (skipping)\n");
779 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
780 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
787 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
788 liMove
.QuadPart
= Chunk
.dwSize
;
789 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
793 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
794 } while (ListCount
[0] < ListSize
[0]);
799 static HRESULT
parse_style_form(IDirectMusicStyle8Impl
*This
, DMUS_PRIVATE_CHUNK
*pChunk
,
803 DMUS_PRIVATE_CHUNK Chunk
;
804 DWORD StreamSize
, StreamCount
, ListSize
[3], ListCount
[3];
805 LARGE_INTEGER liMove
; /* used when skipping chunks */
807 IDirectMusicBand
* pBand
= NULL
;
809 if (pChunk
->fccID
!= DMUS_FOURCC_STYLE_FORM
) {
810 ERR_(dmfile
)(": %s chunk should be a STYLE form\n", debugstr_fourcc (pChunk
->fccID
));
814 StreamSize
= pChunk
->dwSize
- sizeof(FOURCC
);
818 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
819 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
820 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
822 hr
= IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk
, pStm
, &This
->dmobj
.desc
);
823 if (FAILED(hr
)) return hr
;
826 switch (Chunk
.fccID
) {
827 case DMUS_FOURCC_STYLE_CHUNK
: {
828 TRACE_(dmfile
)(": Style chunk\n");
829 IStream_Read (pStm
, &This
->style
, sizeof(DMUS_IO_STYLE
), NULL
);
830 /** TODO dump DMUS_IO_TIMESIG style.timeSig */
831 TRACE_(dmfile
)(" - dblTempo: %g\n", This
->style
.dblTempo
);
836 * should be embedded Bands into style
838 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
839 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
840 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
842 switch (Chunk
.fccID
) {
843 case DMUS_FOURCC_BAND_FORM
: {
844 LPSTREAM pClonedStream
= NULL
;
845 LPDMUS_PRIVATE_STYLE_BAND pNewBand
;
847 TRACE_(dmfile
)(": BAND RIFF\n");
849 IStream_Clone (pStm
, &pClonedStream
);
852 liMove
.QuadPart
-= sizeof(FOURCC
) + (sizeof(FOURCC
)+sizeof(DWORD
));
853 IStream_Seek (pClonedStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
855 hr
= load_band(pClonedStream
, &pBand
);
857 ERR(": could not load track\n");
860 IStream_Release (pClonedStream
);
862 pNewBand
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_STYLE_BAND
));
863 if (NULL
== pNewBand
) {
864 ERR(": no more memory\n");
865 return E_OUTOFMEMORY
;
867 pNewBand
->pBand
= pBand
;
868 IDirectMusicBand_AddRef(pBand
);
869 list_add_tail (&This
->Bands
, &pNewBand
->entry
);
871 IDirectMusicTrack_Release(pBand
); pBand
= NULL
; /* now we can release it as it's inserted */
873 /** now safely move the cursor */
874 liMove
.QuadPart
= ListSize
[0];
875 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
880 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
881 liMove
.QuadPart
= ListSize
[0];
882 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
889 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
890 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
891 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
893 switch (Chunk
.fccID
) {
894 case DMUS_FOURCC_UNFO_LIST
: {
895 TRACE_(dmfile
)(": UNFO list\n");
897 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
898 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
899 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
901 hr
= IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk
, pStm
, &This
->dmobj
.desc
);
902 if (FAILED(hr
)) return hr
;
905 switch (Chunk
.fccID
) {
907 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
908 liMove
.QuadPart
= Chunk
.dwSize
;
909 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
914 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
915 } while (ListCount
[0] < ListSize
[0]);
918 case DMUS_FOURCC_PART_LIST
: {
919 TRACE_(dmfile
)(": PART list\n");
920 hr
= parse_part_list(&Chunk
, pStm
);
921 if (FAILED(hr
)) return hr
;
924 case DMUS_FOURCC_PATTERN_LIST
: {
925 TRACE_(dmfile
)(": PATTERN list\n");
926 hr
= parse_pattern_list(This
, &Chunk
, pStm
);
927 if (FAILED(hr
)) return hr
;
931 TRACE_(dmfile
)(": unknown (skipping)\n");
932 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
933 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
940 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
941 liMove
.QuadPart
= Chunk
.dwSize
;
942 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
947 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
948 } while (StreamCount
< StreamSize
);
953 static HRESULT WINAPI
IPersistStreamImpl_Load(IPersistStream
*iface
, IStream
*pStm
)
955 IDirectMusicStyle8Impl
*This
= impl_from_IPersistStream(iface
);
956 DMUS_PRIVATE_CHUNK Chunk
;
957 LARGE_INTEGER liMove
; /* used when skipping chunks */
960 FIXME("(%p, %p): Loading\n", This
, pStm
);
962 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
963 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
964 switch (Chunk
.fccID
) {
966 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
967 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
968 switch (Chunk
.fccID
) {
969 case DMUS_FOURCC_STYLE_FORM
: {
970 TRACE_(dmfile
)(": Style form\n");
971 hr
= parse_style_form(This
, &Chunk
, pStm
);
972 if (FAILED(hr
)) return hr
;
976 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
977 liMove
.QuadPart
= Chunk
.dwSize
;
978 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
982 TRACE_(dmfile
)(": reading finished\n");
986 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
987 liMove
.QuadPart
= Chunk
.dwSize
;
988 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
996 static const IPersistStreamVtbl persiststream_vtbl
= {
997 dmobj_IPersistStream_QueryInterface
,
998 dmobj_IPersistStream_AddRef
,
999 dmobj_IPersistStream_Release
,
1000 dmobj_IPersistStream_GetClassID
,
1001 unimpl_IPersistStream_IsDirty
,
1002 IPersistStreamImpl_Load
,
1003 unimpl_IPersistStream_Save
,
1004 unimpl_IPersistStream_GetSizeMax
1007 /* for ClassFactory */
1008 HRESULT WINAPI
create_dmstyle(REFIID lpcGUID
, void **ppobj
)
1010 IDirectMusicStyle8Impl
* obj
;
1013 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicStyle8Impl
));
1016 return E_OUTOFMEMORY
;
1018 obj
->IDirectMusicStyle8_iface
.lpVtbl
= &dmstyle8_vtbl
;
1020 dmobject_init(&obj
->dmobj
, &CLSID_DirectMusicStyle
, (IUnknown
*)&obj
->IDirectMusicStyle8_iface
);
1021 obj
->dmobj
.IDirectMusicObject_iface
.lpVtbl
= &dmobject_vtbl
;
1022 obj
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
1023 list_init (&obj
->Bands
);
1024 list_init (&obj
->Motifs
);
1026 DMSTYLE_LockModule();
1027 hr
= IDirectMusicStyle8_QueryInterface(&obj
->IDirectMusicStyle8_iface
, lpcGUID
, ppobj
);
1028 IDirectMusicStyle8_Release(&obj
->IDirectMusicStyle8_iface
);