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 ERR(": no more memory\n");
251 return E_OUTOFMEMORY
;
253 pNewSegTrack
->dwGroupBits
= dwGroupBits
;
254 pNewSegTrack
->pTrack
= pTrack
;
255 IDirectMusicTrack_Init(pTrack
, (IDirectMusicSegment
*)iface
);
256 IDirectMusicTrack_AddRef(pTrack
);
257 list_add_tail (&This
->Tracks
, &pNewSegTrack
->entry
);
262 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack (LPDIRECTMUSICSEGMENT8 iface
, IDirectMusicTrack
* pTrack
) {
263 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
265 struct list
* pEntry
= NULL
;
266 LPDMUS_PRIVATE_SEGMENT_TRACK pIt
= NULL
;
268 TRACE("(%p, %p)\n", This
, pTrack
);
270 LIST_FOR_EACH (pEntry
, &This
->Tracks
) {
271 pIt
= LIST_ENTRY(pEntry
, DMUS_PRIVATE_SEGMENT_TRACK
, entry
);
272 if (pIt
->pTrack
== pTrack
) {
273 TRACE("(%p, %p): track in list\n", This
, pTrack
);
275 list_remove(&pIt
->entry
);
276 IDirectMusicTrack_Init(pIt
->pTrack
, NULL
);
277 IDirectMusicTrack_Release(pIt
->pTrack
);
278 HeapFree(GetProcessHeap(), 0, pIt
);
287 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay (LPDIRECTMUSICSEGMENT8 iface
, IDirectMusicSegmentState
** ppSegState
, IDirectMusicPerformance
* pPerformance
, DWORD dwFlags
) {
288 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
290 FIXME("(%p, %p, %p, %d): semi-stub\n", This
, ppSegState
, pPerformance
, dwFlags
);
291 if (NULL
== ppSegState
) {
294 hr
= DMUSIC_CreateDirectMusicSegmentStateImpl(&IID_IDirectMusicSegmentState
, (void**) ppSegState
, NULL
);
298 /* TODO: DMUS_SEGF_FLAGS */
302 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph (LPDIRECTMUSICSEGMENT8 iface
, IDirectMusicGraph
** ppGraph
) {
303 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
304 FIXME("(%p, %p): semi-stub\n", This
, ppGraph
);
305 if (NULL
== ppGraph
) {
308 if (NULL
== This
->pGraph
) {
309 return DMUS_E_NOT_FOUND
;
312 * should return This, as seen in msdn
313 * "...The segment object implements IDirectMusicGraph directly..."
315 *ppGraph
= This
->pGraph
;
316 IDirectMusicGraph_AddRef(This
->pGraph
);
320 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph (LPDIRECTMUSICSEGMENT8 iface
, IDirectMusicGraph
* pGraph
) {
321 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
322 FIXME("(%p, %p): to complete\n", This
, pGraph
);
323 if (NULL
!= This
->pGraph
) {
324 IDirectMusicGraph_Release(This
->pGraph
);
326 This
->pGraph
= pGraph
;
327 if (NULL
!= This
->pGraph
) {
328 IDirectMusicGraph_AddRef(This
->pGraph
);
333 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType (LPDIRECTMUSICSEGMENT8 iface
, REFGUID rguidNotificationType
) {
334 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
335 FIXME("(%p, %s): stub\n", This
, debugstr_dmguid(rguidNotificationType
));
339 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType (LPDIRECTMUSICSEGMENT8 iface
, REFGUID rguidNotificationType
) {
340 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
341 FIXME("(%p, %s): stub\n", This
, debugstr_dmguid(rguidNotificationType
));
345 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam (LPDIRECTMUSICSEGMENT8 iface
, REFGUID rguidType
, DWORD dwGroupBits
, DWORD dwIndex
, MUSIC_TIME mtTime
, MUSIC_TIME
* pmtNext
, void* pParam
) {
346 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
349 struct list
* pEntry
= NULL
;
350 IDirectMusicTrack
* pTrack
= NULL
;
351 IPersistStream
* pCLSIDStream
= NULL
;
352 LPDMUS_PRIVATE_SEGMENT_TRACK pIt
= NULL
;
355 FIXME("(%p, %s, 0x%x, %d, %d, %p, %p)\n", This
, debugstr_dmguid(rguidType
), dwGroupBits
, dwIndex
, mtTime
, pmtNext
, pParam
);
357 if (DMUS_SEG_ANYTRACK
== dwIndex
) {
359 LIST_FOR_EACH (pEntry
, &This
->Tracks
) {
360 pIt
= LIST_ENTRY(pEntry
, DMUS_PRIVATE_SEGMENT_TRACK
, entry
);
362 hr
= IDirectMusicTrack_QueryInterface(pIt
->pTrack
, &IID_IPersistStream
, (void**) &pCLSIDStream
);
364 ERR("(%p): object %p don't implement IPersistStream Interface. Expect a crash (critical problem)\n", This
, pIt
->pTrack
);
368 TRACE(" - %p -> 0x%x,%p\n", pIt
, pIt
->dwGroupBits
, pIt
->pTrack
);
370 if (0xFFFFFFFF != dwGroupBits
&& 0 == (pIt
->dwGroupBits
& dwGroupBits
)) continue ;
371 hr
= IPersistStream_GetClassID(pCLSIDStream
, &pIt_clsid
);
372 IPersistStream_Release(pCLSIDStream
); pCLSIDStream
= NULL
;
374 ERR("(%p): non-implemented GetClassID for object %p\n", This
, pIt
->pTrack
);
377 if (FALSE
== IsEqualGUID(&pIt_clsid
, rguidType
)) continue ;
378 if (FAILED(IDirectMusicTrack_IsParamSupported(pIt
->pTrack
, rguidType
))) continue ;
379 hr
= IDirectMusicTrack_GetParam(pIt
->pTrack
, rguidType
, mtTime
, pmtNext
, pParam
);
380 if (SUCCEEDED(hr
)) return hr
;
382 ERR("(%p): not found\n", This
);
383 return DMUS_E_TRACK_NOT_FOUND
;
386 hr
= IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack(iface
, &GUID_NULL
, dwGroupBits
, dwIndex
, &pTrack
);
388 ERR("(%p): not found\n", This
);
389 return DMUS_E_TRACK_NOT_FOUND
;
392 hr
= IDirectMusicTrack_GetParam(pTrack
, rguidType
, mtTime
, pmtNext
, pParam
);
393 IDirectMusicTrack_Release(pTrack
); pTrack
= NULL
;
398 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam (LPDIRECTMUSICSEGMENT8 iface
, REFGUID rguidType
, DWORD dwGroupBits
, DWORD dwIndex
, MUSIC_TIME mtTime
, void* pParam
) {
399 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
400 FIXME("(%p, %s, %d, %d, %d, %p): stub\n", This
, debugstr_dmguid(rguidType
), dwGroupBits
, dwIndex
, mtTime
, pParam
);
404 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone (LPDIRECTMUSICSEGMENT8 iface
, MUSIC_TIME mtStart
, MUSIC_TIME mtEnd
, IDirectMusicSegment
** ppSegment
) {
405 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
406 FIXME("(%p, %d, %d, %p): stub\n", This
, mtStart
, mtEnd
, ppSegment
);
410 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint (LPDIRECTMUSICSEGMENT8 iface
, MUSIC_TIME mtStart
) {
411 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
412 TRACE("(%p, %d)\n", This
, mtStart
);
413 if (mtStart
>= This
->header
.mtLength
) {
414 return DMUS_E_OUT_OF_RANGE
;
416 This
->header
.mtPlayStart
= mtStart
;
420 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint (LPDIRECTMUSICSEGMENT8 iface
, MUSIC_TIME
* pmtStart
) {
421 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
422 TRACE("(%p, %p)\n", This
, pmtStart
);
423 if (NULL
== pmtStart
) {
426 *pmtStart
= This
->header
.mtPlayStart
;
430 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints (LPDIRECTMUSICSEGMENT8 iface
, MUSIC_TIME mtStart
, MUSIC_TIME mtEnd
) {
431 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
432 TRACE("(%p, %d, %d)\n", This
, mtStart
, mtEnd
);
433 if (mtStart
>= This
->header
.mtLength
|| mtEnd
> This
->header
.mtLength
|| mtStart
> mtEnd
) {
434 return DMUS_E_OUT_OF_RANGE
;
436 This
->header
.mtLoopStart
= mtStart
;
437 This
->header
.mtLoopEnd
= mtEnd
;
441 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints (LPDIRECTMUSICSEGMENT8 iface
, MUSIC_TIME
* pmtStart
, MUSIC_TIME
* pmtEnd
) {
442 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
443 TRACE("(%p, %p, %p)\n", This
, pmtStart
, pmtEnd
);
444 if (NULL
== pmtStart
|| NULL
== pmtEnd
) {
447 *pmtStart
= This
->header
.mtLoopStart
;
448 *pmtEnd
= This
->header
.mtLoopEnd
;
452 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed (LPDIRECTMUSICSEGMENT8 iface
, DWORD dwNumPChannels
, DWORD
* paPChannels
) {
453 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
454 FIXME("(%p, %d, %p): stub\n", This
, dwNumPChannels
, paPChannels
);
458 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig (LPDIRECTMUSICSEGMENT8 iface
, REFGUID rguidTrackClassID
, DWORD dwGroupBits
, DWORD dwIndex
, DWORD dwFlagsOn
, DWORD dwFlagsOff
) {
459 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
460 FIXME("(%p, %s, %d, %d, %d, %d): stub\n", This
, debugstr_dmguid(rguidTrackClassID
), dwGroupBits
, dwIndex
, dwFlagsOn
, dwFlagsOff
);
464 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig (LPDIRECTMUSICSEGMENT8 iface
, IUnknown
** ppAudioPathConfig
){
465 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
466 FIXME("(%p, %p): stub\n", This
, ppAudioPathConfig
);
470 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose (LPDIRECTMUSICSEGMENT8 iface
, MUSIC_TIME mtTime
, IDirectMusicSegment
* pFromSegment
, IDirectMusicSegment
* pToSegment
, IDirectMusicSegment
** ppComposedSegment
) {
471 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
472 FIXME("(%p, %d, %p, %p, %p): stub\n", This
, mtTime
, pFromSegment
, pToSegment
, ppComposedSegment
);
476 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_Download (LPDIRECTMUSICSEGMENT8 iface
, IUnknown
*pAudioPath
) {
477 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
478 FIXME("(%p, %p): stub\n", This
, pAudioPath
);
482 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload (LPDIRECTMUSICSEGMENT8 iface
, IUnknown
*pAudioPath
) {
483 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, SegmentVtbl
, iface
);
484 FIXME("(%p, %p): stub\n", This
, pAudioPath
);
488 static const IDirectMusicSegment8Vtbl DirectMusicSegment8_Segment_Vtbl
= {
489 IDirectMusicSegment8Impl_IDirectMusicSegment8_QueryInterface
,
490 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef
,
491 IDirectMusicSegment8Impl_IDirectMusicSegment8_Release
,
492 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLength
,
493 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLength
,
494 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetRepeats
,
495 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetRepeats
,
496 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetDefaultResolution
,
497 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetDefaultResolution
,
498 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack
,
499 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrackGroup
,
500 IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack
,
501 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack
,
502 IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay
,
503 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph
,
504 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph
,
505 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType
,
506 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType
,
507 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam
,
508 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam
,
509 IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone
,
510 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint
,
511 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint
,
512 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints
,
513 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints
,
514 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed
,
515 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig
,
516 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig
,
517 IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose
,
518 IDirectMusicSegment8Impl_IDirectMusicSegment8_Download
,
519 IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload
522 /* IDirectMusicSegment8Impl IDirectMusicObject part: */
523 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface
, REFIID riid
, LPVOID
*ppobj
) {
524 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, ObjectVtbl
, iface
);
525 return IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
528 static ULONG WINAPI
IDirectMusicSegment8Impl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface
) {
529 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, ObjectVtbl
, iface
);
530 return IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
533 static ULONG WINAPI
IDirectMusicSegment8Impl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface
) {
534 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, ObjectVtbl
, iface
);
535 return IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
538 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
) {
539 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, ObjectVtbl
, iface
);
540 TRACE("(%p, %p)\n", This
, pDesc
);
541 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
542 memcpy (pDesc
, This
->pDesc
, This
->pDesc
->dwSize
);
546 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface
, LPDMUS_OBJECTDESC pDesc
) {
547 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, ObjectVtbl
, iface
);
548 TRACE("(%p, %p): setting descriptor:\n%s\n", This
, pDesc
, debugstr_DMUS_OBJECTDESC (pDesc
));
550 /* According to MSDN, we should copy only given values, not whole struct */
551 if (pDesc
->dwValidData
& DMUS_OBJ_OBJECT
)
552 This
->pDesc
->guidObject
= pDesc
->guidObject
;
553 if (pDesc
->dwValidData
& DMUS_OBJ_CLASS
)
554 This
->pDesc
->guidClass
= pDesc
->guidClass
;
555 if (pDesc
->dwValidData
& DMUS_OBJ_NAME
)
556 lstrcpynW (This
->pDesc
->wszName
, pDesc
->wszName
, DMUS_MAX_NAME
);
557 if (pDesc
->dwValidData
& DMUS_OBJ_CATEGORY
)
558 lstrcpynW (This
->pDesc
->wszCategory
, pDesc
->wszCategory
, DMUS_MAX_CATEGORY
);
559 if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
)
560 lstrcpynW (This
->pDesc
->wszFileName
, pDesc
->wszFileName
, DMUS_MAX_FILENAME
);
561 if (pDesc
->dwValidData
& DMUS_OBJ_VERSION
)
562 This
->pDesc
->vVersion
= pDesc
->vVersion
;
563 if (pDesc
->dwValidData
& DMUS_OBJ_DATE
)
564 This
->pDesc
->ftDate
= pDesc
->ftDate
;
565 if (pDesc
->dwValidData
& DMUS_OBJ_MEMORY
) {
566 memcpy (&This
->pDesc
->llMemLength
, &pDesc
->llMemLength
, sizeof (pDesc
->llMemLength
));
567 memcpy (This
->pDesc
->pbMemData
, pDesc
->pbMemData
, sizeof (pDesc
->pbMemData
));
569 if (pDesc
->dwValidData
& DMUS_OBJ_STREAM
) {
570 /* according to MSDN, we copy the stream */
571 IStream_Clone (pDesc
->pStream
, &This
->pDesc
->pStream
);
575 This
->pDesc
->dwValidData
|= pDesc
->dwValidData
;
580 static HRESULT WINAPI
IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface
, LPSTREAM pStream
, LPDMUS_OBJECTDESC pDesc
) {
581 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, ObjectVtbl
, iface
);
582 DMUS_PRIVATE_CHUNK Chunk
;
583 DWORD StreamSize
, StreamCount
, ListSize
[1], ListCount
[1];
584 LARGE_INTEGER liMove
; /* used when skipping chunks */
586 TRACE("(%p,%p, %p)\n", This
, pStream
, pDesc
);
588 /* FIXME: should this be determined from stream? */
589 pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
590 pDesc
->guidClass
= CLSID_DirectMusicSegment
;
592 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
593 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
594 switch (Chunk
.fccID
) {
596 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
597 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
598 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
600 if (Chunk
.fccID
== DMUS_FOURCC_SEGMENT_FORM
) {
601 TRACE_(dmfile
)(": segment form\n");
603 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
604 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
605 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
606 switch (Chunk
.fccID
) {
607 case DMUS_FOURCC_GUID_CHUNK
: {
608 TRACE_(dmfile
)(": GUID chunk\n");
609 pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
610 IStream_Read (pStream
, &pDesc
->guidObject
, Chunk
.dwSize
, NULL
);
613 case DMUS_FOURCC_VERSION_CHUNK
: {
614 TRACE_(dmfile
)(": version chunk\n");
615 pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
616 IStream_Read (pStream
, &pDesc
->vVersion
, Chunk
.dwSize
, NULL
);
619 case DMUS_FOURCC_CATEGORY_CHUNK
: {
620 TRACE_(dmfile
)(": category chunk\n");
621 pDesc
->dwValidData
|= DMUS_OBJ_CATEGORY
;
622 IStream_Read (pStream
, pDesc
->wszCategory
, Chunk
.dwSize
, NULL
);
626 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
627 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
628 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
630 switch (Chunk
.fccID
) {
631 /* evil M$ UNFO list, which can (!?) contain INFO elements */
632 case DMUS_FOURCC_UNFO_LIST
: {
633 TRACE_(dmfile
)(": UNFO list\n");
635 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
636 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
637 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
638 switch (Chunk
.fccID
) {
639 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
640 (though strings seem to be valid unicode) */
641 case mmioFOURCC('I','N','A','M'):
642 case DMUS_FOURCC_UNAM_CHUNK
: {
643 TRACE_(dmfile
)(": name chunk\n");
644 pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
645 IStream_Read (pStream
, pDesc
->wszName
, Chunk
.dwSize
, NULL
);
648 case mmioFOURCC('I','A','R','T'):
649 case DMUS_FOURCC_UART_CHUNK
: {
650 TRACE_(dmfile
)(": artist chunk (ignored)\n");
651 liMove
.QuadPart
= Chunk
.dwSize
;
652 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
655 case mmioFOURCC('I','C','O','P'):
656 case DMUS_FOURCC_UCOP_CHUNK
: {
657 TRACE_(dmfile
)(": copyright chunk (ignored)\n");
658 liMove
.QuadPart
= Chunk
.dwSize
;
659 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
662 case mmioFOURCC('I','S','B','J'):
663 case DMUS_FOURCC_USBJ_CHUNK
: {
664 TRACE_(dmfile
)(": subject chunk (ignored)\n");
665 liMove
.QuadPart
= Chunk
.dwSize
;
666 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
669 case mmioFOURCC('I','C','M','T'):
670 case DMUS_FOURCC_UCMT_CHUNK
: {
671 TRACE_(dmfile
)(": comment chunk (ignored)\n");
672 liMove
.QuadPart
= Chunk
.dwSize
;
673 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
677 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
678 liMove
.QuadPart
= Chunk
.dwSize
;
679 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
683 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
684 } while (ListCount
[0] < ListSize
[0]);
687 case DMUS_FOURCC_TRACK_LIST
: {
688 TRACE_(dmfile
)(": TRACK list\n");
690 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
691 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
692 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
693 switch (Chunk
.fccID
) {
695 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
696 liMove
.QuadPart
= Chunk
.dwSize
;
697 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
701 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
702 } while (ListCount
[0] < ListSize
[0]);
706 TRACE_(dmfile
)(": unknown (skipping)\n");
707 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
708 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
715 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
716 liMove
.QuadPart
= Chunk
.dwSize
;
717 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
721 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
722 } while (StreamCount
< StreamSize
);
724 } else if (Chunk
.fccID
== mmioFOURCC('W','A','V','E')) {
725 TRACE_(dmfile
)(": wave form (loading not yet implemented)\n");
726 liMove
.QuadPart
= StreamSize
;
727 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
729 TRACE_(dmfile
)(": unexpected chunk (loading failed)\n");
730 liMove
.QuadPart
= StreamSize
;
731 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
735 TRACE_(dmfile
)(": reading finished\n");
739 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
740 liMove
.QuadPart
= Chunk
.dwSize
;
741 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
742 return DMUS_E_INVALIDFILE
;
746 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc
));
751 static const IDirectMusicObjectVtbl DirectMusicSegment8_Object_Vtbl
= {
752 IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface
,
753 IDirectMusicSegment8Impl_IDirectMusicObject_AddRef
,
754 IDirectMusicSegment8Impl_IDirectMusicObject_Release
,
755 IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor
,
756 IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor
,
757 IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor
760 /* IDirectMusicSegment8Impl IPersistStream part: */
761 static HRESULT WINAPI
IDirectMusicSegment8Impl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface
, REFIID riid
, LPVOID
*ppobj
) {
762 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
763 return IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
766 static ULONG WINAPI
IDirectMusicSegment8Impl_IPersistStream_AddRef (LPPERSISTSTREAM iface
) {
767 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
768 return IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
771 static ULONG WINAPI
IDirectMusicSegment8Impl_IPersistStream_Release (LPPERSISTSTREAM iface
) {
772 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
773 return IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
776 static HRESULT WINAPI
IDirectMusicSegment8Impl_IPersistStream_GetClassID (LPPERSISTSTREAM iface
, CLSID
* pClassID
) {
777 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
778 TRACE("(%p, %p)\n", This
, pClassID
);
779 *pClassID
= CLSID_DirectMusicSegment
;
783 static HRESULT WINAPI
IDirectMusicSegment8Impl_IPersistStream_IsDirty (LPPERSISTSTREAM iface
) {
784 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
785 FIXME("(%p): stub, always S_FALSE\n", This
);
789 static HRESULT
IDirectMusicSegment8Impl_IPersistStream_LoadTrack (LPPERSISTSTREAM iface
, IStream
* pClonedStream
, IDirectMusicTrack
** ppTrack
,
790 DMUS_IO_TRACK_HEADER
* pTrack_hdr
) {
792 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
794 IPersistStream
* pPersistStream
= NULL
;
796 hr
= CoCreateInstance (&pTrack_hdr
->guidClassID
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectMusicTrack
, (LPVOID
*) ppTrack
);
798 ERR(": could not create object\n");
801 /* acquire PersistStream interface */
802 hr
= IDirectMusicTrack_QueryInterface (*ppTrack
, &IID_IPersistStream
, (LPVOID
*) &pPersistStream
);
804 ERR(": could not acquire IPersistStream\n");
808 hr
= IPersistStream_Load (pPersistStream
, pClonedStream
);
810 ERR(": failed to load object\n");
814 /* release all loading-related stuff */
815 IPersistStream_Release (pPersistStream
);
817 hr
= IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack ((LPDIRECTMUSICSEGMENT8
)&This
->SegmentVtbl
, *ppTrack
, pTrack_hdr
->dwGroup
); /* at dsPosition */
819 ERR(": could not insert track\n");
826 static HRESULT
IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (LPPERSISTSTREAM iface
, DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
) {
828 /*ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);*/
830 DMUS_PRIVATE_CHUNK Chunk
;
831 DWORD StreamSize
, StreamCount
, ListSize
[3];
832 LARGE_INTEGER liMove
; /* used when skipping chunks */
834 DMUS_IO_TRACK_HEADER track_hdr
;
835 DMUS_IO_TRACK_EXTRAS_HEADER track_xhdr
;
836 IDirectMusicTrack
* pTrack
= NULL
;
838 if (pChunk
->fccID
!= DMUS_FOURCC_TRACK_FORM
) {
839 ERR_(dmfile
)(": %s chunk should be a TRACK form\n", debugstr_fourcc (pChunk
->fccID
));
843 StreamSize
= pChunk
->dwSize
- sizeof(FOURCC
);
847 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
848 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
849 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
851 switch (Chunk
.fccID
) {
852 case DMUS_FOURCC_TRACK_CHUNK
: {
853 TRACE_(dmfile
)(": track chunk\n");
854 IStream_Read (pStm
, &track_hdr
, sizeof(DMUS_IO_TRACK_HEADER
), NULL
);
855 TRACE_(dmfile
)(" - class: %s\n", debugstr_guid (&track_hdr
.guidClassID
));
856 TRACE_(dmfile
)(" - dwGroup: %d\n", track_hdr
.dwGroup
);
857 TRACE_(dmfile
)(" - ckid: %s\n", debugstr_fourcc (track_hdr
.ckid
));
858 TRACE_(dmfile
)(" - fccType: %s\n", debugstr_fourcc (track_hdr
.fccType
));
861 case DMUS_FOURCC_TRACK_EXTRAS_CHUNK
: {
862 TRACE_(dmfile
)(": track extras chunk\n");
863 IStream_Read (pStm
, &track_xhdr
, sizeof(DMUS_IO_TRACK_EXTRAS_HEADER
), NULL
);
867 case DMUS_FOURCC_COMMANDTRACK_CHUNK
: {
868 TRACE_(dmfile
)(": COMMANDTRACK track\n");
869 liMove
.QuadPart
= Chunk
.dwSize
;
870 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
875 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
876 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
877 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
878 if (Chunk
.fccID
== track_hdr
.fccType
&& 0 == track_hdr
.ckid
) {
879 LPSTREAM pClonedStream
= NULL
;
881 TRACE_(dmfile
)(": TRACK list\n");
883 IStream_Clone (pStm
, &pClonedStream
);
886 liMove
.QuadPart
-= sizeof(FOURCC
) + (sizeof(FOURCC
)+sizeof(DWORD
));
887 IStream_Seek (pClonedStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
889 hr
= IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface
, pClonedStream
, &pTrack
, &track_hdr
);
891 ERR(": could not load track\n");
894 IStream_Release (pClonedStream
);
896 IDirectMusicTrack_Release(pTrack
); pTrack
= NULL
; /* now we can release at as it inserted */
898 liMove
.QuadPart
= ListSize
[0];
899 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
902 TRACE_(dmfile
)(": unknown (skipping)\n");
903 liMove
.QuadPart
= Chunk
.dwSize
;
904 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
910 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
911 TRACE_(dmfile
)(": RIFF chunk of type %s\n", debugstr_fourcc(Chunk
.fccID
));
913 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
915 if (Chunk
.fccID
== track_hdr
.fccType
&& 0 == track_hdr
.ckid
) {
916 LPSTREAM pClonedStream
= NULL
;
918 TRACE_(dmfile
)(": TRACK RIFF\n");
920 IStream_Clone (pStm
, &pClonedStream
);
923 liMove
.QuadPart
-= sizeof(FOURCC
) + (sizeof(FOURCC
)+sizeof(DWORD
));
924 IStream_Seek (pClonedStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
926 hr
= IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface
, pClonedStream
, &pTrack
, &track_hdr
);
928 ERR(": could not load track\n");
931 IStream_Release (pClonedStream
);
933 IDirectMusicTrack_Release(pTrack
); pTrack
= NULL
; /* now we can release at as it inserted */
935 /** now safe move the cursor */
936 liMove
.QuadPart
= ListSize
[0];
937 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
940 TRACE_(dmfile
)(": unknown RIFF fmt (skipping)\n");
941 liMove
.QuadPart
= ListSize
[0];
942 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
948 if (0 == track_hdr
.fccType
&& Chunk
.fccID
== track_hdr
.ckid
) {
949 LPSTREAM pClonedStream
= NULL
;
951 TRACE_(dmfile
)(": TRACK solo\n");
953 IStream_Clone (pStm
, &pClonedStream
);
956 liMove
.QuadPart
-= (sizeof(FOURCC
) + sizeof(DWORD
));
957 IStream_Seek (pClonedStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
959 hr
= IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface
, pClonedStream
, &pTrack
, &track_hdr
);
961 ERR(": could not load track\n");
964 IStream_Release (pClonedStream
);
966 IDirectMusicTrack_Release(pTrack
); pTrack
= NULL
; /* now we can release at as it inserted */
968 liMove
.QuadPart
= Chunk
.dwSize
;
969 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
974 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
975 liMove
.QuadPart
= Chunk
.dwSize
;
976 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
980 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
981 } while (StreamCount
< StreamSize
);
986 static HRESULT
IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (LPPERSISTSTREAM iface
, DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
, IDirectMusicSegment8Impl
* This
) {
989 DMUS_PRIVATE_CHUNK Chunk
;
990 DWORD StreamSize
, ListSize
[3], ListCount
[3];
991 LARGE_INTEGER liMove
; /* used when skipping chunks */
993 if (pChunk
->fccID
!= DMUS_FOURCC_TRACK_LIST
) {
994 ERR_(dmfile
)(": %s chunk should be a TRACK list\n", debugstr_fourcc (pChunk
->fccID
));
998 ListSize
[0] = pChunk
->dwSize
- sizeof(FOURCC
);
1002 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
1003 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
1004 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
1005 switch (Chunk
.fccID
) {
1007 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
1008 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
1009 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
1010 switch (Chunk
.fccID
) {
1011 case DMUS_FOURCC_TRACK_FORM
: {
1012 TRACE_(dmfile
)(": TRACK form\n");
1013 hr
= IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (iface
, &Chunk
, pStm
);
1014 if (FAILED(hr
)) return hr
;
1018 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
1019 liMove
.QuadPart
= StreamSize
;
1020 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
1027 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
1028 liMove
.QuadPart
= Chunk
.dwSize
;
1029 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
1033 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
1034 } while (ListCount
[0] < ListSize
[0]);
1039 static HRESULT
IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (LPPERSISTSTREAM iface
, DMUS_PRIVATE_CHUNK
* pChunk
, IStream
* pStm
, IDirectMusicSegment8Impl
* This
) {
1041 HRESULT hr
= E_FAIL
;
1042 DMUS_PRIVATE_CHUNK Chunk
;
1043 DWORD StreamSize
, StreamCount
, ListSize
[3], ListCount
[3];
1044 LARGE_INTEGER liMove
; /* used when skipping chunks */
1046 if (pChunk
->fccID
!= DMUS_FOURCC_SEGMENT_FORM
) {
1047 ERR_(dmfile
)(": %s chunk should be a segment form\n", debugstr_fourcc (pChunk
->fccID
));
1051 StreamSize
= pChunk
->dwSize
- sizeof(FOURCC
);
1055 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
1056 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
1057 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
1059 hr
= IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk
, pStm
, This
->pDesc
);
1060 if (FAILED(hr
)) return hr
;
1062 if (hr
== S_FALSE
) {
1063 switch (Chunk
.fccID
) {
1064 case DMUS_FOURCC_SEGMENT_CHUNK
: {
1065 DWORD checkSz
= sizeof(FOURCC
);
1066 TRACE_(dmfile
)(": segment chunk\n");
1069 IStream_Read (pStm
, &This
->header
.dwRepeats
, sizeof(This
->header
.dwRepeats
), NULL
);
1070 checkSz
+= sizeof(This
->header
.dwRepeats
);
1071 IStream_Read (pStm
, &This
->header
.mtLength
, sizeof(This
->header
.mtLength
), NULL
);
1072 checkSz
+= sizeof(This
->header
.mtLength
);
1073 IStream_Read (pStm
, &This
->header
.mtPlayStart
, sizeof(This
->header
.mtPlayStart
), NULL
);
1074 checkSz
+= sizeof(This
->header
.mtPlayStart
);
1075 IStream_Read (pStm
, &This
->header
.mtLoopStart
, sizeof(This
->header
.mtLoopStart
), NULL
);
1076 checkSz
+= sizeof(This
->header
.mtLoopStart
);
1077 IStream_Read (pStm
, &This
->header
.mtLoopEnd
, sizeof(This
->header
.mtLoopEnd
), NULL
);
1078 checkSz
+= sizeof(This
->header
.mtLoopEnd
);
1079 IStream_Read (pStm
, &This
->header
.dwResolution
, sizeof(This
->header
.dwResolution
), NULL
);
1080 checkSz
+= sizeof(This
->header
.dwResolution
);
1081 TRACE_(dmfile
)("dwRepeats: %u\n", This
->header
.dwRepeats
);
1082 TRACE_(dmfile
)("mtLength: %u\n", This
->header
.mtLength
);
1083 TRACE_(dmfile
)("mtPlayStart: %u\n", This
->header
.mtPlayStart
);
1084 TRACE_(dmfile
)("mtLoopStart: %u\n", This
->header
.mtLoopStart
);
1085 TRACE_(dmfile
)("mtLoopEnd: %u\n", This
->header
.mtLoopEnd
);
1086 TRACE_(dmfile
)("dwResolution: %u\n", This
->header
.dwResolution
);
1088 if (Chunk
.dwSize
> checkSz
) {
1089 IStream_Read (pStm
, &This
->header
.rtLength
, sizeof(This
->header
.rtLength
), NULL
);
1090 checkSz
+= sizeof(This
->header
.rtLength
);
1091 IStream_Read (pStm
, &This
->header
.dwFlags
, sizeof(This
->header
.dwFlags
), NULL
);
1092 checkSz
+= sizeof(This
->header
.dwFlags
);
1095 if (Chunk
.dwSize
> checkSz
) {
1096 IStream_Read (pStm
, &This
->header
.rtLoopStart
, sizeof(This
->header
.rtLoopStart
), NULL
);
1097 checkSz
+= sizeof(This
->header
.rtLoopStart
);
1098 IStream_Read (pStm
, &This
->header
.rtLoopEnd
, sizeof(This
->header
.rtLoopEnd
), NULL
);
1099 checkSz
+= sizeof(This
->header
.rtLoopEnd
);
1100 IStream_Read (pStm
, &This
->header
.rtPlayStart
, sizeof(This
->header
.rtPlayStart
), NULL
);
1101 checkSz
+= sizeof(This
->header
.rtPlayStart
);
1104 liMove
.QuadPart
= Chunk
.dwSize
- checkSz
+ sizeof(FOURCC
);
1105 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
1109 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
1110 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
1111 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
1113 switch (Chunk
.fccID
) {
1114 case DMUS_FOURCC_UNFO_LIST
: {
1115 TRACE_(dmfile
)(": UNFO list\n");
1117 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
1118 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
1119 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
1121 hr
= IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk
, pStm
, This
->pDesc
);
1122 if (FAILED(hr
)) return hr
;
1124 if (hr
== S_FALSE
) {
1125 switch (Chunk
.fccID
) {
1127 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
1128 liMove
.QuadPart
= Chunk
.dwSize
;
1129 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
1135 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
1136 } while (ListCount
[0] < ListSize
[0]);
1139 case DMUS_FOURCC_TRACK_LIST
: {
1140 TRACE_(dmfile
)(": TRACK list\n");
1141 hr
= IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (iface
, &Chunk
, pStm
, This
);
1142 if (FAILED(hr
)) return hr
;
1146 TRACE_(dmfile
)(": unknown (skipping)\n");
1147 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
1148 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
1155 TRACE_(dmfile
)(": unknown chunk (irrevelant & skipping)\n");
1156 liMove
.QuadPart
= Chunk
.dwSize
;
1157 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
1162 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
1163 } while (StreamCount
< StreamSize
);
1168 static HRESULT
IDirectMusicSegment8Impl_IPersistStream_LoadWave (LPPERSISTSTREAM iface
, IStream
* pClonedStream
, IDirectMusicObject
** ppWaveObject
) {
1170 HRESULT hr
= E_FAIL
;
1171 IPersistStream
* pPersistStream
= NULL
;
1173 hr
= CoCreateInstance (&CLSID_DirectSoundWave
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectMusicObject
, (LPVOID
*) ppWaveObject
);
1175 ERR(": could not create object\n");
1178 /* acquire PersistStream interface */
1179 hr
= IDirectMusicObject_QueryInterface (*ppWaveObject
, &IID_IPersistStream
, (LPVOID
*) &pPersistStream
);
1181 ERR(": could not acquire IPersistStream\n");
1185 hr
= IPersistStream_Load (pPersistStream
, pClonedStream
);
1187 ERR(": failed to load object\n");
1191 /* release all loading-related stuff */
1192 IPersistStream_Release (pPersistStream
);
1197 static HRESULT WINAPI
IDirectMusicSegment8Impl_IPersistStream_Load (LPPERSISTSTREAM iface
, IStream
* pStm
) {
1198 ICOM_THIS_MULTI(IDirectMusicSegment8Impl
, PersistStreamVtbl
, iface
);
1201 DMUS_PRIVATE_CHUNK Chunk
;
1203 /*DWORD ListSize[3], ListCount[3];*/
1204 LARGE_INTEGER liMove
; /* used when skipping chunks */
1206 TRACE("(%p, %p): Loading\n", This
, pStm
);
1207 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
1208 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
1209 switch (Chunk
.fccID
) {
1211 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
1212 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
1213 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
1214 switch (Chunk
.fccID
) {
1215 case DMUS_FOURCC_SEGMENT_FORM
: {
1216 TRACE_(dmfile
)(": segment form\n");
1217 hr
= IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (iface
, &Chunk
, pStm
, This
);
1218 if (FAILED(hr
)) return hr
;
1221 case mmioFOURCC('W','A','V','E'): {
1222 LPSTREAM pClonedStream
= NULL
;
1223 IDirectMusicObject
* pWave
= NULL
;
1225 FIXME_(dmfile
)(": WAVE form (loading to be checked)\n");
1227 IStream_Clone (pStm
, &pClonedStream
);
1229 liMove
.QuadPart
= 0;
1230 liMove
.QuadPart
-= sizeof(FOURCC
) + (sizeof(FOURCC
)+sizeof(DWORD
));
1231 IStream_Seek (pClonedStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
1233 hr
= IDirectMusicSegment8Impl_IPersistStream_LoadWave (iface
, pClonedStream
, &pWave
);
1235 ERR(": could not load track\n");
1238 IStream_Release (pClonedStream
);
1240 IDirectMusicTrack_Release(pWave
); pWave
= NULL
; /* now we can release at as it inserted */
1242 liMove
.QuadPart
= StreamSize
;
1243 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
1247 TRACE_(dmfile
)(": unexpected chunk (loading failed)\n");
1248 liMove
.QuadPart
= StreamSize
;
1249 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
1253 TRACE_(dmfile
)(": reading finished\n");
1257 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
1258 liMove
.QuadPart
= Chunk
.dwSize
;
1259 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
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
;
1294 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicSegment8Impl
));
1297 return E_OUTOFMEMORY
;
1299 obj
->UnknownVtbl
= &DirectMusicSegment8_Unknown_Vtbl
;
1300 obj
->SegmentVtbl
= &DirectMusicSegment8_Segment_Vtbl
;
1301 obj
->ObjectVtbl
= &DirectMusicSegment8_Object_Vtbl
;
1302 obj
->PersistStreamVtbl
= &DirectMusicSegment8_PersistStream_Vtbl
;
1303 obj
->pDesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DMUS_OBJECTDESC
));
1304 DM_STRUCT_INIT(obj
->pDesc
);
1305 obj
->pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
1306 obj
->pDesc
->guidClass
= CLSID_DirectMusicSegment
;
1307 obj
->ref
= 0; /* will be inited by QueryInterface */
1308 list_init (&obj
->Tracks
);
1310 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN
)&obj
->UnknownVtbl
, lpcGUID
, ppobj
);