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 modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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
14 * GNU Library General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 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 IDirectMusicSegment8Impl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
38 } else if (IsEqualIID (riid, &IID_IDirectMusicSegment)
39 || IsEqualIID (riid, &IID_IDirectMusicSegment2)
40 || IsEqualIID (riid, &IID_IDirectMusicSegment8)) {
41 *ppobj = (LPVOID)&This->SegmentVtbl;
42 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef ((LPDIRECTMUSICSEGMENT8)&This->SegmentVtbl);
44 } else if (IsEqualIID (riid, &IID_IDirectMusicObject)) {
45 *ppobj = (LPVOID)&This->ObjectVtbl;
46 IDirectMusicSegment8Impl_IDirectMusicObject_AddRef ((LPDIRECTMUSICOBJECT)&This->ObjectVtbl);
48 } else if (IsEqualIID (riid, &IID_IPersistStream)) {
49 *ppobj = (LPVOID)&This->PersistStreamVtbl;
50 IDirectMusicSegment8Impl_IPersistStream_AddRef ((LPPERSISTSTREAM)&This->PersistStreamVtbl);
54 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
58 ULONG WINAPI IDirectMusicSegment8Impl_IUnknown_AddRef (LPUNKNOWN iface) {
59 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
60 TRACE("(%p): AddRef from %ld\n", This, This->ref);
64 ULONG WINAPI IDirectMusicSegment8Impl_IUnknown_Release (LPUNKNOWN iface) {
65 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
66 ULONG ref = --This->ref;
67 TRACE("(%p): ReleaseRef to %ld\n", This, This->ref);
69 HeapFree(GetProcessHeap(), 0, This);
74 ICOM_VTABLE(IUnknown) DirectMusicSegment8_Unknown_Vtbl = {
75 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
76 IDirectMusicSegment8Impl_IUnknown_QueryInterface,
77 IDirectMusicSegment8Impl_IUnknown_AddRef,
78 IDirectMusicSegment8Impl_IUnknown_Release
81 /* IDirectMusicSegmentImpl IDirectMusicSegment part: */
82 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_QueryInterface (LPDIRECTMUSICSEGMENT8 iface, REFIID riid, LPVOID *ppobj) {
83 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
84 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
87 ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef (LPDIRECTMUSICSEGMENT8 iface) {
88 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
89 return IDirectMusicSegment8Impl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
92 ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Release (LPDIRECTMUSICSEGMENT8 iface) {
93 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
94 return IDirectMusicSegment8Impl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
97 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLength (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtLength) {
98 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
99 TRACE("(%p, %p)\n", This, pmtLength);
100 if (NULL == pmtLength) {
103 *pmtLength = This->header.mtLength;
107 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLength (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtLength) {
108 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
109 TRACE("(%p, %ld)\n", This, mtLength);
110 This->header.mtLength = mtLength;
114 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetRepeats (LPDIRECTMUSICSEGMENT8 iface, DWORD* pdwRepeats) {
115 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
116 TRACE("(%p, %p)\n", This, pdwRepeats);
117 if (NULL == pdwRepeats) {
120 *pdwRepeats = This->header.dwRepeats;
124 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetRepeats (LPDIRECTMUSICSEGMENT8 iface, DWORD dwRepeats) {
125 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
126 TRACE("(%p, %ld)\n", This, dwRepeats);
127 This->header.dwRepeats = dwRepeats;
131 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetDefaultResolution (LPDIRECTMUSICSEGMENT8 iface, DWORD* pdwResolution) {
132 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
133 TRACE("(%p, %p)\n", This, pdwResolution);
134 if (NULL == pdwResolution) {
137 *pdwResolution = This->header.dwResolution;
141 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetDefaultResolution (LPDIRECTMUSICSEGMENT8 iface, DWORD dwResolution) {
142 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
143 TRACE("(%p, %ld)\n", This, dwResolution);
144 This->header.dwResolution = dwResolution;
148 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, IDirectMusicTrack** ppTrack) {
149 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
152 struct list* pEntry = NULL;
153 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
154 IPersistStream* pCLSIDStream = NULL;
157 TRACE("(%p, %s, %ld, 0x%lx, %p)\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, ppTrack);
159 if (NULL == ppTrack) {
163 LIST_FOR_EACH (pEntry, &This->Tracks) {
164 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
165 TRACE(" - %p -> 0x%lx,%p\n", pIt, pIt->dwGroupBits, pIt->pTrack);
166 if (0xFFFFFFFF != dwGroupBits && 0 == (pIt->dwGroupBits & dwGroupBits)) continue ;
167 if (FALSE == IsEqualGUID(&GUID_NULL, rguidType)) {
169 * it rguidType is not null we must check if CLSID are equals
170 * and the unqiue way to get it its using IPersistStream Interface
172 hr = IDirectMusicTrack_QueryInterface(pIt->pTrack, &IID_IPersistStream, (void**) &pCLSIDStream);
174 ERR("(%p): object %p don't implement IPersistStream Interface. Expect a crash (critical problem)\n", This, pIt->pTrack);
177 hr = IPersistStream_GetClassID(pCLSIDStream, &pIt_clsid);
178 IPersistStream_Release(pCLSIDStream); pCLSIDStream = NULL;
180 ERR("(%p): non-implemented GetClassID for object %p\n", This, pIt->pTrack);
183 TRACE(" - %p -> %s\n", pIt, debugstr_dmguid(&pIt_clsid));
184 if (FALSE == IsEqualGUID(&pIt_clsid, rguidType)) continue ;
187 *ppTrack = pIt->pTrack;
188 IDirectMusicTrack_AddRef(*ppTrack);
193 return DMUS_E_NOT_FOUND;
196 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrackGroup (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack, DWORD* pdwGroupBits) {
197 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
199 struct list* pEntry = NULL;
200 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
202 TRACE("(%p, %p, %p)\n", This, pTrack, pdwGroupBits);
204 if (NULL == pdwGroupBits) {
208 LIST_FOR_EACH (pEntry, &This->Tracks) {
209 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
210 TRACE(" - %p -> %ld,%p\n", pIt, pIt->dwGroupBits, pIt->pTrack);
211 if (NULL != pIt && pIt->pTrack == pTrack) {
212 *pdwGroupBits = pIt->dwGroupBits;
217 return DMUS_E_NOT_FOUND;
220 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack, DWORD dwGroupBits) {
221 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
224 struct list* pEntry = NULL;
225 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
226 LPDMUS_PRIVATE_SEGMENT_TRACK pNewSegTrack = NULL;
228 TRACE("(%p, %p, %ld)\n", This, pTrack, dwGroupBits);
230 LIST_FOR_EACH (pEntry, &This->Tracks) {
232 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
233 TRACE(" - #%lu: %p -> %ld,%p\n", i, pIt, pIt->dwGroupBits, pIt->pTrack);
234 if (NULL != pIt && pIt->pTrack == pTrack) {
235 ERR("(%p, %p): track is already in list\n", This, pTrack);
240 pNewSegTrack = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_SEGMENT_TRACK));
241 if (NULL == pNewSegTrack) {
242 ERR(": no more memory\n");
243 return E_OUTOFMEMORY;
245 pNewSegTrack->dwGroupBits = dwGroupBits;
246 pNewSegTrack->pTrack = pTrack;
247 IDirectMusicTrack_Init(pTrack, iface);
248 IDirectMusicTrack_AddRef(pTrack);
249 list_add_tail (&This->Tracks, &pNewSegTrack->entry);
254 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack) {
255 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
257 struct list* pEntry = NULL;
258 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
260 TRACE("(%p, %p)\n", This, pTrack);
262 LIST_FOR_EACH (pEntry, &This->Tracks) {
263 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
264 if (pIt->pTrack == pTrack) {
265 TRACE("(%p, %p): track in list\n", This, pTrack);
267 list_remove(&pIt->entry);
268 IDirectMusicTrack_Init(pIt->pTrack, NULL);
269 IDirectMusicTrack_Release(pIt->pTrack);
270 HeapFree(GetProcessHeap(), 0, pIt);
279 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicSegmentState** ppSegState, IDirectMusicPerformance* pPerformance, DWORD dwFlags) {
280 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
282 FIXME("(%p, %p, %p, %ld): semi-stub\n", This, ppSegState, pPerformance, dwFlags);
283 if (NULL == ppSegState) {
286 hr = DMUSIC_CreateDirectMusicSegmentStateImpl(&IID_IDirectMusicSegmentState, (void**) ppSegState, NULL);
290 /* TODO: DMUS_SEGF_FLAGS */
294 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicGraph** ppGraph) {
295 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
296 FIXME("(%p, %p): semi-stub\n", This, ppGraph);
297 if (NULL == ppGraph) {
300 if (NULL == This->pGraph) {
301 return DMUS_E_NOT_FOUND;
304 * should return This, as seen in msdn
305 * http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c/directx/htm/idirectmusicsegment8getgraph.asp
306 * "...The segment object implements IDirectMusicGraph directly..."
308 *ppGraph = This->pGraph;
309 IDirectMusicGraph_AddRef(This->pGraph);
313 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicGraph* pGraph) {
314 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
315 FIXME("(%p, %p): to complete\n", This, pGraph);
316 if (NULL != This->pGraph) {
317 IDirectMusicGraph_Release(This->pGraph);
319 This->pGraph = pGraph;
320 if (NULL != This->pGraph) {
321 IDirectMusicGraph_AddRef(This->pGraph);
326 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidNotificationType) {
327 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
328 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
332 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidNotificationType) {
333 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
334 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
338 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
339 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
342 struct list* pEntry = NULL;
343 IDirectMusicTrack* pTrack = NULL;
344 IPersistStream* pCLSIDStream = NULL;
345 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
348 FIXME("(%p, %s, 0x%lx, %ld, %ld, %p, %p)\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pmtNext, pParam);
350 if (DMUS_SEG_ANYTRACK == dwIndex) {
352 LIST_FOR_EACH (pEntry, &This->Tracks) {
353 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
355 TRACE(" - %p -> 0x%lx,%p\n", pIt, pIt->dwGroupBits, pIt->pTrack);
357 if (0xFFFFFFFF != dwGroupBits && 0 == (pIt->dwGroupBits & dwGroupBits)) continue ;
358 hr = IPersistStream_GetClassID(pCLSIDStream, &pIt_clsid);
359 IPersistStream_Release(pCLSIDStream); pCLSIDStream = NULL;
361 ERR("(%p): non-implemented GetClassID for object %p\n", This, pIt->pTrack);
364 if (FALSE == IsEqualGUID(&pIt_clsid, rguidType)) continue ;
365 if (FAILED(IDirectMusicTrack_IsParamSupported(pIt->pTrack, rguidType))) continue ;
366 hr = IDirectMusicTrack_GetParam(pIt->pTrack, rguidType, mtTime, pmtNext, pParam);
367 if (SUCCEEDED(hr)) return hr;
369 ERR("(%p): not found\n", This);
370 return DMUS_E_TRACK_NOT_FOUND;
373 hr = IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack(iface, &GUID_NULL, dwGroupBits, dwIndex, &pTrack);
375 ERR("(%p): not found\n", This);
376 return DMUS_E_TRACK_NOT_FOUND;
379 hr = IDirectMusicTrack_GetParam(pTrack, rguidType, mtTime, pmtNext, pParam);
380 IDirectMusicTrack_Release(pTrack); pTrack = NULL;
385 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, void* pParam) {
386 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
387 FIXME("(%p, %s, %ld, %ld, %ld, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pParam);
391 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicSegment** ppSegment) {
392 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
393 FIXME("(%p, %ld, %ld, %p): stub\n", This, mtStart, mtEnd, ppSegment);
397 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart) {
398 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
399 TRACE("(%p, %ld)\n", This, mtStart);
400 if (mtStart >= This->header.mtLength) {
401 return DMUS_E_OUT_OF_RANGE;
403 This->header.mtPlayStart = mtStart;
407 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtStart) {
408 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
409 TRACE("(%p, %p)\n", This, pmtStart);
410 if (NULL == pmtStart) {
413 *pmtStart = This->header.mtPlayStart;
417 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd) {
418 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
419 TRACE("(%p, %ld, %ld)\n", This, mtStart, mtEnd);
420 if (mtStart >= This->header.mtLength || mtEnd > This->header.mtLength || mtStart > mtEnd) {
421 return DMUS_E_OUT_OF_RANGE;
423 This->header.mtLoopStart = mtStart;
424 This->header.mtLoopEnd = mtEnd;
428 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtStart, MUSIC_TIME* pmtEnd) {
429 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
430 TRACE("(%p, %p, %p)\n", This, pmtStart, pmtEnd);
431 if (NULL == pmtStart || NULL == pmtEnd) {
434 *pmtStart = This->header.mtLoopStart;
435 *pmtEnd = This->header.mtLoopEnd;
439 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed (LPDIRECTMUSICSEGMENT8 iface, DWORD dwNumPChannels, DWORD* paPChannels) {
440 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
441 FIXME("(%p, %ld, %p): stub\n", This, dwNumPChannels, paPChannels);
445 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidTrackClassID, DWORD dwGroupBits, DWORD dwIndex, DWORD dwFlagsOn, DWORD dwFlagsOff) {
446 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
447 FIXME("(%p, %s, %ld, %ld, %ld, %ld): stub\n", This, debugstr_dmguid(rguidTrackClassID), dwGroupBits, dwIndex, dwFlagsOn, dwFlagsOff);
451 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig (LPDIRECTMUSICSEGMENT8 iface, IUnknown** ppAudioPathConfig){
452 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
453 FIXME("(%p, %p): stub\n", This, ppAudioPathConfig);
457 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtTime, IDirectMusicSegment* pFromSegment, IDirectMusicSegment* pToSegment, IDirectMusicSegment** ppComposedSegment) {
458 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
459 FIXME("(%p, %ld, %p, %p, %p): stub\n", This, mtTime, pFromSegment, pToSegment, ppComposedSegment);
463 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Download (LPDIRECTMUSICSEGMENT8 iface, IUnknown *pAudioPath) {
464 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
465 FIXME("(%p, %p): stub\n", This, pAudioPath);
469 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload (LPDIRECTMUSICSEGMENT8 iface, IUnknown *pAudioPath) {
470 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
471 FIXME("(%p, %p): stub\n", This, pAudioPath);
475 ICOM_VTABLE(IDirectMusicSegment8) DirectMusicSegment8_Segment_Vtbl = {
476 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
477 IDirectMusicSegment8Impl_IDirectMusicSegment8_QueryInterface,
478 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef,
479 IDirectMusicSegment8Impl_IDirectMusicSegment8_Release,
480 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLength,
481 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLength,
482 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetRepeats,
483 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetRepeats,
484 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetDefaultResolution,
485 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetDefaultResolution,
486 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack,
487 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrackGroup,
488 IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack,
489 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack,
490 IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay,
491 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph,
492 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph,
493 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType,
494 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType,
495 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam,
496 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam,
497 IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone,
498 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint,
499 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint,
500 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints,
501 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints,
502 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed,
503 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig,
504 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig,
505 IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose,
506 IDirectMusicSegment8Impl_IDirectMusicSegment8_Download,
507 IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload
510 /* IDirectMusicSegment8Impl IDirectMusicObject part: */
511 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) {
512 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
513 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
516 ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) {
517 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
518 return IDirectMusicSegment8Impl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
521 ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) {
522 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
523 return IDirectMusicSegment8Impl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
526 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
527 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
528 TRACE("(%p, %p)\n", This, pDesc);
529 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
530 memcpy (pDesc, This->pDesc, This->pDesc->dwSize);
534 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
535 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
536 TRACE("(%p, %p): setting descriptor:\n%s\n", This, pDesc, debugstr_DMUS_OBJECTDESC (pDesc));
538 /* According to MSDN, we should copy only given values, not whole struct */
539 if (pDesc->dwValidData & DMUS_OBJ_OBJECT)
540 memcpy (&This->pDesc->guidObject, &pDesc->guidObject, sizeof (pDesc->guidObject));
541 if (pDesc->dwValidData & DMUS_OBJ_CLASS)
542 memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass));
543 if (pDesc->dwValidData & DMUS_OBJ_NAME)
544 strncpyW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
545 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
546 strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
547 if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
548 strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
549 if (pDesc->dwValidData & DMUS_OBJ_VERSION)
550 memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));
551 if (pDesc->dwValidData & DMUS_OBJ_DATE)
552 memcpy (&This->pDesc->ftDate, &pDesc->ftDate, sizeof (pDesc->ftDate));
553 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
554 memcpy (&This->pDesc->llMemLength, &pDesc->llMemLength, sizeof (pDesc->llMemLength));
555 memcpy (This->pDesc->pbMemData, pDesc->pbMemData, sizeof (pDesc->pbMemData));
557 if (pDesc->dwValidData & DMUS_OBJ_STREAM) {
558 /* according to MSDN, we copy the stream */
559 IStream_Clone (pDesc->pStream, &This->pDesc->pStream);
563 This->pDesc->dwValidData |= pDesc->dwValidData;
568 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc) {
569 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
570 DMUS_PRIVATE_CHUNK Chunk;
571 DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
572 LARGE_INTEGER liMove; /* used when skipping chunks */
574 TRACE("(%p,%p, %p)\n", This, pStream, pDesc);
576 /* FIXME: should this be determined from stream? */
577 pDesc->dwValidData |= DMUS_OBJ_CLASS;
578 memcpy (&pDesc->guidClass, &CLSID_DirectMusicSegment, sizeof(CLSID));
580 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
581 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
582 switch (Chunk.fccID) {
584 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
585 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
586 StreamSize = Chunk.dwSize - sizeof(FOURCC);
588 if (Chunk.fccID == DMUS_FOURCC_SEGMENT_FORM) {
589 TRACE_(dmfile)(": segment form\n");
591 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
592 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
593 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
594 switch (Chunk.fccID) {
595 case DMUS_FOURCC_GUID_CHUNK: {
596 TRACE_(dmfile)(": GUID chunk\n");
597 pDesc->dwValidData |= DMUS_OBJ_OBJECT;
598 IStream_Read (pStream, &pDesc->guidObject, Chunk.dwSize, NULL);
601 case DMUS_FOURCC_VERSION_CHUNK: {
602 TRACE_(dmfile)(": version chunk\n");
603 pDesc->dwValidData |= DMUS_OBJ_VERSION;
604 IStream_Read (pStream, &pDesc->vVersion, Chunk.dwSize, NULL);
607 case DMUS_FOURCC_CATEGORY_CHUNK: {
608 TRACE_(dmfile)(": category chunk\n");
609 pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
610 IStream_Read (pStream, pDesc->wszCategory, Chunk.dwSize, NULL);
614 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
615 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
616 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
618 switch (Chunk.fccID) {
619 /* evil M$ UNFO list, which can (!?) contain INFO elements */
620 case DMUS_FOURCC_UNFO_LIST: {
621 TRACE_(dmfile)(": UNFO list\n");
623 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
624 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
625 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
626 switch (Chunk.fccID) {
627 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
628 (though strings seem to be valid unicode) */
629 case mmioFOURCC('I','N','A','M'):
630 case DMUS_FOURCC_UNAM_CHUNK: {
631 TRACE_(dmfile)(": name chunk\n");
632 pDesc->dwValidData |= DMUS_OBJ_NAME;
633 IStream_Read (pStream, pDesc->wszName, Chunk.dwSize, NULL);
636 case mmioFOURCC('I','A','R','T'):
637 case DMUS_FOURCC_UART_CHUNK: {
638 TRACE_(dmfile)(": artist chunk (ignored)\n");
639 liMove.QuadPart = Chunk.dwSize;
640 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
643 case mmioFOURCC('I','C','O','P'):
644 case DMUS_FOURCC_UCOP_CHUNK: {
645 TRACE_(dmfile)(": copyright chunk (ignored)\n");
646 liMove.QuadPart = Chunk.dwSize;
647 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
650 case mmioFOURCC('I','S','B','J'):
651 case DMUS_FOURCC_USBJ_CHUNK: {
652 TRACE_(dmfile)(": subject chunk (ignored)\n");
653 liMove.QuadPart = Chunk.dwSize;
654 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
657 case mmioFOURCC('I','C','M','T'):
658 case DMUS_FOURCC_UCMT_CHUNK: {
659 TRACE_(dmfile)(": comment chunk (ignored)\n");
660 liMove.QuadPart = Chunk.dwSize;
661 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
665 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
666 liMove.QuadPart = Chunk.dwSize;
667 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
671 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
672 } while (ListCount[0] < ListSize[0]);
675 case DMUS_FOURCC_TRACK_LIST: {
676 TRACE_(dmfile)(": TRACK list\n");
678 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
679 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
680 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
681 switch (Chunk.fccID) {
683 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
684 liMove.QuadPart = Chunk.dwSize;
685 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
689 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
690 } while (ListCount[0] < ListSize[0]);
694 TRACE_(dmfile)(": unknown (skipping)\n");
695 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
696 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
703 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
704 liMove.QuadPart = Chunk.dwSize;
705 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
709 TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
710 } while (StreamCount < StreamSize);
712 } else if (Chunk.fccID == mmioFOURCC('W','A','V','E')) {
713 TRACE_(dmfile)(": wave form (loading not yet implemented)\n");
714 liMove.QuadPart = StreamSize;
715 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
717 TRACE_(dmfile)(": unexpected chunk (loading failed)\n");
718 liMove.QuadPart = StreamSize;
719 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
723 TRACE_(dmfile)(": reading finished\n");
727 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
728 liMove.QuadPart = Chunk.dwSize;
729 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
730 return DMUS_E_INVALIDFILE;
734 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc));
739 ICOM_VTABLE(IDirectMusicObject) DirectMusicSegment8_Object_Vtbl = {
740 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
741 IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface,
742 IDirectMusicSegment8Impl_IDirectMusicObject_AddRef,
743 IDirectMusicSegment8Impl_IDirectMusicObject_Release,
744 IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor,
745 IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor,
746 IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor
749 /* IDirectMusicSegment8Impl IPersistStream part: */
750 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
751 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
752 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
755 ULONG WINAPI IDirectMusicSegment8Impl_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
756 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
757 return IDirectMusicSegment8Impl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
760 ULONG WINAPI IDirectMusicSegment8Impl_IPersistStream_Release (LPPERSISTSTREAM iface) {
761 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
762 return IDirectMusicSegment8Impl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
765 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
766 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
767 TRACE("(%p, %p)\n", This, pClassID);
768 memcpy(pClassID, &CLSID_DirectMusicSegment, sizeof(CLSID));
772 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
773 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
774 FIXME("(%p): stub, always S_FALSE\n", This);
778 static HRESULT IDirectMusicSegment8Impl_IPersistStream_LoadTrack (LPPERSISTSTREAM iface, IStream* pClonedStream, IDirectMusicTrack** ppTrack,
779 DMUS_IO_TRACK_HEADER* pTrack_hdr) {
781 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
783 IPersistStream* pPersistStream = NULL;
785 hr = CoCreateInstance (&pTrack_hdr->guidClassID, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicTrack, (LPVOID*) ppTrack);
787 ERR(": could not create object\n");
790 /* acquire PersistStream interface */
791 hr = IDirectMusicTrack_QueryInterface (*ppTrack, &IID_IPersistStream, (LPVOID*) &pPersistStream);
793 ERR(": could not acquire IPersistStream\n");
797 hr = IPersistStream_Load (pPersistStream, pClonedStream);
799 ERR(": failed to load object\n");
803 /* release all loading-related stuff */
804 IPersistStream_Release (pPersistStream);
806 hr = IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack ((LPDIRECTMUSICSEGMENT8)&This->SegmentVtbl, *ppTrack, pTrack_hdr->dwGroup); /* at dsPosition */
808 ERR(": could not insert track\n");
815 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
817 /*ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);*/
819 DMUS_PRIVATE_CHUNK Chunk;
820 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
821 LARGE_INTEGER liMove; /* used when skipping chunks */
823 DMUS_IO_TRACK_HEADER track_hdr;
824 DMUS_IO_TRACK_EXTRAS_HEADER track_xhdr;
825 IDirectMusicTrack* pTrack = NULL;
827 if (pChunk->fccID != DMUS_FOURCC_TRACK_FORM) {
828 ERR_(dmfile)(": %s chunk should be a TRACK form\n", debugstr_fourcc (pChunk->fccID));
832 StreamSize = pChunk->dwSize - sizeof(FOURCC);
836 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
837 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
838 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
840 switch (Chunk.fccID) {
841 case DMUS_FOURCC_TRACK_CHUNK: {
842 TRACE_(dmfile)(": track chunck\n");
843 IStream_Read (pStm, &track_hdr, sizeof(DMUS_IO_TRACK_HEADER), NULL);
844 TRACE_(dmfile)(" - class: %s\n", debugstr_guid (&track_hdr.guidClassID));
845 TRACE_(dmfile)(" - dwGroup: %ld\n", track_hdr.dwGroup);
846 TRACE_(dmfile)(" - ckid: %s\n", debugstr_fourcc (track_hdr.ckid));
847 TRACE_(dmfile)(" - fccType: %s\n", debugstr_fourcc (track_hdr.fccType));
850 case DMUS_FOURCC_TRACK_EXTRAS_CHUNK: {
851 TRACE_(dmfile)(": track extras chunck\n");
852 IStream_Read (pStm, &track_xhdr, sizeof(DMUS_IO_TRACK_EXTRAS_HEADER), NULL);
856 case DMUS_FOURCC_COMMANDTRACK_CHUNK: {
857 TRACE_(dmfile)(": COMMANDTRACK track\n");
858 liMove.QuadPart = Chunk.dwSize;
859 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
864 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
865 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
866 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
868 if (Chunk.fccID == track_hdr.fccType && 0 == track_hdr.ckid) {
869 LPSTREAM pClonedStream = NULL;
871 TRACE_(dmfile)(": TRACK list\n");
873 IStream_Clone (pStm, &pClonedStream);
876 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
877 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
879 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
881 ERR(": could not load track\n");
884 IStream_Release (pClonedStream);
886 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
888 liMove.QuadPart = ListSize[0];
889 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
892 TRACE_(dmfile)(": unknown (skipping)\n");
893 liMove.QuadPart = Chunk.dwSize;
894 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
900 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
901 TRACE_(dmfile)(": RIFF chunk of type %s\n", debugstr_fourcc(Chunk.fccID));
903 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
905 if (Chunk.fccID == track_hdr.fccType && 0 == track_hdr.ckid) {
906 LPSTREAM pClonedStream = NULL;
908 TRACE_(dmfile)(": TRACK RIFF\n");
910 IStream_Clone (pStm, &pClonedStream);
913 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
914 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
916 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
918 ERR(": could not load track\n");
921 IStream_Release (pClonedStream);
923 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
925 /** now safe move the cursor */
926 liMove.QuadPart = ListSize[0];
927 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
930 TRACE_(dmfile)(": unknown RIFF fmt (skipping)\n");
931 liMove.QuadPart = ListSize[0];
932 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
938 if (0 == track_hdr.fccType && Chunk.fccID == track_hdr.ckid) {
939 LPSTREAM pClonedStream = NULL;
941 TRACE_(dmfile)(": TRACK solo\n");
943 IStream_Clone (pStm, &pClonedStream);
946 liMove.QuadPart -= (sizeof(FOURCC) + sizeof(DWORD));
947 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
949 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
951 ERR(": could not load track\n");
954 IStream_Release (pClonedStream);
956 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
958 liMove.QuadPart = Chunk.dwSize;
959 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
964 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
965 liMove.QuadPart = Chunk.dwSize;
966 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
970 TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
971 } while (StreamCount < StreamSize);
976 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicSegment8Impl* This) {
979 DMUS_PRIVATE_CHUNK Chunk;
980 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
981 LARGE_INTEGER liMove; /* used when skipping chunks */
983 if (pChunk->fccID != DMUS_FOURCC_TRACK_LIST) {
984 ERR_(dmfile)(": %s chunk should be a TRACK list\n", debugstr_fourcc (pChunk->fccID));
988 ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
992 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
993 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
994 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
995 switch (Chunk.fccID) {
997 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
998 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
999 StreamSize = Chunk.dwSize - sizeof(FOURCC);
1001 switch (Chunk.fccID) {
1002 case DMUS_FOURCC_TRACK_FORM: {
1003 TRACE_(dmfile)(": TRACK form\n");
1004 hr = IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (iface, &Chunk, pStm);
1005 if (FAILED(hr)) return hr;
1009 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1010 liMove.QuadPart = StreamSize;
1011 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1018 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1019 liMove.QuadPart = Chunk.dwSize;
1020 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1024 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
1025 } while (ListCount[0] < ListSize[0]);
1030 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicSegment8Impl* This) {
1032 HRESULT hr = E_FAIL;
1033 DMUS_PRIVATE_CHUNK Chunk;
1034 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
1035 LARGE_INTEGER liMove; /* used when skipping chunks */
1037 if (pChunk->fccID != DMUS_FOURCC_SEGMENT_FORM) {
1038 ERR_(dmfile)(": %s chunk should be a segment form\n", debugstr_fourcc (pChunk->fccID));
1042 StreamSize = pChunk->dwSize - sizeof(FOURCC);
1046 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1047 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
1048 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1050 hr = IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk, pStm, This->pDesc);
1051 if (FAILED(hr)) return hr;
1053 if (hr == S_FALSE) {
1054 switch (Chunk.fccID) {
1055 case DMUS_FOURCC_SEGMENT_CHUNK: {
1056 DWORD checkSz = sizeof(FOURCC);
1057 TRACE_(dmfile)(": segment chunk\n");
1060 IStream_Read (pStm, &This->header.dwRepeats, sizeof(This->header.dwRepeats), NULL);
1061 checkSz += sizeof(This->header.dwRepeats);
1062 IStream_Read (pStm, &This->header.mtLength, sizeof(This->header.mtLength), NULL);
1063 checkSz += sizeof(This->header.mtLength);
1064 IStream_Read (pStm, &This->header.mtPlayStart, sizeof(This->header.mtPlayStart), NULL);
1065 checkSz += sizeof(This->header.mtPlayStart);
1066 IStream_Read (pStm, &This->header.mtLoopStart, sizeof(This->header.mtLoopStart), NULL);
1067 checkSz += sizeof(This->header.mtLoopStart);
1068 IStream_Read (pStm, &This->header.mtLoopEnd, sizeof(This->header.mtLoopEnd), NULL);
1069 checkSz += sizeof(This->header.mtLoopEnd);
1070 IStream_Read (pStm, &This->header.dwResolution, sizeof(This->header.dwResolution), NULL);
1071 checkSz += sizeof(This->header.dwResolution);
1072 TRACE_(dmfile)("dwRepeats: %lu\n", This->header.dwRepeats);
1073 TRACE_(dmfile)("mtLength: %lu\n", This->header.mtLength);
1074 TRACE_(dmfile)("mtPlayStart: %lu\n", This->header.mtPlayStart);
1075 TRACE_(dmfile)("mtLoopStart: %lu\n", This->header.mtLoopStart);
1076 TRACE_(dmfile)("mtLoopEnd: %lu\n", This->header.mtLoopEnd);
1077 TRACE_(dmfile)("dwResolution: %lu\n", This->header.dwResolution);
1079 if (Chunk.dwSize > checkSz) {
1080 IStream_Read (pStm, &This->header.rtLength, sizeof(This->header.rtLength), NULL);
1081 checkSz += sizeof(This->header.rtLength);
1082 IStream_Read (pStm, &This->header.dwFlags, sizeof(This->header.dwFlags), NULL);
1083 checkSz += sizeof(This->header.dwFlags);
1086 if (Chunk.dwSize > checkSz) {
1087 IStream_Read (pStm, &This->header.rtLoopStart, sizeof(This->header.rtLoopStart), NULL);
1088 checkSz += sizeof(This->header.rtLoopStart);
1089 IStream_Read (pStm, &This->header.rtLoopEnd, sizeof(This->header.rtLoopEnd), NULL);
1090 checkSz += sizeof(This->header.rtLoopEnd);
1091 IStream_Read (pStm, &This->header.rtPlayStart, sizeof(This->header.rtPlayStart), NULL);
1092 checkSz += sizeof(This->header.rtPlayStart);
1095 liMove.QuadPart = Chunk.dwSize - checkSz + sizeof(FOURCC);
1096 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1100 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
1101 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
1102 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
1104 switch (Chunk.fccID) {
1105 case DMUS_FOURCC_UNFO_LIST: {
1106 TRACE_(dmfile)(": UNFO list\n");
1108 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1109 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
1110 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1112 hr = IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk, pStm, This->pDesc);
1113 if (FAILED(hr)) return hr;
1115 if (hr == S_FALSE) {
1116 switch (Chunk.fccID) {
1118 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1119 liMove.QuadPart = Chunk.dwSize;
1120 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1126 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
1127 } while (ListCount[0] < ListSize[0]);
1130 case DMUS_FOURCC_TRACK_LIST: {
1131 TRACE_(dmfile)(": TRACK list\n");
1132 hr = IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (iface, &Chunk, pStm, This);
1133 if (FAILED(hr)) return hr;
1137 TRACE_(dmfile)(": unknown (skipping)\n");
1138 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
1139 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1146 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1147 liMove.QuadPart = Chunk.dwSize;
1148 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1153 TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
1154 } while (StreamCount < StreamSize);
1159 static HRESULT IDirectMusicSegment8Impl_IPersistStream_LoadWave (LPPERSISTSTREAM iface, IStream* pClonedStream, IDirectMusicObject** ppWaveObject) {
1161 HRESULT hr = E_FAIL;
1162 IPersistStream* pPersistStream = NULL;
1164 hr = CoCreateInstance (&CLSID_DirectSoundWave, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicObject, (LPVOID*) ppWaveObject);
1166 ERR(": could not create object\n");
1169 /* acquire PersistStream interface */
1170 hr = IDirectMusicObject_QueryInterface (*ppWaveObject, &IID_IPersistStream, (LPVOID*) &pPersistStream);
1172 ERR(": could not acquire IPersistStream\n");
1176 hr = IPersistStream_Load (pPersistStream, pClonedStream);
1178 ERR(": failed to load object\n");
1182 /* release all loading-related stuff */
1183 IPersistStream_Release (pPersistStream);
1188 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
1189 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1192 DMUS_PRIVATE_CHUNK Chunk;
1193 DWORD StreamSize, StreamCount;
1194 /*DWORD ListSize[3], ListCount[3];*/
1195 LARGE_INTEGER liMove; /* used when skipping chunks */
1198 TRACE("(%p, %p): Loading\n", This, pStm);
1199 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1200 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1201 switch (Chunk.fccID) {
1203 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
1204 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
1205 StreamSize = Chunk.dwSize - sizeof(FOURCC);
1207 switch (Chunk.fccID) {
1208 case DMUS_FOURCC_SEGMENT_FORM: {
1209 TRACE_(dmfile)(": segment form\n");
1210 hr = IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (iface, &Chunk, pStm, This);
1211 if (FAILED(hr)) return hr;
1214 case mmioFOURCC('W','A','V','E'): {
1215 LPSTREAM pClonedStream = NULL;
1216 IDirectMusicObject* pWave = NULL;
1218 FIXME_(dmfile)(": WAVE form (loading to be checked)\n");
1220 IStream_Clone (pStm, &pClonedStream);
1222 liMove.QuadPart = 0;
1223 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
1224 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
1226 hr = IDirectMusicSegment8Impl_IPersistStream_LoadWave (iface, pClonedStream, &pWave);
1228 ERR(": could not load track\n");
1231 IStream_Release (pClonedStream);
1233 IDirectMusicTrack_Release(pWave); pWave = NULL; /* now we can release at as it inserted */
1235 liMove.QuadPart = StreamSize;
1236 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1240 TRACE_(dmfile)(": unexpected chunk (loading failed)\n");
1241 liMove.QuadPart = StreamSize;
1242 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1246 TRACE_(dmfile)(": reading finished\n");
1250 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
1251 liMove.QuadPart = Chunk.dwSize;
1252 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1260 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
1261 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1262 FIXME("(%p): Saving not implemented yet\n", This);
1266 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
1267 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1268 FIXME("(%p, %p): stub\n", This, pcbSize);
1272 ICOM_VTABLE(IPersistStream) DirectMusicSegment8_PersistStream_Vtbl = {
1273 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
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));
1290 *ppobj = (LPVOID) 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 memcpy (&obj->pDesc->guidClass, &CLSID_DirectMusicSegment, sizeof (CLSID));
1301 obj->ref = 0; /* will be inited by QueryInterface */
1302 list_init (&obj->Tracks);
1304 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&obj->UnknownVtbl, lpcGUID, ppobj);