mshtml: Create nsWineURI even if we don't have valid nsIURI.
[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, %lli, %lli, %lli, %ld, %p, %p, %ld): stub\n", This, pStateData, rtStart, rtEnd, rtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
181         return S_OK;
182 }
183
184 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_GetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, REFERENCE_TIME* prtNext, void* pParam, void* pStateData, DWORD dwFlags) {
185         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
186         FIXME("(%p, %s, %lli, %p, %p, %p, %ld): stub\n", This, debugstr_dmguid(rguidType), rtTime, prtNext, pParam, pStateData, dwFlags);
187         return S_OK;
188 }
189
190 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_SetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, void* pParam, void* pStateData, DWORD dwFlags) {
191         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
192         FIXME("(%p, %s, %lli, %p, %p, %ld): stub\n", This, debugstr_dmguid(rguidType), rtTime, pParam, pStateData, dwFlags);
193         return S_OK;
194 }
195
196 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_Compose (LPDIRECTMUSICTRACK8 iface, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
197         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
198         FIXME("(%p, %p, %ld, %p): stub\n", This, pContext, dwTrackGroup, ppResultTrack);
199         return S_OK;
200 }
201
202 static HRESULT WINAPI IDirectMusicStyleTrack_IDirectMusicTrack_Join (LPDIRECTMUSICTRACK8 iface, IDirectMusicTrack* pNewTrack, MUSIC_TIME mtJoin, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
203         ICOM_THIS_MULTI(IDirectMusicStyleTrack, TrackVtbl, iface);
204         FIXME("(%p, %p, %ld, %p, %ld, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
205         return S_OK;
206 }
207
208 static const IDirectMusicTrack8Vtbl DirectMusicStyleTrack_Track_Vtbl = {
209         IDirectMusicStyleTrack_IDirectMusicTrack_QueryInterface,
210         IDirectMusicStyleTrack_IDirectMusicTrack_AddRef,
211         IDirectMusicStyleTrack_IDirectMusicTrack_Release,
212         IDirectMusicStyleTrack_IDirectMusicTrack_Init,
213         IDirectMusicStyleTrack_IDirectMusicTrack_InitPlay,
214         IDirectMusicStyleTrack_IDirectMusicTrack_EndPlay,
215         IDirectMusicStyleTrack_IDirectMusicTrack_Play,
216         IDirectMusicStyleTrack_IDirectMusicTrack_GetParam,
217         IDirectMusicStyleTrack_IDirectMusicTrack_SetParam,
218         IDirectMusicStyleTrack_IDirectMusicTrack_IsParamSupported,
219         IDirectMusicStyleTrack_IDirectMusicTrack_AddNotificationType,
220         IDirectMusicStyleTrack_IDirectMusicTrack_RemoveNotificationType,
221         IDirectMusicStyleTrack_IDirectMusicTrack_Clone,
222         IDirectMusicStyleTrack_IDirectMusicTrack_PlayEx,
223         IDirectMusicStyleTrack_IDirectMusicTrack_GetParamEx,
224         IDirectMusicStyleTrack_IDirectMusicTrack_SetParamEx,
225         IDirectMusicStyleTrack_IDirectMusicTrack_Compose,
226         IDirectMusicStyleTrack_IDirectMusicTrack_Join
227 };
228
229 /* IDirectMusicStyleTrack IPersistStream part: */
230 static HRESULT WINAPI IDirectMusicStyleTrack_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
231         ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
232         return IDirectMusicStyleTrack_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
233 }
234
235 static ULONG WINAPI IDirectMusicStyleTrack_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
236         ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
237         return IDirectMusicStyleTrack_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
238 }
239
240 static ULONG WINAPI IDirectMusicStyleTrack_IPersistStream_Release (LPPERSISTSTREAM iface) {
241   ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
242   return IDirectMusicStyleTrack_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
243 }
244
245 static HRESULT WINAPI IDirectMusicStyleTrack_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
246   ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
247   TRACE("(%p, %p)\n", This, pClassID);
248   memcpy(pClassID, &CLSID_DirectMusicStyleTrack, sizeof(CLSID));
249   return S_OK;
250 }
251
252 static HRESULT WINAPI IDirectMusicStyleTrack_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
253   ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
254   FIXME("(%p): stub, always S_FALSE\n", This);
255   return S_FALSE;
256 }
257
258 static HRESULT IDirectMusicStyleTrack_IPersistStream_ParseStyleRef (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
259   ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
260   DMUS_PRIVATE_CHUNK Chunk;
261   DWORD ListSize[3], ListCount[3];
262   LARGE_INTEGER liMove; /* used when skipping chunks */
263   HRESULT hr;
264
265   IDirectMusicObject* pObject = NULL;
266   LPDMUS_PRIVATE_STYLE_ITEM pNewItem = NULL;
267
268   if (pChunk->fccID != DMUS_FOURCC_STYLE_REF_LIST) {
269     ERR_(dmfile)(": %s chunk should be a STYLE list\n", debugstr_fourcc (pChunk->fccID));
270     return E_FAIL;
271   }
272
273   ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
274   ListCount[0] = 0;
275
276   do {
277     IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
278     ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
279     TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
280     switch (Chunk.fccID) { 
281     case DMUS_FOURCC_TIME_STAMP_CHUNK: {
282       TRACE_(dmfile)(": Time Stamp chunck\n");
283       pNewItem = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_STYLE_ITEM));
284       if (NULL == pNewItem) {
285         ERR(": no more memory\n");
286         return  E_OUTOFMEMORY;
287       }
288       IStream_Read (pStm, &pNewItem->dwTimeStamp, sizeof(DWORD), NULL);
289       TRACE_(dmfile)(" - dwTimeStamp: %lu\n", pNewItem->dwTimeStamp);
290       list_add_tail (&This->Items, &pNewItem->entry);      
291       break;
292     }
293     case FOURCC_LIST: {
294       IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
295       TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
296       ListSize[1] = Chunk.dwSize - sizeof(FOURCC);
297       ListCount[1] = 0;
298       switch (Chunk.fccID) { 
299         /**
300          * should be a DMRF (DirectMusic Reference) list @TODO
301          */
302       case DMUS_FOURCC_REF_LIST: {
303         FIXME_(dmfile)(": DMRF (DM References) list, not yet handled\n");
304         hr = IDirectMusicUtils_IPersistStream_ParseReference (iface,  &Chunk, pStm, &pObject);
305         if (FAILED(hr)) {
306           ERR(": could not load Reference\n");
307           return hr;
308         }
309         hr = IDirectMusicObject_QueryInterface(pObject, &IID_IDirectMusicStyle8, (LPVOID*)&pNewItem->pObject);
310         if (FAILED(hr)) {
311           ERR(": Reference not an IDirectMusicStyle, exiting\n");
312           exit(-1);
313           return hr;
314         }
315         IDirectMusicObject_Release(pObject);
316         break;                                          
317       }
318       default: {
319         TRACE_(dmfile)(": unknown (skipping)\n");
320         liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
321         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
322         break;                                          
323       }
324       } 
325       break;
326     }
327     default: {
328       TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
329       liMove.QuadPart = Chunk.dwSize;
330       IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
331       break;                                            
332     }
333     }
334     TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
335   } while (ListCount[0] < ListSize[0]);
336
337   return S_OK;
338 }
339
340 static HRESULT IDirectMusicStyleTrack_IPersistStream_ParseStyleTrackList (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
341
342   /*ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);*/
343   DMUS_PRIVATE_CHUNK Chunk;
344   DWORD ListSize[3], ListCount[3];
345   LARGE_INTEGER liMove; /* used when skipping chunks */
346   HRESULT hr;
347
348   if (pChunk->fccID != DMUS_FOURCC_STYLE_TRACK_LIST) {
349     ERR_(dmfile)(": %s chunk should be a STYLETRACK list\n", debugstr_fourcc (pChunk->fccID));
350     return E_FAIL;
351   }  
352
353   ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
354   ListCount[0] = 0;
355
356   do {
357     IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
358     ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
359     TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
360     switch (Chunk.fccID) { 
361     case FOURCC_LIST: { 
362       IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
363       TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
364       ListSize[1] = Chunk.dwSize - sizeof(FOURCC);
365       ListCount[1] = 0;
366       switch (Chunk.fccID) { 
367       case DMUS_FOURCC_STYLE_REF_LIST: {
368         TRACE_(dmfile)(": STYLE_REF list\n"); 
369         hr = IDirectMusicStyleTrack_IPersistStream_ParseStyleRef (iface, &Chunk, pStm);
370         if (FAILED(hr)) return hr;      
371         break;
372       }
373       default: {
374         TRACE_(dmfile)(": unknown (skipping)\n");
375         liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
376         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
377         break;                                          
378       }
379       }
380       break;
381     }
382     default: {
383       TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
384       liMove.QuadPart = Chunk.dwSize;
385       IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
386       break;            
387     }
388     }
389     TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
390   } while (ListCount[0] < ListSize[0]);
391
392   return S_OK;
393 }
394
395 static HRESULT WINAPI IDirectMusicStyleTrack_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
396   ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
397
398   DMUS_PRIVATE_CHUNK Chunk;
399   LARGE_INTEGER liMove;
400   HRESULT hr;
401  
402   FIXME("(%p, %p): Loading not fully implemented yet\n", This, pStm);
403
404   IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
405   TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
406   switch (Chunk.fccID) {        
407   case FOURCC_LIST: {
408     IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
409     TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
410     switch (Chunk.fccID) { 
411     case DMUS_FOURCC_STYLE_TRACK_LIST: {
412       TRACE_(dmfile)(": Chord track list\n");
413       hr = IDirectMusicStyleTrack_IPersistStream_ParseStyleTrackList (iface, &Chunk, pStm);
414       if (FAILED(hr)) return hr;
415       break;    
416     }
417     default: {
418       TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
419       liMove.QuadPart = Chunk.dwSize;
420       IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
421       return E_FAIL;
422     }
423     }
424     TRACE_(dmfile)(": reading finished\n");
425     break;
426   }
427   default: {
428     TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
429     liMove.QuadPart = Chunk.dwSize;
430     IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
431     return E_FAIL;
432   }
433   }
434
435   return S_OK;
436 }
437
438 static HRESULT WINAPI IDirectMusicStyleTrack_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
439   ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
440   FIXME("(%p): Saving not implemented yet\n", This);
441   return E_NOTIMPL;
442 }
443
444 static HRESULT WINAPI IDirectMusicStyleTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
445   ICOM_THIS_MULTI(IDirectMusicStyleTrack, PersistStreamVtbl, iface);
446   FIXME("(%p, %p): stub\n", This, pcbSize);
447   return E_NOTIMPL;
448 }
449
450 static const IPersistStreamVtbl DirectMusicStyleTrack_PersistStream_Vtbl = {
451   IDirectMusicStyleTrack_IPersistStream_QueryInterface,
452   IDirectMusicStyleTrack_IPersistStream_AddRef,
453   IDirectMusicStyleTrack_IPersistStream_Release,
454   IDirectMusicStyleTrack_IPersistStream_GetClassID,
455   IDirectMusicStyleTrack_IPersistStream_IsDirty,
456   IDirectMusicStyleTrack_IPersistStream_Load,
457   IDirectMusicStyleTrack_IPersistStream_Save,
458   IDirectMusicStyleTrack_IPersistStream_GetSizeMax
459 };
460
461 /* for ClassFactory */
462 HRESULT WINAPI DMUSIC_CreateDirectMusicStyleTrack (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
463   IDirectMusicStyleTrack* track;
464   
465   track = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicStyleTrack));
466   if (NULL == track) {
467     *ppobj = NULL;
468     return E_OUTOFMEMORY;
469   }
470   track->UnknownVtbl = &DirectMusicStyleTrack_Unknown_Vtbl;
471   track->TrackVtbl = &DirectMusicStyleTrack_Track_Vtbl;
472   track->PersistStreamVtbl = &DirectMusicStyleTrack_PersistStream_Vtbl;
473   track->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
474   DM_STRUCT_INIT(track->pDesc);
475   track->pDesc->dwValidData |= DMUS_OBJ_CLASS;
476   memcpy (&track->pDesc->guidClass, &CLSID_DirectMusicStyleTrack, sizeof (CLSID));
477   track->ref = 0; /* will be inited by QueryInterface */
478   list_init (&track->Items);
479   
480   return IDirectMusicStyleTrack_IUnknown_QueryInterface ((LPUNKNOWN)&track->UnknownVtbl, lpcGUID, ppobj);
481 }