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
= &This
->UnknownVtbl
;
36 IUnknown_AddRef (iface
);
38 } else if (IsEqualIID (riid
, &IID_IDirectMusicSegment
)
39 || IsEqualIID (riid
, &IID_IDirectMusicSegment2
)
40 || IsEqualIID (riid
, &IID_IDirectMusicSegment8
)) {
41 *ppobj
= &This
->SegmentVtbl
;
42 IUnknown_AddRef (iface
);
44 } else if (IsEqualIID (riid
, &IID_IDirectMusicObject
)) {
45 *ppobj
= &This
->ObjectVtbl
;
46 IUnknown_AddRef (iface
);
48 } else if (IsEqualIID (riid
, &IID_IPersistStream
)) {
49 *ppobj
= &This
->PersistStreamVtbl
;
50 IUnknown_AddRef (iface
);
54 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ppobj
);
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);
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
);
75 HeapFree(GetProcessHeap(), 0, This
);
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
) {
111 *pmtLength
= This
->header
.mtLength
;
115 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLength (LPDIRECTMUSICSEGMENT8 iface
, MUSIC_TIME mtLength
) {
116 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
117 TRACE("(%p, %d)\n", This
, mtLength
);
118 This
->header
.mtLength
= mtLength
;
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
) {
128 *pdwRepeats
= This
->header
.dwRepeats
;
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
;
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
) {
145 *pdwResolution
= This
->header
.dwResolution
;
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
;
156 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack (LPDIRECTMUSICSEGMENT8 iface
, REFGUID rguidType
, DWORD dwGroupBits
, DWORD dwIndex
, IDirectMusicTrack
** ppTrack
) {
157 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
160 struct list
* pEntry
= NULL
;
161 LPDMUS_PRIVATE_SEGMENT_TRACK pIt
= NULL
;
162 IPersistStream
* pCLSIDStream
= NULL
;
165 TRACE("(%p, %s, %d, 0x%x, %p)\n", This
, debugstr_dmguid(rguidType
), dwGroupBits
, dwIndex
, ppTrack
);
167 if (NULL
== ppTrack
) {
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
);
182 ERR("(%p): object %p don't implement IPersistStream Interface. Expect a crash (critical problem)\n", This
, pIt
->pTrack
);
185 hr
= IPersistStream_GetClassID(pCLSIDStream
, &pIt_clsid
);
186 IPersistStream_Release(pCLSIDStream
); pCLSIDStream
= NULL
;
188 ERR("(%p): non-implemented GetClassID for object %p\n", This
, pIt
->pTrack
);
191 TRACE(" - %p -> %s\n", pIt
, debugstr_dmguid(&pIt_clsid
));
192 if (FALSE
== IsEqualGUID(&pIt_clsid
, rguidType
)) continue ;
195 *ppTrack
= pIt
->pTrack
;
196 IDirectMusicTrack_AddRef(*ppTrack
);
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
) {
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
;
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
);
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
) {
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
);
248 pNewSegTrack
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_SEGMENT_TRACK
));
249 if (NULL
== pNewSegTrack
)
250 return E_OUTOFMEMORY
;
252 pNewSegTrack
->dwGroupBits
= dwGroupBits
;
253 pNewSegTrack
->pTrack
= pTrack
;
254 IDirectMusicTrack_Init(pTrack
, (IDirectMusicSegment
*)iface
);
255 IDirectMusicTrack_AddRef(pTrack
);
256 list_add_tail (&This
->Tracks
, &pNewSegTrack
->entry
);
261 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack (LPDIRECTMUSICSEGMENT8 iface
, IDirectMusicTrack
* pTrack
) {
262 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
264 struct list
* pEntry
= NULL
;
265 LPDMUS_PRIVATE_SEGMENT_TRACK pIt
= NULL
;
267 TRACE("(%p, %p)\n", This
, pTrack
);
269 LIST_FOR_EACH (pEntry
, &This
->Tracks
) {
270 pIt
= LIST_ENTRY(pEntry
, DMUS_PRIVATE_SEGMENT_TRACK
, entry
);
271 if (pIt
->pTrack
== pTrack
) {
272 TRACE("(%p, %p): track in list\n", This
, pTrack
);
274 list_remove(&pIt
->entry
);
275 IDirectMusicTrack_Init(pIt
->pTrack
, NULL
);
276 IDirectMusicTrack_Release(pIt
->pTrack
);
277 HeapFree(GetProcessHeap(), 0, pIt
);
286 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay (LPDIRECTMUSICSEGMENT8 iface
, IDirectMusicSegmentState
** ppSegState
, IDirectMusicPerformance
* pPerformance
, DWORD dwFlags
) {
287 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
289 FIXME("(%p, %p, %p, %d): semi-stub\n", This
, ppSegState
, pPerformance
, dwFlags
);
290 if (NULL
== ppSegState
) {
293 hr
= DMUSIC_CreateDirectMusicSegmentStateImpl(&IID_IDirectMusicSegmentState
, (void**) ppSegState
, NULL
);
297 /* TODO: DMUS_SEGF_FLAGS */
301 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph (LPDIRECTMUSICSEGMENT8 iface
, IDirectMusicGraph
** ppGraph
) {
302 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
303 FIXME("(%p, %p): semi-stub\n", This
, ppGraph
);
304 if (NULL
== ppGraph
) {
307 if (NULL
== This
->pGraph
) {
308 return DMUS_E_NOT_FOUND
;
311 * should return This, as seen in msdn
312 * "...The segment object implements IDirectMusicGraph directly..."
314 *ppGraph
= This
->pGraph
;
315 IDirectMusicGraph_AddRef(This
->pGraph
);
319 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph (LPDIRECTMUSICSEGMENT8 iface
, IDirectMusicGraph
* pGraph
) {
320 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
321 FIXME("(%p, %p): to complete\n", This
, pGraph
);
322 if (NULL
!= This
->pGraph
) {
323 IDirectMusicGraph_Release(This
->pGraph
);
325 This
->pGraph
= pGraph
;
326 if (NULL
!= This
->pGraph
) {
327 IDirectMusicGraph_AddRef(This
->pGraph
);
332 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType (LPDIRECTMUSICSEGMENT8 iface
, REFGUID rguidNotificationType
) {
333 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
334 FIXME("(%p, %s): stub\n", This
, debugstr_dmguid(rguidNotificationType
));
338 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType (LPDIRECTMUSICSEGMENT8 iface
, REFGUID rguidNotificationType
) {
339 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
340 FIXME("(%p, %s): stub\n", This
, debugstr_dmguid(rguidNotificationType
));
344 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam (LPDIRECTMUSICSEGMENT8 iface
, REFGUID rguidType
, DWORD dwGroupBits
, DWORD dwIndex
, MUSIC_TIME mtTime
, MUSIC_TIME
* pmtNext
, void* pParam
) {
345 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
348 struct list
* pEntry
= NULL
;
349 IDirectMusicTrack
* pTrack
= NULL
;
350 IPersistStream
* pCLSIDStream
= NULL
;
351 LPDMUS_PRIVATE_SEGMENT_TRACK pIt
= NULL
;
354 FIXME("(%p, %s, 0x%x, %d, %d, %p, %p)\n", This
, debugstr_dmguid(rguidType
), dwGroupBits
, dwIndex
, mtTime
, pmtNext
, pParam
);
356 if (DMUS_SEG_ANYTRACK
== dwIndex
) {
358 LIST_FOR_EACH (pEntry
, &This
->Tracks
) {
359 pIt
= LIST_ENTRY(pEntry
, DMUS_PRIVATE_SEGMENT_TRACK
, entry
);
361 hr
= IDirectMusicTrack_QueryInterface(pIt
->pTrack
, &IID_IPersistStream
, (void**) &pCLSIDStream
);
363 ERR("(%p): object %p don't implement IPersistStream Interface. Expect a crash (critical problem)\n", This
, pIt
->pTrack
);
367 TRACE(" - %p -> 0x%x,%p\n", pIt
, pIt
->dwGroupBits
, pIt
->pTrack
);
369 if (0xFFFFFFFF != dwGroupBits
&& 0 == (pIt
->dwGroupBits
& dwGroupBits
)) continue ;
370 hr
= IPersistStream_GetClassID(pCLSIDStream
, &pIt_clsid
);
371 IPersistStream_Release(pCLSIDStream
); pCLSIDStream
= NULL
;
373 ERR("(%p): non-implemented GetClassID for object %p\n", This
, pIt
->pTrack
);
376 if (FALSE
== IsEqualGUID(&pIt_clsid
, rguidType
)) continue ;
377 if (FAILED(IDirectMusicTrack_IsParamSupported(pIt
->pTrack
, rguidType
))) continue ;
378 hr
= IDirectMusicTrack_GetParam(pIt
->pTrack
, rguidType
, mtTime
, pmtNext
, pParam
);
379 if (SUCCEEDED(hr
)) return hr
;
381 ERR("(%p): not found\n", This
);
382 return DMUS_E_TRACK_NOT_FOUND
;
385 hr
= IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack(iface
, &GUID_NULL
, dwGroupBits
, dwIndex
, &pTrack
);
387 ERR("(%p): not found\n", This
);
388 return DMUS_E_TRACK_NOT_FOUND
;
391 hr
= IDirectMusicTrack_GetParam(pTrack
, rguidType
, mtTime
, pmtNext
, pParam
);
392 IDirectMusicTrack_Release(pTrack
); pTrack
= NULL
;
397 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam (LPDIRECTMUSICSEGMENT8 iface
, REFGUID rguidType
, DWORD dwGroupBits
, DWORD dwIndex
, MUSIC_TIME mtTime
, void* pParam
) {
398 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
399 FIXME("(%p, %s, %d, %d, %d, %p): stub\n", This
, debugstr_dmguid(rguidType
), dwGroupBits
, dwIndex
, mtTime
, pParam
);
403 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone (LPDIRECTMUSICSEGMENT8 iface
, MUSIC_TIME mtStart
, MUSIC_TIME mtEnd
, IDirectMusicSegment
** ppSegment
) {
404 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
405 FIXME("(%p, %d, %d, %p): stub\n", This
, mtStart
, mtEnd
, ppSegment
);
409 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint (LPDIRECTMUSICSEGMENT8 iface
, MUSIC_TIME mtStart
) {
410 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
411 TRACE("(%p, %d)\n", This
, mtStart
);
412 if (mtStart
>= This
->header
.mtLength
) {
413 return DMUS_E_OUT_OF_RANGE
;
415 This
->header
.mtPlayStart
= mtStart
;
419 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint (LPDIRECTMUSICSEGMENT8 iface
, MUSIC_TIME
* pmtStart
) {
420 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
421 TRACE("(%p, %p)\n", This
, pmtStart
);
422 if (NULL
== pmtStart
) {
425 *pmtStart
= This
->header
.mtPlayStart
;
429 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints (LPDIRECTMUSICSEGMENT8 iface
, MUSIC_TIME mtStart
, MUSIC_TIME mtEnd
) {
430 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
431 TRACE("(%p, %d, %d)\n", This
, mtStart
, mtEnd
);
432 if (mtStart
>= This
->header
.mtLength
|| mtEnd
> This
->header
.mtLength
|| mtStart
> mtEnd
) {
433 return DMUS_E_OUT_OF_RANGE
;
435 This
->header
.mtLoopStart
= mtStart
;
436 This
->header
.mtLoopEnd
= mtEnd
;
440 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints (LPDIRECTMUSICSEGMENT8 iface
, MUSIC_TIME
* pmtStart
, MUSIC_TIME
* pmtEnd
) {
441 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
442 TRACE("(%p, %p, %p)\n", This
, pmtStart
, pmtEnd
);
443 if (NULL
== pmtStart
|| NULL
== pmtEnd
) {
446 *pmtStart
= This
->header
.mtLoopStart
;
447 *pmtEnd
= This
->header
.mtLoopEnd
;
451 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed (LPDIRECTMUSICSEGMENT8 iface
, DWORD dwNumPChannels
, DWORD
* paPChannels
) {
452 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
453 FIXME("(%p, %d, %p): stub\n", This
, dwNumPChannels
, paPChannels
);
457 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig (LPDIRECTMUSICSEGMENT8 iface
, REFGUID rguidTrackClassID
, DWORD dwGroupBits
, DWORD dwIndex
, DWORD dwFlagsOn
, DWORD dwFlagsOff
) {
458 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
459 FIXME("(%p, %s, %d, %d, %d, %d): stub\n", This
, debugstr_dmguid(rguidTrackClassID
), dwGroupBits
, dwIndex
, dwFlagsOn
, dwFlagsOff
);
463 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig (LPDIRECTMUSICSEGMENT8 iface
, IUnknown
** ppAudioPathConfig
){
464 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
465 FIXME("(%p, %p): stub\n", This
, ppAudioPathConfig
);
469 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose (LPDIRECTMUSICSEGMENT8 iface
, MUSIC_TIME mtTime
, IDirectMusicSegment
* pFromSegment
, IDirectMusicSegment
* pToSegment
, IDirectMusicSegment
** ppComposedSegment
) {
470 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
471 FIXME("(%p, %d, %p, %p, %p): stub\n", This
, mtTime
, pFromSegment
, pToSegment
, ppComposedSegment
);
475 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_Download (LPDIRECTMUSICSEGMENT8 iface
, IUnknown
*pAudioPath
) {
476 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
477 FIXME("(%p, %p): stub\n", This
, pAudioPath
);
481 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload (LPDIRECTMUSICSEGMENT8 iface
, IUnknown
*pAudioPath
) {
482 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
483 FIXME("(%p, %p): stub\n", This
, pAudioPath
);
487 static const IDirectMusicSegment8Vtbl DirectMusicSegment8_Segment_Vtbl
= {
488 IDirectMusicSegment8Impl_IDirectMusicSegment8_QueryInterface
,
489 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef
,
490 IDirectMusicSegment8Impl_IDirectMusicSegment8_Release
,
491 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLength
,
492 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLength
,
493 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetRepeats
,
494 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetRepeats
,
495 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetDefaultResolution
,
496 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetDefaultResolution
,
497 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack
,
498 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrackGroup
,
499 IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack
,
500 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack
,
501 IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay
,
502 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph
,
503 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph
,
504 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType
,
505 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType
,
506 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam
,
507 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam
,
508 IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone
,
509 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint
,
510 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint
,
511 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints
,
512 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints
,
513 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed
,
514 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig
,
515 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig
,
516 IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose
,
517 IDirectMusicSegment8Impl_IDirectMusicSegment8_Download
,
518 IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload
521 /* IDirectMusicSegment8Impl IDirectMusicObject part: */
522 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface
, REFIID riid
, LPVOID
*ppobj
) {
523 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, ObjectVtbl
, iface
);
524 return IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
527 static ULONG WINAPI
IDirectMusicSegment8Impl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface
) {
528 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, ObjectVtbl
, iface
);
529 return IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
532 static ULONG WINAPI
IDirectMusicSegment8Impl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface
) {
533 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, ObjectVtbl
, iface
);
534 return IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
537 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
) {
538 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, ObjectVtbl
, iface
);
539 TRACE("(%p, %p)\n", This
, pDesc
);
540 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
541 memcpy (pDesc
, This
->pDesc
, This
->pDesc
->dwSize
);
545 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
) {
546 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, ObjectVtbl
, iface
);
547 TRACE("(%p, %p): setting descriptor:\n%s\n", This
, pDesc
, debugstr_DMUS_OBJECTDESC (pDesc
));
549 /* According to MSDN, we should copy only given values, not whole struct */
550 if (pDesc
->dwValidData
& DMUS_OBJ_OBJECT
)
551 This
->pDesc
->guidObject
= pDesc
->guidObject
;
552 if (pDesc
->dwValidData
& DMUS_OBJ_CLASS
)
553 This
->pDesc
->guidClass
= pDesc
->guidClass
;
554 if (pDesc
->dwValidData
& DMUS_OBJ_NAME
)
555 lstrcpynW (This
->pDesc
->wszName
, pDesc
->wszName
, DMUS_MAX_NAME
);
556 if (pDesc
->dwValidData
& DMUS_OBJ_CATEGORY
)
557 lstrcpynW (This
->pDesc
->wszCategory
, pDesc
->wszCategory
, DMUS_MAX_CATEGORY
);
558 if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
)
559 lstrcpynW (This
->pDesc
->wszFileName
, pDesc
->wszFileName
, DMUS_MAX_FILENAME
);
560 if (pDesc
->dwValidData
& DMUS_OBJ_VERSION
)
561 This
->pDesc
->vVersion
= pDesc
->vVersion
;
562 if (pDesc
->dwValidData
& DMUS_OBJ_DATE
)
563 This
->pDesc
->ftDate
= pDesc
->ftDate
;
564 if (pDesc
->dwValidData
& DMUS_OBJ_MEMORY
) {
565 This
->pDesc
->llMemLength
= pDesc
->llMemLength
;
566 memcpy (This
->pDesc
->pbMemData
, pDesc
->pbMemData
, pDesc
->llMemLength
);
568 if (pDesc
->dwValidData
& DMUS_OBJ_STREAM
) {
569 /* according to MSDN, we copy the stream */
570 IStream_Clone (pDesc
->pStream
, &This
->pDesc
->pStream
);
574 This
->pDesc
->dwValidData
|= pDesc
->dwValidData
;
579 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface
, LPSTREAM pStream
, LPDMUS_OBJECTDESC pDesc
) {
580 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, ObjectVtbl
, iface
);
581 DMUS_PRIVATE_CHUNK Chunk
;
582 DWORD StreamSize
, StreamCount
, ListSize
[1], ListCount
[1];
583 LARGE_INTEGER liMove
; /* used when skipping chunks */
585 TRACE("(%p,%p, %p)\n", This
, pStream
, pDesc
);
587 /* FIXME: should this be determined from stream? */
588 pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
589 pDesc
->guidClass
= CLSID_DirectMusicSegment
;
591 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
592 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
593 switch (Chunk
.fccID
) {
595 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
596 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
597 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
599 if (Chunk
.fccID
== DMUS_FOURCC_SEGMENT_FORM
) {
600 TRACE_(dmfile
)(": segment form\n");
602 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
603 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
604 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
605 switch (Chunk
.fccID
) {
606 case DMUS_FOURCC_GUID_CHUNK
: {
607 TRACE_(dmfile
)(": GUID chunk\n");
608 pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
609 IStream_Read (pStream
, &pDesc
->guidObject
, Chunk
.dwSize
, NULL
);
612 case DMUS_FOURCC_VERSION_CHUNK
: {
613 TRACE_(dmfile
)(": version chunk\n");
614 pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
615 IStream_Read (pStream
, &pDesc
->vVersion
, Chunk
.dwSize
, NULL
);
618 case DMUS_FOURCC_CATEGORY_CHUNK
: {
619 TRACE_(dmfile
)(": category chunk\n");
620 pDesc
->dwValidData
|= DMUS_OBJ_CATEGORY
;
621 IStream_Read (pStream
, pDesc
->wszCategory
, Chunk
.dwSize
, NULL
);
625 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
626 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
627 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
629 switch (Chunk
.fccID
) {
630 /* evil M$ UNFO list, which can (!?) contain INFO elements */
631 case DMUS_FOURCC_UNFO_LIST
: {
632 TRACE_(dmfile
)(": UNFO list\n");
634 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
635 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
636 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
637 switch (Chunk
.fccID
) {
638 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
639 (though strings seem to be valid unicode) */
640 case mmioFOURCC('I','N','A','M'):
641 case DMUS_FOURCC_UNAM_CHUNK
: {
642 TRACE_(dmfile
)(": name chunk\n");
643 pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
644 IStream_Read (pStream
, pDesc
->wszName
, Chunk
.dwSize
, NULL
);
647 case mmioFOURCC('I','A','R','T'):
648 case DMUS_FOURCC_UART_CHUNK
: {
649 TRACE_(dmfile
)(": artist chunk (ignored)\n");
650 liMove
.QuadPart
= Chunk
.dwSize
;
651 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
654 case mmioFOURCC('I','C','O','P'):
655 case DMUS_FOURCC_UCOP_CHUNK
: {
656 TRACE_(dmfile
)(": copyright chunk (ignored)\n");
657 liMove
.QuadPart
= Chunk
.dwSize
;
658 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
661 case mmioFOURCC('I','S','B','J'):
662 case DMUS_FOURCC_USBJ_CHUNK
: {
663 TRACE_(dmfile
)(": subject chunk (ignored)\n");
664 liMove
.QuadPart
= Chunk
.dwSize
;
665 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
668 case mmioFOURCC('I','C','M','T'):
669 case DMUS_FOURCC_UCMT_CHUNK
: {
670 TRACE_(dmfile
)(": comment chunk (ignored)\n");
671 liMove
.QuadPart
= Chunk
.dwSize
;
672 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
676 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
677 liMove
.QuadPart
= Chunk
.dwSize
;
678 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
682 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
683 } while (ListCount
[0] < ListSize
[0]);
686 case DMUS_FOURCC_TRACK_LIST
: {
687 TRACE_(dmfile
)(": TRACK list\n");
689 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
690 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
691 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
692 switch (Chunk
.fccID
) {
694 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
695 liMove
.QuadPart
= Chunk
.dwSize
;
696 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
700 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
701 } while (ListCount
[0] < ListSize
[0]);
705 TRACE_(dmfile
)(": unknown (skipping)\n");
706 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
707 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
714 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
715 liMove
.QuadPart
= Chunk
.dwSize
;
716 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
720 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
721 } while (StreamCount
< StreamSize
);
723 } else if (Chunk
.fccID
== mmioFOURCC('W','A','V','E')) {
724 TRACE_(dmfile
)(": wave form (loading not yet implemented)\n");
725 liMove
.QuadPart
= StreamSize
;
726 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
728 TRACE_(dmfile
)(": unexpected chunk (loading failed)\n");
729 liMove
.QuadPart
= StreamSize
;
730 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
734 TRACE_(dmfile
)(": reading finished\n");
738 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
739 liMove
.QuadPart
= Chunk
.dwSize
;
740 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
741 return DMUS_E_INVALIDFILE
;
745 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc
));
750 static const IDirectMusicObjectVtbl DirectMusicSegment8_Object_Vtbl
= {
751 IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface
,
752 IDirectMusicSegment8Impl_IDirectMusicObject_AddRef
,
753 IDirectMusicSegment8Impl_IDirectMusicObject_Release
,
754 IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor
,
755 IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor
,
756 IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor
759 /* IDirectMusicSegment8Impl IPersistStream part: */
760 static HRESULT WINAPI
IDirectMusicSegment8Impl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface
, REFIID riid
, LPVOID
*ppobj
) {
761 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
762 return IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
765 static ULONG WINAPI
IDirectMusicSegment8Impl_IPersistStream_AddRef (LPPERSISTSTREAM iface
) {
766 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
767 return IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
770 static ULONG WINAPI
IDirectMusicSegment8Impl_IPersistStream_Release (LPPERSISTSTREAM iface
) {
771 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
772 return IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
775 static HRESULT WINAPI
IDirectMusicSegment8Impl_IPersistStream_GetClassID (LPPERSISTSTREAM iface
, CLSID
* pClassID
) {
776 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
777 TRACE("(%p, %p)\n", This
, pClassID
);
778 *pClassID
= CLSID_DirectMusicSegment
;
782 static HRESULT WINAPI
IDirectMusicSegment8Impl_IPersistStream_IsDirty (LPPERSISTSTREAM iface
) {
783 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
784 FIXME("(%p): stub, always S_FALSE\n", This
);
788 static HRESULT
IDirectMusicSegment8Impl_IPersistStream_LoadTrack (LPPERSISTSTREAM iface
, IStream
* pClonedStream
, IDirectMusicTrack
** ppTrack
,
789 DMUS_IO_TRACK_HEADER
* pTrack_hdr
) {
791 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
793 IPersistStream
* pPersistStream
= NULL
;
795 hr
= CoCreateInstance (&pTrack_hdr
->guidClassID
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectMusicTrack
, (LPVOID
*) ppTrack
);
797 ERR(": could not create object\n");
800 /* acquire PersistStream interface */
801 hr
= IDirectMusicTrack_QueryInterface (*ppTrack
, &IID_IPersistStream
, (LPVOID
*) &pPersistStream
);
803 ERR(": could not acquire IPersistStream\n");
807 hr
= IPersistStream_Load (pPersistStream
, pClonedStream
);
809 ERR(": failed to load object\n");
813 /* release all loading-related stuff */
814 IPersistStream_Release (pPersistStream
);
816 hr
= IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack ((LPDIRECTMUSICSEGMENT8
)&This
->SegmentVtbl
, *ppTrack
, pTrack_hdr
->dwGroup
); /* at dsPosition */
818 ERR(": could not insert track\n");
825 static HRESULT
IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (LPPERSISTSTREAM iface
, DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
) {
827 /*ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);*/
829 DMUS_PRIVATE_CHUNK Chunk
;
830 DWORD StreamSize
, StreamCount
, ListSize
[3];
831 LARGE_INTEGER liMove
; /* used when skipping chunks */
833 DMUS_IO_TRACK_HEADER track_hdr
;
834 DMUS_IO_TRACK_EXTRAS_HEADER track_xhdr
;
835 IDirectMusicTrack
* pTrack
= NULL
;
837 if (pChunk
->fccID
!= DMUS_FOURCC_TRACK_FORM
) {
838 ERR_(dmfile
)(": %s chunk should be a TRACK form\n", debugstr_fourcc (pChunk
->fccID
));
842 StreamSize
= pChunk
->dwSize
- sizeof(FOURCC
);
846 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
847 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
848 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
850 switch (Chunk
.fccID
) {
851 case DMUS_FOURCC_TRACK_CHUNK
: {
852 TRACE_(dmfile
)(": track chunk\n");
853 IStream_Read (pStm
, &track_hdr
, sizeof(DMUS_IO_TRACK_HEADER
), NULL
);
854 TRACE_(dmfile
)(" - class: %s\n", debugstr_guid (&track_hdr
.guidClassID
));
855 TRACE_(dmfile
)(" - dwGroup: %d\n", track_hdr
.dwGroup
);
856 TRACE_(dmfile
)(" - ckid: %s\n", debugstr_fourcc (track_hdr
.ckid
));
857 TRACE_(dmfile
)(" - fccType: %s\n", debugstr_fourcc (track_hdr
.fccType
));
860 case DMUS_FOURCC_TRACK_EXTRAS_CHUNK
: {
861 TRACE_(dmfile
)(": track extras chunk\n");
862 IStream_Read (pStm
, &track_xhdr
, sizeof(DMUS_IO_TRACK_EXTRAS_HEADER
), NULL
);
866 case DMUS_FOURCC_COMMANDTRACK_CHUNK
: {
867 TRACE_(dmfile
)(": COMMANDTRACK track\n");
868 liMove
.QuadPart
= Chunk
.dwSize
;
869 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
874 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
875 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
876 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
877 if (Chunk
.fccID
== track_hdr
.fccType
&& 0 == track_hdr
.ckid
) {
878 LPSTREAM pClonedStream
= NULL
;
880 TRACE_(dmfile
)(": TRACK list\n");
882 IStream_Clone (pStm
, &pClonedStream
);
885 liMove
.QuadPart
-= sizeof(FOURCC
) + (sizeof(FOURCC
)+sizeof(DWORD
));
886 IStream_Seek (pClonedStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
888 hr
= IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface
, pClonedStream
, &pTrack
, &track_hdr
);
890 ERR(": could not load track\n");
893 IStream_Release (pClonedStream
);
895 IDirectMusicTrack_Release(pTrack
); pTrack
= NULL
; /* now we can release at as it inserted */
897 liMove
.QuadPart
= ListSize
[0];
898 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
901 TRACE_(dmfile
)(": unknown (skipping)\n");
902 liMove
.QuadPart
= Chunk
.dwSize
;
903 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
909 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
910 TRACE_(dmfile
)(": RIFF chunk of type %s\n", debugstr_fourcc(Chunk
.fccID
));
912 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
914 if (Chunk
.fccID
== track_hdr
.fccType
&& 0 == track_hdr
.ckid
) {
915 LPSTREAM pClonedStream
= NULL
;
917 TRACE_(dmfile
)(": TRACK RIFF\n");
919 IStream_Clone (pStm
, &pClonedStream
);
922 liMove
.QuadPart
-= sizeof(FOURCC
) + (sizeof(FOURCC
)+sizeof(DWORD
));
923 IStream_Seek (pClonedStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
925 hr
= IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface
, pClonedStream
, &pTrack
, &track_hdr
);
927 ERR(": could not load track\n");
930 IStream_Release (pClonedStream
);
932 IDirectMusicTrack_Release(pTrack
); pTrack
= NULL
; /* now we can release at as it inserted */
934 /** now safe move the cursor */
935 liMove
.QuadPart
= ListSize
[0];
936 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
939 TRACE_(dmfile
)(": unknown RIFF fmt (skipping)\n");
940 liMove
.QuadPart
= ListSize
[0];
941 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
947 if (0 == track_hdr
.fccType
&& Chunk
.fccID
== track_hdr
.ckid
) {
948 LPSTREAM pClonedStream
= NULL
;
950 TRACE_(dmfile
)(": TRACK solo\n");
952 IStream_Clone (pStm
, &pClonedStream
);
955 liMove
.QuadPart
-= (sizeof(FOURCC
) + sizeof(DWORD
));
956 IStream_Seek (pClonedStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
958 hr
= IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface
, pClonedStream
, &pTrack
, &track_hdr
);
960 ERR(": could not load track\n");
963 IStream_Release (pClonedStream
);
965 IDirectMusicTrack_Release(pTrack
); pTrack
= NULL
; /* now we can release at as it inserted */
967 liMove
.QuadPart
= Chunk
.dwSize
;
968 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
973 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
974 liMove
.QuadPart
= Chunk
.dwSize
;
975 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
979 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
980 } while (StreamCount
< StreamSize
);
985 static HRESULT
IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (LPPERSISTSTREAM iface
, DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
, IDirectMusicSegment8Impl
* This
) {
988 DMUS_PRIVATE_CHUNK Chunk
;
989 DWORD StreamSize
, ListSize
[3], ListCount
[3];
990 LARGE_INTEGER liMove
; /* used when skipping chunks */
992 if (pChunk
->fccID
!= DMUS_FOURCC_TRACK_LIST
) {
993 ERR_(dmfile
)(": %s chunk should be a TRACK list\n", debugstr_fourcc (pChunk
->fccID
));
997 ListSize
[0] = pChunk
->dwSize
- sizeof(FOURCC
);
1001 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
1002 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
1003 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
1004 switch (Chunk
.fccID
) {
1006 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
1007 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
1008 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
1009 switch (Chunk
.fccID
) {
1010 case DMUS_FOURCC_TRACK_FORM
: {
1011 TRACE_(dmfile
)(": TRACK form\n");
1012 hr
= IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (iface
, &Chunk
, pStm
);
1013 if (FAILED(hr
)) return hr
;
1017 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
1018 liMove
.QuadPart
= StreamSize
;
1019 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
1026 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
1027 liMove
.QuadPart
= Chunk
.dwSize
;
1028 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
1032 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
1033 } while (ListCount
[0] < ListSize
[0]);
1038 static HRESULT
IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (LPPERSISTSTREAM iface
, DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
, IDirectMusicSegment8Impl
* This
) {
1040 HRESULT hr
= E_FAIL
;
1041 DMUS_PRIVATE_CHUNK Chunk
;
1042 DWORD StreamSize
, StreamCount
, ListSize
[3], ListCount
[3];
1043 LARGE_INTEGER liMove
; /* used when skipping chunks */
1045 if (pChunk
->fccID
!= DMUS_FOURCC_SEGMENT_FORM
) {
1046 ERR_(dmfile
)(": %s chunk should be a segment form\n", debugstr_fourcc (pChunk
->fccID
));
1050 StreamSize
= pChunk
->dwSize
- sizeof(FOURCC
);
1054 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
1055 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
1056 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
1058 hr
= IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk
, pStm
, This
->pDesc
);
1059 if (FAILED(hr
)) return hr
;
1061 if (hr
== S_FALSE
) {
1062 switch (Chunk
.fccID
) {
1063 case DMUS_FOURCC_SEGMENT_CHUNK
: {
1064 DWORD checkSz
= sizeof(FOURCC
);
1065 TRACE_(dmfile
)(": segment chunk\n");
1068 IStream_Read (pStm
, &This
->header
.dwRepeats
, sizeof(This
->header
.dwRepeats
), NULL
);
1069 checkSz
+= sizeof(This
->header
.dwRepeats
);
1070 IStream_Read (pStm
, &This
->header
.mtLength
, sizeof(This
->header
.mtLength
), NULL
);
1071 checkSz
+= sizeof(This
->header
.mtLength
);
1072 IStream_Read (pStm
, &This
->header
.mtPlayStart
, sizeof(This
->header
.mtPlayStart
), NULL
);
1073 checkSz
+= sizeof(This
->header
.mtPlayStart
);
1074 IStream_Read (pStm
, &This
->header
.mtLoopStart
, sizeof(This
->header
.mtLoopStart
), NULL
);
1075 checkSz
+= sizeof(This
->header
.mtLoopStart
);
1076 IStream_Read (pStm
, &This
->header
.mtLoopEnd
, sizeof(This
->header
.mtLoopEnd
), NULL
);
1077 checkSz
+= sizeof(This
->header
.mtLoopEnd
);
1078 IStream_Read (pStm
, &This
->header
.dwResolution
, sizeof(This
->header
.dwResolution
), NULL
);
1079 checkSz
+= sizeof(This
->header
.dwResolution
);
1080 TRACE_(dmfile
)("dwRepeats: %u\n", This
->header
.dwRepeats
);
1081 TRACE_(dmfile
)("mtLength: %u\n", This
->header
.mtLength
);
1082 TRACE_(dmfile
)("mtPlayStart: %u\n", This
->header
.mtPlayStart
);
1083 TRACE_(dmfile
)("mtLoopStart: %u\n", This
->header
.mtLoopStart
);
1084 TRACE_(dmfile
)("mtLoopEnd: %u\n", This
->header
.mtLoopEnd
);
1085 TRACE_(dmfile
)("dwResolution: %u\n", This
->header
.dwResolution
);
1087 if (Chunk
.dwSize
> checkSz
) {
1088 IStream_Read (pStm
, &This
->header
.rtLength
, sizeof(This
->header
.rtLength
), NULL
);
1089 checkSz
+= sizeof(This
->header
.rtLength
);
1090 IStream_Read (pStm
, &This
->header
.dwFlags
, sizeof(This
->header
.dwFlags
), NULL
);
1091 checkSz
+= sizeof(This
->header
.dwFlags
);
1094 if (Chunk
.dwSize
> checkSz
) {
1095 IStream_Read (pStm
, &This
->header
.rtLoopStart
, sizeof(This
->header
.rtLoopStart
), NULL
);
1096 checkSz
+= sizeof(This
->header
.rtLoopStart
);
1097 IStream_Read (pStm
, &This
->header
.rtLoopEnd
, sizeof(This
->header
.rtLoopEnd
), NULL
);
1098 checkSz
+= sizeof(This
->header
.rtLoopEnd
);
1099 IStream_Read (pStm
, &This
->header
.rtPlayStart
, sizeof(This
->header
.rtPlayStart
), NULL
);
1100 checkSz
+= sizeof(This
->header
.rtPlayStart
);
1103 liMove
.QuadPart
= Chunk
.dwSize
- checkSz
+ sizeof(FOURCC
);
1104 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
1108 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
1109 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
1110 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
1112 switch (Chunk
.fccID
) {
1113 case DMUS_FOURCC_UNFO_LIST
: {
1114 TRACE_(dmfile
)(": UNFO list\n");
1116 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
1117 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
1118 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
1120 hr
= IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk
, pStm
, This
->pDesc
);
1121 if (FAILED(hr
)) return hr
;
1123 if (hr
== S_FALSE
) {
1124 switch (Chunk
.fccID
) {
1126 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
1127 liMove
.QuadPart
= Chunk
.dwSize
;
1128 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
1134 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
1135 } while (ListCount
[0] < ListSize
[0]);
1138 case DMUS_FOURCC_TRACK_LIST
: {
1139 TRACE_(dmfile
)(": TRACK list\n");
1140 hr
= IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (iface
, &Chunk
, pStm
, This
);
1141 if (FAILED(hr
)) return hr
;
1145 TRACE_(dmfile
)(": unknown (skipping)\n");
1146 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
1147 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
1154 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
1155 liMove
.QuadPart
= Chunk
.dwSize
;
1156 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
1161 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
1162 } while (StreamCount
< StreamSize
);
1167 static HRESULT
IDirectMusicSegment8Impl_IPersistStream_LoadWave (LPPERSISTSTREAM iface
, IStream
* pClonedStream
, IDirectMusicObject
** ppWaveObject
) {
1169 HRESULT hr
= E_FAIL
;
1170 IPersistStream
* pPersistStream
= NULL
;
1172 hr
= CoCreateInstance (&CLSID_DirectSoundWave
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectMusicObject
, (LPVOID
*) ppWaveObject
);
1174 ERR(": could not create object\n");
1177 /* acquire PersistStream interface */
1178 hr
= IDirectMusicObject_QueryInterface (*ppWaveObject
, &IID_IPersistStream
, (LPVOID
*) &pPersistStream
);
1180 ERR(": could not acquire IPersistStream\n");
1184 hr
= IPersistStream_Load (pPersistStream
, pClonedStream
);
1186 ERR(": failed to load object\n");
1190 /* release all loading-related stuff */
1191 IPersistStream_Release (pPersistStream
);
1196 static HRESULT WINAPI
IDirectMusicSegment8Impl_IPersistStream_Load (LPPERSISTSTREAM iface
, IStream
* pStm
) {
1197 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
1200 DMUS_PRIVATE_CHUNK Chunk
;
1202 /*DWORD ListSize[3], ListCount[3];*/
1203 LARGE_INTEGER liMove
; /* used when skipping chunks */
1205 TRACE("(%p, %p): Loading\n", This
, pStm
);
1206 hr
= IStream_Read (pStm
, &Chunk
, sizeof(Chunk
), NULL
);
1208 WARN("IStream_Read failed: %08x\n", hr
);
1209 return DMUS_E_UNSUPPORTED_STREAM
;
1211 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
1212 switch (Chunk
.fccID
) {
1214 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
1215 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
1216 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
1217 switch (Chunk
.fccID
) {
1218 case DMUS_FOURCC_SEGMENT_FORM
: {
1219 TRACE_(dmfile
)(": segment form\n");
1220 hr
= IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (iface
, &Chunk
, pStm
, This
);
1221 if (FAILED(hr
)) return hr
;
1224 case mmioFOURCC('W','A','V','E'): {
1225 LPSTREAM pClonedStream
= NULL
;
1226 IDirectMusicObject
* pWave
= NULL
;
1228 FIXME_(dmfile
)(": WAVE form (loading to be checked)\n");
1230 IStream_Clone (pStm
, &pClonedStream
);
1232 liMove
.QuadPart
= - (LONGLONG
)(sizeof(FOURCC
) * 2 + sizeof(DWORD
));
1233 IStream_Seek (pClonedStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
1235 hr
= IDirectMusicSegment8Impl_IPersistStream_LoadWave (iface
, pClonedStream
, &pWave
);
1237 ERR(": could not load track\n");
1240 IStream_Release (pClonedStream
);
1242 IDirectMusicTrack_Release(pWave
); pWave
= NULL
; /* now we can release at as it inserted */
1244 liMove
.QuadPart
= StreamSize
;
1245 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
1249 TRACE_(dmfile
)(": unexpected chunk (loading failed)\n");
1250 liMove
.QuadPart
= StreamSize
;
1251 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
1252 return DMUS_E_UNSUPPORTED_STREAM
;
1255 TRACE_(dmfile
)(": reading finished\n");
1259 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
1260 return DMUS_E_UNSUPPORTED_STREAM
;
1267 static HRESULT WINAPI
IDirectMusicSegment8Impl_IPersistStream_Save (LPPERSISTSTREAM iface
, IStream
* pStm
, BOOL fClearDirty
) {
1268 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
1269 FIXME("(%p): Saving not implemented yet\n", This
);
1273 static HRESULT WINAPI
IDirectMusicSegment8Impl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface
, ULARGE_INTEGER
* pcbSize
) {
1274 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
1275 FIXME("(%p, %p): stub\n", This
, pcbSize
);
1279 static const IPersistStreamVtbl DirectMusicSegment8_PersistStream_Vtbl
= {
1280 IDirectMusicSegment8Impl_IPersistStream_QueryInterface
,
1281 IDirectMusicSegment8Impl_IPersistStream_AddRef
,
1282 IDirectMusicSegment8Impl_IPersistStream_Release
,
1283 IDirectMusicSegment8Impl_IPersistStream_GetClassID
,
1284 IDirectMusicSegment8Impl_IPersistStream_IsDirty
,
1285 IDirectMusicSegment8Impl_IPersistStream_Load
,
1286 IDirectMusicSegment8Impl_IPersistStream_Save
,
1287 IDirectMusicSegment8Impl_IPersistStream_GetSizeMax
1290 /* for ClassFactory */
1291 HRESULT WINAPI
DMUSIC_CreateDirectMusicSegmentImpl (LPCGUID lpcGUID
, LPVOID
* ppobj
, LPUNKNOWN pUnkOuter
) {
1292 IDirectMusicSegment8Impl
* obj
;
1296 return CLASS_E_NOAGGREGATION
;
1299 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicSegment8Impl
));
1302 return E_OUTOFMEMORY
;
1304 obj
->UnknownVtbl
= &DirectMusicSegment8_Unknown_Vtbl
;
1305 obj
->SegmentVtbl
= &DirectMusicSegment8_Segment_Vtbl
;
1306 obj
->ObjectVtbl
= &DirectMusicSegment8_Object_Vtbl
;
1307 obj
->PersistStreamVtbl
= &DirectMusicSegment8_PersistStream_Vtbl
;
1308 obj
->pDesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DMUS_OBJECTDESC
));
1309 DM_STRUCT_INIT(obj
->pDesc
);
1310 obj
->pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
1311 obj
->pDesc
->guidClass
= CLSID_DirectMusicSegment
;
1312 obj
->ref
= 0; /* will be inited by QueryInterface */
1313 list_init (&obj
->Tracks
);
1315 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN
)&obj
->UnknownVtbl
, lpcGUID
, ppobj
);