dwrite: Stub for CreateMonitorRenderingParams().
[wine] / dlls / dmime / segtriggertrack.c
1 /* IDirectMusicSegTriggerTrack Implementation
2  *
3  * Copyright (C) 2003-2004 Rok Mandeljc
4  * Copyright (C) 2003-2004 Raphael Junqueira
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "dmime_private.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
24 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
25
26 /*****************************************************************************
27  * IDirectMusicSegTriggerTrack implementation
28  */
29 /* IDirectMusicSegTriggerTrack IUnknown part: */
30 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
31         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, UnknownVtbl, iface);
32         TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
33
34         if (IsEqualIID (riid, &IID_IUnknown)) {
35                 *ppobj = &This->UnknownVtbl;
36                 IUnknown_AddRef (iface);
37                 return S_OK;
38         } else if (IsEqualIID (riid, &IID_IDirectMusicTrack)
39           || IsEqualIID (riid, &IID_IDirectMusicTrack8)) {
40                 *ppobj = (LPDIRECTMUSICTRACK8)&This->TrackVtbl;
41                 IUnknown_AddRef (iface);
42                 return S_OK;
43         } else if (IsEqualIID (riid, &IID_IPersistStream)) {
44                 *ppobj = &This->PersistStreamVtbl;
45                 IUnknown_AddRef (iface);
46                 return S_OK;
47         }
48         
49         WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
50         return E_NOINTERFACE;
51 }
52
53 static ULONG WINAPI IDirectMusicSegTriggerTrack_IUnknown_AddRef (LPUNKNOWN iface) {
54         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, UnknownVtbl, iface);
55         ULONG ref = InterlockedIncrement(&This->ref);
56
57         TRACE("(%p): AddRef from %d\n", This, ref - 1);
58
59         DMIME_LockModule();
60
61         return ref;
62 }
63
64 static ULONG WINAPI IDirectMusicSegTriggerTrack_IUnknown_Release (LPUNKNOWN iface) {
65         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, UnknownVtbl, iface);
66         ULONG ref = InterlockedDecrement(&This->ref);
67         TRACE("(%p): ReleaseRef to %d\n", This, ref);
68         
69         if (ref == 0) {
70                 HeapFree(GetProcessHeap(), 0, This);
71         }
72
73         DMIME_UnlockModule();
74         
75         return ref;
76 }
77
78 static const IUnknownVtbl DirectMusicSegTriggerTrack_Unknown_Vtbl = {
79         IDirectMusicSegTriggerTrack_IUnknown_QueryInterface,
80         IDirectMusicSegTriggerTrack_IUnknown_AddRef,
81         IDirectMusicSegTriggerTrack_IUnknown_Release
82 };
83
84 /* IDirectMusicSegTriggerTrack IDirectMusicTrack8 part: */
85 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_QueryInterface (LPDIRECTMUSICTRACK8 iface, REFIID riid, LPVOID *ppobj) {
86         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
87         return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
88 }
89
90 static ULONG WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_AddRef (LPDIRECTMUSICTRACK8 iface) {
91         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
92         return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
93 }
94
95 static ULONG WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_Release (LPDIRECTMUSICTRACK8 iface) {
96         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
97         return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
98 }
99
100 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_Init (LPDIRECTMUSICTRACK8 iface, IDirectMusicSegment* pSegment)
101 {
102         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
103         FIXME("(%p, %p): stub\n", This, pSegment);
104         return S_OK;
105 }
106
107 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_InitPlay (LPDIRECTMUSICTRACK8 iface, IDirectMusicSegmentState* pSegmentState, IDirectMusicPerformance* pPerformance, void** ppStateData, DWORD dwVirtualTrack8ID, DWORD dwFlags)
108 {
109         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
110         FIXME("(%p, %p, %p, %p, %d, %d): stub\n", This, pSegmentState, pPerformance, ppStateData, dwVirtualTrack8ID, dwFlags);
111         return S_OK;
112 }
113
114 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_EndPlay (LPDIRECTMUSICTRACK8 iface, void* pStateData)
115 {
116         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
117         FIXME("(%p, %p): stub\n", This, pStateData);
118         return S_OK;
119 }
120
121 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_Play (LPDIRECTMUSICTRACK8 iface, void* pStateData, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, MUSIC_TIME mtOffset, DWORD dwFlags, IDirectMusicPerformance* pPerf, IDirectMusicSegmentState* pSegSt, DWORD dwVirtualID)
122 {
123         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
124         FIXME("(%p, %p, %d, %d, %d, %d, %p, %p, %d): stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
125         return S_OK;
126 }
127
128 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_GetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
129         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
130         FIXME("(%p, %s, %d, %p, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pmtNext, pParam);
131         return S_OK;
132 }
133
134 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_SetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, void* pParam) {
135         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
136         FIXME("(%p, %s, %d, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pParam);
137         return S_OK;
138 }
139
140 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_IsParamSupported (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType) {
141         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
142
143         TRACE("(%p, %s)\n", This, debugstr_dmguid(rguidType));
144         /* didn't find any params */
145         TRACE("param unsupported\n");
146         return DMUS_E_TYPE_UNSUPPORTED;
147 }
148
149 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_AddNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
150         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
151         FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
152         return S_OK;
153 }
154
155 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_RemoveNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
156         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
157         FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
158         return S_OK;
159 }
160
161 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_Clone (LPDIRECTMUSICTRACK8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicTrack** ppTrack) {
162         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
163         FIXME("(%p, %d, %d, %p): stub\n", This, mtStart, mtEnd, ppTrack);
164         return S_OK;
165 }
166
167 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_PlayEx (LPDIRECTMUSICTRACK8 iface, void* pStateData, REFERENCE_TIME rtStart, REFERENCE_TIME rtEnd, REFERENCE_TIME rtOffset, DWORD dwFlags, IDirectMusicPerformance* pPerf, IDirectMusicSegmentState* pSegSt, DWORD dwVirtualID) {
168         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
169         FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %d, %p, %p, %d): stub\n", This, pStateData, wine_dbgstr_longlong(rtStart),
170             wine_dbgstr_longlong(rtEnd), wine_dbgstr_longlong(rtOffset), dwFlags, pPerf, pSegSt, dwVirtualID);
171         return S_OK;
172 }
173
174 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_GetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, REFERENCE_TIME* prtNext, void* pParam, void* pStateData, DWORD dwFlags) {
175         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
176         FIXME("(%p, %s, 0x%s, %p, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
177             wine_dbgstr_longlong(rtTime), prtNext, pParam, pStateData, dwFlags);
178         return S_OK;
179 }
180
181 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_SetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, void* pParam, void* pStateData, DWORD dwFlags) {
182         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
183         FIXME("(%p, %s, 0x%s, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
184             wine_dbgstr_longlong(rtTime), pParam, pStateData, dwFlags);
185         return S_OK;
186 }
187
188 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_Compose (LPDIRECTMUSICTRACK8 iface, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
189         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
190         FIXME("(%p, %p, %d, %p): stub\n", This, pContext, dwTrackGroup, ppResultTrack);
191         return S_OK;
192 }
193
194 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IDirectMusicTrack_Join (LPDIRECTMUSICTRACK8 iface, IDirectMusicTrack* pNewTrack, MUSIC_TIME mtJoin, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
195         ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, TrackVtbl, iface);
196         FIXME("(%p, %p, %d, %p, %d, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
197         return S_OK;
198 }
199
200 static const IDirectMusicTrack8Vtbl DirectMusicSegTriggerTrack_Track_Vtbl = {
201         IDirectMusicSegTriggerTrack_IDirectMusicTrack_QueryInterface,
202         IDirectMusicSegTriggerTrack_IDirectMusicTrack_AddRef,
203         IDirectMusicSegTriggerTrack_IDirectMusicTrack_Release,
204         IDirectMusicSegTriggerTrack_IDirectMusicTrack_Init,
205         IDirectMusicSegTriggerTrack_IDirectMusicTrack_InitPlay,
206         IDirectMusicSegTriggerTrack_IDirectMusicTrack_EndPlay,
207         IDirectMusicSegTriggerTrack_IDirectMusicTrack_Play,
208         IDirectMusicSegTriggerTrack_IDirectMusicTrack_GetParam,
209         IDirectMusicSegTriggerTrack_IDirectMusicTrack_SetParam,
210         IDirectMusicSegTriggerTrack_IDirectMusicTrack_IsParamSupported,
211         IDirectMusicSegTriggerTrack_IDirectMusicTrack_AddNotificationType,
212         IDirectMusicSegTriggerTrack_IDirectMusicTrack_RemoveNotificationType,
213         IDirectMusicSegTriggerTrack_IDirectMusicTrack_Clone,
214         IDirectMusicSegTriggerTrack_IDirectMusicTrack_PlayEx,
215         IDirectMusicSegTriggerTrack_IDirectMusicTrack_GetParamEx,
216         IDirectMusicSegTriggerTrack_IDirectMusicTrack_SetParamEx,
217         IDirectMusicSegTriggerTrack_IDirectMusicTrack_Compose,
218         IDirectMusicSegTriggerTrack_IDirectMusicTrack_Join
219 };
220
221 /* IDirectMusicSegTriggerTrack IPersistStream part: */
222 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
223   ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, PersistStreamVtbl, iface);
224   return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
225 }
226
227 static ULONG WINAPI IDirectMusicSegTriggerTrack_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
228   ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, PersistStreamVtbl, iface);
229   return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
230 }
231
232 static ULONG WINAPI IDirectMusicSegTriggerTrack_IPersistStream_Release (LPPERSISTSTREAM iface) {
233   ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, PersistStreamVtbl, iface);
234   return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
235 }
236
237 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
238   ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
239   TRACE("(%p, %p)\n", This, pClassID);
240   *pClassID = CLSID_DirectMusicSegTriggerTrack;
241   return S_OK;
242 }
243
244 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
245   ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, PersistStreamVtbl, iface);
246   FIXME("(%p): stub, always S_FALSE\n", This);
247   return S_FALSE;
248 }
249
250 static HRESULT IDirectMusicSegTriggerTrack_IPersistStream_ParseSegment (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
251   ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, PersistStreamVtbl, iface);
252   DMUS_PRIVATE_CHUNK Chunk;
253   DWORD ListSize[3], ListCount[3];
254   LARGE_INTEGER liMove; /* used when skipping chunks */
255   HRESULT hr;
256
257   IDirectMusicObject* pObject = NULL;
258   LPDMUS_PRIVATE_SEGMENT_ITEM pNewItem = NULL;
259
260   if (pChunk->fccID != DMUS_FOURCC_SEGMENT_LIST) {
261     ERR_(dmfile)(": %s chunk should be a SEGMENT list\n", debugstr_fourcc (pChunk->fccID));
262     return E_FAIL;
263   }
264
265   ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
266   ListCount[0] = 0;
267
268   do {
269     IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
270     ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
271     TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
272     switch (Chunk.fccID) { 
273     case DMUS_FOURCC_SEGMENTITEM_CHUNK: {
274       TRACE_(dmfile)(": segment item chunk\n"); 
275       /** alloc new item entry */
276       pNewItem = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_SEGMENT_ITEM));
277       if (!pNewItem) {
278         ERR(": no more memory\n");
279         return  E_OUTOFMEMORY;
280       }
281       IStream_Read (pStm, &pNewItem->header, sizeof(DMUS_IO_SEGMENT_ITEM_HEADER), NULL);
282       TRACE_(dmfile)(" - lTimePhysical: %u\n", pNewItem->header.lTimeLogical);
283       TRACE_(dmfile)(" - lTimePhysical: %u\n", pNewItem->header.lTimePhysical);
284       TRACE_(dmfile)(" - dwPlayFlags: 0x%08x\n", pNewItem->header.dwPlayFlags);
285       TRACE_(dmfile)(" - dwFlags: 0x%08x\n", pNewItem->header.dwFlags);
286       list_add_tail (&This->Items, &pNewItem->entry);
287       break;
288     }
289     case DMUS_FOURCC_SEGMENTITEMNAME_CHUNK: {
290       TRACE_(dmfile)(": segment item name chunk\n");
291       if (!pNewItem) {
292         ERR(": pNewItem not allocated, bad chunk order?\n");
293         return E_FAIL;
294       }
295       IStream_Read (pStm, pNewItem->wszName, Chunk.dwSize, NULL);
296       TRACE_(dmfile)(" - name: %s\n", debugstr_w(pNewItem->wszName));
297       break;
298     }
299     case FOURCC_LIST: {
300       IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
301       TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
302       ListSize[1] = Chunk.dwSize - sizeof(FOURCC);
303       ListCount[1] = 0;
304       switch (Chunk.fccID) { 
305       case DMUS_FOURCC_REF_LIST: {
306         FIXME_(dmfile)(": DMRF (DM References) list\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         if (!pNewItem) {
313           ERR(": pNewItem not allocated, bad chunk order?\n");
314           return E_FAIL;
315         }
316         pNewItem->pObject = pObject;
317         break;                                          
318       }
319       default: {
320         TRACE_(dmfile)(": unknown (skipping)\n");
321         liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
322         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
323         break;                                          
324       }
325       } 
326       break;
327     }
328     default: {
329       TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
330       liMove.QuadPart = Chunk.dwSize;
331       IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
332       break;                                            
333     }
334     }
335     TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
336   } while (ListCount[0] < ListSize[0]);
337   
338   return S_OK;
339 }
340
341 static HRESULT IDirectMusicSegTriggerTrack_IPersistStream_ParseSegmentsList (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
342   /*ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, PersistStreamVtbl, iface);*/
343   HRESULT hr = E_FAIL;
344   DMUS_PRIVATE_CHUNK Chunk;
345   DWORD ListSize[3], ListCount[3];
346   LARGE_INTEGER liMove; /* used when skipping chunks */
347
348   if (pChunk->fccID != DMUS_FOURCC_SEGMENTS_LIST) {
349     ERR_(dmfile)(": %s chunk should be a SEGMENTS 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 = %d)", 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_SEGMENT_LIST: {
368         TRACE_(dmfile)(": SEGMENT list\n"); 
369         hr = IDirectMusicSegTriggerTrack_IPersistStream_ParseSegment (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 (irrelevant & 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] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
390   } while (ListCount[0] < ListSize[0]);
391   
392   return S_OK;
393 }
394
395 static HRESULT IDirectMusicSegTriggerTrack_IPersistStream_ParseSegTrackList (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
396   /*ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, PersistStreamVtbl, iface);*/
397   HRESULT hr = E_FAIL;
398   DMUS_PRIVATE_CHUNK Chunk;
399   DWORD ListSize[3], ListCount[3];
400   LARGE_INTEGER liMove; /* used when skipping chunks */
401
402   if (pChunk->fccID != DMUS_FOURCC_SEGTRACK_LIST) {
403     ERR_(dmfile)(": %s chunk should be a SEGTRACK list\n", debugstr_fourcc (pChunk->fccID));
404     return E_FAIL;
405   }  
406
407   ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
408   ListCount[0] = 0;
409
410   do {
411     IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
412     ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
413     TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
414     switch (Chunk.fccID) { 
415     case DMUS_FOURCC_SEGTRACK_CHUNK: {
416       TRACE_(dmfile)(": segment trigger track chunk\n");
417       liMove.QuadPart = Chunk.dwSize;
418       IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
419       break;
420     }
421     case FOURCC_LIST: {
422       IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
423       TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
424       ListSize[1] = Chunk.dwSize - sizeof(FOURCC);
425       ListCount[1] = 0;
426       switch (Chunk.fccID) { 
427       case DMUS_FOURCC_SEGMENTS_LIST: {
428         TRACE_(dmfile)(": SEGMENTS list\n"); 
429         hr = IDirectMusicSegTriggerTrack_IPersistStream_ParseSegmentsList (iface, &Chunk, pStm);
430         if (FAILED(hr)) return hr;
431         break;
432       }
433       default: {
434         TRACE_(dmfile)(": unknown (skipping)\n");
435         liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
436         IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
437         break;                                          
438       }
439       } 
440       break;
441     }
442     default: {
443       TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
444       liMove.QuadPart = Chunk.dwSize;
445       IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
446       break;                                            
447     }
448     }
449     TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
450   } while (ListCount[0] < ListSize[0]);
451
452   return S_OK;
453 }
454
455 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
456   ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, PersistStreamVtbl, iface);
457
458   DMUS_PRIVATE_CHUNK Chunk;
459   LARGE_INTEGER liMove;
460   HRESULT hr;
461
462   TRACE("(%p, %p): Loading\n", This, pStm);
463   
464 #if 1
465   IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
466   TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
467   switch (Chunk.fccID) {        
468   case FOURCC_LIST: {
469     IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
470     TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
471     switch (Chunk.fccID) {
472     case DMUS_FOURCC_SEGTRACK_LIST: {
473       TRACE_(dmfile)(": segment trigger track list\n");
474       hr = IDirectMusicSegTriggerTrack_IPersistStream_ParseSegTrackList (iface, &Chunk, pStm);
475       if (FAILED(hr)) return hr;
476       break;    
477     }
478     default: {
479       TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
480       liMove.QuadPart = Chunk.dwSize;
481       IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
482       return E_FAIL;
483     }
484     }
485     TRACE_(dmfile)(": reading finished\n");
486     break;
487   }
488   default: {
489     TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
490     liMove.QuadPart = Chunk.dwSize;
491     IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
492     return E_FAIL;
493   }
494   }  
495 #endif
496
497   return S_OK;
498 }
499
500 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
501   ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, PersistStreamVtbl, iface);
502   FIXME("(%p): Saving not implemented yet\n", This);
503   return E_NOTIMPL;
504 }
505
506 static HRESULT WINAPI IDirectMusicSegTriggerTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
507   ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, PersistStreamVtbl, iface);
508   FIXME("(%p, %p): stub\n", This, pcbSize);
509   return E_NOTIMPL;
510 }
511
512 static const IPersistStreamVtbl DirectMusicSegTriggerTrack_PersistStream_Vtbl = {
513   IDirectMusicSegTriggerTrack_IPersistStream_QueryInterface,
514   IDirectMusicSegTriggerTrack_IPersistStream_AddRef,
515   IDirectMusicSegTriggerTrack_IPersistStream_Release,
516   IDirectMusicSegTriggerTrack_IPersistStream_GetClassID,
517   IDirectMusicSegTriggerTrack_IPersistStream_IsDirty,
518   IDirectMusicSegTriggerTrack_IPersistStream_Load,
519   IDirectMusicSegTriggerTrack_IPersistStream_Save,
520   IDirectMusicSegTriggerTrack_IPersistStream_GetSizeMax
521 };
522
523 /* for ClassFactory */
524 HRESULT WINAPI DMUSIC_CreateDirectMusicSegTriggerTrack (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
525   IDirectMusicSegTriggerTrack* track;
526         
527   track = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSegTriggerTrack));
528   if (NULL == track) {
529     *ppobj = NULL;
530     return E_OUTOFMEMORY;
531   }
532   track->UnknownVtbl = &DirectMusicSegTriggerTrack_Unknown_Vtbl;
533   track->TrackVtbl = &DirectMusicSegTriggerTrack_Track_Vtbl;
534   track->PersistStreamVtbl = &DirectMusicSegTriggerTrack_PersistStream_Vtbl;
535   track->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
536   DM_STRUCT_INIT(track->pDesc);
537   track->pDesc->dwValidData |= DMUS_OBJ_CLASS;
538   track->pDesc->guidClass = CLSID_DirectMusicSegTriggerTrack;
539   track->ref = 0; /* will be inited by QueryInterface */
540   list_init (&track->Items);
541
542   return IDirectMusicSegTriggerTrack_IUnknown_QueryInterface ((LPUNKNOWN)&track->UnknownVtbl, lpcGUID, ppobj);
543 }