d3d10core: Remove unnecessary DllMain implementation.
[wine.git] / dlls / dmime / segment.c
blob1bdf163767101da23158b66f7beb4d4aae9192f6
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 static inline IDirectMusicSegment8Impl *impl_from_IDirectMusicSegment8(IDirectMusicSegment8 *iface)
31 return CONTAINING_RECORD(iface, IDirectMusicSegment8Impl, IDirectMusicSegment8_iface);
34 static HRESULT WINAPI IDirectMusicSegment8Impl_QueryInterface(IDirectMusicSegment8 *iface,
35 REFIID riid, void **ret_iface)
37 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
39 *ret_iface = NULL;
41 if (IsEqualIID (riid, &IID_IUnknown) || IsEqualIID (riid, &IID_IDirectMusicSegment) ||
42 IsEqualIID(riid, &IID_IDirectMusicSegment2) ||
43 IsEqualIID (riid, &IID_IDirectMusicSegment8))
44 *ret_iface = iface;
45 else if (IsEqualIID (riid, &IID_IDirectMusicObject))
46 *ret_iface = &This->ObjectVtbl;
47 else if (IsEqualIID (riid, &IID_IPersistStream))
48 *ret_iface = &This->PersistStreamVtbl;
49 else {
50 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ret_iface);
51 return E_NOINTERFACE;
54 IUnknown_AddRef((IUnknown*)*ret_iface);
55 return S_OK;
58 static ULONG WINAPI IDirectMusicSegment8Impl_AddRef(IDirectMusicSegment8 *iface)
60 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
61 LONG ref = InterlockedIncrement(&This->ref);
63 TRACE("(%p) ref=%d\n", This, ref);
65 return ref;
68 static ULONG WINAPI IDirectMusicSegment8Impl_Release(IDirectMusicSegment8 *iface)
70 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
71 LONG ref = InterlockedDecrement(&This->ref);
73 TRACE("(%p) ref=%d\n", This, ref);
75 if (!ref) {
76 HeapFree(GetProcessHeap(), 0, This);
77 DMIME_UnlockModule();
80 return ref;
83 static HRESULT WINAPI IDirectMusicSegment8Impl_GetLength(IDirectMusicSegment8 *iface,
84 MUSIC_TIME *pmtLength)
86 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
88 TRACE("(%p, %p)\n", This, pmtLength);
89 if (NULL == pmtLength) {
90 return E_POINTER;
92 *pmtLength = This->header.mtLength;
93 return S_OK;
96 static HRESULT WINAPI IDirectMusicSegment8Impl_SetLength(IDirectMusicSegment8 *iface,
97 MUSIC_TIME mtLength)
99 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
101 TRACE("(%p, %d)\n", This, mtLength);
102 This->header.mtLength = mtLength;
103 return S_OK;
106 static HRESULT WINAPI IDirectMusicSegment8Impl_GetRepeats(IDirectMusicSegment8 *iface,
107 DWORD *pdwRepeats)
109 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
111 TRACE("(%p, %p)\n", This, pdwRepeats);
112 if (NULL == pdwRepeats) {
113 return E_POINTER;
115 *pdwRepeats = This->header.dwRepeats;
116 return S_OK;
119 static HRESULT WINAPI IDirectMusicSegment8Impl_SetRepeats(IDirectMusicSegment8 *iface,
120 DWORD dwRepeats)
122 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
124 TRACE("(%p, %d)\n", This, dwRepeats);
125 This->header.dwRepeats = dwRepeats;
126 return S_OK;
129 static HRESULT WINAPI IDirectMusicSegment8Impl_GetDefaultResolution(IDirectMusicSegment8 *iface,
130 DWORD *pdwResolution)
132 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
134 TRACE("(%p, %p)\n", This, pdwResolution);
135 if (NULL == pdwResolution) {
136 return E_POINTER;
138 *pdwResolution = This->header.dwResolution;
139 return S_OK;
142 static HRESULT WINAPI IDirectMusicSegment8Impl_SetDefaultResolution(IDirectMusicSegment8 *iface,
143 DWORD dwResolution)
145 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
147 TRACE("(%p, %d)\n", This, dwResolution);
148 This->header.dwResolution = dwResolution;
149 return S_OK;
152 static HRESULT WINAPI IDirectMusicSegment8Impl_GetTrack(IDirectMusicSegment8 *iface,
153 REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, IDirectMusicTrack **ppTrack)
155 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
156 CLSID pIt_clsid;
157 struct list* pEntry = NULL;
158 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
159 IPersistStream* pCLSIDStream = NULL;
160 HRESULT hr = S_OK;
162 TRACE("(%p, %s, %d, 0x%x, %p)\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, ppTrack);
164 if (NULL == ppTrack) {
165 return E_POINTER;
168 LIST_FOR_EACH (pEntry, &This->Tracks) {
169 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
170 TRACE(" - %p -> 0x%x,%p\n", pIt, pIt->dwGroupBits, pIt->pTrack);
171 if (0xFFFFFFFF != dwGroupBits && 0 == (pIt->dwGroupBits & dwGroupBits)) continue ;
172 if (FALSE == IsEqualGUID(&GUID_NULL, rguidType)) {
174 * it rguidType is not null we must check if CLSIDs are equal
175 * and the unique way to get it is using IPersistStream Interface
177 hr = IDirectMusicTrack_QueryInterface(pIt->pTrack, &IID_IPersistStream, (void**) &pCLSIDStream);
178 if (FAILED(hr)) {
179 ERR("(%p): object %p don't implement IPersistStream Interface. Expect a crash (critical problem)\n", This, pIt->pTrack);
180 continue ;
182 hr = IPersistStream_GetClassID(pCLSIDStream, &pIt_clsid);
183 IPersistStream_Release(pCLSIDStream); pCLSIDStream = NULL;
184 if (FAILED(hr)) {
185 ERR("(%p): non-implemented GetClassID for object %p\n", This, pIt->pTrack);
186 continue ;
188 TRACE(" - %p -> %s\n", pIt, debugstr_dmguid(&pIt_clsid));
189 if (FALSE == IsEqualGUID(&pIt_clsid, rguidType)) continue ;
191 if (0 == dwIndex) {
192 *ppTrack = pIt->pTrack;
193 IDirectMusicTrack_AddRef(*ppTrack);
194 return S_OK;
196 --dwIndex;
198 return DMUS_E_NOT_FOUND;
201 static HRESULT WINAPI IDirectMusicSegment8Impl_GetTrackGroup(IDirectMusicSegment8 *iface,
202 IDirectMusicTrack *pTrack, DWORD *pdwGroupBits)
204 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
205 struct list* pEntry = NULL;
206 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
208 TRACE("(%p, %p, %p)\n", This, pTrack, pdwGroupBits);
210 if (NULL == pdwGroupBits) {
211 return E_POINTER;
214 LIST_FOR_EACH (pEntry, &This->Tracks) {
215 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
216 TRACE(" - %p -> %d,%p\n", pIt, pIt->dwGroupBits, pIt->pTrack);
217 if (NULL != pIt && pIt->pTrack == pTrack) {
218 *pdwGroupBits = pIt->dwGroupBits;
219 return S_OK;
223 return DMUS_E_NOT_FOUND;
226 static HRESULT WINAPI IDirectMusicSegment8Impl_InsertTrack(IDirectMusicSegment8 *iface,
227 IDirectMusicTrack *pTrack, DWORD dwGroupBits)
229 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
230 DWORD i = 0;
231 struct list* pEntry = NULL;
232 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
233 LPDMUS_PRIVATE_SEGMENT_TRACK pNewSegTrack = NULL;
235 TRACE("(%p, %p, %d)\n", This, pTrack, dwGroupBits);
237 LIST_FOR_EACH (pEntry, &This->Tracks) {
238 i++;
239 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
240 TRACE(" - #%u: %p -> %d,%p\n", i, pIt, pIt->dwGroupBits, pIt->pTrack);
241 if (NULL != pIt && pIt->pTrack == pTrack) {
242 ERR("(%p, %p): track is already in list\n", This, pTrack);
243 return E_FAIL;
247 pNewSegTrack = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_SEGMENT_TRACK));
248 if (NULL == pNewSegTrack)
249 return E_OUTOFMEMORY;
251 pNewSegTrack->dwGroupBits = dwGroupBits;
252 pNewSegTrack->pTrack = pTrack;
253 IDirectMusicTrack_Init(pTrack, (IDirectMusicSegment *)iface);
254 IDirectMusicTrack_AddRef(pTrack);
255 list_add_tail (&This->Tracks, &pNewSegTrack->entry);
257 return S_OK;
260 static HRESULT WINAPI IDirectMusicSegment8Impl_RemoveTrack(IDirectMusicSegment8 *iface,
261 IDirectMusicTrack *pTrack)
263 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
264 struct list* pEntry = NULL;
265 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
267 TRACE("(%p, %p)\n", This, pTrack);
269 LIST_FOR_EACH (pEntry, &This->Tracks) {
270 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
271 if (pIt->pTrack == pTrack) {
272 TRACE("(%p, %p): track in list\n", This, pTrack);
274 list_remove(&pIt->entry);
275 IDirectMusicTrack_Init(pIt->pTrack, NULL);
276 IDirectMusicTrack_Release(pIt->pTrack);
277 HeapFree(GetProcessHeap(), 0, pIt);
279 return S_OK;
283 return S_FALSE;
286 static HRESULT WINAPI IDirectMusicSegment8Impl_InitPlay(IDirectMusicSegment8 *iface,
287 IDirectMusicSegmentState **ppSegState, IDirectMusicPerformance *pPerformance, DWORD dwFlags)
289 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
290 HRESULT hr;
292 FIXME("(%p, %p, %p, %d): semi-stub\n", This, ppSegState, pPerformance, dwFlags);
293 if (NULL == ppSegState) {
294 return E_POINTER;
296 hr = create_dmsegmentstate(&IID_IDirectMusicSegmentState,(void**) ppSegState);
297 if (FAILED(hr)) {
298 return hr;
300 /* TODO: DMUS_SEGF_FLAGS */
301 return S_OK;
304 static HRESULT WINAPI IDirectMusicSegment8Impl_GetGraph(IDirectMusicSegment8 *iface,
305 IDirectMusicGraph **ppGraph)
307 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
309 FIXME("(%p, %p): semi-stub\n", This, ppGraph);
310 if (NULL == ppGraph) {
311 return E_POINTER;
313 if (NULL == This->pGraph) {
314 return DMUS_E_NOT_FOUND;
316 /**
317 * should return This, as seen in msdn
318 * "...The segment object implements IDirectMusicGraph directly..."
320 *ppGraph = This->pGraph;
321 IDirectMusicGraph_AddRef(This->pGraph);
322 return S_OK;
325 static HRESULT WINAPI IDirectMusicSegment8Impl_SetGraph(IDirectMusicSegment8 *iface,
326 IDirectMusicGraph *pGraph)
328 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
330 FIXME("(%p, %p): to complete\n", This, pGraph);
331 if (NULL != This->pGraph) {
332 IDirectMusicGraph_Release(This->pGraph);
334 This->pGraph = pGraph;
335 if (NULL != This->pGraph) {
336 IDirectMusicGraph_AddRef(This->pGraph);
338 return S_OK;
341 static HRESULT WINAPI IDirectMusicSegment8Impl_AddNotificationType(IDirectMusicSegment8 *iface,
342 REFGUID rguidNotificationType)
344 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
345 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
346 return S_OK;
349 static HRESULT WINAPI IDirectMusicSegment8Impl_RemoveNotificationType(IDirectMusicSegment8 *iface,
350 REFGUID rguidNotificationType)
352 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
353 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
354 return S_OK;
357 static HRESULT WINAPI IDirectMusicSegment8Impl_GetParam(IDirectMusicSegment8 *iface,
358 REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, MUSIC_TIME *pmtNext,
359 void *pParam)
361 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
362 CLSID pIt_clsid;
363 struct list* pEntry = NULL;
364 IDirectMusicTrack* pTrack = NULL;
365 IPersistStream* pCLSIDStream = NULL;
366 LPDMUS_PRIVATE_SEGMENT_TRACK pIt = NULL;
367 HRESULT hr = S_OK;
369 FIXME("(%p, %s, 0x%x, %d, %d, %p, %p)\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pmtNext, pParam);
371 if (DMUS_SEG_ANYTRACK == dwIndex) {
373 LIST_FOR_EACH (pEntry, &This->Tracks) {
374 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_SEGMENT_TRACK, entry);
376 hr = IDirectMusicTrack_QueryInterface(pIt->pTrack, &IID_IPersistStream, (void**) &pCLSIDStream);
377 if (FAILED(hr)) {
378 ERR("(%p): object %p don't implement IPersistStream Interface. Expect a crash (critical problem)\n", This, pIt->pTrack);
379 continue ;
382 TRACE(" - %p -> 0x%x,%p\n", pIt, pIt->dwGroupBits, pIt->pTrack);
384 if (0xFFFFFFFF != dwGroupBits && 0 == (pIt->dwGroupBits & dwGroupBits)) continue ;
385 hr = IPersistStream_GetClassID(pCLSIDStream, &pIt_clsid);
386 IPersistStream_Release(pCLSIDStream); pCLSIDStream = NULL;
387 if (FAILED(hr)) {
388 ERR("(%p): non-implemented GetClassID for object %p\n", This, pIt->pTrack);
389 continue ;
391 if (FALSE == IsEqualGUID(&pIt_clsid, rguidType)) continue ;
392 if (FAILED(IDirectMusicTrack_IsParamSupported(pIt->pTrack, rguidType))) continue ;
393 hr = IDirectMusicTrack_GetParam(pIt->pTrack, rguidType, mtTime, pmtNext, pParam);
394 if (SUCCEEDED(hr)) return hr;
396 ERR("(%p): not found\n", This);
397 return DMUS_E_TRACK_NOT_FOUND;
400 hr = IDirectMusicSegment8Impl_GetTrack(iface, &GUID_NULL, dwGroupBits, dwIndex, &pTrack);
401 if (FAILED(hr)) {
402 ERR("(%p): not found\n", This);
403 return DMUS_E_TRACK_NOT_FOUND;
406 hr = IDirectMusicTrack_GetParam(pTrack, rguidType, mtTime, pmtNext, pParam);
407 IDirectMusicTrack_Release(pTrack); pTrack = NULL;
409 return hr;
412 static HRESULT WINAPI IDirectMusicSegment8Impl_SetParam(IDirectMusicSegment8 *iface,
413 REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, void *pParam)
415 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
416 FIXME("(%p, %s, %d, %d, %d, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pParam);
417 return S_OK;
420 static HRESULT WINAPI IDirectMusicSegment8Impl_Clone(IDirectMusicSegment8 *iface,
421 MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicSegment **ppSegment)
423 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
424 FIXME("(%p, %d, %d, %p): stub\n", This, mtStart, mtEnd, ppSegment);
425 return S_OK;
428 static HRESULT WINAPI IDirectMusicSegment8Impl_SetStartPoint(IDirectMusicSegment8 *iface,
429 MUSIC_TIME mtStart)
431 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
433 TRACE("(%p, %d)\n", This, mtStart);
434 if (mtStart >= This->header.mtLength) {
435 return DMUS_E_OUT_OF_RANGE;
437 This->header.mtPlayStart = mtStart;
438 return S_OK;
441 static HRESULT WINAPI IDirectMusicSegment8Impl_GetStartPoint(IDirectMusicSegment8 *iface,
442 MUSIC_TIME *pmtStart)
444 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
446 TRACE("(%p, %p)\n", This, pmtStart);
447 if (NULL == pmtStart) {
448 return E_POINTER;
450 *pmtStart = This->header.mtPlayStart;
451 return S_OK;
454 static HRESULT WINAPI IDirectMusicSegment8Impl_SetLoopPoints(IDirectMusicSegment8 *iface,
455 MUSIC_TIME mtStart, MUSIC_TIME mtEnd)
457 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
459 TRACE("(%p, %d, %d)\n", This, mtStart, mtEnd);
460 if (mtStart >= This->header.mtLength || mtEnd > This->header.mtLength || mtStart > mtEnd) {
461 return DMUS_E_OUT_OF_RANGE;
463 This->header.mtLoopStart = mtStart;
464 This->header.mtLoopEnd = mtEnd;
465 return S_OK;
468 static HRESULT WINAPI IDirectMusicSegment8Impl_GetLoopPoints(IDirectMusicSegment8 *iface,
469 MUSIC_TIME *pmtStart, MUSIC_TIME *pmtEnd)
471 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
473 TRACE("(%p, %p, %p)\n", This, pmtStart, pmtEnd);
474 if (NULL == pmtStart || NULL == pmtEnd) {
475 return E_POINTER;
477 *pmtStart = This->header.mtLoopStart;
478 *pmtEnd = This->header.mtLoopEnd;
479 return S_OK;
482 static HRESULT WINAPI IDirectMusicSegment8Impl_SetPChannelsUsed(IDirectMusicSegment8 *iface,
483 DWORD dwNumPChannels, DWORD *paPChannels)
485 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
486 FIXME("(%p, %d, %p): stub\n", This, dwNumPChannels, paPChannels);
487 return S_OK;
490 static HRESULT WINAPI IDirectMusicSegment8Impl_SetTrackConfig(IDirectMusicSegment8 *iface,
491 REFGUID rguidTrackClassID, DWORD dwGroupBits, DWORD dwIndex, DWORD dwFlagsOn,
492 DWORD dwFlagsOff)
494 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
495 FIXME("(%p, %s, %d, %d, %d, %d): stub\n", This, debugstr_dmguid(rguidTrackClassID), dwGroupBits, dwIndex, dwFlagsOn, dwFlagsOff);
496 return S_OK;
499 static HRESULT WINAPI IDirectMusicSegment8Impl_GetAudioPathConfig(IDirectMusicSegment8 *iface,
500 IUnknown **ppAudioPathConfig)
502 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
503 FIXME("(%p, %p): stub\n", This, ppAudioPathConfig);
504 return S_OK;
507 static HRESULT WINAPI IDirectMusicSegment8Impl_Compose(IDirectMusicSegment8 *iface,
508 MUSIC_TIME mtTime, IDirectMusicSegment *pFromSegment, IDirectMusicSegment *pToSegment,
509 IDirectMusicSegment **ppComposedSegment)
511 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
512 FIXME("(%p, %d, %p, %p, %p): stub\n", This, mtTime, pFromSegment, pToSegment, ppComposedSegment);
513 return S_OK;
516 static HRESULT WINAPI IDirectMusicSegment8Impl_Download(IDirectMusicSegment8 *iface,
517 IUnknown *pAudioPath)
519 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
520 FIXME("(%p, %p): stub\n", This, pAudioPath);
521 return S_OK;
524 static HRESULT WINAPI IDirectMusicSegment8Impl_Unload(IDirectMusicSegment8 *iface,
525 IUnknown *pAudioPath)
527 IDirectMusicSegment8Impl *This = impl_from_IDirectMusicSegment8(iface);
528 FIXME("(%p, %p): stub\n", This, pAudioPath);
529 return S_OK;
532 static const IDirectMusicSegment8Vtbl dmsegment8_vtbl = {
533 IDirectMusicSegment8Impl_QueryInterface,
534 IDirectMusicSegment8Impl_AddRef,
535 IDirectMusicSegment8Impl_Release,
536 IDirectMusicSegment8Impl_GetLength,
537 IDirectMusicSegment8Impl_SetLength,
538 IDirectMusicSegment8Impl_GetRepeats,
539 IDirectMusicSegment8Impl_SetRepeats,
540 IDirectMusicSegment8Impl_GetDefaultResolution,
541 IDirectMusicSegment8Impl_SetDefaultResolution,
542 IDirectMusicSegment8Impl_GetTrack,
543 IDirectMusicSegment8Impl_GetTrackGroup,
544 IDirectMusicSegment8Impl_InsertTrack,
545 IDirectMusicSegment8Impl_RemoveTrack,
546 IDirectMusicSegment8Impl_InitPlay,
547 IDirectMusicSegment8Impl_GetGraph,
548 IDirectMusicSegment8Impl_SetGraph,
549 IDirectMusicSegment8Impl_AddNotificationType,
550 IDirectMusicSegment8Impl_RemoveNotificationType,
551 IDirectMusicSegment8Impl_GetParam,
552 IDirectMusicSegment8Impl_SetParam,
553 IDirectMusicSegment8Impl_Clone,
554 IDirectMusicSegment8Impl_SetStartPoint,
555 IDirectMusicSegment8Impl_GetStartPoint,
556 IDirectMusicSegment8Impl_SetLoopPoints,
557 IDirectMusicSegment8Impl_GetLoopPoints,
558 IDirectMusicSegment8Impl_SetPChannelsUsed,
559 IDirectMusicSegment8Impl_SetTrackConfig,
560 IDirectMusicSegment8Impl_GetAudioPathConfig,
561 IDirectMusicSegment8Impl_Compose,
562 IDirectMusicSegment8Impl_Download,
563 IDirectMusicSegment8Impl_Unload
566 /* IDirectMusicSegment8Impl IDirectMusicObject part: */
567 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) {
568 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
569 return IDirectMusicSegment8_QueryInterface(&This->IDirectMusicSegment8_iface, riid, ppobj);
572 static ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) {
573 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
574 return IDirectMusicSegment8_AddRef(&This->IDirectMusicSegment8_iface);
577 static ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) {
578 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
579 return IDirectMusicSegment8_Release(&This->IDirectMusicSegment8_iface);
582 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
583 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
584 TRACE("(%p, %p)\n", This, pDesc);
585 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
586 memcpy (pDesc, This->pDesc, This->pDesc->dwSize);
587 return S_OK;
590 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
591 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
592 TRACE("(%p, %p): setting descriptor:\n%s\n", This, pDesc, debugstr_DMUS_OBJECTDESC (pDesc));
594 /* According to MSDN, we should copy only given values, not whole struct */
595 if (pDesc->dwValidData & DMUS_OBJ_OBJECT)
596 This->pDesc->guidObject = pDesc->guidObject;
597 if (pDesc->dwValidData & DMUS_OBJ_CLASS)
598 This->pDesc->guidClass = pDesc->guidClass;
599 if (pDesc->dwValidData & DMUS_OBJ_NAME)
600 lstrcpynW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
601 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
602 lstrcpynW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
603 if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
604 lstrcpynW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
605 if (pDesc->dwValidData & DMUS_OBJ_VERSION)
606 This->pDesc->vVersion = pDesc->vVersion;
607 if (pDesc->dwValidData & DMUS_OBJ_DATE)
608 This->pDesc->ftDate = pDesc->ftDate;
609 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
610 This->pDesc->llMemLength = pDesc->llMemLength;
611 memcpy (This->pDesc->pbMemData, pDesc->pbMemData, pDesc->llMemLength);
613 if (pDesc->dwValidData & DMUS_OBJ_STREAM) {
614 /* according to MSDN, we copy the stream */
615 IStream_Clone (pDesc->pStream, &This->pDesc->pStream);
618 /* add new flags */
619 This->pDesc->dwValidData |= pDesc->dwValidData;
621 return S_OK;
624 static HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc) {
625 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
626 DMUS_PRIVATE_CHUNK Chunk;
627 DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
628 LARGE_INTEGER liMove; /* used when skipping chunks */
630 TRACE("(%p,%p, %p)\n", This, pStream, pDesc);
632 /* FIXME: should this be determined from stream? */
633 pDesc->dwValidData |= DMUS_OBJ_CLASS;
634 pDesc->guidClass = CLSID_DirectMusicSegment;
636 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
637 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
638 switch (Chunk.fccID) {
639 case FOURCC_RIFF: {
640 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
641 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
642 StreamSize = Chunk.dwSize - sizeof(FOURCC);
643 StreamCount = 0;
644 if (Chunk.fccID == DMUS_FOURCC_SEGMENT_FORM) {
645 TRACE_(dmfile)(": segment form\n");
646 do {
647 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
648 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
649 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
650 switch (Chunk.fccID) {
651 case DMUS_FOURCC_GUID_CHUNK: {
652 TRACE_(dmfile)(": GUID chunk\n");
653 pDesc->dwValidData |= DMUS_OBJ_OBJECT;
654 IStream_Read (pStream, &pDesc->guidObject, Chunk.dwSize, NULL);
655 break;
657 case DMUS_FOURCC_VERSION_CHUNK: {
658 TRACE_(dmfile)(": version chunk\n");
659 pDesc->dwValidData |= DMUS_OBJ_VERSION;
660 IStream_Read (pStream, &pDesc->vVersion, Chunk.dwSize, NULL);
661 break;
663 case DMUS_FOURCC_CATEGORY_CHUNK: {
664 TRACE_(dmfile)(": category chunk\n");
665 pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
666 IStream_Read (pStream, pDesc->wszCategory, Chunk.dwSize, NULL);
667 break;
669 case FOURCC_LIST: {
670 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
671 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
672 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
673 ListCount[0] = 0;
674 switch (Chunk.fccID) {
675 /* evil M$ UNFO list, which can (!?) contain INFO elements */
676 case DMUS_FOURCC_UNFO_LIST: {
677 TRACE_(dmfile)(": UNFO list\n");
678 do {
679 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
680 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
681 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
682 switch (Chunk.fccID) {
683 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
684 (though strings seem to be valid unicode) */
685 case mmioFOURCC('I','N','A','M'):
686 case DMUS_FOURCC_UNAM_CHUNK: {
687 TRACE_(dmfile)(": name chunk\n");
688 pDesc->dwValidData |= DMUS_OBJ_NAME;
689 IStream_Read (pStream, pDesc->wszName, Chunk.dwSize, NULL);
690 break;
692 case mmioFOURCC('I','A','R','T'):
693 case DMUS_FOURCC_UART_CHUNK: {
694 TRACE_(dmfile)(": artist chunk (ignored)\n");
695 liMove.QuadPart = Chunk.dwSize;
696 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
697 break;
699 case mmioFOURCC('I','C','O','P'):
700 case DMUS_FOURCC_UCOP_CHUNK: {
701 TRACE_(dmfile)(": copyright chunk (ignored)\n");
702 liMove.QuadPart = Chunk.dwSize;
703 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
704 break;
706 case mmioFOURCC('I','S','B','J'):
707 case DMUS_FOURCC_USBJ_CHUNK: {
708 TRACE_(dmfile)(": subject chunk (ignored)\n");
709 liMove.QuadPart = Chunk.dwSize;
710 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
711 break;
713 case mmioFOURCC('I','C','M','T'):
714 case DMUS_FOURCC_UCMT_CHUNK: {
715 TRACE_(dmfile)(": comment chunk (ignored)\n");
716 liMove.QuadPart = Chunk.dwSize;
717 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
718 break;
720 default: {
721 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
722 liMove.QuadPart = Chunk.dwSize;
723 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
724 break;
727 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
728 } while (ListCount[0] < ListSize[0]);
729 break;
731 case DMUS_FOURCC_TRACK_LIST: {
732 TRACE_(dmfile)(": TRACK list\n");
733 do {
734 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
735 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
736 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
737 switch (Chunk.fccID) {
738 default: {
739 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
740 liMove.QuadPart = Chunk.dwSize;
741 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
742 break;
745 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
746 } while (ListCount[0] < ListSize[0]);
747 break;
749 default: {
750 TRACE_(dmfile)(": unknown (skipping)\n");
751 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
752 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
753 break;
756 break;
758 default: {
759 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
760 liMove.QuadPart = Chunk.dwSize;
761 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
762 break;
765 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
766 } while (StreamCount < StreamSize);
767 break;
768 } else if (Chunk.fccID == mmioFOURCC('W','A','V','E')) {
769 TRACE_(dmfile)(": wave form (loading not yet implemented)\n");
770 liMove.QuadPart = StreamSize;
771 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
772 } else {
773 TRACE_(dmfile)(": unexpected chunk (loading failed)\n");
774 liMove.QuadPart = StreamSize;
775 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
776 return E_FAIL;
779 TRACE_(dmfile)(": reading finished\n");
780 break;
782 default: {
783 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
784 liMove.QuadPart = Chunk.dwSize;
785 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
786 return DMUS_E_INVALIDFILE;
790 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc));
792 return S_OK;
795 static const IDirectMusicObjectVtbl DirectMusicSegment8_Object_Vtbl = {
796 IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface,
797 IDirectMusicSegment8Impl_IDirectMusicObject_AddRef,
798 IDirectMusicSegment8Impl_IDirectMusicObject_Release,
799 IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor,
800 IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor,
801 IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor
804 /* IDirectMusicSegment8Impl IPersistStream part: */
805 static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
806 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
807 return IDirectMusicSegment8_QueryInterface(&This->IDirectMusicSegment8_iface, riid, ppobj);
810 static ULONG WINAPI IDirectMusicSegment8Impl_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
811 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
812 return IDirectMusicSegment8_AddRef(&This->IDirectMusicSegment8_iface);
815 static ULONG WINAPI IDirectMusicSegment8Impl_IPersistStream_Release (LPPERSISTSTREAM iface) {
816 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
817 return IDirectMusicSegment8_Release(&This->IDirectMusicSegment8_iface);
820 static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
821 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
822 TRACE("(%p, %p)\n", This, pClassID);
823 *pClassID = CLSID_DirectMusicSegment;
824 return S_OK;
827 static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
828 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
829 FIXME("(%p): stub, always S_FALSE\n", This);
830 return S_FALSE;
833 static HRESULT IDirectMusicSegment8Impl_IPersistStream_LoadTrack (LPPERSISTSTREAM iface, IStream* pClonedStream, IDirectMusicTrack** ppTrack,
834 DMUS_IO_TRACK_HEADER* pTrack_hdr) {
836 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
837 HRESULT hr = E_FAIL;
838 IPersistStream* pPersistStream = NULL;
840 hr = CoCreateInstance (&pTrack_hdr->guidClassID, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicTrack, (LPVOID*) ppTrack);
841 if (FAILED(hr)) {
842 ERR(": could not create object\n");
843 return hr;
845 /* acquire PersistStream interface */
846 hr = IDirectMusicTrack_QueryInterface (*ppTrack, &IID_IPersistStream, (LPVOID*) &pPersistStream);
847 if (FAILED(hr)) {
848 ERR(": could not acquire IPersistStream\n");
849 return hr;
851 /* load */
852 hr = IPersistStream_Load (pPersistStream, pClonedStream);
853 if (FAILED(hr)) {
854 ERR(": failed to load object\n");
855 return hr;
858 /* release all loading-related stuff */
859 IPersistStream_Release (pPersistStream);
861 hr = IDirectMusicSegment8_InsertTrack(&This->IDirectMusicSegment8_iface, *ppTrack,
862 pTrack_hdr->dwGroup); /* at dsPosition */
863 if (FAILED(hr)) {
864 ERR(": could not insert track\n");
865 return hr;
868 return S_OK;
871 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
873 /*ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);*/
874 HRESULT hr = E_FAIL;
875 DMUS_PRIVATE_CHUNK Chunk;
876 DWORD StreamSize, StreamCount, ListSize[3];
877 LARGE_INTEGER liMove; /* used when skipping chunks */
879 DMUS_IO_TRACK_HEADER track_hdr;
880 DMUS_IO_TRACK_EXTRAS_HEADER track_xhdr;
881 IDirectMusicTrack* pTrack = NULL;
883 if (pChunk->fccID != DMUS_FOURCC_TRACK_FORM) {
884 ERR_(dmfile)(": %s chunk should be a TRACK form\n", debugstr_fourcc (pChunk->fccID));
885 return E_FAIL;
888 StreamSize = pChunk->dwSize - sizeof(FOURCC);
889 StreamCount = 0;
891 do {
892 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
893 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
894 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
896 switch (Chunk.fccID) {
897 case DMUS_FOURCC_TRACK_CHUNK: {
898 TRACE_(dmfile)(": track chunk\n");
899 IStream_Read (pStm, &track_hdr, sizeof(DMUS_IO_TRACK_HEADER), NULL);
900 TRACE_(dmfile)(" - class: %s\n", debugstr_guid (&track_hdr.guidClassID));
901 TRACE_(dmfile)(" - dwGroup: %d\n", track_hdr.dwGroup);
902 TRACE_(dmfile)(" - ckid: %s\n", debugstr_fourcc (track_hdr.ckid));
903 TRACE_(dmfile)(" - fccType: %s\n", debugstr_fourcc (track_hdr.fccType));
904 break;
906 case DMUS_FOURCC_TRACK_EXTRAS_CHUNK: {
907 TRACE_(dmfile)(": track extras chunk\n");
908 IStream_Read (pStm, &track_xhdr, sizeof(DMUS_IO_TRACK_EXTRAS_HEADER), NULL);
909 break;
912 case DMUS_FOURCC_COMMANDTRACK_CHUNK: {
913 TRACE_(dmfile)(": COMMANDTRACK track\n");
914 liMove.QuadPart = Chunk.dwSize;
915 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
916 break;
919 case FOURCC_LIST: {
920 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
921 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
922 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
923 if (Chunk.fccID == track_hdr.fccType && 0 == track_hdr.ckid) {
924 LPSTREAM pClonedStream = NULL;
926 TRACE_(dmfile)(": TRACK list\n");
928 IStream_Clone (pStm, &pClonedStream);
930 liMove.QuadPart = 0;
931 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
932 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
934 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
935 if (FAILED(hr)) {
936 ERR(": could not load track\n");
937 return hr;
939 IStream_Release (pClonedStream);
941 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
943 liMove.QuadPart = ListSize[0];
944 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
946 } else {
947 TRACE_(dmfile)(": unknown (skipping)\n");
948 liMove.QuadPart = Chunk.dwSize;
949 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
951 break;
954 case FOURCC_RIFF: {
955 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
956 TRACE_(dmfile)(": RIFF chunk of type %s\n", debugstr_fourcc(Chunk.fccID));
958 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
960 if (Chunk.fccID == track_hdr.fccType && 0 == track_hdr.ckid) {
961 LPSTREAM pClonedStream = NULL;
963 TRACE_(dmfile)(": TRACK RIFF\n");
965 IStream_Clone (pStm, &pClonedStream);
967 liMove.QuadPart = 0;
968 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
969 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
971 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
972 if (FAILED(hr)) {
973 ERR(": could not load track\n");
974 return hr;
976 IStream_Release (pClonedStream);
978 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
980 /** now safe move the cursor */
981 liMove.QuadPart = ListSize[0];
982 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
984 } else {
985 TRACE_(dmfile)(": unknown RIFF fmt (skipping)\n");
986 liMove.QuadPart = ListSize[0];
987 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
989 break;
992 default: {
993 if (0 == track_hdr.fccType && Chunk.fccID == track_hdr.ckid) {
994 LPSTREAM pClonedStream = NULL;
996 TRACE_(dmfile)(": TRACK solo\n");
998 IStream_Clone (pStm, &pClonedStream);
1000 liMove.QuadPart = 0;
1001 liMove.QuadPart -= (sizeof(FOURCC) + sizeof(DWORD));
1002 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
1004 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
1005 if (FAILED(hr)) {
1006 ERR(": could not load track\n");
1007 return hr;
1009 IStream_Release (pClonedStream);
1011 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
1013 liMove.QuadPart = Chunk.dwSize;
1014 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1016 break;
1019 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
1020 liMove.QuadPart = Chunk.dwSize;
1021 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1022 break;
1025 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
1026 } while (StreamCount < StreamSize);
1028 return S_OK;
1031 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicSegment8Impl* This) {
1033 HRESULT hr = E_FAIL;
1034 DMUS_PRIVATE_CHUNK Chunk;
1035 DWORD StreamSize, ListSize[3], ListCount[3];
1036 LARGE_INTEGER liMove; /* used when skipping chunks */
1038 if (pChunk->fccID != DMUS_FOURCC_TRACK_LIST) {
1039 ERR_(dmfile)(": %s chunk should be a TRACK list\n", debugstr_fourcc (pChunk->fccID));
1040 return E_FAIL;
1043 ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
1044 ListCount[0] = 0;
1046 do {
1047 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1048 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
1049 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1050 switch (Chunk.fccID) {
1051 case FOURCC_RIFF: {
1052 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
1053 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
1054 StreamSize = Chunk.dwSize - sizeof(FOURCC);
1055 switch (Chunk.fccID) {
1056 case DMUS_FOURCC_TRACK_FORM: {
1057 TRACE_(dmfile)(": TRACK form\n");
1058 hr = IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (iface, &Chunk, pStm);
1059 if (FAILED(hr)) return hr;
1060 break;
1062 default: {
1063 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
1064 liMove.QuadPart = StreamSize;
1065 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1066 break;
1069 break;
1071 default: {
1072 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
1073 liMove.QuadPart = Chunk.dwSize;
1074 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1075 break;
1078 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
1079 } while (ListCount[0] < ListSize[0]);
1081 return S_OK;
1084 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicSegment8Impl* This) {
1086 HRESULT hr = E_FAIL;
1087 DMUS_PRIVATE_CHUNK Chunk;
1088 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
1089 LARGE_INTEGER liMove; /* used when skipping chunks */
1091 if (pChunk->fccID != DMUS_FOURCC_SEGMENT_FORM) {
1092 ERR_(dmfile)(": %s chunk should be a segment form\n", debugstr_fourcc (pChunk->fccID));
1093 return E_FAIL;
1096 StreamSize = pChunk->dwSize - sizeof(FOURCC);
1097 StreamCount = 0;
1099 do {
1100 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1101 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
1102 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1104 hr = IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk, pStm, This->pDesc);
1105 if (FAILED(hr)) return hr;
1107 if (hr == S_FALSE) {
1108 switch (Chunk.fccID) {
1109 case DMUS_FOURCC_SEGMENT_CHUNK: {
1110 DWORD checkSz = sizeof(FOURCC);
1111 TRACE_(dmfile)(": segment chunk\n");
1112 /** DX 7 */
1113 IStream_Read (pStm, &This->header.dwRepeats, sizeof(This->header.dwRepeats), NULL);
1114 checkSz += sizeof(This->header.dwRepeats);
1115 IStream_Read (pStm, &This->header.mtLength, sizeof(This->header.mtLength), NULL);
1116 checkSz += sizeof(This->header.mtLength);
1117 IStream_Read (pStm, &This->header.mtPlayStart, sizeof(This->header.mtPlayStart), NULL);
1118 checkSz += sizeof(This->header.mtPlayStart);
1119 IStream_Read (pStm, &This->header.mtLoopStart, sizeof(This->header.mtLoopStart), NULL);
1120 checkSz += sizeof(This->header.mtLoopStart);
1121 IStream_Read (pStm, &This->header.mtLoopEnd, sizeof(This->header.mtLoopEnd), NULL);
1122 checkSz += sizeof(This->header.mtLoopEnd);
1123 IStream_Read (pStm, &This->header.dwResolution, sizeof(This->header.dwResolution), NULL);
1124 checkSz += sizeof(This->header.dwResolution);
1125 TRACE_(dmfile)("dwRepeats: %u\n", This->header.dwRepeats);
1126 TRACE_(dmfile)("mtLength: %u\n", This->header.mtLength);
1127 TRACE_(dmfile)("mtPlayStart: %u\n", This->header.mtPlayStart);
1128 TRACE_(dmfile)("mtLoopStart: %u\n", This->header.mtLoopStart);
1129 TRACE_(dmfile)("mtLoopEnd: %u\n", This->header.mtLoopEnd);
1130 TRACE_(dmfile)("dwResolution: %u\n", This->header.dwResolution);
1131 /** DX 8 */
1132 if (Chunk.dwSize > checkSz) {
1133 IStream_Read (pStm, &This->header.rtLength, sizeof(This->header.rtLength), NULL);
1134 checkSz += sizeof(This->header.rtLength);
1135 IStream_Read (pStm, &This->header.dwFlags, sizeof(This->header.dwFlags), NULL);
1136 checkSz += sizeof(This->header.dwFlags);
1138 /** DX 9 */
1139 if (Chunk.dwSize > checkSz) {
1140 IStream_Read (pStm, &This->header.rtLoopStart, sizeof(This->header.rtLoopStart), NULL);
1141 checkSz += sizeof(This->header.rtLoopStart);
1142 IStream_Read (pStm, &This->header.rtLoopEnd, sizeof(This->header.rtLoopEnd), NULL);
1143 checkSz += sizeof(This->header.rtLoopEnd);
1144 IStream_Read (pStm, &This->header.rtPlayStart, sizeof(This->header.rtPlayStart), NULL);
1145 checkSz += sizeof(This->header.rtPlayStart);
1147 liMove.QuadPart = Chunk.dwSize - checkSz + sizeof(FOURCC);
1148 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1149 break;
1151 case FOURCC_LIST: {
1152 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
1153 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
1154 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
1155 ListCount[0] = 0;
1156 switch (Chunk.fccID) {
1157 case DMUS_FOURCC_UNFO_LIST: {
1158 TRACE_(dmfile)(": UNFO list\n");
1159 do {
1160 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1161 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
1162 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1164 hr = IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk, pStm, This->pDesc);
1165 if (FAILED(hr)) return hr;
1167 if (hr == S_FALSE) {
1168 switch (Chunk.fccID) {
1169 default: {
1170 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
1171 liMove.QuadPart = Chunk.dwSize;
1172 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1173 break;
1178 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
1179 } while (ListCount[0] < ListSize[0]);
1180 break;
1182 case DMUS_FOURCC_TRACK_LIST: {
1183 TRACE_(dmfile)(": TRACK list\n");
1184 hr = IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (iface, &Chunk, pStm, This);
1185 if (FAILED(hr)) return hr;
1186 break;
1188 default: {
1189 TRACE_(dmfile)(": unknown (skipping)\n");
1190 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
1191 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1192 break;
1195 break;
1197 default: {
1198 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
1199 liMove.QuadPart = Chunk.dwSize;
1200 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1201 break;
1205 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
1206 } while (StreamCount < StreamSize);
1208 return S_OK;
1211 static HRESULT IDirectMusicSegment8Impl_IPersistStream_LoadWave (LPPERSISTSTREAM iface, IStream* pClonedStream, IDirectMusicObject** ppWaveObject) {
1213 HRESULT hr = E_FAIL;
1214 IPersistStream* pPersistStream = NULL;
1216 hr = CoCreateInstance (&CLSID_DirectSoundWave, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicObject, (LPVOID*) ppWaveObject);
1217 if (FAILED(hr)) {
1218 ERR(": could not create object\n");
1219 return hr;
1221 /* acquire PersistStream interface */
1222 hr = IDirectMusicObject_QueryInterface (*ppWaveObject, &IID_IPersistStream, (LPVOID*) &pPersistStream);
1223 if (FAILED(hr)) {
1224 ERR(": could not acquire IPersistStream\n");
1225 return hr;
1227 /* load */
1228 hr = IPersistStream_Load (pPersistStream, pClonedStream);
1229 if (FAILED(hr)) {
1230 ERR(": failed to load object\n");
1231 return hr;
1234 /* release all loading-related stuff */
1235 IPersistStream_Release (pPersistStream);
1237 return S_OK;
1240 static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
1241 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1243 HRESULT hr;
1244 DMUS_PRIVATE_CHUNK Chunk;
1245 DWORD StreamSize;
1246 /*DWORD ListSize[3], ListCount[3];*/
1247 LARGE_INTEGER liMove; /* used when skipping chunks */
1249 TRACE("(%p, %p): Loading\n", This, pStm);
1250 hr = IStream_Read (pStm, &Chunk, sizeof(Chunk), NULL);
1251 if(hr != S_OK){
1252 WARN("IStream_Read failed: %08x\n", hr);
1253 return DMUS_E_UNSUPPORTED_STREAM;
1255 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1256 switch (Chunk.fccID) {
1257 case FOURCC_RIFF: {
1258 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
1259 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
1260 StreamSize = Chunk.dwSize - sizeof(FOURCC);
1261 switch (Chunk.fccID) {
1262 case DMUS_FOURCC_SEGMENT_FORM: {
1263 TRACE_(dmfile)(": segment form\n");
1264 hr = IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (iface, &Chunk, pStm, This);
1265 if (FAILED(hr)) return hr;
1266 break;
1268 case mmioFOURCC('W','A','V','E'): {
1269 LPSTREAM pClonedStream = NULL;
1270 IDirectMusicObject* pWave = NULL;
1272 FIXME_(dmfile)(": WAVE form (loading to be checked)\n");
1274 IStream_Clone (pStm, &pClonedStream);
1276 liMove.QuadPart = - (LONGLONG)(sizeof(FOURCC) * 2 + sizeof(DWORD));
1277 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
1279 hr = IDirectMusicSegment8Impl_IPersistStream_LoadWave (iface, pClonedStream, &pWave);
1280 if (FAILED(hr)) {
1281 ERR(": could not load track\n");
1282 return hr;
1284 IStream_Release (pClonedStream);
1286 IDirectMusicTrack_Release(pWave); pWave = NULL; /* now we can release at as it inserted */
1288 liMove.QuadPart = StreamSize;
1289 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1290 break;
1292 default: {
1293 TRACE_(dmfile)(": unexpected chunk (loading failed)\n");
1294 liMove.QuadPart = StreamSize;
1295 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1296 return DMUS_E_UNSUPPORTED_STREAM;
1299 TRACE_(dmfile)(": reading finished\n");
1300 break;
1302 default: {
1303 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
1304 return DMUS_E_UNSUPPORTED_STREAM;
1308 return S_OK;
1311 static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
1312 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1313 FIXME("(%p): Saving not implemented yet\n", This);
1314 return E_NOTIMPL;
1317 static HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
1318 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1319 FIXME("(%p, %p): stub\n", This, pcbSize);
1320 return E_NOTIMPL;
1323 static const IPersistStreamVtbl DirectMusicSegment8_PersistStream_Vtbl = {
1324 IDirectMusicSegment8Impl_IPersistStream_QueryInterface,
1325 IDirectMusicSegment8Impl_IPersistStream_AddRef,
1326 IDirectMusicSegment8Impl_IPersistStream_Release,
1327 IDirectMusicSegment8Impl_IPersistStream_GetClassID,
1328 IDirectMusicSegment8Impl_IPersistStream_IsDirty,
1329 IDirectMusicSegment8Impl_IPersistStream_Load,
1330 IDirectMusicSegment8Impl_IPersistStream_Save,
1331 IDirectMusicSegment8Impl_IPersistStream_GetSizeMax
1334 /* for ClassFactory */
1335 HRESULT WINAPI create_dmsegment(REFIID lpcGUID, void **ppobj)
1337 IDirectMusicSegment8Impl* obj;
1338 HRESULT hr;
1340 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSegment8Impl));
1341 if (NULL == obj) {
1342 *ppobj = NULL;
1343 return E_OUTOFMEMORY;
1345 obj->IDirectMusicSegment8_iface.lpVtbl = &dmsegment8_vtbl;
1346 obj->ObjectVtbl = &DirectMusicSegment8_Object_Vtbl;
1347 obj->PersistStreamVtbl = &DirectMusicSegment8_PersistStream_Vtbl;
1348 obj->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
1349 DM_STRUCT_INIT(obj->pDesc);
1350 obj->pDesc->dwValidData |= DMUS_OBJ_CLASS;
1351 obj->pDesc->guidClass = CLSID_DirectMusicSegment;
1352 obj->ref = 1;
1353 list_init (&obj->Tracks);
1355 DMIME_LockModule();
1356 hr = IDirectMusicSegment8_QueryInterface(&obj->IDirectMusicSegment8_iface, lpcGUID, ppobj);
1357 IDirectMusicSegment8_Release(&obj->IDirectMusicSegment8_iface);
1359 return hr;