comctl32: imagelist: SetImageCount can be used to decrease image count (with testcase).
[wine] / dlls / dmstyle / styletrack.c
1 /* IDirectMusicStyleTrack Implementation
2  *
3  * Copyright (C) 2003-2004 Rok Mandeljc
4  *
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.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #include "dmstyle_private.h"
21
22 WINE_DEFAULT_DEBUG_CHANNEL(dmstyle);
23 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
24
25 static ULONG WINAPI IDirectMusicStyleTrack_IUnknown_AddRef (LPUNKNOWN iface);
26 static ULONG WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_AddRef (LPDIRECTMUSICTRACK8 iface);
27 static ULONG WINAPI IDirectMusicStyleTrack_IPersistStream_AddRef (LPPERSISTSTREAM iface);
28
29 /*****************************************************************************
30  * IDirectMusicStyleTrack implementation
31  */
32 /* IDirectMusicStyleTrack IUnknown part: */
33 static HRESULT WINAPI IDirectMusicStyleTrack_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
34         ICOM_THIS_MULTI(IDirectMusicStyleTrack, UnknownVtbl, iface);
35         TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
36
37         if (IsEqualIID (riid, &IID_IUnknown)) {
38                 *ppobj = (LPUNKNOWN)&This->UnknownVtbl;
39                 IDirectMusicStyleTrack_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
40                 return S_OK;
41         } else if (IsEqualIID (riid, &IID_IDirectMusicTrack)
42           || IsEqualIID (riid, &IID_IDirectMusicTrack8)) {
43                 *ppobj = (LPDIRECTMUSICTRACK8)&This->TrackVtbl;
44                 IDirectMusicStyleTrack_IDirectMusicTrack_AddRef ((LPDIRECTMUSICTRACK8)&This->TrackVtbl);
45                 return S_OK;
46         } else if (IsEqualIID (riid, &IID_IPersistStream)) {
47                 *ppobj = (LPPERSISTSTREAM)&This->PersistStreamVtbl;
48                 IDirectMusicStyleTrack_IPersistStream_AddRef ((LPPERSISTSTREAM)&This->PersistStreamVtbl);
49                 return S_OK;
50         }
51         
52         WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
53         return E_NOINTERFACE;
54 }
55
56 static ULONG WINAPI IDirectMusicStyleTrack_IUnknown_AddRef (LPUNKNOWN iface) {
57         ICOM_THIS_MULTI(IDirectMusicStyleTrack, UnknownVtbl, iface);
58         ULONG ref = InterlockedIncrement(&This->ref);
59
60         TRACE("(%p): AddRef from %ld\n", This, ref - 1);
61
62         DMSTYLE_LockModule();
63
64         return ref;
65 }
66
67 static ULONG WINAPI IDirectMusicStyleTrack_IUnknown_Release (LPUNKNOWN iface) {
68         ICOM_THIS_MULTI(IDirectMusicStyleTrack, UnknownVtbl, iface);
69         ULONG ref = InterlockedDecrement(&This->ref);
70
71         TRACE("(%p): ReleaseRef to %ld\n", This, ref);
72
73         if (ref == 0) {
74                 HeapFree(GetProcessHeap(), 0, This);
75         }
76         
77         DMSTYLE_UnlockModule();
78         
79         return ref;
80 }
81
82 static const IUnknownVtbl DirectMusicStyleTrack_Unknown_Vtbl = {
83         IDirectMusicStyleTrack_IUnknown_QueryInterface,
84         IDirectMusicStyleTrack_IUnknown_AddRef,
85         IDirectMusicStyleTrack_IUnknown_Release
86 };
87
88 /* IDirectMusicStyleTrack IDirectMusicTrack8 part: */
89 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_QueryInterface (LPDIRECTMUSICTRACK8 iface, REFIID riid, LPVOID *ppobj) {
90         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
91         return IDirectMusicStyleTrack_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
92 }
93
94 static ULONG WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_AddRef (LPDIRECTMUSICTRACK8 iface) {
95         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
96         return IDirectMusicStyleTrack_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
97 }
98
99 static ULONG WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_Release (LPDIRECTMUSICTRACK8 iface) {
100         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
101         return IDirectMusicStyleTrack_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
102 }
103
104 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_Init (LPDIRECTMUSICTRACK8 iface, IDirectMusicSegment* pSegment)
105 {
106         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
107         FIXME("(%p, %p): stub\n", This, pSegment);
108         return S_OK;
109 }
110
111 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_InitPlay (LPDIRECTMUSICTRACK8 iface, IDirectMusicSegmentState* pSegmentState, IDirectMusicPerformance* pPerformance, void** ppStateData, DWORD dwVirtualTrack8ID, DWORD dwFlags)
112 {
113         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
114         FIXME("(%p, %p, %p, %p, %ld, %ld): stub\n", This, pSegmentState, pPerformance, ppStateData, dwVirtualTrack8ID, dwFlags);
115         return S_OK;
116 }
117
118 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_EndPlay (LPDIRECTMUSICTRACK8 iface, void* pStateData)
119 {
120         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
121         FIXME("(%p, %p): stub\n", This, pStateData);
122         return S_OK;
123 }
124
125 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_Play (LPDIRECTMUSICTRACK8 iface, void* pStateData, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, MUSIC_TIME mtOffset, DWORD dwFlags, IDirectMusicPerformance* pPerf, IDirectMusicSegmentState* pSegSt, DWORD dwVirtualID)
126 {
127         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
128         FIXME("(%p, %p, %ld, %ld, %ld, %ld, %p, %p, %ld): stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
129         return S_OK;
130 }
131
132 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_GetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
133         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
134         FIXME("(%p, %s, %ld, %p, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pmtNext, pParam);
135         return S_OK;
136 }
137
138 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_SetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, void* pParam) {
139         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
140         FIXME("(%p, %s, %ld, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pParam);
141         return S_OK;
142 }
143
144 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_IsParamSupported (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType) {
145         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
146
147         TRACE("(%p, %s): ", This, debugstr_dmguid(rguidType));
148         if (IsEqualGUID (rguidType, &GUID_DisableTimeSig)
149                 || IsEqualGUID (rguidType, &GUID_EnableTimeSig)
150                 || IsEqualGUID (rguidType, &GUID_IDirectMusicStyle)
151                 || IsEqualGUID (rguidType, &GUID_SeedVariations)
152                 || IsEqualGUID (rguidType, &GUID_TimeSignature)) {
153                 TRACE("param supported\n");
154                 return S_OK;
155         }
156         TRACE("param unsupported\n");
157         return DMUS_E_TYPE_UNSUPPORTED;
158 }
159
160 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_AddNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
161         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
162         FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
163         return S_OK;
164 }
165
166 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_RemoveNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
167         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
168         FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
169         return S_OK;
170 }
171
172 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_Clone (LPDIRECTMUSICTRACK8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicTrack** ppTrack) {
173         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
174         FIXME("(%p, %ld, %ld, %p): stub\n", This, mtStart, mtEnd, ppTrack);
175         return S_OK;
176 }
177
178 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_PlayEx (LPDIRECTMUSICTRACK8 iface, void* pStateData, REFERENCE_TIME rtStart, REFERENCE_TIME rtEnd, REFERENCE_TIME rtOffset, DWORD dwFlags, IDirectMusicPerformance* pPerf, IDirectMusicSegmentState* pSegSt, DWORD dwVirtualID) {
179         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
180         FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %ld, %p, %p, %ld): stub\n", This, pStateData, wine_dbgstr_longlong(rtStart),
181             wine_dbgstr_longlong(rtEnd), wine_dbgstr_longlong(rtOffset), dwFlags, pPerf, pSegSt, dwVirtualID);
182         return S_OK;
183 }
184
185 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_GetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, REFERENCE_TIME* prtNext, void* pParam, void* pStateData, DWORD dwFlags) {
186         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
187         FIXME("(%p, %s, 0x%s, %p, %p, %p, %ld): stub\n", This, debugstr_dmguid(rguidType),
188             wine_dbgstr_longlong(rtTime), prtNext, pParam, pStateData, dwFlags);
189         return S_OK;
190 }
191
192 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_SetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, void* pParam, void* pStateData, DWORD dwFlags) {
193         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
194         FIXME("(%p, %s, 0x%s, %p, %p, %ld): stub\n", This, debugstr_dmguid(rguidType),
195             wine_dbgstr_longlong(rtTime), pParam, pStateData, dwFlags);
196         return S_OK;
197 }
198
199 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_Compose (LPDIRECTMUSICTRACK8 iface, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
200         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
201         FIXME("(%p, %p, %ld, %p): stub\n", This, pContext, dwTrackGroup, ppResultTrack);
202         return S_OK;
203 }
204
205 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_Join (LPDIRECTMUSICTRACK8 iface, IDirectMusicTrack* pNewTrack, MUSIC_TIME mtJoin, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
206         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
207         FIXME("(%p, %p, %ld, %p, %ld, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
208         return S_OK;
209 }
210
211 static const IDirectMusicTrack8Vtbl DirectMusicStyleTrack_Track_Vtbl = {
212         IDirectMusicStyleTrack_IDirectMusicTrack_QueryInterface,
213         IDirectMusicStyleTrack_IDirectMusicTrack_AddRef,
214         IDirectMusicStyleTrack_IDirectMusicTrack_Release,
215         IDirectMusicStyleTrack_IDirectMusicTrack_Init,
216         IDirectMusicStyleTrack_IDirectMusicTrack_InitPlay,
217         IDirectMusicStyleTrack_IDirectMusicTrack_EndPlay,
218         IDirectMusicStyleTrack_IDirectMusicTrack_Play,
219         IDirectMusicStyleTrack_IDirectMusicTrack_GetParam,
220         IDirectMusicStyleTrack_IDirectMusicTrack_SetParam,
221         IDirectMusicStyleTrack_IDirectMusicTrack_IsParamSupported,
222         IDirectMusicStyleTrack_IDirectMusicTrack_AddNotificationType,
223         IDirectMusicStyleTrack_IDirectMusicTrack_RemoveNotificationType,
224         IDirectMusicStyleTrack_IDirectMusicTrack_Clone,
225         IDirectMusicStyleTrack_IDirectMusicTrack_PlayEx,
226         IDirectMusicStyleTrack_IDirectMusicTrack_GetParamEx,
227         IDirectMusicStyleTrack_IDirectMusicTrack_SetParamEx,
228         IDirectMusicStyleTrack_IDirectMusicTrack_Compose,
229         IDirectMusicStyleTrack_IDirectMusicTrack_Join
230 };
231
232 /* IDirectMusicStyleTrack IPersistStream part: */
233 static HRESULT WINAPI IDirectMusicStyleTrack_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
234         ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
235         return IDirectMusicStyleTrack_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
236 }
237
238 static ULONG WINAPI IDirectMusicStyleTrack_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
239         ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
240         return IDirectMusicStyleTrack_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
241 }
242
243 static ULONG WINAPI IDirectMusicStyleTrack_IPersistStream_Release (LPPERSISTSTREAM iface) {
244   ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
245   return IDirectMusicStyleTrack_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
246 }
247
248 static HRESULT WINAPI IDirectMusicStyleTrack_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
249   ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
250   TRACE("(%p, %p)\n", This, pClassID);
251   memcpy(pClassID, &CLSID_DirectMusicStyleTrack, sizeof(CLSID));
252   return S_OK;
253 }
254
255 static HRESULT WINAPI IDirectMusicStyleTrack_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
256   ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
257   FIXME("(%p): stub, always S_FALSE\n", This);
258   return S_FALSE;
259 }
260
261 static HRESULT IDirectMusicStyleTrack_IPersistStream_ParseStyleRef (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
262   ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
263   DMUS_PRIVATE_CHUNK Chunk;
264   DWORD ListSize[3], ListCount[3];
265   LARGE_INTEGER liMove; /* used when skipping chunks */
266   HRESULT hr;
267
268   IDirectMusicObject* pObject = NULL;
269   LPDMUS_PRIVATE_STYLE_ITEM pNewItem = NULL;
270
271   if (pChunk->fccID != DMUS_FOURCC_STYLE_REF_LIST) {
272     ERR_(dmfile)(": %s chunk should be a STYLE list\n", debugstr_fourcc (pChunk->fccID));
273     return E_FAIL;
274   }
275
276   ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
277   ListCount[0] = 0;
278
279   do {
280     IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
281     ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
282     TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
283     switch (Chunk.fccID) { 
284     case DMUS_FOURCC_TIME_STAMP_CHUNK: {
285       TRACE_(dmfile)(": Time Stamp chunck\n");
286       pNewItem = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_STYLE_ITEM));
287       if (NULL == pNewItem) {
288         ERR(": no more memory\n");
289         return  E_OUTOFMEMORY;
290       }
291       IStream_Read (pStm, &pNewItem->dwTimeStamp, sizeof(DWORD), NULL);
292       TRACE_(dmfile)(" - dwTimeStamp: %lu\n", pNewItem->dwTimeStamp);
293       list_add_tail (&This->Items, &pNewItem->entry);      
294       break;
295     }
296     case FOURCC_LIST: {
297       IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
298       TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
299       ListSize[1] = Chunk.dwSize - sizeof(FOURCC);
300       ListCount[1] = 0;
301       switch (Chunk.fccID) { 
302         /**
303          * should be a DMRF (DirectMusic Reference) list @TODO
304          */
305       case DMUS_FOURCC_REF_LIST: {
306         FIXME_(dmfile)(": DMRF (DM References) list, not yet handled\n");
307         hr = IDirectMusicUtils_IPersistStream_ParseReference (iface,  &Chunk, pStm, &pObject);
308         if (FAILED(hr)) {
309           ERR(": could not load Reference\n");
310           return hr;
311         }
312         hr = IDirectMusicObject_QueryInterface(pObject, &IID_IDirectMusicStyle8, (LPVOID*)&pNewItem->pObject);
313         if (FAILED(hr)) {
314           ERR(": Reference not an IDirectMusicStyle, exiting\n");
315           exit(-1);
316           return hr;
317         }
318         IDirectMusicObject_Release(pObject);
319         break;                                          
320       }
321       default: {
322         TRACE_(dmfile)(": unknown (skipping)\n");
323         liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
324         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
325         break;                                          
326       }
327       } 
328       break;
329     }
330     default: {
331       TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
332       liMove.QuadPart = Chunk.dwSize;
333       IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
334       break;                                            
335     }
336     }
337     TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
338   } while (ListCount[0] < ListSize[0]);
339
340   return S_OK;
341 }
342
343 static HRESULT IDirectMusicStyleTrack_IPersistStream_ParseStyleTrackList (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
344
345   /*ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);*/
346   DMUS_PRIVATE_CHUNK Chunk;
347   DWORD ListSize[3], ListCount[3];
348   LARGE_INTEGER liMove; /* used when skipping chunks */
349   HRESULT hr;
350
351   if (pChunk->fccID != DMUS_FOURCC_STYLE_TRACK_LIST) {
352     ERR_(dmfile)(": %s chunk should be a STYLETRACK list\n", debugstr_fourcc (pChunk->fccID));
353     return E_FAIL;
354   }  
355
356   ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
357   ListCount[0] = 0;
358
359   do {
360     IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
361     ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
362     TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
363     switch (Chunk.fccID) { 
364     case FOURCC_LIST: { 
365       IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
366       TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
367       ListSize[1] = Chunk.dwSize - sizeof(FOURCC);
368       ListCount[1] = 0;
369       switch (Chunk.fccID) { 
370       case DMUS_FOURCC_STYLE_REF_LIST: {
371         TRACE_(dmfile)(": STYLE_REF list\n"); 
372         hr = IDirectMusicStyleTrack_IPersistStream_ParseStyleRef (iface, &Chunk, pStm);
373         if (FAILED(hr)) return hr;      
374         break;
375       }
376       default: {
377         TRACE_(dmfile)(": unknown (skipping)\n");
378         liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
379         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
380         break;                                          
381       }
382       }
383       break;
384     }
385     default: {
386       TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
387       liMove.QuadPart = Chunk.dwSize;
388       IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
389       break;            
390     }
391     }
392     TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
393   } while (ListCount[0] < ListSize[0]);
394
395   return S_OK;
396 }
397
398 static HRESULT WINAPI IDirectMusicStyleTrack_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
399   ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
400
401   DMUS_PRIVATE_CHUNK Chunk;
402   LARGE_INTEGER liMove;
403   HRESULT hr;
404  
405   FIXME("(%p, %p): Loading not fully implemented yet\n", This, pStm);
406
407   IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
408   TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
409   switch (Chunk.fccID) {        
410   case FOURCC_LIST: {
411     IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
412     TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
413     switch (Chunk.fccID) { 
414     case DMUS_FOURCC_STYLE_TRACK_LIST: {
415       TRACE_(dmfile)(": Chord track list\n");
416       hr = IDirectMusicStyleTrack_IPersistStream_ParseStyleTrackList (iface, &Chunk, pStm);
417       if (FAILED(hr)) return hr;
418       break;    
419     }
420     default: {
421       TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
422       liMove.QuadPart = Chunk.dwSize;
423       IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
424       return E_FAIL;
425     }
426     }
427     TRACE_(dmfile)(": reading finished\n");
428     break;
429   }
430   default: {
431     TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
432     liMove.QuadPart = Chunk.dwSize;
433     IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
434     return E_FAIL;
435   }
436   }
437
438   return S_OK;
439 }
440
441 static HRESULT WINAPI IDirectMusicStyleTrack_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
442   ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
443   FIXME("(%p): Saving not implemented yet\n", This);
444   return E_NOTIMPL;
445 }
446
447 static HRESULT WINAPI IDirectMusicStyleTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
448   ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
449   FIXME("(%p, %p): stub\n", This, pcbSize);
450   return E_NOTIMPL;
451 }
452
453 static const IPersistStreamVtbl DirectMusicStyleTrack_PersistStream_Vtbl = {
454   IDirectMusicStyleTrack_IPersistStream_QueryInterface,
455   IDirectMusicStyleTrack_IPersistStream_AddRef,
456   IDirectMusicStyleTrack_IPersistStream_Release,
457   IDirectMusicStyleTrack_IPersistStream_GetClassID,
458   IDirectMusicStyleTrack_IPersistStream_IsDirty,
459   IDirectMusicStyleTrack_IPersistStream_Load,
460   IDirectMusicStyleTrack_IPersistStream_Save,
461   IDirectMusicStyleTrack_IPersistStream_GetSizeMax
462 };
463
464 /* for ClassFactory */
465 HRESULT WINAPI DMUSIC_CreateDirectMusicStyleTrack (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
466   IDirectMusicStyleTrack* track;
467   
468   track = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicStyleTrack));
469   if (NULL == track) {
470     *ppobj = NULL;
471     return E_OUTOFMEMORY;
472   }
473   track->UnknownVtbl = &DirectMusicStyleTrack_Unknown_Vtbl;
474   track->TrackVtbl = &DirectMusicStyleTrack_Track_Vtbl;
475   track->PersistStreamVtbl = &DirectMusicStyleTrack_PersistStream_Vtbl;
476   track->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
477   DM_STRUCT_INIT(track->pDesc);
478   track->pDesc->dwValidData |= DMUS_OBJ_CLASS;
479   memcpy (&track->pDesc->guidClass, &CLSID_DirectMusicStyleTrack, sizeof (CLSID));
480   track->ref = 0; /* will be inited by QueryInterface */
481   list_init (&track->Items);
482   
483   return IDirectMusicStyleTrack_IUnknown_QueryInterface ((LPUNKNOWN)&track->UnknownVtbl, lpcGUID, ppobj);
484 }