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