Update a url.
[wine.git] / dlls / dmime / segment.c
blobabc212bbc17324a2ec38be8b6c5fd57cb72ed71d
1 /* IDirectMusicSegment8 Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
4 * Copyright (C) 2003-2004 Raphael Junqueira
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Library General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "dmime_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
24 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
26 /*****************************************************************************
27 * IDirectMusicSegmentImpl implementation
29 /* IDirectMusicSegment IUnknown part: */
30 HRESULT WINAPI IDirectMusicSegment8Impl_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
31 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
32 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
34 if (IsEqualIID (riid, &IID_IUnknown)) {
35 *ppobj = (LPVOID)&This->UnknownVtbl;
36 IDirectMusicSegment8Impl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
37 return S_OK;
38 } else if (IsEqualIID (riid, &IID_IDirectMusicSegment)
39 || IsEqualIID (riid, &IID_IDirectMusicSegment2)
40 || IsEqualIID (riid, &IID_IDirectMusicSegment8)) {
41 *ppobj = (LPVOID)&This->SegmentVtbl;
42 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef ((LPDIRECTMUSICSEGMENT8)&This->SegmentVtbl);
43 return S_OK;
44 } else if (IsEqualIID (riid, &IID_IDirectMusicObject)) {
45 *ppobj = (LPVOID)&This->ObjectVtbl;
46 IDirectMusicSegment8Impl_IDirectMusicObject_AddRef ((LPDIRECTMUSICOBJECT)&This->ObjectVtbl);
47 return S_OK;
48 } else if (IsEqualIID (riid, &IID_IPersistStream)) {
49 *ppobj = (LPVOID)&This->PersistStreamVtbl;
50 IDirectMusicSegment8Impl_IPersistStream_AddRef ((LPPERSISTSTREAM)&This->PersistStreamVtbl);
51 return S_OK;
54 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
55 return E_NOINTERFACE;
58 ULONG WINAPI IDirectMusicSegment8Impl_IUnknown_AddRef (LPUNKNOWN iface) {
59 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
60 TRACE("(%p): AddRef from %ld\n", This, This->ref);
61 return ++(This->ref);
64 ULONG WINAPI IDirectMusicSegment8Impl_IUnknown_Release (LPUNKNOWN iface) {
65 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
66 ULONG ref = --This->ref;
67 TRACE("(%p): ReleaseRef to %ld\n", This, This->ref);
68 if (ref == 0) {
69 HeapFree(GetProcessHeap(), 0, This);
71 return ref;
74 IUnknownVtbl DirectMusicSegment8_Unknown_Vtbl = {
75 IDirectMusicSegment8Impl_IUnknown_QueryInterface,
76 IDirectMusicSegment8Impl_IUnknown_AddRef,
77 IDirectMusicSegment8Impl_IUnknown_Release
80 /* IDirectMusicSegmentImpl IDirectMusicSegment part: */
81 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_QueryInterface (LPDIRECTMUSICSEGMENT8 iface, REFIID riid, LPVOID *ppobj) {
82 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
83 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
86 ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef (LPDIRECTMUSICSEGMENT8 iface) {
87 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
88 return IDirectMusicSegment8Impl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
91 ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Release (LPDIRECTMUSICSEGMENT8 iface) {
92 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
93 return IDirectMusicSegment8Impl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
96 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLength (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtLength) {
97 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
98 TRACE("(%p, %p)\n", This, pmtLength);
99 if (NULL == pmtLength) {
100 return E_POINTER;
102 *pmtLength = This->header.mtLength;
103 return S_OK;
106 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLength (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtLength) {
107 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
108 TRACE("(%p, %ld)\n", This, mtLength);
109 This->header.mtLength = mtLength;
110 return S_OK;
113 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetRepeats (LPDIRECTMUSICSEGMENT8 iface, DWORD* pdwRepeats) {
114 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
115 TRACE("(%p, %p)\n", This, pdwRepeats);
116 if (NULL == pdwRepeats) {
117 return E_POINTER;
119 *pdwRepeats = This->header.dwRepeats;
120 return S_OK;
123 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetRepeats (LPDIRECTMUSICSEGMENT8 iface, DWORD dwRepeats) {
124 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
125 TRACE("(%p, %ld)\n", This, dwRepeats);
126 This->header.dwRepeats = dwRepeats;
127 return S_OK;
130 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetDefaultResolution (LPDIRECTMUSICSEGMENT8 iface, DWORD* pdwResolution) {
131 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
132 TRACE("(%p, %p)\n", This, pdwResolution);
133 if (NULL == pdwResolution) {
134 return E_POINTER;
136 *pdwResolution = This->header.dwResolution;
137 return S_OK;
140 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetDefaultResolution (LPDIRECTMUSICSEGMENT8 iface, DWORD dwResolution) {
141 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
142 TRACE("(%p, %ld)\n", This, dwResolution);
143 This->header.dwResolution = dwResolution;
144 return S_OK;
147 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, IDirectMusicTrack** ppTrack) {
148 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
150 CLSID pIt_clsid;
151 struct list* pEntry = NULL;
152 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
153 IPersistStream* pCLSIDStream = NULL;
154 HRESULT hr = S_OK;
156 TRACE("(%p, %s, %ld, 0x%lx, %p)\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, ppTrack);
158 if (NULL == ppTrack) {
159 return E_POINTER;
162 LIST_FOR_EACH (pEntry, &This->Tracks) {
163 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
164 TRACE(" - %p -> 0x%lx,%p\n", pIt, pIt->dwGroupBits, pIt->pTrack);
165 if (0xFFFFFFFF != dwGroupBits && 0 == (pIt->dwGroupBits & dwGroupBits)) continue ;
166 if (FALSE == IsEqualGUID(&GUID_NULL, rguidType)) {
168 * it rguidType is not null we must check if CLSID are equals
169 * and the unqiue way to get it its using IPersistStream Interface
171 hr = IDirectMusicTrack_QueryInterface(pIt->pTrack, &IID_IPersistStream, (void**) &pCLSIDStream);
172 if (FAILED(hr)) {
173 ERR("(%p): object %p don't implement IPersistStream Interface. Expect a crash (critical problem)\n", This, pIt->pTrack);
174 continue ;
176 hr = IPersistStream_GetClassID(pCLSIDStream, &pIt_clsid);
177 IPersistStream_Release(pCLSIDStream); pCLSIDStream = NULL;
178 if (FAILED(hr)) {
179 ERR("(%p): non-implemented GetClassID for object %p\n", This, pIt->pTrack);
180 continue ;
182 TRACE(" - %p -> %s\n", pIt, debugstr_dmguid(&pIt_clsid));
183 if (FALSE == IsEqualGUID(&pIt_clsid, rguidType)) continue ;
185 if (0 == dwIndex) {
186 *ppTrack = pIt->pTrack;
187 IDirectMusicTrack_AddRef(*ppTrack);
188 return S_OK;
190 --dwIndex;
192 return DMUS_E_NOT_FOUND;
195 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrackGroup (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack, DWORD* pdwGroupBits) {
196 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
198 struct list* pEntry = NULL;
199 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
201 TRACE("(%p, %p, %p)\n", This, pTrack, pdwGroupBits);
203 if (NULL == pdwGroupBits) {
204 return E_POINTER;
207 LIST_FOR_EACH (pEntry, &This->Tracks) {
208 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
209 TRACE(" - %p -> %ld,%p\n", pIt, pIt->dwGroupBits, pIt->pTrack);
210 if (NULL != pIt && pIt->pTrack == pTrack) {
211 *pdwGroupBits = pIt->dwGroupBits;
212 return S_OK;
216 return DMUS_E_NOT_FOUND;
219 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack, DWORD dwGroupBits) {
220 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
222 DWORD i = 0;
223 struct list* pEntry = NULL;
224 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
225 LPDMUS_PRIVATE_SEGMENT_TRACK pNewSegTrack = NULL;
227 TRACE("(%p, %p, %ld)\n", This, pTrack, dwGroupBits);
229 LIST_FOR_EACH (pEntry, &This->Tracks) {
230 i++;
231 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
232 TRACE(" - #%lu: %p -> %ld,%p\n", i, pIt, pIt->dwGroupBits, pIt->pTrack);
233 if (NULL != pIt && pIt->pTrack == pTrack) {
234 ERR("(%p, %p): track is already in list\n", This, pTrack);
235 return E_FAIL;
239 pNewSegTrack = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_SEGMENT_TRACK));
240 if (NULL == pNewSegTrack) {
241 ERR(": no more memory\n");
242 return E_OUTOFMEMORY;
244 pNewSegTrack->dwGroupBits = dwGroupBits;
245 pNewSegTrack->pTrack = pTrack;
246 IDirectMusicTrack_Init(pTrack, iface);
247 IDirectMusicTrack_AddRef(pTrack);
248 list_add_tail (&This->Tracks, &pNewSegTrack->entry);
250 return S_OK;
253 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack) {
254 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
256 struct list* pEntry = NULL;
257 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
259 TRACE("(%p, %p)\n", This, pTrack);
261 LIST_FOR_EACH (pEntry, &This->Tracks) {
262 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
263 if (pIt->pTrack == pTrack) {
264 TRACE("(%p, %p): track in list\n", This, pTrack);
266 list_remove(&pIt->entry);
267 IDirectMusicTrack_Init(pIt->pTrack, NULL);
268 IDirectMusicTrack_Release(pIt->pTrack);
269 HeapFree(GetProcessHeap(), 0, pIt);
271 return S_OK;
275 return S_FALSE;
278 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicSegmentState** ppSegState, IDirectMusicPerformance* pPerformance, DWORD dwFlags) {
279 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
280 HRESULT hr;
281 FIXME("(%p, %p, %p, %ld): semi-stub\n", This, ppSegState, pPerformance, dwFlags);
282 if (NULL == ppSegState) {
283 return E_POINTER;
285 hr = DMUSIC_CreateDirectMusicSegmentStateImpl(&IID_IDirectMusicSegmentState, (void**) ppSegState, NULL);
286 if (FAILED(hr)) {
287 return hr;
289 /* TODO: DMUS_SEGF_FLAGS */
290 return S_OK;
293 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicGraph** ppGraph) {
294 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
295 FIXME("(%p, %p): semi-stub\n", This, ppGraph);
296 if (NULL == ppGraph) {
297 return E_POINTER;
299 if (NULL == This->pGraph) {
300 return DMUS_E_NOT_FOUND;
302 /**
303 * should return This, as seen in msdn
304 * http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c/directx/htm/idirectmusicsegment8getgraph.asp
305 * "...The segment object implements IDirectMusicGraph directly..."
307 *ppGraph = This->pGraph;
308 IDirectMusicGraph_AddRef(This->pGraph);
309 return S_OK;
312 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicGraph* pGraph) {
313 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
314 FIXME("(%p, %p): to complete\n", This, pGraph);
315 if (NULL != This->pGraph) {
316 IDirectMusicGraph_Release(This->pGraph);
318 This->pGraph = pGraph;
319 if (NULL != This->pGraph) {
320 IDirectMusicGraph_AddRef(This->pGraph);
322 return S_OK;
325 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidNotificationType) {
326 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
327 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
328 return S_OK;
331 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidNotificationType) {
332 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
333 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
334 return S_OK;
337 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
338 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
340 CLSID pIt_clsid;
341 struct list* pEntry = NULL;
342 IDirectMusicTrack* pTrack = NULL;
343 IPersistStream* pCLSIDStream = NULL;
344 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
345 HRESULT hr = S_OK;
347 FIXME("(%p, %s, 0x%lx, %ld, %ld, %p, %p)\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pmtNext, pParam);
349 if (DMUS_SEG_ANYTRACK == dwIndex) {
351 LIST_FOR_EACH (pEntry, &This->Tracks) {
352 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
354 TRACE(" - %p -> 0x%lx,%p\n", pIt, pIt->dwGroupBits, pIt->pTrack);
356 if (0xFFFFFFFF != dwGroupBits && 0 == (pIt->dwGroupBits & dwGroupBits)) continue ;
357 hr = IPersistStream_GetClassID(pCLSIDStream, &pIt_clsid);
358 IPersistStream_Release(pCLSIDStream); pCLSIDStream = NULL;
359 if (FAILED(hr)) {
360 ERR("(%p): non-implemented GetClassID for object %p\n", This, pIt->pTrack);
361 continue ;
363 if (FALSE == IsEqualGUID(&pIt_clsid, rguidType)) continue ;
364 if (FAILED(IDirectMusicTrack_IsParamSupported(pIt->pTrack, rguidType))) continue ;
365 hr = IDirectMusicTrack_GetParam(pIt->pTrack, rguidType, mtTime, pmtNext, pParam);
366 if (SUCCEEDED(hr)) return hr;
368 ERR("(%p): not found\n", This);
369 return DMUS_E_TRACK_NOT_FOUND;
372 hr = IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack(iface, &GUID_NULL, dwGroupBits, dwIndex, &pTrack);
373 if (FAILED(hr)) {
374 ERR("(%p): not found\n", This);
375 return DMUS_E_TRACK_NOT_FOUND;
378 hr = IDirectMusicTrack_GetParam(pTrack, rguidType, mtTime, pmtNext, pParam);
379 IDirectMusicTrack_Release(pTrack); pTrack = NULL;
381 return hr;
384 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, void* pParam) {
385 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
386 FIXME("(%p, %s, %ld, %ld, %ld, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pParam);
387 return S_OK;
390 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicSegment** ppSegment) {
391 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
392 FIXME("(%p, %ld, %ld, %p): stub\n", This, mtStart, mtEnd, ppSegment);
393 return S_OK;
396 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart) {
397 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
398 TRACE("(%p, %ld)\n", This, mtStart);
399 if (mtStart >= This->header.mtLength) {
400 return DMUS_E_OUT_OF_RANGE;
402 This->header.mtPlayStart = mtStart;
403 return S_OK;
406 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtStart) {
407 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
408 TRACE("(%p, %p)\n", This, pmtStart);
409 if (NULL == pmtStart) {
410 return E_POINTER;
412 *pmtStart = This->header.mtPlayStart;
413 return S_OK;
416 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd) {
417 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
418 TRACE("(%p, %ld, %ld)\n", This, mtStart, mtEnd);
419 if (mtStart >= This->header.mtLength || mtEnd > This->header.mtLength || mtStart > mtEnd) {
420 return DMUS_E_OUT_OF_RANGE;
422 This->header.mtLoopStart = mtStart;
423 This->header.mtLoopEnd = mtEnd;
424 return S_OK;
427 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtStart, MUSIC_TIME* pmtEnd) {
428 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
429 TRACE("(%p, %p, %p)\n", This, pmtStart, pmtEnd);
430 if (NULL == pmtStart || NULL == pmtEnd) {
431 return E_POINTER;
433 *pmtStart = This->header.mtLoopStart;
434 *pmtEnd = This->header.mtLoopEnd;
435 return S_OK;
438 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed (LPDIRECTMUSICSEGMENT8 iface, DWORD dwNumPChannels, DWORD* paPChannels) {
439 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
440 FIXME("(%p, %ld, %p): stub\n", This, dwNumPChannels, paPChannels);
441 return S_OK;
444 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidTrackClassID, DWORD dwGroupBits, DWORD dwIndex, DWORD dwFlagsOn, DWORD dwFlagsOff) {
445 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
446 FIXME("(%p, %s, %ld, %ld, %ld, %ld): stub\n", This, debugstr_dmguid(rguidTrackClassID), dwGroupBits, dwIndex, dwFlagsOn, dwFlagsOff);
447 return S_OK;
450 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig (LPDIRECTMUSICSEGMENT8 iface, IUnknown** ppAudioPathConfig){
451 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
452 FIXME("(%p, %p): stub\n", This, ppAudioPathConfig);
453 return S_OK;
456 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtTime, IDirectMusicSegment* pFromSegment, IDirectMusicSegment* pToSegment, IDirectMusicSegment** ppComposedSegment) {
457 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
458 FIXME("(%p, %ld, %p, %p, %p): stub\n", This, mtTime, pFromSegment, pToSegment, ppComposedSegment);
459 return S_OK;
462 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Download (LPDIRECTMUSICSEGMENT8 iface, IUnknown *pAudioPath) {
463 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
464 FIXME("(%p, %p): stub\n", This, pAudioPath);
465 return S_OK;
468 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload (LPDIRECTMUSICSEGMENT8 iface, IUnknown *pAudioPath) {
469 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
470 FIXME("(%p, %p): stub\n", This, pAudioPath);
471 return S_OK;
474 IDirectMusicSegment8Vtbl DirectMusicSegment8_Segment_Vtbl = {
475 IDirectMusicSegment8Impl_IDirectMusicSegment8_QueryInterface,
476 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef,
477 IDirectMusicSegment8Impl_IDirectMusicSegment8_Release,
478 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLength,
479 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLength,
480 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetRepeats,
481 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetRepeats,
482 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetDefaultResolution,
483 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetDefaultResolution,
484 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack,
485 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrackGroup,
486 IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack,
487 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack,
488 IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay,
489 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph,
490 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph,
491 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType,
492 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType,
493 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam,
494 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam,
495 IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone,
496 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint,
497 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint,
498 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints,
499 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints,
500 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed,
501 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig,
502 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig,
503 IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose,
504 IDirectMusicSegment8Impl_IDirectMusicSegment8_Download,
505 IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload
508 /* IDirectMusicSegment8Impl IDirectMusicObject part: */
509 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) {
510 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
511 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
514 ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) {
515 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
516 return IDirectMusicSegment8Impl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
519 ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) {
520 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
521 return IDirectMusicSegment8Impl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
524 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
525 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
526 TRACE("(%p, %p)\n", This, pDesc);
527 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
528 memcpy (pDesc, This->pDesc, This->pDesc->dwSize);
529 return S_OK;
532 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
533 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
534 TRACE("(%p, %p): setting descriptor:\n%s\n", This, pDesc, debugstr_DMUS_OBJECTDESC (pDesc));
536 /* According to MSDN, we should copy only given values, not whole struct */
537 if (pDesc->dwValidData & DMUS_OBJ_OBJECT)
538 memcpy (&This->pDesc->guidObject, &pDesc->guidObject, sizeof (pDesc->guidObject));
539 if (pDesc->dwValidData & DMUS_OBJ_CLASS)
540 memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass));
541 if (pDesc->dwValidData & DMUS_OBJ_NAME)
542 strncpyW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
543 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
544 strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
545 if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
546 strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
547 if (pDesc->dwValidData & DMUS_OBJ_VERSION)
548 memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));
549 if (pDesc->dwValidData & DMUS_OBJ_DATE)
550 memcpy (&This->pDesc->ftDate, &pDesc->ftDate, sizeof (pDesc->ftDate));
551 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
552 memcpy (&This->pDesc->llMemLength, &pDesc->llMemLength, sizeof (pDesc->llMemLength));
553 memcpy (This->pDesc->pbMemData, pDesc->pbMemData, sizeof (pDesc->pbMemData));
555 if (pDesc->dwValidData & DMUS_OBJ_STREAM) {
556 /* according to MSDN, we copy the stream */
557 IStream_Clone (pDesc->pStream, &This->pDesc->pStream);
560 /* add new flags */
561 This->pDesc->dwValidData |= pDesc->dwValidData;
563 return S_OK;
566 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc) {
567 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
568 DMUS_PRIVATE_CHUNK Chunk;
569 DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
570 LARGE_INTEGER liMove; /* used when skipping chunks */
572 TRACE("(%p,%p, %p)\n", This, pStream, pDesc);
574 /* FIXME: should this be determined from stream? */
575 pDesc->dwValidData |= DMUS_OBJ_CLASS;
576 memcpy (&pDesc->guidClass, &CLSID_DirectMusicSegment, sizeof(CLSID));
578 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
579 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
580 switch (Chunk.fccID) {
581 case FOURCC_RIFF: {
582 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
583 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
584 StreamSize = Chunk.dwSize - sizeof(FOURCC);
585 StreamCount = 0;
586 if (Chunk.fccID == DMUS_FOURCC_SEGMENT_FORM) {
587 TRACE_(dmfile)(": segment form\n");
588 do {
589 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
590 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
591 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
592 switch (Chunk.fccID) {
593 case DMUS_FOURCC_GUID_CHUNK: {
594 TRACE_(dmfile)(": GUID chunk\n");
595 pDesc->dwValidData |= DMUS_OBJ_OBJECT;
596 IStream_Read (pStream, &pDesc->guidObject, Chunk.dwSize, NULL);
597 break;
599 case DMUS_FOURCC_VERSION_CHUNK: {
600 TRACE_(dmfile)(": version chunk\n");
601 pDesc->dwValidData |= DMUS_OBJ_VERSION;
602 IStream_Read (pStream, &pDesc->vVersion, Chunk.dwSize, NULL);
603 break;
605 case DMUS_FOURCC_CATEGORY_CHUNK: {
606 TRACE_(dmfile)(": category chunk\n");
607 pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
608 IStream_Read (pStream, pDesc->wszCategory, Chunk.dwSize, NULL);
609 break;
611 case FOURCC_LIST: {
612 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
613 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
614 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
615 ListCount[0] = 0;
616 switch (Chunk.fccID) {
617 /* evil M$ UNFO list, which can (!?) contain INFO elements */
618 case DMUS_FOURCC_UNFO_LIST: {
619 TRACE_(dmfile)(": UNFO list\n");
620 do {
621 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
622 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
623 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
624 switch (Chunk.fccID) {
625 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
626 (though strings seem to be valid unicode) */
627 case mmioFOURCC('I','N','A','M'):
628 case DMUS_FOURCC_UNAM_CHUNK: {
629 TRACE_(dmfile)(": name chunk\n");
630 pDesc->dwValidData |= DMUS_OBJ_NAME;
631 IStream_Read (pStream, pDesc->wszName, Chunk.dwSize, NULL);
632 break;
634 case mmioFOURCC('I','A','R','T'):
635 case DMUS_FOURCC_UART_CHUNK: {
636 TRACE_(dmfile)(": artist chunk (ignored)\n");
637 liMove.QuadPart = Chunk.dwSize;
638 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
639 break;
641 case mmioFOURCC('I','C','O','P'):
642 case DMUS_FOURCC_UCOP_CHUNK: {
643 TRACE_(dmfile)(": copyright chunk (ignored)\n");
644 liMove.QuadPart = Chunk.dwSize;
645 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
646 break;
648 case mmioFOURCC('I','S','B','J'):
649 case DMUS_FOURCC_USBJ_CHUNK: {
650 TRACE_(dmfile)(": subject chunk (ignored)\n");
651 liMove.QuadPart = Chunk.dwSize;
652 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
653 break;
655 case mmioFOURCC('I','C','M','T'):
656 case DMUS_FOURCC_UCMT_CHUNK: {
657 TRACE_(dmfile)(": comment chunk (ignored)\n");
658 liMove.QuadPart = Chunk.dwSize;
659 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
660 break;
662 default: {
663 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
664 liMove.QuadPart = Chunk.dwSize;
665 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
666 break;
669 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
670 } while (ListCount[0] < ListSize[0]);
671 break;
673 case DMUS_FOURCC_TRACK_LIST: {
674 TRACE_(dmfile)(": TRACK list\n");
675 do {
676 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
677 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
678 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
679 switch (Chunk.fccID) {
680 default: {
681 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
682 liMove.QuadPart = Chunk.dwSize;
683 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
684 break;
687 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
688 } while (ListCount[0] < ListSize[0]);
689 break;
691 default: {
692 TRACE_(dmfile)(": unknown (skipping)\n");
693 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
694 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
695 break;
698 break;
700 default: {
701 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
702 liMove.QuadPart = Chunk.dwSize;
703 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
704 break;
707 TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
708 } while (StreamCount < StreamSize);
709 break;
710 } else if (Chunk.fccID == mmioFOURCC('W','A','V','E')) {
711 TRACE_(dmfile)(": wave form (loading not yet implemented)\n");
712 liMove.QuadPart = StreamSize;
713 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
714 } else {
715 TRACE_(dmfile)(": unexpected chunk (loading failed)\n");
716 liMove.QuadPart = StreamSize;
717 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
718 return E_FAIL;
721 TRACE_(dmfile)(": reading finished\n");
722 break;
724 default: {
725 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
726 liMove.QuadPart = Chunk.dwSize;
727 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
728 return DMUS_E_INVALIDFILE;
732 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc));
734 return S_OK;
737 IDirectMusicObjectVtbl DirectMusicSegment8_Object_Vtbl = {
738 IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface,
739 IDirectMusicSegment8Impl_IDirectMusicObject_AddRef,
740 IDirectMusicSegment8Impl_IDirectMusicObject_Release,
741 IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor,
742 IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor,
743 IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor
746 /* IDirectMusicSegment8Impl IPersistStream part: */
747 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
748 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
749 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
752 ULONG WINAPI IDirectMusicSegment8Impl_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
753 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
754 return IDirectMusicSegment8Impl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
757 ULONG WINAPI IDirectMusicSegment8Impl_IPersistStream_Release (LPPERSISTSTREAM iface) {
758 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
759 return IDirectMusicSegment8Impl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
762 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
763 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
764 TRACE("(%p, %p)\n", This, pClassID);
765 memcpy(pClassID, &CLSID_DirectMusicSegment, sizeof(CLSID));
766 return S_OK;
769 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
770 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
771 FIXME("(%p): stub, always S_FALSE\n", This);
772 return S_FALSE;
775 static HRESULT IDirectMusicSegment8Impl_IPersistStream_LoadTrack (LPPERSISTSTREAM iface, IStream* pClonedStream, IDirectMusicTrack** ppTrack,
776 DMUS_IO_TRACK_HEADER* pTrack_hdr) {
778 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
779 HRESULT hr = E_FAIL;
780 IPersistStream* pPersistStream = NULL;
782 hr = CoCreateInstance (&pTrack_hdr->guidClassID, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicTrack, (LPVOID*) ppTrack);
783 if (FAILED(hr)) {
784 ERR(": could not create object\n");
785 return hr;
787 /* acquire PersistStream interface */
788 hr = IDirectMusicTrack_QueryInterface (*ppTrack, &IID_IPersistStream, (LPVOID*) &pPersistStream);
789 if (FAILED(hr)) {
790 ERR(": could not acquire IPersistStream\n");
791 return hr;
793 /* load */
794 hr = IPersistStream_Load (pPersistStream, pClonedStream);
795 if (FAILED(hr)) {
796 ERR(": failed to load object\n");
797 return hr;
800 /* release all loading-related stuff */
801 IPersistStream_Release (pPersistStream);
803 hr = IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack ((LPDIRECTMUSICSEGMENT8)&This->SegmentVtbl, *ppTrack, pTrack_hdr->dwGroup); /* at dsPosition */
804 if (FAILED(hr)) {
805 ERR(": could not insert track\n");
806 return hr;
809 return S_OK;
812 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
814 /*ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);*/
815 HRESULT hr = E_FAIL;
816 DMUS_PRIVATE_CHUNK Chunk;
817 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
818 LARGE_INTEGER liMove; /* used when skipping chunks */
820 DMUS_IO_TRACK_HEADER track_hdr;
821 DMUS_IO_TRACK_EXTRAS_HEADER track_xhdr;
822 IDirectMusicTrack* pTrack = NULL;
824 if (pChunk->fccID != DMUS_FOURCC_TRACK_FORM) {
825 ERR_(dmfile)(": %s chunk should be a TRACK form\n", debugstr_fourcc (pChunk->fccID));
826 return E_FAIL;
829 StreamSize = pChunk->dwSize - sizeof(FOURCC);
830 StreamCount = 0;
832 do {
833 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
834 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
835 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
837 switch (Chunk.fccID) {
838 case DMUS_FOURCC_TRACK_CHUNK: {
839 TRACE_(dmfile)(": track chunck\n");
840 IStream_Read (pStm, &track_hdr, sizeof(DMUS_IO_TRACK_HEADER), NULL);
841 TRACE_(dmfile)(" - class: %s\n", debugstr_guid (&track_hdr.guidClassID));
842 TRACE_(dmfile)(" - dwGroup: %ld\n", track_hdr.dwGroup);
843 TRACE_(dmfile)(" - ckid: %s\n", debugstr_fourcc (track_hdr.ckid));
844 TRACE_(dmfile)(" - fccType: %s\n", debugstr_fourcc (track_hdr.fccType));
845 break;
847 case DMUS_FOURCC_TRACK_EXTRAS_CHUNK: {
848 TRACE_(dmfile)(": track extras chunck\n");
849 IStream_Read (pStm, &track_xhdr, sizeof(DMUS_IO_TRACK_EXTRAS_HEADER), NULL);
850 break;
853 case DMUS_FOURCC_COMMANDTRACK_CHUNK: {
854 TRACE_(dmfile)(": COMMANDTRACK track\n");
855 liMove.QuadPart = Chunk.dwSize;
856 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
857 break;
860 case FOURCC_LIST: {
861 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
862 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
863 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
864 ListCount[0] = 0;
865 if (Chunk.fccID == track_hdr.fccType && 0 == track_hdr.ckid) {
866 LPSTREAM pClonedStream = NULL;
868 TRACE_(dmfile)(": TRACK list\n");
870 IStream_Clone (pStm, &pClonedStream);
872 liMove.QuadPart = 0;
873 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
874 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
876 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
877 if (FAILED(hr)) {
878 ERR(": could not load track\n");
879 return hr;
881 IStream_Release (pClonedStream);
883 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
885 liMove.QuadPart = ListSize[0];
886 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
888 } else {
889 TRACE_(dmfile)(": unknown (skipping)\n");
890 liMove.QuadPart = Chunk.dwSize;
891 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
893 break;
896 case FOURCC_RIFF: {
897 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
898 TRACE_(dmfile)(": RIFF chunk of type %s\n", debugstr_fourcc(Chunk.fccID));
900 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
902 if (Chunk.fccID == track_hdr.fccType && 0 == track_hdr.ckid) {
903 LPSTREAM pClonedStream = NULL;
905 TRACE_(dmfile)(": TRACK RIFF\n");
907 IStream_Clone (pStm, &pClonedStream);
909 liMove.QuadPart = 0;
910 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
911 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
913 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
914 if (FAILED(hr)) {
915 ERR(": could not load track\n");
916 return hr;
918 IStream_Release (pClonedStream);
920 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
922 /** now safe move the cursor */
923 liMove.QuadPart = ListSize[0];
924 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
926 } else {
927 TRACE_(dmfile)(": unknown RIFF fmt (skipping)\n");
928 liMove.QuadPart = ListSize[0];
929 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
931 break;
934 default: {
935 if (0 == track_hdr.fccType && Chunk.fccID == track_hdr.ckid) {
936 LPSTREAM pClonedStream = NULL;
938 TRACE_(dmfile)(": TRACK solo\n");
940 IStream_Clone (pStm, &pClonedStream);
942 liMove.QuadPart = 0;
943 liMove.QuadPart -= (sizeof(FOURCC) + sizeof(DWORD));
944 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
946 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
947 if (FAILED(hr)) {
948 ERR(": could not load track\n");
949 return hr;
951 IStream_Release (pClonedStream);
953 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
955 liMove.QuadPart = Chunk.dwSize;
956 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
958 break;
961 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
962 liMove.QuadPart = Chunk.dwSize;
963 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
964 break;
967 TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
968 } while (StreamCount < StreamSize);
970 return S_OK;
973 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicSegment8Impl* This) {
975 HRESULT hr = E_FAIL;
976 DMUS_PRIVATE_CHUNK Chunk;
977 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
978 LARGE_INTEGER liMove; /* used when skipping chunks */
980 if (pChunk->fccID != DMUS_FOURCC_TRACK_LIST) {
981 ERR_(dmfile)(": %s chunk should be a TRACK list\n", debugstr_fourcc (pChunk->fccID));
982 return E_FAIL;
985 ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
986 ListCount[0] = 0;
988 do {
989 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
990 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
991 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
992 switch (Chunk.fccID) {
993 case FOURCC_RIFF: {
994 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
995 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
996 StreamSize = Chunk.dwSize - sizeof(FOURCC);
997 StreamCount = 0;
998 switch (Chunk.fccID) {
999 case DMUS_FOURCC_TRACK_FORM: {
1000 TRACE_(dmfile)(": TRACK form\n");
1001 hr = IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (iface, &Chunk, pStm);
1002 if (FAILED(hr)) return hr;
1003 break;
1005 default: {
1006 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1007 liMove.QuadPart = StreamSize;
1008 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1009 break;
1012 break;
1014 default: {
1015 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1016 liMove.QuadPart = Chunk.dwSize;
1017 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1018 break;
1021 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
1022 } while (ListCount[0] < ListSize[0]);
1024 return S_OK;
1027 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicSegment8Impl* This) {
1029 HRESULT hr = E_FAIL;
1030 DMUS_PRIVATE_CHUNK Chunk;
1031 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
1032 LARGE_INTEGER liMove; /* used when skipping chunks */
1034 if (pChunk->fccID != DMUS_FOURCC_SEGMENT_FORM) {
1035 ERR_(dmfile)(": %s chunk should be a segment form\n", debugstr_fourcc (pChunk->fccID));
1036 return E_FAIL;
1039 StreamSize = pChunk->dwSize - sizeof(FOURCC);
1040 StreamCount = 0;
1042 do {
1043 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1044 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
1045 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1047 hr = IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk, pStm, This->pDesc);
1048 if (FAILED(hr)) return hr;
1050 if (hr == S_FALSE) {
1051 switch (Chunk.fccID) {
1052 case DMUS_FOURCC_SEGMENT_CHUNK: {
1053 DWORD checkSz = sizeof(FOURCC);
1054 TRACE_(dmfile)(": segment chunk\n");
1055 #if 1
1056 /** DX 7 */
1057 IStream_Read (pStm, &This->header.dwRepeats, sizeof(This->header.dwRepeats), NULL);
1058 checkSz += sizeof(This->header.dwRepeats);
1059 IStream_Read (pStm, &This->header.mtLength, sizeof(This->header.mtLength), NULL);
1060 checkSz += sizeof(This->header.mtLength);
1061 IStream_Read (pStm, &This->header.mtPlayStart, sizeof(This->header.mtPlayStart), NULL);
1062 checkSz += sizeof(This->header.mtPlayStart);
1063 IStream_Read (pStm, &This->header.mtLoopStart, sizeof(This->header.mtLoopStart), NULL);
1064 checkSz += sizeof(This->header.mtLoopStart);
1065 IStream_Read (pStm, &This->header.mtLoopEnd, sizeof(This->header.mtLoopEnd), NULL);
1066 checkSz += sizeof(This->header.mtLoopEnd);
1067 IStream_Read (pStm, &This->header.dwResolution, sizeof(This->header.dwResolution), NULL);
1068 checkSz += sizeof(This->header.dwResolution);
1069 TRACE_(dmfile)("dwRepeats: %lu\n", This->header.dwRepeats);
1070 TRACE_(dmfile)("mtLength: %lu\n", This->header.mtLength);
1071 TRACE_(dmfile)("mtPlayStart: %lu\n", This->header.mtPlayStart);
1072 TRACE_(dmfile)("mtLoopStart: %lu\n", This->header.mtLoopStart);
1073 TRACE_(dmfile)("mtLoopEnd: %lu\n", This->header.mtLoopEnd);
1074 TRACE_(dmfile)("dwResolution: %lu\n", This->header.dwResolution);
1075 /** DX 8 */
1076 if (Chunk.dwSize > checkSz) {
1077 IStream_Read (pStm, &This->header.rtLength, sizeof(This->header.rtLength), NULL);
1078 checkSz += sizeof(This->header.rtLength);
1079 IStream_Read (pStm, &This->header.dwFlags, sizeof(This->header.dwFlags), NULL);
1080 checkSz += sizeof(This->header.dwFlags);
1082 /** DX 9 */
1083 if (Chunk.dwSize > checkSz) {
1084 IStream_Read (pStm, &This->header.rtLoopStart, sizeof(This->header.rtLoopStart), NULL);
1085 checkSz += sizeof(This->header.rtLoopStart);
1086 IStream_Read (pStm, &This->header.rtLoopEnd, sizeof(This->header.rtLoopEnd), NULL);
1087 checkSz += sizeof(This->header.rtLoopEnd);
1088 IStream_Read (pStm, &This->header.rtPlayStart, sizeof(This->header.rtPlayStart), NULL);
1089 checkSz += sizeof(This->header.rtPlayStart);
1091 #endif
1092 liMove.QuadPart = Chunk.dwSize - checkSz + sizeof(FOURCC);
1093 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1094 break;
1096 case FOURCC_LIST: {
1097 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
1098 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
1099 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
1100 ListCount[0] = 0;
1101 switch (Chunk.fccID) {
1102 case DMUS_FOURCC_UNFO_LIST: {
1103 TRACE_(dmfile)(": UNFO list\n");
1104 do {
1105 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1106 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
1107 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1109 hr = IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk, pStm, This->pDesc);
1110 if (FAILED(hr)) return hr;
1112 if (hr == S_FALSE) {
1113 switch (Chunk.fccID) {
1114 default: {
1115 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1116 liMove.QuadPart = Chunk.dwSize;
1117 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1118 break;
1123 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
1124 } while (ListCount[0] < ListSize[0]);
1125 break;
1127 case DMUS_FOURCC_TRACK_LIST: {
1128 TRACE_(dmfile)(": TRACK list\n");
1129 hr = IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (iface, &Chunk, pStm, This);
1130 if (FAILED(hr)) return hr;
1131 break;
1133 default: {
1134 TRACE_(dmfile)(": unknown (skipping)\n");
1135 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
1136 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1137 break;
1140 break;
1142 default: {
1143 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
1144 liMove.QuadPart = Chunk.dwSize;
1145 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1146 break;
1150 TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
1151 } while (StreamCount < StreamSize);
1153 return S_OK;
1156 static HRESULT IDirectMusicSegment8Impl_IPersistStream_LoadWave (LPPERSISTSTREAM iface, IStream* pClonedStream, IDirectMusicObject** ppWaveObject) {
1158 HRESULT hr = E_FAIL;
1159 IPersistStream* pPersistStream = NULL;
1161 hr = CoCreateInstance (&CLSID_DirectSoundWave, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicObject, (LPVOID*) ppWaveObject);
1162 if (FAILED(hr)) {
1163 ERR(": could not create object\n");
1164 return hr;
1166 /* acquire PersistStream interface */
1167 hr = IDirectMusicObject_QueryInterface (*ppWaveObject, &IID_IPersistStream, (LPVOID*) &pPersistStream);
1168 if (FAILED(hr)) {
1169 ERR(": could not acquire IPersistStream\n");
1170 return hr;
1172 /* load */
1173 hr = IPersistStream_Load (pPersistStream, pClonedStream);
1174 if (FAILED(hr)) {
1175 ERR(": failed to load object\n");
1176 return hr;
1179 /* release all loading-related stuff */
1180 IPersistStream_Release (pPersistStream);
1182 return S_OK;
1185 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
1186 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1188 HRESULT hr;
1189 DMUS_PRIVATE_CHUNK Chunk;
1190 DWORD StreamSize, StreamCount;
1191 /*DWORD ListSize[3], ListCount[3];*/
1192 LARGE_INTEGER liMove; /* used when skipping chunks */
1195 TRACE("(%p, %p): Loading\n", This, pStm);
1196 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1197 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1198 switch (Chunk.fccID) {
1199 case FOURCC_RIFF: {
1200 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
1201 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
1202 StreamSize = Chunk.dwSize - sizeof(FOURCC);
1203 StreamCount = 0;
1204 switch (Chunk.fccID) {
1205 case DMUS_FOURCC_SEGMENT_FORM: {
1206 TRACE_(dmfile)(": segment form\n");
1207 hr = IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (iface, &Chunk, pStm, This);
1208 if (FAILED(hr)) return hr;
1209 break;
1211 case mmioFOURCC('W','A','V','E'): {
1212 LPSTREAM pClonedStream = NULL;
1213 IDirectMusicObject* pWave = NULL;
1215 FIXME_(dmfile)(": WAVE form (loading to be checked)\n");
1217 IStream_Clone (pStm, &pClonedStream);
1219 liMove.QuadPart = 0;
1220 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
1221 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
1223 hr = IDirectMusicSegment8Impl_IPersistStream_LoadWave (iface, pClonedStream, &pWave);
1224 if (FAILED(hr)) {
1225 ERR(": could not load track\n");
1226 return hr;
1228 IStream_Release (pClonedStream);
1230 IDirectMusicTrack_Release(pWave); pWave = NULL; /* now we can release at as it inserted */
1232 liMove.QuadPart = StreamSize;
1233 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1234 break;
1236 default: {
1237 TRACE_(dmfile)(": unexpected chunk (loading failed)\n");
1238 liMove.QuadPart = StreamSize;
1239 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1240 return E_FAIL;
1243 TRACE_(dmfile)(": reading finished\n");
1244 break;
1246 default: {
1247 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
1248 liMove.QuadPart = Chunk.dwSize;
1249 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1250 return E_FAIL;
1254 return S_OK;
1257 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
1258 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1259 FIXME("(%p): Saving not implemented yet\n", This);
1260 return E_NOTIMPL;
1263 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
1264 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1265 FIXME("(%p, %p): stub\n", This, pcbSize);
1266 return E_NOTIMPL;
1269 IPersistStreamVtbl DirectMusicSegment8_PersistStream_Vtbl = {
1270 IDirectMusicSegment8Impl_IPersistStream_QueryInterface,
1271 IDirectMusicSegment8Impl_IPersistStream_AddRef,
1272 IDirectMusicSegment8Impl_IPersistStream_Release,
1273 IDirectMusicSegment8Impl_IPersistStream_GetClassID,
1274 IDirectMusicSegment8Impl_IPersistStream_IsDirty,
1275 IDirectMusicSegment8Impl_IPersistStream_Load,
1276 IDirectMusicSegment8Impl_IPersistStream_Save,
1277 IDirectMusicSegment8Impl_IPersistStream_GetSizeMax
1280 /* for ClassFactory */
1281 HRESULT WINAPI DMUSIC_CreateDirectMusicSegmentImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
1282 IDirectMusicSegment8Impl* obj;
1284 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSegment8Impl));
1285 if (NULL == obj) {
1286 *ppobj = (LPVOID) NULL;
1287 return E_OUTOFMEMORY;
1289 obj->UnknownVtbl = &DirectMusicSegment8_Unknown_Vtbl;
1290 obj->SegmentVtbl = &DirectMusicSegment8_Segment_Vtbl;
1291 obj->ObjectVtbl = &DirectMusicSegment8_Object_Vtbl;
1292 obj->PersistStreamVtbl = &DirectMusicSegment8_PersistStream_Vtbl;
1293 obj->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
1294 DM_STRUCT_INIT(obj->pDesc);
1295 obj->pDesc->dwValidData |= DMUS_OBJ_CLASS;
1296 memcpy (&obj->pDesc->guidClass, &CLSID_DirectMusicSegment, sizeof (CLSID));
1297 obj->ref = 0; /* will be inited by QueryInterface */
1298 list_init (&obj->Tracks);
1300 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&obj->UnknownVtbl, lpcGUID, ppobj);