wininet: Change a couple fixme's to warn's.
[wine/multimedia.git] / dlls / dmime / segment.c
blobf736c7188d27d96de45ab1c32854a9dc97a672c8
1 /* IDirectMusicSegment8 Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
4 * Copyright (C) 2003-2004 Raphael Junqueira
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.
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.
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
21 #include "dmime_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
24 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
26 /*****************************************************************************
27 * IDirectMusicSegmentImpl implementation
29 /* IDirectMusicSegment IUnknown part: */
30 static HRESULT WINAPI IDirectMusicSegment8Impl_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
31 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
32 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
34 if (IsEqualIID (riid, &IID_IUnknown)) {
35 *ppobj = (LPVOID)&This->UnknownVtbl;
36 IUnknown_AddRef (iface);
37 return S_OK;
38 } else if (IsEqualIID (riid, &IID_IDirectMusicSegment)
39 || IsEqualIID (riid, &IID_IDirectMusicSegment2)
40 || IsEqualIID (riid, &IID_IDirectMusicSegment8)) {
41 *ppobj = (LPVOID)&This->SegmentVtbl;
42 IUnknown_AddRef (iface);
43 return S_OK;
44 } else if (IsEqualIID (riid, &IID_IDirectMusicObject)) {
45 *ppobj = (LPVOID)&This->ObjectVtbl;
46 IUnknown_AddRef (iface);
47 return S_OK;
48 } else if (IsEqualIID (riid, &IID_IPersistStream)) {
49 *ppobj = (LPVOID)&This->PersistStreamVtbl;
50 IUnknown_AddRef (iface);
51 return S_OK;
54 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
55 return E_NOINTERFACE;
58 static ULONG WINAPI IDirectMusicSegment8Impl_IUnknown_AddRef (LPUNKNOWN iface) {
59 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
60 ULONG ref = InterlockedIncrement(&This->ref);
62 TRACE("(%p): AddRef from %d\n", This, ref - 1);
64 DMIME_LockModule();
66 return ref;
69 static ULONG WINAPI IDirectMusicSegment8Impl_IUnknown_Release (LPUNKNOWN iface) {
70 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
71 ULONG ref = InterlockedDecrement(&This->ref);
72 TRACE("(%p): ReleaseRef to %d\n", This, ref);
74 if (ref == 0) {
75 HeapFree(GetProcessHeap(), 0, This);
78 DMIME_UnlockModule();
80 return ref;
83 static const IUnknownVtbl DirectMusicSegment8_Unknown_Vtbl = {
84 IDirectMusicSegment8Impl_IUnknown_QueryInterface,
85 IDirectMusicSegment8Impl_IUnknown_AddRef,
86 IDirectMusicSegment8Impl_IUnknown_Release
89 /* IDirectMusicSegmentImpl IDirectMusicSegment part: */
90 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_QueryInterface (LPDIRECTMUSICSEGMENT8 iface, REFIID riid, LPVOID *ppobj) {
91 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
92 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
95 static ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef (LPDIRECTMUSICSEGMENT8 iface) {
96 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
97 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
100 static ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Release (LPDIRECTMUSICSEGMENT8 iface) {
101 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
102 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
105 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLength (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtLength) {
106 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
107 TRACE("(%p, %p)\n", This, pmtLength);
108 if (NULL == pmtLength) {
109 return E_POINTER;
111 *pmtLength = This->header.mtLength;
112 return S_OK;
115 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLength (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtLength) {
116 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
117 TRACE("(%p, %ld)\n", This, mtLength);
118 This->header.mtLength = mtLength;
119 return S_OK;
122 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetRepeats (LPDIRECTMUSICSEGMENT8 iface, DWORD* pdwRepeats) {
123 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
124 TRACE("(%p, %p)\n", This, pdwRepeats);
125 if (NULL == pdwRepeats) {
126 return E_POINTER;
128 *pdwRepeats = This->header.dwRepeats;
129 return S_OK;
132 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetRepeats (LPDIRECTMUSICSEGMENT8 iface, DWORD dwRepeats) {
133 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
134 TRACE("(%p, %d)\n", This, dwRepeats);
135 This->header.dwRepeats = dwRepeats;
136 return S_OK;
139 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetDefaultResolution (LPDIRECTMUSICSEGMENT8 iface, DWORD* pdwResolution) {
140 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
141 TRACE("(%p, %p)\n", This, pdwResolution);
142 if (NULL == pdwResolution) {
143 return E_POINTER;
145 *pdwResolution = This->header.dwResolution;
146 return S_OK;
149 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetDefaultResolution (LPDIRECTMUSICSEGMENT8 iface, DWORD dwResolution) {
150 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
151 TRACE("(%p, %d)\n", This, dwResolution);
152 This->header.dwResolution = dwResolution;
153 return S_OK;
156 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, IDirectMusicTrack** ppTrack) {
157 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
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;
165 TRACE("(%p, %s, %d, 0x%x, %p)\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, ppTrack);
167 if (NULL == ppTrack) {
168 return E_POINTER;
171 LIST_FOR_EACH (pEntry, &This->Tracks) {
172 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
173 TRACE(" - %p -> 0x%x,%p\n", pIt, pIt->dwGroupBits, pIt->pTrack);
174 if (0xFFFFFFFF != dwGroupBits && 0 == (pIt->dwGroupBits & dwGroupBits)) continue ;
175 if (FALSE == IsEqualGUID(&GUID_NULL, rguidType)) {
177 * it rguidType is not null we must check if CLSID are equals
178 * and the unique way to get it is using IPersistStream Interface
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 ;
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 ;
191 TRACE(" - %p -> %s\n", pIt, debugstr_dmguid(&pIt_clsid));
192 if (FALSE == IsEqualGUID(&pIt_clsid, rguidType)) continue ;
194 if (0 == dwIndex) {
195 *ppTrack = pIt->pTrack;
196 IDirectMusicTrack_AddRef(*ppTrack);
197 return S_OK;
199 --dwIndex;
201 return DMUS_E_NOT_FOUND;
204 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrackGroup (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack, DWORD* pdwGroupBits) {
205 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
207 struct list* pEntry = NULL;
208 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
210 TRACE("(%p, %p, %p)\n", This, pTrack, pdwGroupBits);
212 if (NULL == pdwGroupBits) {
213 return E_POINTER;
216 LIST_FOR_EACH (pEntry, &This->Tracks) {
217 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
218 TRACE(" - %p -> %d,%p\n", pIt, pIt->dwGroupBits, pIt->pTrack);
219 if (NULL != pIt && pIt->pTrack == pTrack) {
220 *pdwGroupBits = pIt->dwGroupBits;
221 return S_OK;
225 return DMUS_E_NOT_FOUND;
228 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack, DWORD dwGroupBits) {
229 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
231 DWORD i = 0;
232 struct list* pEntry = NULL;
233 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
234 LPDMUS_PRIVATE_SEGMENT_TRACK pNewSegTrack = NULL;
236 TRACE("(%p, %p, %d)\n", This, pTrack, dwGroupBits);
238 LIST_FOR_EACH (pEntry, &This->Tracks) {
239 i++;
240 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
241 TRACE(" - #%u: %p -> %d,%p\n", i, pIt, pIt->dwGroupBits, pIt->pTrack);
242 if (NULL != pIt && pIt->pTrack == pTrack) {
243 ERR("(%p, %p): track is already in list\n", This, pTrack);
244 return E_FAIL;
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;
253 pNewSegTrack->dwGroupBits = dwGroupBits;
254 pNewSegTrack->pTrack = pTrack;
255 IDirectMusicTrack_Init(pTrack, (IDirectMusicSegment *)iface);
256 IDirectMusicTrack_AddRef(pTrack);
257 list_add_tail (&This->Tracks, &pNewSegTrack->entry);
259 return S_OK;
262 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack) {
263 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
265 struct list* pEntry = NULL;
266 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
268 TRACE("(%p, %p)\n", This, pTrack);
270 LIST_FOR_EACH (pEntry, &This->Tracks) {
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);
275 list_remove(&pIt->entry);
276 IDirectMusicTrack_Init(pIt->pTrack, NULL);
277 IDirectMusicTrack_Release(pIt->pTrack);
278 HeapFree(GetProcessHeap(), 0, pIt);
280 return S_OK;
284 return S_FALSE;
287 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicSegmentState** ppSegState, IDirectMusicPerformance* pPerformance, DWORD dwFlags) {
288 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
289 HRESULT hr;
290 FIXME("(%p, %p, %p, %d): semi-stub\n", This, ppSegState, pPerformance, dwFlags);
291 if (NULL == ppSegState) {
292 return E_POINTER;
294 hr = DMUSIC_CreateDirectMusicSegmentStateImpl(&IID_IDirectMusicSegmentState, (void**) ppSegState, NULL);
295 if (FAILED(hr)) {
296 return hr;
298 /* TODO: DMUS_SEGF_FLAGS */
299 return S_OK;
302 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicGraph** ppGraph) {
303 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
304 FIXME("(%p, %p): semi-stub\n", This, ppGraph);
305 if (NULL == ppGraph) {
306 return E_POINTER;
308 if (NULL == This->pGraph) {
309 return DMUS_E_NOT_FOUND;
311 /**
312 * should return This, as seen in msdn
313 * "...The segment object implements IDirectMusicGraph directly..."
315 *ppGraph = This->pGraph;
316 IDirectMusicGraph_AddRef(This->pGraph);
317 return S_OK;
320 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicGraph* pGraph) {
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);
326 This->pGraph = pGraph;
327 if (NULL != This->pGraph) {
328 IDirectMusicGraph_AddRef(This->pGraph);
330 return S_OK;
333 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidNotificationType) {
334 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
335 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
336 return S_OK;
339 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidNotificationType) {
340 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
341 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
342 return S_OK;
345 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
346 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
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;
355 FIXME("(%p, %s, 0x%x, %d, %ld, %p, %p)\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pmtNext, pParam);
357 if (DMUS_SEG_ANYTRACK == dwIndex) {
359 LIST_FOR_EACH (pEntry, &This->Tracks) {
360 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
362 TRACE(" - %p -> 0x%x,%p\n", pIt, pIt->dwGroupBits, pIt->pTrack);
364 if (0xFFFFFFFF != dwGroupBits && 0 == (pIt->dwGroupBits & dwGroupBits)) continue ;
365 hr = IPersistStream_GetClassID(pCLSIDStream, &pIt_clsid);
366 IPersistStream_Release(pCLSIDStream); pCLSIDStream = NULL;
367 if (FAILED(hr)) {
368 ERR("(%p): non-implemented GetClassID for object %p\n", This, pIt->pTrack);
369 continue ;
371 if (FALSE == IsEqualGUID(&pIt_clsid, rguidType)) continue ;
372 if (FAILED(IDirectMusicTrack_IsParamSupported(pIt->pTrack, rguidType))) continue ;
373 hr = IDirectMusicTrack_GetParam(pIt->pTrack, rguidType, mtTime, pmtNext, pParam);
374 if (SUCCEEDED(hr)) return hr;
376 ERR("(%p): not found\n", This);
377 return DMUS_E_TRACK_NOT_FOUND;
380 hr = IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack(iface, &GUID_NULL, dwGroupBits, dwIndex, &pTrack);
381 if (FAILED(hr)) {
382 ERR("(%p): not found\n", This);
383 return DMUS_E_TRACK_NOT_FOUND;
386 hr = IDirectMusicTrack_GetParam(pTrack, rguidType, mtTime, pmtNext, pParam);
387 IDirectMusicTrack_Release(pTrack); pTrack = NULL;
389 return hr;
392 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, void* pParam) {
393 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
394 FIXME("(%p, %s, %d, %d, %ld, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pParam);
395 return S_OK;
398 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicSegment** ppSegment) {
399 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
400 FIXME("(%p, %ld, %ld, %p): stub\n", This, mtStart, mtEnd, ppSegment);
401 return S_OK;
404 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart) {
405 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
406 TRACE("(%p, %ld)\n", This, mtStart);
407 if (mtStart >= This->header.mtLength) {
408 return DMUS_E_OUT_OF_RANGE;
410 This->header.mtPlayStart = mtStart;
411 return S_OK;
414 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtStart) {
415 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
416 TRACE("(%p, %p)\n", This, pmtStart);
417 if (NULL == pmtStart) {
418 return E_POINTER;
420 *pmtStart = This->header.mtPlayStart;
421 return S_OK;
424 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd) {
425 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
426 TRACE("(%p, %ld, %ld)\n", This, mtStart, mtEnd);
427 if (mtStart >= This->header.mtLength || mtEnd > This->header.mtLength || mtStart > mtEnd) {
428 return DMUS_E_OUT_OF_RANGE;
430 This->header.mtLoopStart = mtStart;
431 This->header.mtLoopEnd = mtEnd;
432 return S_OK;
435 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtStart, MUSIC_TIME* pmtEnd) {
436 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
437 TRACE("(%p, %p, %p)\n", This, pmtStart, pmtEnd);
438 if (NULL == pmtStart || NULL == pmtEnd) {
439 return E_POINTER;
441 *pmtStart = This->header.mtLoopStart;
442 *pmtEnd = This->header.mtLoopEnd;
443 return S_OK;
446 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed (LPDIRECTMUSICSEGMENT8 iface, DWORD dwNumPChannels, DWORD* paPChannels) {
447 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
448 FIXME("(%p, %d, %p): stub\n", This, dwNumPChannels, paPChannels);
449 return S_OK;
452 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidTrackClassID, DWORD dwGroupBits, DWORD dwIndex, DWORD dwFlagsOn, DWORD dwFlagsOff) {
453 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
454 FIXME("(%p, %s, %d, %d, %d, %d): stub\n", This, debugstr_dmguid(rguidTrackClassID), dwGroupBits, dwIndex, dwFlagsOn, dwFlagsOff);
455 return S_OK;
458 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig (LPDIRECTMUSICSEGMENT8 iface, IUnknown** ppAudioPathConfig){
459 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
460 FIXME("(%p, %p): stub\n", This, ppAudioPathConfig);
461 return S_OK;
464 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtTime, IDirectMusicSegment* pFromSegment, IDirectMusicSegment* pToSegment, IDirectMusicSegment** ppComposedSegment) {
465 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
466 FIXME("(%p, %ld, %p, %p, %p): stub\n", This, mtTime, pFromSegment, pToSegment, ppComposedSegment);
467 return S_OK;
470 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Download (LPDIRECTMUSICSEGMENT8 iface, IUnknown *pAudioPath) {
471 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
472 FIXME("(%p, %p): stub\n", This, pAudioPath);
473 return S_OK;
476 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload (LPDIRECTMUSICSEGMENT8 iface, IUnknown *pAudioPath) {
477 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
478 FIXME("(%p, %p): stub\n", This, pAudioPath);
479 return S_OK;
482 static const IDirectMusicSegment8Vtbl DirectMusicSegment8_Segment_Vtbl = {
483 IDirectMusicSegment8Impl_IDirectMusicSegment8_QueryInterface,
484 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef,
485 IDirectMusicSegment8Impl_IDirectMusicSegment8_Release,
486 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLength,
487 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLength,
488 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetRepeats,
489 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetRepeats,
490 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetDefaultResolution,
491 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetDefaultResolution,
492 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack,
493 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrackGroup,
494 IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack,
495 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack,
496 IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay,
497 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph,
498 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph,
499 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType,
500 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType,
501 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam,
502 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam,
503 IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone,
504 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint,
505 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint,
506 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints,
507 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints,
508 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed,
509 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig,
510 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig,
511 IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose,
512 IDirectMusicSegment8Impl_IDirectMusicSegment8_Download,
513 IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload
516 /* IDirectMusicSegment8Impl IDirectMusicObject part: */
517 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) {
518 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
519 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
522 static ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) {
523 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
524 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
527 static ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) {
528 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
529 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
532 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
533 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
534 TRACE("(%p, %p)\n", This, pDesc);
535 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
536 memcpy (pDesc, This->pDesc, This->pDesc->dwSize);
537 return S_OK;
540 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
541 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
542 TRACE("(%p, %p): setting descriptor:\n%s\n", This, pDesc, debugstr_DMUS_OBJECTDESC (pDesc));
544 /* According to MSDN, we should copy only given values, not whole struct */
545 if (pDesc->dwValidData & DMUS_OBJ_OBJECT)
546 This->pDesc->guidObject = pDesc->guidObject;
547 if (pDesc->dwValidData & DMUS_OBJ_CLASS)
548 This->pDesc->guidClass = pDesc->guidClass;
549 if (pDesc->dwValidData & DMUS_OBJ_NAME)
550 lstrcpynW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
551 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
552 lstrcpynW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
553 if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
554 lstrcpynW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
555 if (pDesc->dwValidData & DMUS_OBJ_VERSION)
556 This->pDesc->vVersion = pDesc->vVersion;
557 if (pDesc->dwValidData & DMUS_OBJ_DATE)
558 This->pDesc->ftDate = pDesc->ftDate;
559 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
560 memcpy (&This->pDesc->llMemLength, &pDesc->llMemLength, sizeof (pDesc->llMemLength));
561 memcpy (This->pDesc->pbMemData, pDesc->pbMemData, sizeof (pDesc->pbMemData));
563 if (pDesc->dwValidData & DMUS_OBJ_STREAM) {
564 /* according to MSDN, we copy the stream */
565 IStream_Clone (pDesc->pStream, &This->pDesc->pStream);
568 /* add new flags */
569 This->pDesc->dwValidData |= pDesc->dwValidData;
571 return S_OK;
574 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc) {
575 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
576 DMUS_PRIVATE_CHUNK Chunk;
577 DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
578 LARGE_INTEGER liMove; /* used when skipping chunks */
580 TRACE("(%p,%p, %p)\n", This, pStream, pDesc);
582 /* FIXME: should this be determined from stream? */
583 pDesc->dwValidData |= DMUS_OBJ_CLASS;
584 pDesc->guidClass = CLSID_DirectMusicSegment;
586 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
587 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
588 switch (Chunk.fccID) {
589 case FOURCC_RIFF: {
590 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
591 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
592 StreamSize = Chunk.dwSize - sizeof(FOURCC);
593 StreamCount = 0;
594 if (Chunk.fccID == DMUS_FOURCC_SEGMENT_FORM) {
595 TRACE_(dmfile)(": segment form\n");
596 do {
597 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
598 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
599 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
600 switch (Chunk.fccID) {
601 case DMUS_FOURCC_GUID_CHUNK: {
602 TRACE_(dmfile)(": GUID chunk\n");
603 pDesc->dwValidData |= DMUS_OBJ_OBJECT;
604 IStream_Read (pStream, &pDesc->guidObject, Chunk.dwSize, NULL);
605 break;
607 case DMUS_FOURCC_VERSION_CHUNK: {
608 TRACE_(dmfile)(": version chunk\n");
609 pDesc->dwValidData |= DMUS_OBJ_VERSION;
610 IStream_Read (pStream, &pDesc->vVersion, Chunk.dwSize, NULL);
611 break;
613 case DMUS_FOURCC_CATEGORY_CHUNK: {
614 TRACE_(dmfile)(": category chunk\n");
615 pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
616 IStream_Read (pStream, pDesc->wszCategory, Chunk.dwSize, NULL);
617 break;
619 case FOURCC_LIST: {
620 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
621 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
622 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
623 ListCount[0] = 0;
624 switch (Chunk.fccID) {
625 /* evil M$ UNFO list, which can (!?) contain INFO elements */
626 case DMUS_FOURCC_UNFO_LIST: {
627 TRACE_(dmfile)(": UNFO list\n");
628 do {
629 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
630 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
631 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
632 switch (Chunk.fccID) {
633 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
634 (though strings seem to be valid unicode) */
635 case mmioFOURCC('I','N','A','M'):
636 case DMUS_FOURCC_UNAM_CHUNK: {
637 TRACE_(dmfile)(": name chunk\n");
638 pDesc->dwValidData |= DMUS_OBJ_NAME;
639 IStream_Read (pStream, pDesc->wszName, Chunk.dwSize, NULL);
640 break;
642 case mmioFOURCC('I','A','R','T'):
643 case DMUS_FOURCC_UART_CHUNK: {
644 TRACE_(dmfile)(": artist chunk (ignored)\n");
645 liMove.QuadPart = Chunk.dwSize;
646 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
647 break;
649 case mmioFOURCC('I','C','O','P'):
650 case DMUS_FOURCC_UCOP_CHUNK: {
651 TRACE_(dmfile)(": copyright chunk (ignored)\n");
652 liMove.QuadPart = Chunk.dwSize;
653 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
654 break;
656 case mmioFOURCC('I','S','B','J'):
657 case DMUS_FOURCC_USBJ_CHUNK: {
658 TRACE_(dmfile)(": subject chunk (ignored)\n");
659 liMove.QuadPart = Chunk.dwSize;
660 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
661 break;
663 case mmioFOURCC('I','C','M','T'):
664 case DMUS_FOURCC_UCMT_CHUNK: {
665 TRACE_(dmfile)(": comment chunk (ignored)\n");
666 liMove.QuadPart = Chunk.dwSize;
667 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
668 break;
670 default: {
671 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
672 liMove.QuadPart = Chunk.dwSize;
673 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
674 break;
677 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
678 } while (ListCount[0] < ListSize[0]);
679 break;
681 case DMUS_FOURCC_TRACK_LIST: {
682 TRACE_(dmfile)(": TRACK list\n");
683 do {
684 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
685 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
686 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
687 switch (Chunk.fccID) {
688 default: {
689 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
690 liMove.QuadPart = Chunk.dwSize;
691 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
692 break;
695 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
696 } while (ListCount[0] < ListSize[0]);
697 break;
699 default: {
700 TRACE_(dmfile)(": unknown (skipping)\n");
701 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
702 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
703 break;
706 break;
708 default: {
709 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
710 liMove.QuadPart = Chunk.dwSize;
711 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
712 break;
715 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
716 } while (StreamCount < StreamSize);
717 break;
718 } else if (Chunk.fccID == mmioFOURCC('W','A','V','E')) {
719 TRACE_(dmfile)(": wave form (loading not yet implemented)\n");
720 liMove.QuadPart = StreamSize;
721 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
722 } else {
723 TRACE_(dmfile)(": unexpected chunk (loading failed)\n");
724 liMove.QuadPart = StreamSize;
725 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
726 return E_FAIL;
729 TRACE_(dmfile)(": reading finished\n");
730 break;
732 default: {
733 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
734 liMove.QuadPart = Chunk.dwSize;
735 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
736 return DMUS_E_INVALIDFILE;
740 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc));
742 return S_OK;
745 static const IDirectMusicObjectVtbl DirectMusicSegment8_Object_Vtbl = {
746 IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface,
747 IDirectMusicSegment8Impl_IDirectMusicObject_AddRef,
748 IDirectMusicSegment8Impl_IDirectMusicObject_Release,
749 IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor,
750 IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor,
751 IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor
754 /* IDirectMusicSegment8Impl IPersistStream part: */
755 static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
756 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
757 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
760 static ULONG WINAPI IDirectMusicSegment8Impl_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
761 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
762 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
765 static ULONG WINAPI IDirectMusicSegment8Impl_IPersistStream_Release (LPPERSISTSTREAM iface) {
766 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
767 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
770 static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
771 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
772 TRACE("(%p, %p)\n", This, pClassID);
773 *pClassID = CLSID_DirectMusicSegment;
774 return S_OK;
777 static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
778 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
779 FIXME("(%p): stub, always S_FALSE\n", This);
780 return S_FALSE;
783 static HRESULT IDirectMusicSegment8Impl_IPersistStream_LoadTrack (LPPERSISTSTREAM iface, IStream* pClonedStream, IDirectMusicTrack** ppTrack,
784 DMUS_IO_TRACK_HEADER* pTrack_hdr) {
786 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
787 HRESULT hr = E_FAIL;
788 IPersistStream* pPersistStream = NULL;
790 hr = CoCreateInstance (&pTrack_hdr->guidClassID, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicTrack, (LPVOID*) ppTrack);
791 if (FAILED(hr)) {
792 ERR(": could not create object\n");
793 return hr;
795 /* acquire PersistStream interface */
796 hr = IDirectMusicTrack_QueryInterface (*ppTrack, &IID_IPersistStream, (LPVOID*) &pPersistStream);
797 if (FAILED(hr)) {
798 ERR(": could not acquire IPersistStream\n");
799 return hr;
801 /* load */
802 hr = IPersistStream_Load (pPersistStream, pClonedStream);
803 if (FAILED(hr)) {
804 ERR(": failed to load object\n");
805 return hr;
808 /* release all loading-related stuff */
809 IPersistStream_Release (pPersistStream);
811 hr = IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack ((LPDIRECTMUSICSEGMENT8)&This->SegmentVtbl, *ppTrack, pTrack_hdr->dwGroup); /* at dsPosition */
812 if (FAILED(hr)) {
813 ERR(": could not insert track\n");
814 return hr;
817 return S_OK;
820 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
822 /*ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);*/
823 HRESULT hr = E_FAIL;
824 DMUS_PRIVATE_CHUNK Chunk;
825 DWORD StreamSize, StreamCount, ListSize[3];
826 LARGE_INTEGER liMove; /* used when skipping chunks */
828 DMUS_IO_TRACK_HEADER track_hdr;
829 DMUS_IO_TRACK_EXTRAS_HEADER track_xhdr;
830 IDirectMusicTrack* pTrack = NULL;
832 if (pChunk->fccID != DMUS_FOURCC_TRACK_FORM) {
833 ERR_(dmfile)(": %s chunk should be a TRACK form\n", debugstr_fourcc (pChunk->fccID));
834 return E_FAIL;
837 StreamSize = pChunk->dwSize - sizeof(FOURCC);
838 StreamCount = 0;
840 do {
841 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
842 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
843 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
845 switch (Chunk.fccID) {
846 case DMUS_FOURCC_TRACK_CHUNK: {
847 TRACE_(dmfile)(": track chunk\n");
848 IStream_Read (pStm, &track_hdr, sizeof(DMUS_IO_TRACK_HEADER), NULL);
849 TRACE_(dmfile)(" - class: %s\n", debugstr_guid (&track_hdr.guidClassID));
850 TRACE_(dmfile)(" - dwGroup: %d\n", track_hdr.dwGroup);
851 TRACE_(dmfile)(" - ckid: %s\n", debugstr_fourcc (track_hdr.ckid));
852 TRACE_(dmfile)(" - fccType: %s\n", debugstr_fourcc (track_hdr.fccType));
853 break;
855 case DMUS_FOURCC_TRACK_EXTRAS_CHUNK: {
856 TRACE_(dmfile)(": track extras chunk\n");
857 IStream_Read (pStm, &track_xhdr, sizeof(DMUS_IO_TRACK_EXTRAS_HEADER), NULL);
858 break;
861 case DMUS_FOURCC_COMMANDTRACK_CHUNK: {
862 TRACE_(dmfile)(": COMMANDTRACK track\n");
863 liMove.QuadPart = Chunk.dwSize;
864 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
865 break;
868 case FOURCC_LIST: {
869 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
870 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
871 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
872 if (Chunk.fccID == track_hdr.fccType && 0 == track_hdr.ckid) {
873 LPSTREAM pClonedStream = NULL;
875 TRACE_(dmfile)(": TRACK list\n");
877 IStream_Clone (pStm, &pClonedStream);
879 liMove.QuadPart = 0;
880 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
881 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
883 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
884 if (FAILED(hr)) {
885 ERR(": could not load track\n");
886 return hr;
888 IStream_Release (pClonedStream);
890 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
892 liMove.QuadPart = ListSize[0];
893 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
895 } else {
896 TRACE_(dmfile)(": unknown (skipping)\n");
897 liMove.QuadPart = Chunk.dwSize;
898 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
900 break;
903 case FOURCC_RIFF: {
904 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
905 TRACE_(dmfile)(": RIFF chunk of type %s\n", debugstr_fourcc(Chunk.fccID));
907 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
909 if (Chunk.fccID == track_hdr.fccType && 0 == track_hdr.ckid) {
910 LPSTREAM pClonedStream = NULL;
912 TRACE_(dmfile)(": TRACK RIFF\n");
914 IStream_Clone (pStm, &pClonedStream);
916 liMove.QuadPart = 0;
917 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
918 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
920 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
921 if (FAILED(hr)) {
922 ERR(": could not load track\n");
923 return hr;
925 IStream_Release (pClonedStream);
927 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
929 /** now safe move the cursor */
930 liMove.QuadPart = ListSize[0];
931 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
933 } else {
934 TRACE_(dmfile)(": unknown RIFF fmt (skipping)\n");
935 liMove.QuadPart = ListSize[0];
936 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
938 break;
941 default: {
942 if (0 == track_hdr.fccType && Chunk.fccID == track_hdr.ckid) {
943 LPSTREAM pClonedStream = NULL;
945 TRACE_(dmfile)(": TRACK solo\n");
947 IStream_Clone (pStm, &pClonedStream);
949 liMove.QuadPart = 0;
950 liMove.QuadPart -= (sizeof(FOURCC) + sizeof(DWORD));
951 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
953 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
954 if (FAILED(hr)) {
955 ERR(": could not load track\n");
956 return hr;
958 IStream_Release (pClonedStream);
960 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
962 liMove.QuadPart = Chunk.dwSize;
963 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
965 break;
968 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
969 liMove.QuadPart = Chunk.dwSize;
970 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
971 break;
974 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
975 } while (StreamCount < StreamSize);
977 return S_OK;
980 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicSegment8Impl* This) {
982 HRESULT hr = E_FAIL;
983 DMUS_PRIVATE_CHUNK Chunk;
984 DWORD StreamSize, ListSize[3], ListCount[3];
985 LARGE_INTEGER liMove; /* used when skipping chunks */
987 if (pChunk->fccID != DMUS_FOURCC_TRACK_LIST) {
988 ERR_(dmfile)(": %s chunk should be a TRACK list\n", debugstr_fourcc (pChunk->fccID));
989 return E_FAIL;
992 ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
993 ListCount[0] = 0;
995 do {
996 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
997 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
998 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
999 switch (Chunk.fccID) {
1000 case FOURCC_RIFF: {
1001 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
1002 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
1003 StreamSize = Chunk.dwSize - sizeof(FOURCC);
1004 switch (Chunk.fccID) {
1005 case DMUS_FOURCC_TRACK_FORM: {
1006 TRACE_(dmfile)(": TRACK form\n");
1007 hr = IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (iface, &Chunk, pStm);
1008 if (FAILED(hr)) return hr;
1009 break;
1011 default: {
1012 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1013 liMove.QuadPart = StreamSize;
1014 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1015 break;
1018 break;
1020 default: {
1021 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1022 liMove.QuadPart = Chunk.dwSize;
1023 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1024 break;
1027 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
1028 } while (ListCount[0] < ListSize[0]);
1030 return S_OK;
1033 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicSegment8Impl* This) {
1035 HRESULT hr = E_FAIL;
1036 DMUS_PRIVATE_CHUNK Chunk;
1037 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
1038 LARGE_INTEGER liMove; /* used when skipping chunks */
1040 if (pChunk->fccID != DMUS_FOURCC_SEGMENT_FORM) {
1041 ERR_(dmfile)(": %s chunk should be a segment form\n", debugstr_fourcc (pChunk->fccID));
1042 return E_FAIL;
1045 StreamSize = pChunk->dwSize - sizeof(FOURCC);
1046 StreamCount = 0;
1048 do {
1049 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1050 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
1051 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1053 hr = IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk, pStm, This->pDesc);
1054 if (FAILED(hr)) return hr;
1056 if (hr == S_FALSE) {
1057 switch (Chunk.fccID) {
1058 case DMUS_FOURCC_SEGMENT_CHUNK: {
1059 DWORD checkSz = sizeof(FOURCC);
1060 TRACE_(dmfile)(": segment chunk\n");
1061 #if 1
1062 /** DX 7 */
1063 IStream_Read (pStm, &This->header.dwRepeats, sizeof(This->header.dwRepeats), NULL);
1064 checkSz += sizeof(This->header.dwRepeats);
1065 IStream_Read (pStm, &This->header.mtLength, sizeof(This->header.mtLength), NULL);
1066 checkSz += sizeof(This->header.mtLength);
1067 IStream_Read (pStm, &This->header.mtPlayStart, sizeof(This->header.mtPlayStart), NULL);
1068 checkSz += sizeof(This->header.mtPlayStart);
1069 IStream_Read (pStm, &This->header.mtLoopStart, sizeof(This->header.mtLoopStart), NULL);
1070 checkSz += sizeof(This->header.mtLoopStart);
1071 IStream_Read (pStm, &This->header.mtLoopEnd, sizeof(This->header.mtLoopEnd), NULL);
1072 checkSz += sizeof(This->header.mtLoopEnd);
1073 IStream_Read (pStm, &This->header.dwResolution, sizeof(This->header.dwResolution), NULL);
1074 checkSz += sizeof(This->header.dwResolution);
1075 TRACE_(dmfile)("dwRepeats: %u\n", This->header.dwRepeats);
1076 TRACE_(dmfile)("mtLength: %lu\n", This->header.mtLength);
1077 TRACE_(dmfile)("mtPlayStart: %lu\n", This->header.mtPlayStart);
1078 TRACE_(dmfile)("mtLoopStart: %lu\n", This->header.mtLoopStart);
1079 TRACE_(dmfile)("mtLoopEnd: %lu\n", This->header.mtLoopEnd);
1080 TRACE_(dmfile)("dwResolution: %u\n", This->header.dwResolution);
1081 /** DX 8 */
1082 if (Chunk.dwSize > checkSz) {
1083 IStream_Read (pStm, &This->header.rtLength, sizeof(This->header.rtLength), NULL);
1084 checkSz += sizeof(This->header.rtLength);
1085 IStream_Read (pStm, &This->header.dwFlags, sizeof(This->header.dwFlags), NULL);
1086 checkSz += sizeof(This->header.dwFlags);
1088 /** DX 9 */
1089 if (Chunk.dwSize > checkSz) {
1090 IStream_Read (pStm, &This->header.rtLoopStart, sizeof(This->header.rtLoopStart), NULL);
1091 checkSz += sizeof(This->header.rtLoopStart);
1092 IStream_Read (pStm, &This->header.rtLoopEnd, sizeof(This->header.rtLoopEnd), NULL);
1093 checkSz += sizeof(This->header.rtLoopEnd);
1094 IStream_Read (pStm, &This->header.rtPlayStart, sizeof(This->header.rtPlayStart), NULL);
1095 checkSz += sizeof(This->header.rtPlayStart);
1097 #endif
1098 liMove.QuadPart = Chunk.dwSize - checkSz + sizeof(FOURCC);
1099 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1100 break;
1102 case FOURCC_LIST: {
1103 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
1104 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
1105 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
1106 ListCount[0] = 0;
1107 switch (Chunk.fccID) {
1108 case DMUS_FOURCC_UNFO_LIST: {
1109 TRACE_(dmfile)(": UNFO list\n");
1110 do {
1111 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1112 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
1113 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1115 hr = IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk, pStm, This->pDesc);
1116 if (FAILED(hr)) return hr;
1118 if (hr == S_FALSE) {
1119 switch (Chunk.fccID) {
1120 default: {
1121 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1122 liMove.QuadPart = Chunk.dwSize;
1123 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1124 break;
1129 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
1130 } while (ListCount[0] < ListSize[0]);
1131 break;
1133 case DMUS_FOURCC_TRACK_LIST: {
1134 TRACE_(dmfile)(": TRACK list\n");
1135 hr = IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (iface, &Chunk, pStm, This);
1136 if (FAILED(hr)) return hr;
1137 break;
1139 default: {
1140 TRACE_(dmfile)(": unknown (skipping)\n");
1141 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
1142 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1143 break;
1146 break;
1148 default: {
1149 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1150 liMove.QuadPart = Chunk.dwSize;
1151 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1152 break;
1156 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
1157 } while (StreamCount < StreamSize);
1159 return S_OK;
1162 static HRESULT IDirectMusicSegment8Impl_IPersistStream_LoadWave (LPPERSISTSTREAM iface, IStream* pClonedStream, IDirectMusicObject** ppWaveObject) {
1164 HRESULT hr = E_FAIL;
1165 IPersistStream* pPersistStream = NULL;
1167 hr = CoCreateInstance (&CLSID_DirectSoundWave, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicObject, (LPVOID*) ppWaveObject);
1168 if (FAILED(hr)) {
1169 ERR(": could not create object\n");
1170 return hr;
1172 /* acquire PersistStream interface */
1173 hr = IDirectMusicObject_QueryInterface (*ppWaveObject, &IID_IPersistStream, (LPVOID*) &pPersistStream);
1174 if (FAILED(hr)) {
1175 ERR(": could not acquire IPersistStream\n");
1176 return hr;
1178 /* load */
1179 hr = IPersistStream_Load (pPersistStream, pClonedStream);
1180 if (FAILED(hr)) {
1181 ERR(": failed to load object\n");
1182 return hr;
1185 /* release all loading-related stuff */
1186 IPersistStream_Release (pPersistStream);
1188 return S_OK;
1191 static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
1192 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1194 HRESULT hr;
1195 DMUS_PRIVATE_CHUNK Chunk;
1196 DWORD StreamSize;
1197 /*DWORD ListSize[3], ListCount[3];*/
1198 LARGE_INTEGER liMove; /* used when skipping chunks */
1200 TRACE("(%p, %p): Loading\n", This, pStm);
1201 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1202 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1203 switch (Chunk.fccID) {
1204 case FOURCC_RIFF: {
1205 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
1206 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
1207 StreamSize = Chunk.dwSize - sizeof(FOURCC);
1208 switch (Chunk.fccID) {
1209 case DMUS_FOURCC_SEGMENT_FORM: {
1210 TRACE_(dmfile)(": segment form\n");
1211 hr = IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (iface, &Chunk, pStm, This);
1212 if (FAILED(hr)) return hr;
1213 break;
1215 case mmioFOURCC('W','A','V','E'): {
1216 LPSTREAM pClonedStream = NULL;
1217 IDirectMusicObject* pWave = NULL;
1219 FIXME_(dmfile)(": WAVE form (loading to be checked)\n");
1221 IStream_Clone (pStm, &pClonedStream);
1223 liMove.QuadPart = 0;
1224 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
1225 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
1227 hr = IDirectMusicSegment8Impl_IPersistStream_LoadWave (iface, pClonedStream, &pWave);
1228 if (FAILED(hr)) {
1229 ERR(": could not load track\n");
1230 return hr;
1232 IStream_Release (pClonedStream);
1234 IDirectMusicTrack_Release(pWave); pWave = NULL; /* now we can release at as it inserted */
1236 liMove.QuadPart = StreamSize;
1237 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1238 break;
1240 default: {
1241 TRACE_(dmfile)(": unexpected chunk (loading failed)\n");
1242 liMove.QuadPart = StreamSize;
1243 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1244 return E_FAIL;
1247 TRACE_(dmfile)(": reading finished\n");
1248 break;
1250 default: {
1251 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
1252 liMove.QuadPart = Chunk.dwSize;
1253 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1254 return E_FAIL;
1258 return S_OK;
1261 static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
1262 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1263 FIXME("(%p): Saving not implemented yet\n", This);
1264 return E_NOTIMPL;
1267 static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
1268 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1269 FIXME("(%p, %p): stub\n", This, pcbSize);
1270 return E_NOTIMPL;
1273 static const IPersistStreamVtbl DirectMusicSegment8_PersistStream_Vtbl = {
1274 IDirectMusicSegment8Impl_IPersistStream_QueryInterface,
1275 IDirectMusicSegment8Impl_IPersistStream_AddRef,
1276 IDirectMusicSegment8Impl_IPersistStream_Release,
1277 IDirectMusicSegment8Impl_IPersistStream_GetClassID,
1278 IDirectMusicSegment8Impl_IPersistStream_IsDirty,
1279 IDirectMusicSegment8Impl_IPersistStream_Load,
1280 IDirectMusicSegment8Impl_IPersistStream_Save,
1281 IDirectMusicSegment8Impl_IPersistStream_GetSizeMax
1284 /* for ClassFactory */
1285 HRESULT WINAPI DMUSIC_CreateDirectMusicSegmentImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
1286 IDirectMusicSegment8Impl* obj;
1288 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSegment8Impl));
1289 if (NULL == obj) {
1290 *ppobj = NULL;
1291 return E_OUTOFMEMORY;
1293 obj->UnknownVtbl = &DirectMusicSegment8_Unknown_Vtbl;
1294 obj->SegmentVtbl = &DirectMusicSegment8_Segment_Vtbl;
1295 obj->ObjectVtbl = &DirectMusicSegment8_Object_Vtbl;
1296 obj->PersistStreamVtbl = &DirectMusicSegment8_PersistStream_Vtbl;
1297 obj->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
1298 DM_STRUCT_INIT(obj->pDesc);
1299 obj->pDesc->dwValidData |= DMUS_OBJ_CLASS;
1300 obj->pDesc->guidClass = CLSID_DirectMusicSegment;
1301 obj->ref = 0; /* will be inited by QueryInterface */
1302 list_init (&obj->Tracks);
1304 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&obj->UnknownVtbl, lpcGUID, ppobj);