msvidc32: Add Ukrainian translations.
[wine] / dlls / dmime / segment.c
CommitLineData
473c5657 1/* IDirectMusicSegment8 Implementation
61035c8f 2 *
0382ea1d 3 * Copyright (C) 2003-2004 Rok Mandeljc
a4215336 4 * Copyright (C) 2003-2004 Raphael Junqueira
61035c8f 5 *
7718d2bd
AJ
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.
61035c8f
RM
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
7718d2bd
AJ
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
61035c8f 15 *
7718d2bd
AJ
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
61035c8f
RM
19 */
20
473c5657 21#include "dmime_private.h"
61035c8f 22
df167d17
RM
23WINE_DEFAULT_DEBUG_CHANNEL(dmime);
24WINE_DECLARE_DEBUG_CHANNEL(dmfile);
61035c8f 25
df167d17 26/*****************************************************************************
0382ea1d 27 * IDirectMusicSegmentImpl implementation
df167d17 28 */
0382ea1d 29/* IDirectMusicSegment IUnknown part: */
06e23dad 30static HRESULT WINAPI IDirectMusicSegment8Impl_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
0382ea1d 31 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
b26d65bb 32 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
0382ea1d
RM
33
34 if (IsEqualIID (riid, &IID_IUnknown)) {
49177a09 35 *ppobj = &This->UnknownVtbl;
06e23dad 36 IUnknown_AddRef (iface);
0382ea1d
RM
37 return S_OK;
38 } else if (IsEqualIID (riid, &IID_IDirectMusicSegment)
39 || IsEqualIID (riid, &IID_IDirectMusicSegment2)
40 || IsEqualIID (riid, &IID_IDirectMusicSegment8)) {
49177a09 41 *ppobj = &This->SegmentVtbl;
06e23dad 42 IUnknown_AddRef (iface);
0382ea1d
RM
43 return S_OK;
44 } else if (IsEqualIID (riid, &IID_IDirectMusicObject)) {
49177a09 45 *ppobj = &This->ObjectVtbl;
06e23dad 46 IUnknown_AddRef (iface);
0382ea1d
RM
47 return S_OK;
48 } else if (IsEqualIID (riid, &IID_IPersistStream)) {
49177a09 49 *ppobj = &This->PersistStreamVtbl;
06e23dad 50 IUnknown_AddRef (iface);
a4a5e9ae 51 return S_OK;
61035c8f 52 }
df167d17 53
b26d65bb 54 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
61035c8f
RM
55 return E_NOINTERFACE;
56}
57
06e23dad 58static ULONG WINAPI IDirectMusicSegment8Impl_IUnknown_AddRef (LPUNKNOWN iface) {
0382ea1d 59 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
3da8524b
PV
60 ULONG ref = InterlockedIncrement(&This->ref);
61
891e0166 62 TRACE("(%p): AddRef from %d\n", This, ref - 1);
3da8524b 63
1727eb48
JH
64 DMIME_LockModule();
65
3da8524b 66 return ref;
61035c8f
RM
67}
68
ff536fbe 69static ULONG WINAPI IDirectMusicSegment8Impl_IUnknown_Release (LPUNKNOWN iface) {
0382ea1d 70 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
3da8524b 71 ULONG ref = InterlockedDecrement(&This->ref);
891e0166 72 TRACE("(%p): ReleaseRef to %d\n", This, ref);
1727eb48 73
df167d17 74 if (ref == 0) {
61035c8f
RM
75 HeapFree(GetProcessHeap(), 0, This);
76 }
1727eb48
JH
77
78 DMIME_UnlockModule();
79
61035c8f
RM
80 return ref;
81}
82
247246ed 83static const IUnknownVtbl DirectMusicSegment8_Unknown_Vtbl = {
c77788b5
RJ
84 IDirectMusicSegment8Impl_IUnknown_QueryInterface,
85 IDirectMusicSegment8Impl_IUnknown_AddRef,
86 IDirectMusicSegment8Impl_IUnknown_Release
0382ea1d 87};
a4a5e9ae 88
0382ea1d 89/* IDirectMusicSegmentImpl IDirectMusicSegment part: */
06e23dad 90static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_QueryInterface (LPDIRECTMUSICSEGMENT8 iface, REFIID riid, LPVOID *ppobj) {
c77788b5 91 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
06e23dad 92 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
61035c8f
RM
93}
94
06e23dad 95static ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef (LPDIRECTMUSICSEGMENT8 iface) {
c77788b5 96 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
06e23dad 97 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
0382ea1d 98}
a4a5e9ae 99
ff536fbe 100static ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Release (LPDIRECTMUSICSEGMENT8 iface) {
c77788b5 101 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
06e23dad 102 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
0382ea1d 103}
a4a5e9ae 104
ff536fbe 105static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLength (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtLength) {
c77788b5
RJ
106 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
107 TRACE("(%p, %p)\n", This, pmtLength);
108 if (NULL == pmtLength) {
109 return E_POINTER;
110 }
111 *pmtLength = This->header.mtLength;
112 return S_OK;
61035c8f
RM
113}
114
ff536fbe 115static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLength (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtLength) {
c77788b5 116 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
4bfb33ec 117 TRACE("(%p, %d)\n", This, mtLength);
c77788b5
RJ
118 This->header.mtLength = mtLength;
119 return S_OK;
61035c8f
RM
120}
121
ff536fbe 122static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetRepeats (LPDIRECTMUSICSEGMENT8 iface, DWORD* pdwRepeats) {
c77788b5
RJ
123 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
124 TRACE("(%p, %p)\n", This, pdwRepeats);
125 if (NULL == pdwRepeats) {
126 return E_POINTER;
127 }
128 *pdwRepeats = This->header.dwRepeats;
129 return S_OK;
61035c8f
RM
130}
131
ff536fbe 132static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetRepeats (LPDIRECTMUSICSEGMENT8 iface, DWORD dwRepeats) {
c77788b5 133 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
891e0166 134 TRACE("(%p, %d)\n", This, dwRepeats);
c77788b5
RJ
135 This->header.dwRepeats = dwRepeats;
136 return S_OK;
61035c8f
RM
137}
138
ff536fbe 139static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetDefaultResolution (LPDIRECTMUSICSEGMENT8 iface, DWORD* pdwResolution) {
c77788b5
RJ
140 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
141 TRACE("(%p, %p)\n", This, pdwResolution);
142 if (NULL == pdwResolution) {
143 return E_POINTER;
144 }
145 *pdwResolution = This->header.dwResolution;
146 return S_OK;
61035c8f
RM
147}
148
ff536fbe 149static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetDefaultResolution (LPDIRECTMUSICSEGMENT8 iface, DWORD dwResolution) {
c77788b5 150 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
891e0166 151 TRACE("(%p, %d)\n", This, dwResolution);
c77788b5
RJ
152 This->header.dwResolution = dwResolution;
153 return S_OK;
0382ea1d 154}
a4a5e9ae 155
ff536fbe 156static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, IDirectMusicTrack** ppTrack) {
c77788b5 157 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
8d954393
RJ
158
159 CLSID pIt_clsid;
160 struct list* pEntry = NULL;
161 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
162 IPersistStream* pCLSIDStream = NULL;
163 HRESULT hr = S_OK;
164
891e0166 165 TRACE("(%p, %s, %d, 0x%x, %p)\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, ppTrack);
8d954393
RJ
166
167 if (NULL == ppTrack) {
168 return E_POINTER;
169 }
170
171 LIST_FOR_EACH (pEntry, &This->Tracks) {
172 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
891e0166 173 TRACE(" - %p -> 0x%x,%p\n", pIt, pIt->dwGroupBits, pIt->pTrack);
8d954393
RJ
174 if (0xFFFFFFFF != dwGroupBits && 0 == (pIt->dwGroupBits & dwGroupBits)) continue ;
175 if (FALSE == IsEqualGUID(&GUID_NULL, rguidType)) {
176 /**
177 * it rguidType is not null we must check if CLSID are equals
06d429d6 178 * and the unique way to get it is using IPersistStream Interface
8d954393
RJ
179 */
180 hr = IDirectMusicTrack_QueryInterface(pIt->pTrack, &IID_IPersistStream, (void**) &pCLSIDStream);
181 if (FAILED(hr)) {
182 ERR("(%p): object %p don't implement IPersistStream Interface. Expect a crash (critical problem)\n", This, pIt->pTrack);
183 continue ;
184 }
185 hr = IPersistStream_GetClassID(pCLSIDStream, &pIt_clsid);
186 IPersistStream_Release(pCLSIDStream); pCLSIDStream = NULL;
187 if (FAILED(hr)) {
188 ERR("(%p): non-implemented GetClassID for object %p\n", This, pIt->pTrack);
189 continue ;
190 }
191 TRACE(" - %p -> %s\n", pIt, debugstr_dmguid(&pIt_clsid));
192 if (FALSE == IsEqualGUID(&pIt_clsid, rguidType)) continue ;
193 }
194 if (0 == dwIndex) {
195 *ppTrack = pIt->pTrack;
196 IDirectMusicTrack_AddRef(*ppTrack);
197 return S_OK;
198 }
199 --dwIndex;
200 }
201 return DMUS_E_NOT_FOUND;
61035c8f
RM
202}
203
ff536fbe 204static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrackGroup (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack, DWORD* pdwGroupBits) {
c77788b5 205 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
8d954393
RJ
206
207 struct list* pEntry = NULL;
208 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
209
210 TRACE("(%p, %p, %p)\n", This, pTrack, pdwGroupBits);
211
212 if (NULL == pdwGroupBits) {
213 return E_POINTER;
214 }
215
216 LIST_FOR_EACH (pEntry, &This->Tracks) {
217 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
891e0166 218 TRACE(" - %p -> %d,%p\n", pIt, pIt->dwGroupBits, pIt->pTrack);
8d954393
RJ
219 if (NULL != pIt && pIt->pTrack == pTrack) {
220 *pdwGroupBits = pIt->dwGroupBits;
221 return S_OK;
222 }
223 }
224
225 return DMUS_E_NOT_FOUND;
61035c8f
RM
226}
227
ff536fbe 228static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack, DWORD dwGroupBits) {
c77788b5 229 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
858557f4 230
858557f4 231 DWORD i = 0;
8d954393 232 struct list* pEntry = NULL;
858557f4 233 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
8d954393 234 LPDMUS_PRIVATE_SEGMENT_TRACK pNewSegTrack = NULL;
858557f4 235
891e0166 236 TRACE("(%p, %p, %d)\n", This, pTrack, dwGroupBits);
858557f4
RJ
237
238 LIST_FOR_EACH (pEntry, &This->Tracks) {
239 i++;
240 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
891e0166 241 TRACE(" - #%u: %p -> %d,%p\n", i, pIt, pIt->dwGroupBits, pIt->pTrack);
858557f4
RJ
242 if (NULL != pIt && pIt->pTrack == pTrack) {
243 ERR("(%p, %p): track is already in list\n", This, pTrack);
244 return E_FAIL;
245 }
246 }
247
248 pNewSegTrack = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_SEGMENT_TRACK));
249 if (NULL == pNewSegTrack) {
250 ERR(": no more memory\n");
251 return E_OUTOFMEMORY;
252 }
253 pNewSegTrack->dwGroupBits = dwGroupBits;
254 pNewSegTrack->pTrack = pTrack;
b8d3075d 255 IDirectMusicTrack_Init(pTrack, (IDirectMusicSegment *)iface);
858557f4
RJ
256 IDirectMusicTrack_AddRef(pTrack);
257 list_add_tail (&This->Tracks, &pNewSegTrack->entry);
258
c77788b5 259 return S_OK;
61035c8f
RM
260}
261
ff536fbe 262static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack) {
c77788b5 263 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
858557f4 264
8d954393 265 struct list* pEntry = NULL;
858557f4
RJ
266 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
267
8d954393 268 TRACE("(%p, %p)\n", This, pTrack);
858557f4
RJ
269
270 LIST_FOR_EACH (pEntry, &This->Tracks) {
858557f4
RJ
271 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
272 if (pIt->pTrack == pTrack) {
273 TRACE("(%p, %p): track in list\n", This, pTrack);
274
275 list_remove(&pIt->entry);
276 IDirectMusicTrack_Init(pIt->pTrack, NULL);
277 IDirectMusicTrack_Release(pIt->pTrack);
278 HeapFree(GetProcessHeap(), 0, pIt);
279
280 return S_OK;
281 }
282 }
283
284 return S_FALSE;
61035c8f
RM
285}
286
ff536fbe 287static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicSegmentState** ppSegState, IDirectMusicPerformance* pPerformance, DWORD dwFlags) {
c77788b5
RJ
288 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
289 HRESULT hr;
891e0166 290 FIXME("(%p, %p, %p, %d): semi-stub\n", This, ppSegState, pPerformance, dwFlags);
c77788b5
RJ
291 if (NULL == ppSegState) {
292 return E_POINTER;
293 }
294 hr = DMUSIC_CreateDirectMusicSegmentStateImpl(&IID_IDirectMusicSegmentState, (void**) ppSegState, NULL);
295 if (FAILED(hr)) {
296 return hr;
297 }
298 /* TODO: DMUS_SEGF_FLAGS */
299 return S_OK;
61035c8f
RM
300}
301
ff536fbe 302static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicGraph** ppGraph) {
c77788b5
RJ
303 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
304 FIXME("(%p, %p): semi-stub\n", This, ppGraph);
305 if (NULL == ppGraph) {
306 return E_POINTER;
307 }
308 if (NULL == This->pGraph) {
309 return DMUS_E_NOT_FOUND;
310 }
311 /**
312 * should return This, as seen in msdn
c77788b5
RJ
313 * "...The segment object implements IDirectMusicGraph directly..."
314 */
315 *ppGraph = This->pGraph;
316 IDirectMusicGraph_AddRef(This->pGraph);
317 return S_OK;
61035c8f
RM
318}
319
ff536fbe 320static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicGraph* pGraph) {
c77788b5
RJ
321 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
322 FIXME("(%p, %p): to complete\n", This, pGraph);
323 if (NULL != This->pGraph) {
324 IDirectMusicGraph_Release(This->pGraph);
325 }
326 This->pGraph = pGraph;
327 if (NULL != This->pGraph) {
328 IDirectMusicGraph_AddRef(This->pGraph);
329 }
330 return S_OK;
61035c8f
RM
331}
332
ff536fbe 333static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidNotificationType) {
8d954393
RJ
334 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
335 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
336 return S_OK;
61035c8f
RM
337}
338
ff536fbe 339static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidNotificationType) {
8d954393
RJ
340 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
341 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
342 return S_OK;
61035c8f
RM
343}
344
ff536fbe 345static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
8d954393
RJ
346 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
347
348 CLSID pIt_clsid;
349 struct list* pEntry = NULL;
350 IDirectMusicTrack* pTrack = NULL;
351 IPersistStream* pCLSIDStream = NULL;
352 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
353 HRESULT hr = S_OK;
354
4bfb33ec 355 FIXME("(%p, %s, 0x%x, %d, %d, %p, %p)\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pmtNext, pParam);
8d954393
RJ
356
357 if (DMUS_SEG_ANYTRACK == dwIndex) {
358
359 LIST_FOR_EACH (pEntry, &This->Tracks) {
360 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
361
98158988
MM
362 hr = IDirectMusicTrack_QueryInterface(pIt->pTrack, &IID_IPersistStream, (void**) &pCLSIDStream);
363 if (FAILED(hr)) {
364 ERR("(%p): object %p don't implement IPersistStream Interface. Expect a crash (critical problem)\n", This, pIt->pTrack);
365 continue ;
366 }
367
891e0166 368 TRACE(" - %p -> 0x%x,%p\n", pIt, pIt->dwGroupBits, pIt->pTrack);
8d954393
RJ
369
370 if (0xFFFFFFFF != dwGroupBits && 0 == (pIt->dwGroupBits & dwGroupBits)) continue ;
371 hr = IPersistStream_GetClassID(pCLSIDStream, &pIt_clsid);
372 IPersistStream_Release(pCLSIDStream); pCLSIDStream = NULL;
373 if (FAILED(hr)) {
374 ERR("(%p): non-implemented GetClassID for object %p\n", This, pIt->pTrack);
375 continue ;
376 }
377 if (FALSE == IsEqualGUID(&pIt_clsid, rguidType)) continue ;
378 if (FAILED(IDirectMusicTrack_IsParamSupported(pIt->pTrack, rguidType))) continue ;
379 hr = IDirectMusicTrack_GetParam(pIt->pTrack, rguidType, mtTime, pmtNext, pParam);
380 if (SUCCEEDED(hr)) return hr;
381 }
382 ERR("(%p): not found\n", This);
383 return DMUS_E_TRACK_NOT_FOUND;
384 }
385
386 hr = IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack(iface, &GUID_NULL, dwGroupBits, dwIndex, &pTrack);
387 if (FAILED(hr)) {
388 ERR("(%p): not found\n", This);
389 return DMUS_E_TRACK_NOT_FOUND;
390 }
391
392 hr = IDirectMusicTrack_GetParam(pTrack, rguidType, mtTime, pmtNext, pParam);
393 IDirectMusicTrack_Release(pTrack); pTrack = NULL;
394
395 return hr;
61035c8f
RM
396}
397
ff536fbe 398static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, void* pParam) {
8d954393 399 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
4bfb33ec 400 FIXME("(%p, %s, %d, %d, %d, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pParam);
8d954393 401 return S_OK;
61035c8f
RM
402}
403
ff536fbe 404static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicSegment** ppSegment) {
8d954393 405 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
4bfb33ec 406 FIXME("(%p, %d, %d, %p): stub\n", This, mtStart, mtEnd, ppSegment);
8d954393 407 return S_OK;
61035c8f
RM
408}
409
ff536fbe 410static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart) {
c77788b5 411 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
4bfb33ec 412 TRACE("(%p, %d)\n", This, mtStart);
c77788b5
RJ
413 if (mtStart >= This->header.mtLength) {
414 return DMUS_E_OUT_OF_RANGE;
415 }
416 This->header.mtPlayStart = mtStart;
417 return S_OK;
61035c8f
RM
418}
419
ff536fbe 420static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtStart) {
c77788b5
RJ
421 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
422 TRACE("(%p, %p)\n", This, pmtStart);
423 if (NULL == pmtStart) {
424 return E_POINTER;
425 }
426 *pmtStart = This->header.mtPlayStart;
427 return S_OK;
61035c8f
RM
428}
429
ff536fbe 430static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd) {
c77788b5 431 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
4bfb33ec 432 TRACE("(%p, %d, %d)\n", This, mtStart, mtEnd);
c77788b5
RJ
433 if (mtStart >= This->header.mtLength || mtEnd > This->header.mtLength || mtStart > mtEnd) {
434 return DMUS_E_OUT_OF_RANGE;
435 }
436 This->header.mtLoopStart = mtStart;
437 This->header.mtLoopEnd = mtEnd;
438 return S_OK;
61035c8f
RM
439}
440
ff536fbe 441static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtStart, MUSIC_TIME* pmtEnd) {
c77788b5
RJ
442 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
443 TRACE("(%p, %p, %p)\n", This, pmtStart, pmtEnd);
444 if (NULL == pmtStart || NULL == pmtEnd) {
445 return E_POINTER;
446 }
447 *pmtStart = This->header.mtLoopStart;
448 *pmtEnd = This->header.mtLoopEnd;
449 return S_OK;
61035c8f
RM
450}
451
ff536fbe 452static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed (LPDIRECTMUSICSEGMENT8 iface, DWORD dwNumPChannels, DWORD* paPChannels) {
0382ea1d 453 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
891e0166 454 FIXME("(%p, %d, %p): stub\n", This, dwNumPChannels, paPChannels);
a4a5e9ae 455 return S_OK;
61035c8f
RM
456}
457
ff536fbe 458static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidTrackClassID, DWORD dwGroupBits, DWORD dwIndex, DWORD dwFlagsOn, DWORD dwFlagsOff) {
0382ea1d 459 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
891e0166 460 FIXME("(%p, %s, %d, %d, %d, %d): stub\n", This, debugstr_dmguid(rguidTrackClassID), dwGroupBits, dwIndex, dwFlagsOn, dwFlagsOff);
a4a5e9ae 461 return S_OK;
61035c8f
RM
462}
463
ff536fbe 464static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig (LPDIRECTMUSICSEGMENT8 iface, IUnknown** ppAudioPathConfig){
0382ea1d 465 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
a4a5e9ae 466 FIXME("(%p, %p): stub\n", This, ppAudioPathConfig);
a4a5e9ae 467 return S_OK;
61035c8f
RM
468}
469
ff536fbe 470static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtTime, IDirectMusicSegment* pFromSegment, IDirectMusicSegment* pToSegment, IDirectMusicSegment** ppComposedSegment) {
0382ea1d 471 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
4bfb33ec 472 FIXME("(%p, %d, %p, %p, %p): stub\n", This, mtTime, pFromSegment, pToSegment, ppComposedSegment);
a4a5e9ae 473 return S_OK;
61035c8f
RM
474}
475
ff536fbe 476static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Download (LPDIRECTMUSICSEGMENT8 iface, IUnknown *pAudioPath) {
0382ea1d 477 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
a4a5e9ae 478 FIXME("(%p, %p): stub\n", This, pAudioPath);
a4a5e9ae 479 return S_OK;
61035c8f
RM
480}
481
ff536fbe 482static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload (LPDIRECTMUSICSEGMENT8 iface, IUnknown *pAudioPath) {
0382ea1d 483 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
a4a5e9ae 484 FIXME("(%p, %p): stub\n", This, pAudioPath);
a4a5e9ae 485 return S_OK;
61035c8f
RM
486}
487
247246ed 488static const IDirectMusicSegment8Vtbl DirectMusicSegment8_Segment_Vtbl = {
0382ea1d
RM
489 IDirectMusicSegment8Impl_IDirectMusicSegment8_QueryInterface,
490 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef,
491 IDirectMusicSegment8Impl_IDirectMusicSegment8_Release,
492 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLength,
493 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLength,
494 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetRepeats,
495 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetRepeats,
496 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetDefaultResolution,
497 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetDefaultResolution,
498 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack,
499 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrackGroup,
500 IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack,
501 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack,
502 IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay,
503 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph,
504 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph,
505 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType,
506 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType,
507 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam,
508 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam,
509 IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone,
510 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint,
511 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint,
512 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints,
513 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints,
514 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed,
515 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig,
516 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig,
517 IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose,
518 IDirectMusicSegment8Impl_IDirectMusicSegment8_Download,
519 IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload
61035c8f
RM
520};
521
0382ea1d 522/* IDirectMusicSegment8Impl IDirectMusicObject part: */
06e23dad 523static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) {
0382ea1d 524 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
06e23dad 525 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
df167d17
RM
526}
527
06e23dad 528static ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) {
0382ea1d 529 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
06e23dad 530 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
df167d17
RM
531}
532
ff536fbe 533static ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) {
0382ea1d 534 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
06e23dad 535 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
df167d17
RM
536}
537
ff536fbe 538static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
0382ea1d 539 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
df167d17 540 TRACE("(%p, %p)\n", This, pDesc);
0382ea1d
RM
541 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
542 memcpy (pDesc, This->pDesc, This->pDesc->dwSize);
df167d17
RM
543 return S_OK;
544}
545
ff536fbe 546static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
0382ea1d 547 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
b26d65bb 548 TRACE("(%p, %p): setting descriptor:\n%s\n", This, pDesc, debugstr_DMUS_OBJECTDESC (pDesc));
be2f48cd 549
0382ea1d
RM
550 /* According to MSDN, we should copy only given values, not whole struct */
551 if (pDesc->dwValidData & DMUS_OBJ_OBJECT)
be2f48cd 552 This->pDesc->guidObject = pDesc->guidObject;
0382ea1d 553 if (pDesc->dwValidData & DMUS_OBJ_CLASS)
be2f48cd 554 This->pDesc->guidClass = pDesc->guidClass;
0382ea1d 555 if (pDesc->dwValidData & DMUS_OBJ_NAME)
6e3bcb5a 556 lstrcpynW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
0382ea1d 557 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
6e3bcb5a 558 lstrcpynW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
0382ea1d 559 if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
6e3bcb5a 560 lstrcpynW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
0382ea1d 561 if (pDesc->dwValidData & DMUS_OBJ_VERSION)
be2f48cd 562 This->pDesc->vVersion = pDesc->vVersion;
0382ea1d 563 if (pDesc->dwValidData & DMUS_OBJ_DATE)
be2f48cd 564 This->pDesc->ftDate = pDesc->ftDate;
0382ea1d
RM
565 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
566 memcpy (&This->pDesc->llMemLength, &pDesc->llMemLength, sizeof (pDesc->llMemLength));
567 memcpy (This->pDesc->pbMemData, pDesc->pbMemData, sizeof (pDesc->pbMemData));
568 }
569 if (pDesc->dwValidData & DMUS_OBJ_STREAM) {
570 /* according to MSDN, we copy the stream */
571 IStream_Clone (pDesc->pStream, &This->pDesc->pStream);
572 }
573
574 /* add new flags */
575 This->pDesc->dwValidData |= pDesc->dwValidData;
df167d17
RM
576
577 return S_OK;
578}
579
ff536fbe 580static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc) {
0382ea1d
RM
581 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
582 DMUS_PRIVATE_CHUNK Chunk;
583 DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
584 LARGE_INTEGER liMove; /* used when skipping chunks */
df167d17 585
0382ea1d 586 TRACE("(%p,%p, %p)\n", This, pStream, pDesc);
be2f48cd 587
0382ea1d
RM
588 /* FIXME: should this be determined from stream? */
589 pDesc->dwValidData |= DMUS_OBJ_CLASS;
be2f48cd
AT
590 pDesc->guidClass = CLSID_DirectMusicSegment;
591
0382ea1d 592 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
891e0166 593 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
0382ea1d
RM
594 switch (Chunk.fccID) {
595 case FOURCC_RIFF: {
596 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
597 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
598 StreamSize = Chunk.dwSize - sizeof(FOURCC);
599 StreamCount = 0;
600 if (Chunk.fccID == DMUS_FOURCC_SEGMENT_FORM) {
601 TRACE_(dmfile)(": segment form\n");
602 do {
603 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
604 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
891e0166 605 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
0382ea1d
RM
606 switch (Chunk.fccID) {
607 case DMUS_FOURCC_GUID_CHUNK: {
608 TRACE_(dmfile)(": GUID chunk\n");
609 pDesc->dwValidData |= DMUS_OBJ_OBJECT;
610 IStream_Read (pStream, &pDesc->guidObject, Chunk.dwSize, NULL);
611 break;
612 }
613 case DMUS_FOURCC_VERSION_CHUNK: {
614 TRACE_(dmfile)(": version chunk\n");
615 pDesc->dwValidData |= DMUS_OBJ_VERSION;
616 IStream_Read (pStream, &pDesc->vVersion, Chunk.dwSize, NULL);
617 break;
618 }
619 case DMUS_FOURCC_CATEGORY_CHUNK: {
620 TRACE_(dmfile)(": category chunk\n");
621 pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
622 IStream_Read (pStream, pDesc->wszCategory, Chunk.dwSize, NULL);
623 break;
624 }
625 case FOURCC_LIST: {
626 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
627 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
628 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
629 ListCount[0] = 0;
630 switch (Chunk.fccID) {
631 /* evil M$ UNFO list, which can (!?) contain INFO elements */
632 case DMUS_FOURCC_UNFO_LIST: {
633 TRACE_(dmfile)(": UNFO list\n");
634 do {
635 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
636 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
891e0166 637 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
0382ea1d
RM
638 switch (Chunk.fccID) {
639 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
410bdd36 640 (though strings seem to be valid unicode) */
0382ea1d
RM
641 case mmioFOURCC('I','N','A','M'):
642 case DMUS_FOURCC_UNAM_CHUNK: {
643 TRACE_(dmfile)(": name chunk\n");
644 pDesc->dwValidData |= DMUS_OBJ_NAME;
645 IStream_Read (pStream, pDesc->wszName, Chunk.dwSize, NULL);
646 break;
647 }
648 case mmioFOURCC('I','A','R','T'):
649 case DMUS_FOURCC_UART_CHUNK: {
650 TRACE_(dmfile)(": artist chunk (ignored)\n");
651 liMove.QuadPart = Chunk.dwSize;
652 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
653 break;
654 }
655 case mmioFOURCC('I','C','O','P'):
656 case DMUS_FOURCC_UCOP_CHUNK: {
657 TRACE_(dmfile)(": copyright chunk (ignored)\n");
658 liMove.QuadPart = Chunk.dwSize;
659 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
660 break;
661 }
662 case mmioFOURCC('I','S','B','J'):
663 case DMUS_FOURCC_USBJ_CHUNK: {
664 TRACE_(dmfile)(": subject chunk (ignored)\n");
665 liMove.QuadPart = Chunk.dwSize;
666 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
667 break;
668 }
669 case mmioFOURCC('I','C','M','T'):
670 case DMUS_FOURCC_UCMT_CHUNK: {
671 TRACE_(dmfile)(": comment chunk (ignored)\n");
672 liMove.QuadPart = Chunk.dwSize;
673 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
674 break;
675 }
676 default: {
677 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
678 liMove.QuadPart = Chunk.dwSize;
679 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
680 break;
681 }
682 }
891e0166 683 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
0382ea1d
RM
684 } while (ListCount[0] < ListSize[0]);
685 break;
686 }
410bdd36
RJ
687 case DMUS_FOURCC_TRACK_LIST: {
688 TRACE_(dmfile)(": TRACK list\n");
689 do {
690 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
691 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
891e0166 692 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
410bdd36
RJ
693 switch (Chunk.fccID) {
694 default: {
695 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
696 liMove.QuadPart = Chunk.dwSize;
697 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
698 break;
699 }
700 }
891e0166 701 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
410bdd36
RJ
702 } while (ListCount[0] < ListSize[0]);
703 break;
704 }
705 default: {
706 TRACE_(dmfile)(": unknown (skipping)\n");
707 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
708 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
709 break;
0382ea1d
RM
710 }
711 }
712 break;
713 }
714 default: {
715 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
716 liMove.QuadPart = Chunk.dwSize;
717 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
718 break;
719 }
720 }
891e0166 721 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
0382ea1d
RM
722 } while (StreamCount < StreamSize);
723 break;
410bdd36 724 } else if (Chunk.fccID == mmioFOURCC('W','A','V','E')) {
1afbcd71 725 TRACE_(dmfile)(": wave form (loading not yet implemented)\n");
410bdd36
RJ
726 liMove.QuadPart = StreamSize;
727 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
0382ea1d 728 } else {
1afbcd71 729 TRACE_(dmfile)(": unexpected chunk (loading failed)\n");
0382ea1d
RM
730 liMove.QuadPart = StreamSize;
731 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
732 return E_FAIL;
733 }
734
735 TRACE_(dmfile)(": reading finished\n");
736 break;
df167d17 737 }
0382ea1d
RM
738 default: {
739 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
740 liMove.QuadPart = Chunk.dwSize;
741 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
742 return DMUS_E_INVALIDFILE;
743 }
744 }
745
b26d65bb 746 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc));
473c5657 747
0382ea1d 748 return S_OK;
df167d17
RM
749}
750
247246ed 751static const IDirectMusicObjectVtbl DirectMusicSegment8_Object_Vtbl = {
8d954393
RJ
752 IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface,
753 IDirectMusicSegment8Impl_IDirectMusicObject_AddRef,
754 IDirectMusicSegment8Impl_IDirectMusicObject_Release,
755 IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor,
756 IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor,
757 IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor
0382ea1d 758};
df167d17 759
0382ea1d 760/* IDirectMusicSegment8Impl IPersistStream part: */
06e23dad 761static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
1afbcd71 762 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
06e23dad 763 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
61035c8f 764}
df167d17 765
06e23dad 766static ULONG WINAPI IDirectMusicSegment8Impl_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
1afbcd71 767 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
06e23dad 768 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
df167d17
RM
769}
770
ff536fbe 771static ULONG WINAPI IDirectMusicSegment8Impl_IPersistStream_Release (LPPERSISTSTREAM iface) {
1afbcd71 772 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
06e23dad 773 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
df167d17
RM
774}
775
ff536fbe 776static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
1afbcd71
RJ
777 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
778 TRACE("(%p, %p)\n", This, pClassID);
be2f48cd 779 *pClassID = CLSID_DirectMusicSegment;
1afbcd71 780 return S_OK;
df167d17
RM
781}
782
ff536fbe 783static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
1afbcd71
RJ
784 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
785 FIXME("(%p): stub, always S_FALSE\n", This);
786 return S_FALSE;
df167d17
RM
787}
788
1afbcd71
RJ
789static HRESULT IDirectMusicSegment8Impl_IPersistStream_LoadTrack (LPPERSISTSTREAM iface, IStream* pClonedStream, IDirectMusicTrack** ppTrack,
790 DMUS_IO_TRACK_HEADER* pTrack_hdr) {
791
43def08e 792 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1afbcd71
RJ
793 HRESULT hr = E_FAIL;
794 IPersistStream* pPersistStream = NULL;
795
796 hr = CoCreateInstance (&pTrack_hdr->guidClassID, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicTrack, (LPVOID*) ppTrack);
797 if (FAILED(hr)) {
798 ERR(": could not create object\n");
799 return hr;
800 }
801 /* acquire PersistStream interface */
802 hr = IDirectMusicTrack_QueryInterface (*ppTrack, &IID_IPersistStream, (LPVOID*) &pPersistStream);
803 if (FAILED(hr)) {
804 ERR(": could not acquire IPersistStream\n");
805 return hr;
806 }
807 /* load */
808 hr = IPersistStream_Load (pPersistStream, pClonedStream);
809 if (FAILED(hr)) {
810 ERR(": failed to load object\n");
811 return hr;
812 }
813
814 /* release all loading-related stuff */
815 IPersistStream_Release (pPersistStream);
816
858557f4 817 hr = IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack ((LPDIRECTMUSICSEGMENT8)&This->SegmentVtbl, *ppTrack, pTrack_hdr->dwGroup); /* at dsPosition */
43def08e
RJ
818 if (FAILED(hr)) {
819 ERR(": could not insert track\n");
820 return hr;
821 }
822
1afbcd71
RJ
823 return S_OK;
824}
825
43def08e 826static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
1afbcd71 827
43def08e 828 /*ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);*/
1afbcd71
RJ
829 HRESULT hr = E_FAIL;
830 DMUS_PRIVATE_CHUNK Chunk;
a73ab629 831 DWORD StreamSize, StreamCount, ListSize[3];
1afbcd71 832 LARGE_INTEGER liMove; /* used when skipping chunks */
a73ab629 833
1afbcd71
RJ
834 DMUS_IO_TRACK_HEADER track_hdr;
835 DMUS_IO_TRACK_EXTRAS_HEADER track_xhdr;
836 IDirectMusicTrack* pTrack = NULL;
837
838 if (pChunk->fccID != DMUS_FOURCC_TRACK_FORM) {
839 ERR_(dmfile)(": %s chunk should be a TRACK form\n", debugstr_fourcc (pChunk->fccID));
840 return E_FAIL;
841 }
842
843 StreamSize = pChunk->dwSize - sizeof(FOURCC);
844 StreamCount = 0;
845
846 do {
847 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
848 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
891e0166 849 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1afbcd71
RJ
850
851 switch (Chunk.fccID) {
852 case DMUS_FOURCC_TRACK_CHUNK: {
633ee950 853 TRACE_(dmfile)(": track chunk\n");
1afbcd71 854 IStream_Read (pStm, &track_hdr, sizeof(DMUS_IO_TRACK_HEADER), NULL);
a4215336 855 TRACE_(dmfile)(" - class: %s\n", debugstr_guid (&track_hdr.guidClassID));
891e0166 856 TRACE_(dmfile)(" - dwGroup: %d\n", track_hdr.dwGroup);
a4215336
RJ
857 TRACE_(dmfile)(" - ckid: %s\n", debugstr_fourcc (track_hdr.ckid));
858 TRACE_(dmfile)(" - fccType: %s\n", debugstr_fourcc (track_hdr.fccType));
1afbcd71
RJ
859 break;
860 }
861 case DMUS_FOURCC_TRACK_EXTRAS_CHUNK: {
633ee950 862 TRACE_(dmfile)(": track extras chunk\n");
1afbcd71
RJ
863 IStream_Read (pStm, &track_xhdr, sizeof(DMUS_IO_TRACK_EXTRAS_HEADER), NULL);
864 break;
865 }
866
867 case DMUS_FOURCC_COMMANDTRACK_CHUNK: {
868 TRACE_(dmfile)(": COMMANDTRACK track\n");
869 liMove.QuadPart = Chunk.dwSize;
870 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
871 break;
872 }
873
874 case FOURCC_LIST: {
875 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
876 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
877 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
1afbcd71
RJ
878 if (Chunk.fccID == track_hdr.fccType && 0 == track_hdr.ckid) {
879 LPSTREAM pClonedStream = NULL;
880
881 TRACE_(dmfile)(": TRACK list\n");
882
883 IStream_Clone (pStm, &pClonedStream);
ee51a0c0 884
1afbcd71 885 liMove.QuadPart = 0;
ee51a0c0 886 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
1afbcd71 887 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
ee51a0c0 888
1afbcd71
RJ
889 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
890 if (FAILED(hr)) {
891 ERR(": could not load track\n");
892 return hr;
df167d17 893 }
43def08e 894 IStream_Release (pClonedStream);
1afbcd71 895
1afbcd71 896 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
1afbcd71 897
ee51a0c0
RJ
898 liMove.QuadPart = ListSize[0];
899 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
900
1afbcd71
RJ
901 } else {
902 TRACE_(dmfile)(": unknown (skipping)\n");
903 liMove.QuadPart = Chunk.dwSize;
904 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
905 }
906 break;
907 }
ee51a0c0 908
1afbcd71
RJ
909 case FOURCC_RIFF: {
910 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
beaa084f 911 TRACE_(dmfile)(": RIFF chunk of type %s\n", debugstr_fourcc(Chunk.fccID));
ee51a0c0 912
1afbcd71 913 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
ee51a0c0 914
1afbcd71 915 if (Chunk.fccID == track_hdr.fccType && 0 == track_hdr.ckid) {
ee51a0c0
RJ
916 LPSTREAM pClonedStream = NULL;
917
1afbcd71 918 TRACE_(dmfile)(": TRACK RIFF\n");
ee51a0c0
RJ
919
920 IStream_Clone (pStm, &pClonedStream);
921
922 liMove.QuadPart = 0;
43def08e 923 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
ee51a0c0 924 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
1afbcd71 925
ee51a0c0
RJ
926 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
927 if (FAILED(hr)) {
928 ERR(": could not load track\n");
929 return hr;
930 }
ee51a0c0
RJ
931 IStream_Release (pClonedStream);
932
ee51a0c0
RJ
933 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
934
935 /** now safe move the cursor */
936 liMove.QuadPart = ListSize[0];
937 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
938
1afbcd71 939 } else {
ee51a0c0
RJ
940 TRACE_(dmfile)(": unknown RIFF fmt (skipping)\n");
941 liMove.QuadPart = ListSize[0];
1afbcd71
RJ
942 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
943 }
944 break;
945 }
ee51a0c0 946
1afbcd71
RJ
947 default: {
948 if (0 == track_hdr.fccType && Chunk.fccID == track_hdr.ckid) {
949 LPSTREAM pClonedStream = NULL;
950
951 TRACE_(dmfile)(": TRACK solo\n");
952
953 IStream_Clone (pStm, &pClonedStream);
954
955 liMove.QuadPart = 0;
956 liMove.QuadPart -= (sizeof(FOURCC) + sizeof(DWORD));
957 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
958
959 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
960 if (FAILED(hr)) {
961 ERR(": could not load track\n");
962 return hr;
963 }
1afbcd71
RJ
964 IStream_Release (pClonedStream);
965
1afbcd71
RJ
966 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
967
968 liMove.QuadPart = Chunk.dwSize;
969 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
970
971 break;
972 }
973
974 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
975 liMove.QuadPart = Chunk.dwSize;
976 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
977 break;
978 }
979 }
891e0166 980 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
1afbcd71
RJ
981 } while (StreamCount < StreamSize);
982
983 return S_OK;
984}
985
986static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicSegment8Impl* This) {
987
988 HRESULT hr = E_FAIL;
989 DMUS_PRIVATE_CHUNK Chunk;
a73ab629 990 DWORD StreamSize, ListSize[3], ListCount[3];
1afbcd71
RJ
991 LARGE_INTEGER liMove; /* used when skipping chunks */
992
993 if (pChunk->fccID != DMUS_FOURCC_TRACK_LIST) {
994 ERR_(dmfile)(": %s chunk should be a TRACK list\n", debugstr_fourcc (pChunk->fccID));
995 return E_FAIL;
996 }
997
ee51a0c0 998 ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
1afbcd71
RJ
999 ListCount[0] = 0;
1000
1001 do {
1002 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1003 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
891e0166 1004 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1afbcd71
RJ
1005 switch (Chunk.fccID) {
1006 case FOURCC_RIFF: {
1007 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
1008 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
1009 StreamSize = Chunk.dwSize - sizeof(FOURCC);
1afbcd71
RJ
1010 switch (Chunk.fccID) {
1011 case DMUS_FOURCC_TRACK_FORM: {
1012 TRACE_(dmfile)(": TRACK form\n");
43def08e 1013 hr = IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (iface, &Chunk, pStm);
1afbcd71
RJ
1014 if (FAILED(hr)) return hr;
1015 break;
1016 }
1017 default: {
1018 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1019 liMove.QuadPart = StreamSize;
1020 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1021 break;
1022 }
1023 }
1024 break;
1025 }
1026 default: {
1027 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1028 liMove.QuadPart = Chunk.dwSize;
1029 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1030 break;
1031 }
1032 }
891e0166 1033 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
1afbcd71
RJ
1034 } while (ListCount[0] < ListSize[0]);
1035
1036 return S_OK;
1037}
1038
1039static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicSegment8Impl* This) {
1040
1041 HRESULT hr = E_FAIL;
1042 DMUS_PRIVATE_CHUNK Chunk;
1043 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
1044 LARGE_INTEGER liMove; /* used when skipping chunks */
1045
1046 if (pChunk->fccID != DMUS_FOURCC_SEGMENT_FORM) {
1047 ERR_(dmfile)(": %s chunk should be a segment form\n", debugstr_fourcc (pChunk->fccID));
1048 return E_FAIL;
1049 }
1050
1051 StreamSize = pChunk->dwSize - sizeof(FOURCC);
1052 StreamCount = 0;
1053
1054 do {
1055 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1056 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
891e0166 1057 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1afbcd71 1058
106e13ab 1059 hr = IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk, pStm, This->pDesc);
1afbcd71
RJ
1060 if (FAILED(hr)) return hr;
1061
1062 if (hr == S_FALSE) {
1063 switch (Chunk.fccID) {
1064 case DMUS_FOURCC_SEGMENT_CHUNK: {
ee51a0c0 1065 DWORD checkSz = sizeof(FOURCC);
43def08e 1066 TRACE_(dmfile)(": segment chunk\n");
ee51a0c0 1067#if 1
c77788b5
RJ
1068 /** DX 7 */
1069 IStream_Read (pStm, &This->header.dwRepeats, sizeof(This->header.dwRepeats), NULL);
1070 checkSz += sizeof(This->header.dwRepeats);
1071 IStream_Read (pStm, &This->header.mtLength, sizeof(This->header.mtLength), NULL);
1072 checkSz += sizeof(This->header.mtLength);
1073 IStream_Read (pStm, &This->header.mtPlayStart, sizeof(This->header.mtPlayStart), NULL);
1074 checkSz += sizeof(This->header.mtPlayStart);
1075 IStream_Read (pStm, &This->header.mtLoopStart, sizeof(This->header.mtLoopStart), NULL);
1076 checkSz += sizeof(This->header.mtLoopStart);
1077 IStream_Read (pStm, &This->header.mtLoopEnd, sizeof(This->header.mtLoopEnd), NULL);
1078 checkSz += sizeof(This->header.mtLoopEnd);
1079 IStream_Read (pStm, &This->header.dwResolution, sizeof(This->header.dwResolution), NULL);
1080 checkSz += sizeof(This->header.dwResolution);
891e0166 1081 TRACE_(dmfile)("dwRepeats: %u\n", This->header.dwRepeats);
4bfb33ec
MS
1082 TRACE_(dmfile)("mtLength: %u\n", This->header.mtLength);
1083 TRACE_(dmfile)("mtPlayStart: %u\n", This->header.mtPlayStart);
1084 TRACE_(dmfile)("mtLoopStart: %u\n", This->header.mtLoopStart);
1085 TRACE_(dmfile)("mtLoopEnd: %u\n", This->header.mtLoopEnd);
891e0166 1086 TRACE_(dmfile)("dwResolution: %u\n", This->header.dwResolution);
c77788b5
RJ
1087 /** DX 8 */
1088 if (Chunk.dwSize > checkSz) {
1089 IStream_Read (pStm, &This->header.rtLength, sizeof(This->header.rtLength), NULL);
1090 checkSz += sizeof(This->header.rtLength);
1091 IStream_Read (pStm, &This->header.dwFlags, sizeof(This->header.dwFlags), NULL);
1092 checkSz += sizeof(This->header.dwFlags);
1093 }
1094 /** DX 9 */
1095 if (Chunk.dwSize > checkSz) {
1096 IStream_Read (pStm, &This->header.rtLoopStart, sizeof(This->header.rtLoopStart), NULL);
1097 checkSz += sizeof(This->header.rtLoopStart);
1098 IStream_Read (pStm, &This->header.rtLoopEnd, sizeof(This->header.rtLoopEnd), NULL);
1099 checkSz += sizeof(This->header.rtLoopEnd);
1100 IStream_Read (pStm, &This->header.rtPlayStart, sizeof(This->header.rtPlayStart), NULL);
1101 checkSz += sizeof(This->header.rtPlayStart);
1102 }
ee51a0c0
RJ
1103#endif
1104 liMove.QuadPart = Chunk.dwSize - checkSz + sizeof(FOURCC);
1afbcd71
RJ
1105 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1106 break;
1107 }
1108 case FOURCC_LIST: {
1109 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
1110 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
1111 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
1112 ListCount[0] = 0;
1113 switch (Chunk.fccID) {
1114 case DMUS_FOURCC_UNFO_LIST: {
1115 TRACE_(dmfile)(": UNFO list\n");
1116 do {
1117 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1118 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
891e0166 1119 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1afbcd71 1120
106e13ab 1121 hr = IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk, pStm, This->pDesc);
1afbcd71
RJ
1122 if (FAILED(hr)) return hr;
1123
1124 if (hr == S_FALSE) {
1125 switch (Chunk.fccID) {
1126 default: {
1127 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1128 liMove.QuadPart = Chunk.dwSize;
1129 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1130 break;
1131 }
1132 }
1133 }
1134
891e0166 1135 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
1afbcd71
RJ
1136 } while (ListCount[0] < ListSize[0]);
1137 break;
1138 }
1139 case DMUS_FOURCC_TRACK_LIST: {
1140 TRACE_(dmfile)(": TRACK list\n");
1141 hr = IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (iface, &Chunk, pStm, This);
1142 if (FAILED(hr)) return hr;
1143 break;
1144 }
1145 default: {
1146 TRACE_(dmfile)(": unknown (skipping)\n");
1147 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
1148 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1149 break;
1150 }
1151 }
1152 break;
1153 }
1154 default: {
1155 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1156 liMove.QuadPart = Chunk.dwSize;
1157 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1158 break;
1159 }
1160 }
1161 }
891e0166 1162 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
1afbcd71
RJ
1163 } while (StreamCount < StreamSize);
1164
1165 return S_OK;
1166}
1167
41b9ae33
RJ
1168static HRESULT IDirectMusicSegment8Impl_IPersistStream_LoadWave (LPPERSISTSTREAM iface, IStream* pClonedStream, IDirectMusicObject** ppWaveObject) {
1169
1170 HRESULT hr = E_FAIL;
1171 IPersistStream* pPersistStream = NULL;
1172
1173 hr = CoCreateInstance (&CLSID_DirectSoundWave, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicObject, (LPVOID*) ppWaveObject);
1174 if (FAILED(hr)) {
1175 ERR(": could not create object\n");
1176 return hr;
1177 }
1178 /* acquire PersistStream interface */
f10b3881 1179 hr = IDirectMusicObject_QueryInterface (*ppWaveObject, &IID_IPersistStream, (LPVOID*) &pPersistStream);
41b9ae33
RJ
1180 if (FAILED(hr)) {
1181 ERR(": could not acquire IPersistStream\n");
1182 return hr;
1183 }
1184 /* load */
1185 hr = IPersistStream_Load (pPersistStream, pClonedStream);
1186 if (FAILED(hr)) {
1187 ERR(": failed to load object\n");
1188 return hr;
1189 }
1190
1191 /* release all loading-related stuff */
1192 IPersistStream_Release (pPersistStream);
1193
1194 return S_OK;
1195}
1196
ff536fbe 1197static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
1afbcd71 1198 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
a73ab629 1199
1afbcd71
RJ
1200 HRESULT hr;
1201 DMUS_PRIVATE_CHUNK Chunk;
a73ab629 1202 DWORD StreamSize;
1afbcd71
RJ
1203 /*DWORD ListSize[3], ListCount[3];*/
1204 LARGE_INTEGER liMove; /* used when skipping chunks */
a73ab629 1205
beaa084f 1206 TRACE("(%p, %p): Loading\n", This, pStm);
1afbcd71 1207 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
891e0166 1208 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1afbcd71
RJ
1209 switch (Chunk.fccID) {
1210 case FOURCC_RIFF: {
1211 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
1212 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
1213 StreamSize = Chunk.dwSize - sizeof(FOURCC);
1afbcd71
RJ
1214 switch (Chunk.fccID) {
1215 case DMUS_FOURCC_SEGMENT_FORM: {
1216 TRACE_(dmfile)(": segment form\n");
1217 hr = IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (iface, &Chunk, pStm, This);
1218 if (FAILED(hr)) return hr;
1219 break;
1220 }
1221 case mmioFOURCC('W','A','V','E'): {
41b9ae33
RJ
1222 LPSTREAM pClonedStream = NULL;
1223 IDirectMusicObject* pWave = NULL;
1224
1225 FIXME_(dmfile)(": WAVE form (loading to be checked)\n");
1226
1227 IStream_Clone (pStm, &pClonedStream);
1228
1229 liMove.QuadPart = 0;
1230 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
1231 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
1232
1233 hr = IDirectMusicSegment8Impl_IPersistStream_LoadWave (iface, pClonedStream, &pWave);
1234 if (FAILED(hr)) {
1235 ERR(": could not load track\n");
1236 return hr;
1237 }
1238 IStream_Release (pClonedStream);
1239
1240 IDirectMusicTrack_Release(pWave); pWave = NULL; /* now we can release at as it inserted */
1241
1afbcd71
RJ
1242 liMove.QuadPart = StreamSize;
1243 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1244 break;
1245 }
1246 default: {
1247 TRACE_(dmfile)(": unexpected chunk (loading failed)\n");
1248 liMove.QuadPart = StreamSize;
1249 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1250 return E_FAIL;
1251 }
1252 }
1253 TRACE_(dmfile)(": reading finished\n");
1254 break;
1255 }
1256 default: {
1257 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
1258 liMove.QuadPart = Chunk.dwSize;
1259 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1260 return E_FAIL;
1261 }
1262 }
1263
1264 return S_OK;
df167d17
RM
1265}
1266
ff536fbe 1267static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
8d954393
RJ
1268 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1269 FIXME("(%p): Saving not implemented yet\n", This);
ee51a0c0 1270 return E_NOTIMPL;
df167d17
RM
1271}
1272
ff536fbe 1273static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
8d954393
RJ
1274 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1275 FIXME("(%p, %p): stub\n", This, pcbSize);
1afbcd71 1276 return E_NOTIMPL;
df167d17
RM
1277}
1278
247246ed 1279static const IPersistStreamVtbl DirectMusicSegment8_PersistStream_Vtbl = {
1afbcd71
RJ
1280 IDirectMusicSegment8Impl_IPersistStream_QueryInterface,
1281 IDirectMusicSegment8Impl_IPersistStream_AddRef,
1282 IDirectMusicSegment8Impl_IPersistStream_Release,
1283 IDirectMusicSegment8Impl_IPersistStream_GetClassID,
1284 IDirectMusicSegment8Impl_IPersistStream_IsDirty,
1285 IDirectMusicSegment8Impl_IPersistStream_Load,
1286 IDirectMusicSegment8Impl_IPersistStream_Save,
1287 IDirectMusicSegment8Impl_IPersistStream_GetSizeMax
df167d17 1288};
0382ea1d
RM
1289
1290/* for ClassFactory */
1291HRESULT WINAPI DMUSIC_CreateDirectMusicSegmentImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
1afbcd71
RJ
1292 IDirectMusicSegment8Impl* obj;
1293
1294 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSegment8Impl));
1295 if (NULL == obj) {
ee0344a4 1296 *ppobj = NULL;
1afbcd71
RJ
1297 return E_OUTOFMEMORY;
1298 }
1299 obj->UnknownVtbl = &DirectMusicSegment8_Unknown_Vtbl;
1300 obj->SegmentVtbl = &DirectMusicSegment8_Segment_Vtbl;
1301 obj->ObjectVtbl = &DirectMusicSegment8_Object_Vtbl;
1302 obj->PersistStreamVtbl = &DirectMusicSegment8_PersistStream_Vtbl;
1303 obj->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
1304 DM_STRUCT_INIT(obj->pDesc);
1305 obj->pDesc->dwValidData |= DMUS_OBJ_CLASS;
be2f48cd 1306 obj->pDesc->guidClass = CLSID_DirectMusicSegment;
1afbcd71 1307 obj->ref = 0; /* will be inited by QueryInterface */
858557f4 1308 list_init (&obj->Tracks);
be2f48cd 1309
1afbcd71 1310 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&obj->UnknownVtbl, lpcGUID, ppobj);
0382ea1d 1311}