1 /* IDirectMusicSegment8 Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
4 * Copyright (C) 2003-2004 Raphael Junqueira
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Library General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "dmime_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
24 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
26 /*****************************************************************************
27 * IDirectMusicSegmentImpl implementation
29 /* IDirectMusicSegment IUnknown part: */
30 HRESULT WINAPI IDirectMusicSegment8Impl_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
31 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
32 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
34 if (IsEqualIID (riid, &IID_IUnknown)) {
35 *ppobj = (LPVOID)&This->UnknownVtbl;
36 IDirectMusicSegment8Impl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
38 } else if (IsEqualIID (riid, &IID_IDirectMusicSegment)
39 || IsEqualIID (riid, &IID_IDirectMusicSegment2)
40 || IsEqualIID (riid, &IID_IDirectMusicSegment8)) {
41 *ppobj = (LPVOID)&This->SegmentVtbl;
42 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef ((LPDIRECTMUSICSEGMENT8)&This->SegmentVtbl);
44 } else if (IsEqualIID (riid, &IID_IDirectMusicObject)) {
45 *ppobj = (LPVOID)&This->ObjectVtbl;
46 IDirectMusicSegment8Impl_IDirectMusicObject_AddRef ((LPDIRECTMUSICOBJECT)&This->ObjectVtbl);
48 } else if (IsEqualIID (riid, &IID_IPersistStream)) {
49 *ppobj = (LPVOID)&This->PersistStreamVtbl;
50 IDirectMusicSegment8Impl_IPersistStream_AddRef ((LPPERSISTSTREAM)&This->PersistStreamVtbl);
54 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
58 ULONG WINAPI IDirectMusicSegment8Impl_IUnknown_AddRef (LPUNKNOWN iface) {
59 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
60 TRACE("(%p): AddRef from %ld\n", This, This->ref);
64 ULONG WINAPI IDirectMusicSegment8Impl_IUnknown_Release (LPUNKNOWN iface) {
65 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
66 ULONG ref = --This->ref;
67 TRACE("(%p): ReleaseRef to %ld\n", This, This->ref);
69 HeapFree(GetProcessHeap(), 0, This);
74 ICOM_VTABLE(IUnknown) DirectMusicSegment8_Unknown_Vtbl = {
75 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
76 IDirectMusicSegment8Impl_IUnknown_QueryInterface,
77 IDirectMusicSegment8Impl_IUnknown_AddRef,
78 IDirectMusicSegment8Impl_IUnknown_Release
81 /* IDirectMusicSegmentImpl IDirectMusicSegment part: */
82 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_QueryInterface (LPDIRECTMUSICSEGMENT8 iface, REFIID riid, LPVOID *ppobj) {
83 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
84 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
87 ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef (LPDIRECTMUSICSEGMENT8 iface) {
88 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
89 return IDirectMusicSegment8Impl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
92 ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Release (LPDIRECTMUSICSEGMENT8 iface) {
93 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
94 return IDirectMusicSegment8Impl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
97 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLength (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtLength) {
98 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
99 TRACE("(%p, %p)\n", This, pmtLength);
100 if (NULL == pmtLength) {
103 *pmtLength = This->header.mtLength;
107 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLength (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtLength) {
108 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
109 TRACE("(%p, %ld)\n", This, mtLength);
110 This->header.mtLength = mtLength;
114 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetRepeats (LPDIRECTMUSICSEGMENT8 iface, DWORD* pdwRepeats) {
115 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
116 TRACE("(%p, %p)\n", This, pdwRepeats);
117 if (NULL == pdwRepeats) {
120 *pdwRepeats = This->header.dwRepeats;
124 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetRepeats (LPDIRECTMUSICSEGMENT8 iface, DWORD dwRepeats) {
125 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
126 TRACE("(%p, %ld)\n", This, dwRepeats);
127 This->header.dwRepeats = dwRepeats;
131 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetDefaultResolution (LPDIRECTMUSICSEGMENT8 iface, DWORD* pdwResolution) {
132 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
133 TRACE("(%p, %p)\n", This, pdwResolution);
134 if (NULL == pdwResolution) {
137 *pdwResolution = This->header.dwResolution;
141 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetDefaultResolution (LPDIRECTMUSICSEGMENT8 iface, DWORD dwResolution) {
142 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
143 TRACE("(%p, %ld)\n", This, dwResolution);
144 This->header.dwResolution = dwResolution;
148 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, IDirectMusicTrack** ppTrack) {
149 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
150 FIXME("(%p, %s, %ld, %ld, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, ppTrack);
154 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrackGroup (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack, DWORD* pdwGroupBits) {
155 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
156 FIXME("(%p, %p, %p): stub\n", This, pTrack, pdwGroupBits);
160 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack, DWORD dwGroupBits) {
161 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
162 FIXME("(%p, %p, %ld): stub\n", This, pTrack, dwGroupBits);
166 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack) {
167 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
168 FIXME("(%p, %p): stub\n", This, pTrack);
172 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicSegmentState** ppSegState, IDirectMusicPerformance* pPerformance, DWORD dwFlags) {
173 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
175 FIXME("(%p, %p, %p, %ld): semi-stub\n", This, ppSegState, pPerformance, dwFlags);
176 if (NULL == ppSegState) {
179 hr = DMUSIC_CreateDirectMusicSegmentStateImpl(&IID_IDirectMusicSegmentState, (void**) ppSegState, NULL);
183 /* TODO: DMUS_SEGF_FLAGS */
187 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicGraph** ppGraph) {
188 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
189 FIXME("(%p, %p): semi-stub\n", This, ppGraph);
190 if (NULL == ppGraph) {
193 if (NULL == This->pGraph) {
194 return DMUS_E_NOT_FOUND;
197 * should return This, as seen in msdn
198 * http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c/directx/htm/idirectmusicsegment8getgraph.asp
199 * "...The segment object implements IDirectMusicGraph directly..."
201 *ppGraph = This->pGraph;
202 IDirectMusicGraph_AddRef(This->pGraph);
206 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicGraph* pGraph) {
207 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
208 FIXME("(%p, %p): to complete\n", This, pGraph);
209 if (NULL != This->pGraph) {
210 IDirectMusicGraph_Release(This->pGraph);
212 This->pGraph = pGraph;
213 if (NULL != This->pGraph) {
214 IDirectMusicGraph_AddRef(This->pGraph);
219 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidNotificationType) {
220 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
221 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
225 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidNotificationType) {
226 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
227 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
231 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
232 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
233 FIXME("(%p, %s, %ld, %ld, %ld, %p, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pmtNext, pParam);
237 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, void* pParam) {
238 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
239 FIXME("(%p, %s, %ld, %ld, %ld, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pParam);
243 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicSegment** ppSegment) {
244 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
245 FIXME("(%p, %ld, %ld, %p): stub\n", This, mtStart, mtEnd, ppSegment);
249 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart) {
250 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
251 TRACE("(%p, %ld)\n", This, mtStart);
252 if (mtStart >= This->header.mtLength) {
253 return DMUS_E_OUT_OF_RANGE;
255 This->header.mtPlayStart = mtStart;
259 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtStart) {
260 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
261 TRACE("(%p, %p)\n", This, pmtStart);
262 if (NULL == pmtStart) {
265 *pmtStart = This->header.mtPlayStart;
269 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd) {
270 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
271 TRACE("(%p, %ld, %ld)\n", This, mtStart, mtEnd);
272 if (mtStart >= This->header.mtLength || mtEnd > This->header.mtLength || mtStart > mtEnd) {
273 return DMUS_E_OUT_OF_RANGE;
275 This->header.mtLoopStart = mtStart;
276 This->header.mtLoopEnd = mtEnd;
280 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtStart, MUSIC_TIME* pmtEnd) {
281 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
282 TRACE("(%p, %p, %p)\n", This, pmtStart, pmtEnd);
283 if (NULL == pmtStart || NULL == pmtEnd) {
286 *pmtStart = This->header.mtLoopStart;
287 *pmtEnd = This->header.mtLoopEnd;
291 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed (LPDIRECTMUSICSEGMENT8 iface, DWORD dwNumPChannels, DWORD* paPChannels) {
292 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
293 FIXME("(%p, %ld, %p): stub\n", This, dwNumPChannels, paPChannels);
297 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidTrackClassID, DWORD dwGroupBits, DWORD dwIndex, DWORD dwFlagsOn, DWORD dwFlagsOff) {
298 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
299 FIXME("(%p, %s, %ld, %ld, %ld, %ld): stub\n", This, debugstr_dmguid(rguidTrackClassID), dwGroupBits, dwIndex, dwFlagsOn, dwFlagsOff);
303 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig (LPDIRECTMUSICSEGMENT8 iface, IUnknown** ppAudioPathConfig){
304 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
305 FIXME("(%p, %p): stub\n", This, ppAudioPathConfig);
309 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtTime, IDirectMusicSegment* pFromSegment, IDirectMusicSegment* pToSegment, IDirectMusicSegment** ppComposedSegment) {
310 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
311 FIXME("(%p, %ld, %p, %p, %p): stub\n", This, mtTime, pFromSegment, pToSegment, ppComposedSegment);
315 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Download (LPDIRECTMUSICSEGMENT8 iface, IUnknown *pAudioPath) {
316 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
317 FIXME("(%p, %p): stub\n", This, pAudioPath);
321 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload (LPDIRECTMUSICSEGMENT8 iface, IUnknown *pAudioPath) {
322 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
323 FIXME("(%p, %p): stub\n", This, pAudioPath);
327 ICOM_VTABLE(IDirectMusicSegment8) DirectMusicSegment8_Segment_Vtbl = {
328 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
329 IDirectMusicSegment8Impl_IDirectMusicSegment8_QueryInterface,
330 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef,
331 IDirectMusicSegment8Impl_IDirectMusicSegment8_Release,
332 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLength,
333 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLength,
334 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetRepeats,
335 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetRepeats,
336 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetDefaultResolution,
337 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetDefaultResolution,
338 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack,
339 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrackGroup,
340 IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack,
341 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack,
342 IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay,
343 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph,
344 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph,
345 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType,
346 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType,
347 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam,
348 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam,
349 IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone,
350 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint,
351 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint,
352 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints,
353 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints,
354 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed,
355 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig,
356 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig,
357 IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose,
358 IDirectMusicSegment8Impl_IDirectMusicSegment8_Download,
359 IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload
362 /* IDirectMusicSegment8Impl IDirectMusicObject part: */
363 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) {
364 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
365 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
368 ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) {
369 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
370 return IDirectMusicSegment8Impl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
373 ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) {
374 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
375 return IDirectMusicSegment8Impl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
378 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
379 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
380 TRACE("(%p, %p)\n", This, pDesc);
381 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
382 memcpy (pDesc, This->pDesc, This->pDesc->dwSize);
386 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
387 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
388 TRACE("(%p, %p): setting descriptor:\n%s\n", This, pDesc, debugstr_DMUS_OBJECTDESC (pDesc));
390 /* According to MSDN, we should copy only given values, not whole struct */
391 if (pDesc->dwValidData & DMUS_OBJ_OBJECT)
392 memcpy (&This->pDesc->guidObject, &pDesc->guidObject, sizeof (pDesc->guidObject));
393 if (pDesc->dwValidData & DMUS_OBJ_CLASS)
394 memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass));
395 if (pDesc->dwValidData & DMUS_OBJ_NAME)
396 strncpyW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
397 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
398 strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
399 if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
400 strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
401 if (pDesc->dwValidData & DMUS_OBJ_VERSION)
402 memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));
403 if (pDesc->dwValidData & DMUS_OBJ_DATE)
404 memcpy (&This->pDesc->ftDate, &pDesc->ftDate, sizeof (pDesc->ftDate));
405 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
406 memcpy (&This->pDesc->llMemLength, &pDesc->llMemLength, sizeof (pDesc->llMemLength));
407 memcpy (This->pDesc->pbMemData, pDesc->pbMemData, sizeof (pDesc->pbMemData));
409 if (pDesc->dwValidData & DMUS_OBJ_STREAM) {
410 /* according to MSDN, we copy the stream */
411 IStream_Clone (pDesc->pStream, &This->pDesc->pStream);
415 This->pDesc->dwValidData |= pDesc->dwValidData;
420 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc) {
421 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
422 DMUS_PRIVATE_CHUNK Chunk;
423 DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
424 LARGE_INTEGER liMove; /* used when skipping chunks */
426 TRACE("(%p,%p, %p)\n", This, pStream, pDesc);
428 /* FIXME: should this be determined from stream? */
429 pDesc->dwValidData |= DMUS_OBJ_CLASS;
430 memcpy (&pDesc->guidClass, &CLSID_DirectMusicSegment, sizeof(CLSID));
432 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
433 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
434 switch (Chunk.fccID) {
436 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
437 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
438 StreamSize = Chunk.dwSize - sizeof(FOURCC);
440 if (Chunk.fccID == DMUS_FOURCC_SEGMENT_FORM) {
441 TRACE_(dmfile)(": segment form\n");
443 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
444 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
445 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
446 switch (Chunk.fccID) {
447 case DMUS_FOURCC_GUID_CHUNK: {
448 TRACE_(dmfile)(": GUID chunk\n");
449 pDesc->dwValidData |= DMUS_OBJ_OBJECT;
450 IStream_Read (pStream, &pDesc->guidObject, Chunk.dwSize, NULL);
453 case DMUS_FOURCC_VERSION_CHUNK: {
454 TRACE_(dmfile)(": version chunk\n");
455 pDesc->dwValidData |= DMUS_OBJ_VERSION;
456 IStream_Read (pStream, &pDesc->vVersion, Chunk.dwSize, NULL);
459 case DMUS_FOURCC_CATEGORY_CHUNK: {
460 TRACE_(dmfile)(": category chunk\n");
461 pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
462 IStream_Read (pStream, pDesc->wszCategory, Chunk.dwSize, NULL);
466 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
467 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
468 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
470 switch (Chunk.fccID) {
471 /* evil M$ UNFO list, which can (!?) contain INFO elements */
472 case DMUS_FOURCC_UNFO_LIST: {
473 TRACE_(dmfile)(": UNFO list\n");
475 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
476 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
477 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
478 switch (Chunk.fccID) {
479 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
480 (though strings seem to be valid unicode) */
481 case mmioFOURCC('I','N','A','M'):
482 case DMUS_FOURCC_UNAM_CHUNK: {
483 TRACE_(dmfile)(": name chunk\n");
484 pDesc->dwValidData |= DMUS_OBJ_NAME;
485 IStream_Read (pStream, pDesc->wszName, Chunk.dwSize, NULL);
488 case mmioFOURCC('I','A','R','T'):
489 case DMUS_FOURCC_UART_CHUNK: {
490 TRACE_(dmfile)(": artist chunk (ignored)\n");
491 liMove.QuadPart = Chunk.dwSize;
492 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
495 case mmioFOURCC('I','C','O','P'):
496 case DMUS_FOURCC_UCOP_CHUNK: {
497 TRACE_(dmfile)(": copyright chunk (ignored)\n");
498 liMove.QuadPart = Chunk.dwSize;
499 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
502 case mmioFOURCC('I','S','B','J'):
503 case DMUS_FOURCC_USBJ_CHUNK: {
504 TRACE_(dmfile)(": subject chunk (ignored)\n");
505 liMove.QuadPart = Chunk.dwSize;
506 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
509 case mmioFOURCC('I','C','M','T'):
510 case DMUS_FOURCC_UCMT_CHUNK: {
511 TRACE_(dmfile)(": comment chunk (ignored)\n");
512 liMove.QuadPart = Chunk.dwSize;
513 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
517 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
518 liMove.QuadPart = Chunk.dwSize;
519 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
523 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
524 } while (ListCount[0] < ListSize[0]);
527 case DMUS_FOURCC_TRACK_LIST: {
528 TRACE_(dmfile)(": TRACK list\n");
530 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
531 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
532 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
533 switch (Chunk.fccID) {
535 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
536 liMove.QuadPart = Chunk.dwSize;
537 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
541 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
542 } while (ListCount[0] < ListSize[0]);
546 TRACE_(dmfile)(": unknown (skipping)\n");
547 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
548 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
555 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
556 liMove.QuadPart = Chunk.dwSize;
557 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
561 TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
562 } while (StreamCount < StreamSize);
564 } else if (Chunk.fccID == mmioFOURCC('W','A','V','E')) {
565 TRACE_(dmfile)(": wave form (loading not yet implemented)\n");
566 liMove.QuadPart = StreamSize;
567 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
569 TRACE_(dmfile)(": unexpected chunk (loading failed)\n");
570 liMove.QuadPart = StreamSize;
571 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
575 TRACE_(dmfile)(": reading finished\n");
579 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
580 liMove.QuadPart = Chunk.dwSize;
581 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
582 return DMUS_E_INVALIDFILE;
586 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc));
591 ICOM_VTABLE(IDirectMusicObject) DirectMusicSegment8_Object_Vtbl = {
592 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
593 IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface,
594 IDirectMusicSegment8Impl_IDirectMusicObject_AddRef,
595 IDirectMusicSegment8Impl_IDirectMusicObject_Release,
596 IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor,
597 IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor,
598 IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor
601 /* IDirectMusicSegment8Impl IPersistStream part: */
602 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
603 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
604 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
607 ULONG WINAPI IDirectMusicSegment8Impl_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
608 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
609 return IDirectMusicSegment8Impl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
612 ULONG WINAPI IDirectMusicSegment8Impl_IPersistStream_Release (LPPERSISTSTREAM iface) {
613 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
614 return IDirectMusicSegment8Impl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
617 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
618 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
619 TRACE("(%p, %p)\n", This, pClassID);
620 memcpy(pClassID, &CLSID_DirectMusicContainer, sizeof(CLSID));
624 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
625 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
626 FIXME("(%p): stub, always S_FALSE\n", This);
630 static HRESULT IDirectMusicSegment8Impl_IPersistStream_LoadTrack (LPPERSISTSTREAM iface, IStream* pClonedStream, IDirectMusicTrack** ppTrack,
631 DMUS_IO_TRACK_HEADER* pTrack_hdr) {
633 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
635 IPersistStream* pPersistStream = NULL;
637 hr = CoCreateInstance (&pTrack_hdr->guidClassID, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicTrack, (LPVOID*) ppTrack);
639 ERR(": could not create object\n");
642 /* acquire PersistStream interface */
643 hr = IDirectMusicTrack_QueryInterface (*ppTrack, &IID_IPersistStream, (LPVOID*) &pPersistStream);
645 ERR(": could not acquire IPersistStream\n");
649 hr = IPersistStream_Load (pPersistStream, pClonedStream);
651 ERR(": failed to load object\n");
655 /* release all loading-related stuff */
656 IPersistStream_Release (pPersistStream);
658 hr = IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack ((LPDIRECTMUSICSEGMENT8)This->SegmentVtbl, *ppTrack, pTrack_hdr->dwGroup); /* at dsPosition */
660 ERR(": could not insert track\n");
667 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
669 /*ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);*/
671 DMUS_PRIVATE_CHUNK Chunk;
672 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
673 LARGE_INTEGER liMove; /* used when skipping chunks */
675 DMUS_IO_TRACK_HEADER track_hdr;
676 DMUS_IO_TRACK_EXTRAS_HEADER track_xhdr;
677 IDirectMusicTrack* pTrack = NULL;
679 if (pChunk->fccID != DMUS_FOURCC_TRACK_FORM) {
680 ERR_(dmfile)(": %s chunk should be a TRACK form\n", debugstr_fourcc (pChunk->fccID));
684 StreamSize = pChunk->dwSize - sizeof(FOURCC);
688 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
689 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
690 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
692 switch (Chunk.fccID) {
693 case DMUS_FOURCC_TRACK_CHUNK: {
694 TRACE_(dmfile)(": track chunck\n");
695 IStream_Read (pStm, &track_hdr, sizeof(DMUS_IO_TRACK_HEADER), NULL);
696 TRACE_(dmfile)(" - class: %s\n", debugstr_guid (&track_hdr.guidClassID));
697 TRACE_(dmfile)(" - dwGroup: %ld\n", track_hdr.dwGroup);
698 TRACE_(dmfile)(" - ckid: %s\n", debugstr_fourcc (track_hdr.ckid));
699 TRACE_(dmfile)(" - fccType: %s\n", debugstr_fourcc (track_hdr.fccType));
702 case DMUS_FOURCC_TRACK_EXTRAS_CHUNK: {
703 TRACE_(dmfile)(": track extras chunck\n");
704 IStream_Read (pStm, &track_xhdr, sizeof(DMUS_IO_TRACK_EXTRAS_HEADER), NULL);
708 case DMUS_FOURCC_COMMANDTRACK_CHUNK: {
709 TRACE_(dmfile)(": COMMANDTRACK track\n");
710 liMove.QuadPart = Chunk.dwSize;
711 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
716 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
717 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
718 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
720 if (Chunk.fccID == track_hdr.fccType && 0 == track_hdr.ckid) {
721 LPSTREAM pClonedStream = NULL;
723 TRACE_(dmfile)(": TRACK list\n");
725 IStream_Clone (pStm, &pClonedStream);
728 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
729 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
731 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
733 ERR(": could not load track\n");
736 IStream_Release (pClonedStream);
738 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
740 liMove.QuadPart = ListSize[0];
741 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
744 TRACE_(dmfile)(": unknown (skipping)\n");
745 liMove.QuadPart = Chunk.dwSize;
746 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
752 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
753 TRACE_(dmfile)(": RIFF chunk of type %s\n", debugstr_fourcc(Chunk.fccID));
755 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
757 if (Chunk.fccID == track_hdr.fccType && 0 == track_hdr.ckid) {
758 LPSTREAM pClonedStream = NULL;
760 TRACE_(dmfile)(": TRACK RIFF\n");
762 IStream_Clone (pStm, &pClonedStream);
765 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
766 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
768 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
770 ERR(": could not load track\n");
773 IStream_Release (pClonedStream);
775 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
777 /** now safe move the cursor */
778 liMove.QuadPart = ListSize[0];
779 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
782 TRACE_(dmfile)(": unknown RIFF fmt (skipping)\n");
783 liMove.QuadPart = ListSize[0];
784 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
790 if (0 == track_hdr.fccType && Chunk.fccID == track_hdr.ckid) {
791 LPSTREAM pClonedStream = NULL;
793 TRACE_(dmfile)(": TRACK solo\n");
795 IStream_Clone (pStm, &pClonedStream);
798 liMove.QuadPart -= (sizeof(FOURCC) + sizeof(DWORD));
799 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
801 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
803 ERR(": could not load track\n");
806 IStream_Release (pClonedStream);
808 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
810 liMove.QuadPart = Chunk.dwSize;
811 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
816 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
817 liMove.QuadPart = Chunk.dwSize;
818 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
822 TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
823 } while (StreamCount < StreamSize);
828 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicSegment8Impl* This) {
831 DMUS_PRIVATE_CHUNK Chunk;
832 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
833 LARGE_INTEGER liMove; /* used when skipping chunks */
835 if (pChunk->fccID != DMUS_FOURCC_TRACK_LIST) {
836 ERR_(dmfile)(": %s chunk should be a TRACK list\n", debugstr_fourcc (pChunk->fccID));
840 ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
844 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
845 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
846 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
847 switch (Chunk.fccID) {
849 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
850 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
851 StreamSize = Chunk.dwSize - sizeof(FOURCC);
853 switch (Chunk.fccID) {
854 case DMUS_FOURCC_TRACK_FORM: {
855 TRACE_(dmfile)(": TRACK form\n");
856 hr = IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (iface, &Chunk, pStm);
857 if (FAILED(hr)) return hr;
861 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
862 liMove.QuadPart = StreamSize;
863 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
870 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
871 liMove.QuadPart = Chunk.dwSize;
872 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
876 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
877 } while (ListCount[0] < ListSize[0]);
882 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicSegment8Impl* This) {
885 DMUS_PRIVATE_CHUNK Chunk;
886 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
887 LARGE_INTEGER liMove; /* used when skipping chunks */
889 if (pChunk->fccID != DMUS_FOURCC_SEGMENT_FORM) {
890 ERR_(dmfile)(": %s chunk should be a segment form\n", debugstr_fourcc (pChunk->fccID));
894 StreamSize = pChunk->dwSize - sizeof(FOURCC);
898 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
899 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
900 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
902 hr = IDirectMusicImpl_IPersistStream_ParseDescGeneric(&Chunk, pStm, This->pDesc);
903 if (FAILED(hr)) return hr;
906 switch (Chunk.fccID) {
907 case DMUS_FOURCC_SEGMENT_CHUNK: {
908 DWORD checkSz = sizeof(FOURCC);
909 TRACE_(dmfile)(": segment chunk\n");
912 IStream_Read (pStm, &This->header.dwRepeats, sizeof(This->header.dwRepeats), NULL);
913 checkSz += sizeof(This->header.dwRepeats);
914 IStream_Read (pStm, &This->header.mtLength, sizeof(This->header.mtLength), NULL);
915 checkSz += sizeof(This->header.mtLength);
916 IStream_Read (pStm, &This->header.mtPlayStart, sizeof(This->header.mtPlayStart), NULL);
917 checkSz += sizeof(This->header.mtPlayStart);
918 IStream_Read (pStm, &This->header.mtLoopStart, sizeof(This->header.mtLoopStart), NULL);
919 checkSz += sizeof(This->header.mtLoopStart);
920 IStream_Read (pStm, &This->header.mtLoopEnd, sizeof(This->header.mtLoopEnd), NULL);
921 checkSz += sizeof(This->header.mtLoopEnd);
922 IStream_Read (pStm, &This->header.dwResolution, sizeof(This->header.dwResolution), NULL);
923 checkSz += sizeof(This->header.dwResolution);
924 TRACE_(dmfile)("dwRepeats: %lu\n", This->header.dwRepeats);
925 TRACE_(dmfile)("mtLength: %lu\n", This->header.mtLength);
926 TRACE_(dmfile)("mtPlayStart: %lu\n", This->header.mtPlayStart);
927 TRACE_(dmfile)("mtLoopStart: %lu\n", This->header.mtLoopStart);
928 TRACE_(dmfile)("mtLoopEnd: %lu\n", This->header.mtLoopEnd);
929 TRACE_(dmfile)("dwResolution: %lu\n", This->header.dwResolution);
931 if (Chunk.dwSize > checkSz) {
932 IStream_Read (pStm, &This->header.rtLength, sizeof(This->header.rtLength), NULL);
933 checkSz += sizeof(This->header.rtLength);
934 IStream_Read (pStm, &This->header.dwFlags, sizeof(This->header.dwFlags), NULL);
935 checkSz += sizeof(This->header.dwFlags);
938 if (Chunk.dwSize > checkSz) {
939 IStream_Read (pStm, &This->header.rtLoopStart, sizeof(This->header.rtLoopStart), NULL);
940 checkSz += sizeof(This->header.rtLoopStart);
941 IStream_Read (pStm, &This->header.rtLoopEnd, sizeof(This->header.rtLoopEnd), NULL);
942 checkSz += sizeof(This->header.rtLoopEnd);
943 IStream_Read (pStm, &This->header.rtPlayStart, sizeof(This->header.rtPlayStart), NULL);
944 checkSz += sizeof(This->header.rtPlayStart);
947 liMove.QuadPart = Chunk.dwSize - checkSz + sizeof(FOURCC);
948 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
952 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
953 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
954 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
956 switch (Chunk.fccID) {
957 case DMUS_FOURCC_UNFO_LIST: {
958 TRACE_(dmfile)(": UNFO list\n");
960 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
961 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
962 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
964 hr = IDirectMusicImpl_IPersistStream_ParseUNFOGeneric(&Chunk, pStm, This->pDesc);
965 if (FAILED(hr)) return hr;
968 switch (Chunk.fccID) {
970 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
971 liMove.QuadPart = Chunk.dwSize;
972 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
978 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
979 } while (ListCount[0] < ListSize[0]);
982 case DMUS_FOURCC_TRACK_LIST: {
983 TRACE_(dmfile)(": TRACK list\n");
984 hr = IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (iface, &Chunk, pStm, This);
985 if (FAILED(hr)) return hr;
989 TRACE_(dmfile)(": unknown (skipping)\n");
990 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
991 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
998 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
999 liMove.QuadPart = Chunk.dwSize;
1000 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
1005 TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
1006 } while (StreamCount < StreamSize);
1011 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
1012 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
1015 DMUS_PRIVATE_CHUNK Chunk;
1016 DWORD StreamSize, StreamCount;
1017 /*DWORD ListSize[3], ListCount[3];*/
1018 LARGE_INTEGER liMove; /* used when skipping chunks */
1021 TRACE("(%p, %p): Loading\n", This, pStm);
1022 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
1023 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
1024 switch (Chunk.fccID) {
1026 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
1027 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
1028 StreamSize = Chunk.dwSize - sizeof(FOURCC);
1030 switch (Chunk.fccID) {
1031 case DMUS_FOURCC_SEGMENT_FORM: {
1032 TRACE_(dmfile)(": segment form\n");
1033 hr = IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (iface, &Chunk, pStm, This);
1034 if (FAILED(hr)) return hr;
1037 case mmioFOURCC('W','A','V','E'): {
1038 FIXME_(dmfile)(": WAVE form (loading not yet implemented)\n");
1039 liMove.QuadPart = StreamSize;
1040 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1044 TRACE_(dmfile)(": unexpected chunk (loading failed)\n");
1045 liMove.QuadPart = StreamSize;
1046 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1050 TRACE_(dmfile)(": reading finished\n");
1054 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
1055 liMove.QuadPart = Chunk.dwSize;
1056 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1064 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
1068 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
1072 ICOM_VTABLE(IPersistStream) DirectMusicSegment8_PersistStream_Vtbl = {
1073 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1074 IDirectMusicSegment8Impl_IPersistStream_QueryInterface,
1075 IDirectMusicSegment8Impl_IPersistStream_AddRef,
1076 IDirectMusicSegment8Impl_IPersistStream_Release,
1077 IDirectMusicSegment8Impl_IPersistStream_GetClassID,
1078 IDirectMusicSegment8Impl_IPersistStream_IsDirty,
1079 IDirectMusicSegment8Impl_IPersistStream_Load,
1080 IDirectMusicSegment8Impl_IPersistStream_Save,
1081 IDirectMusicSegment8Impl_IPersistStream_GetSizeMax
1084 /* for ClassFactory */
1085 HRESULT WINAPI DMUSIC_CreateDirectMusicSegmentImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
1086 IDirectMusicSegment8Impl* obj;
1088 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSegment8Impl));
1090 *ppobj = (LPVOID) NULL;
1091 return E_OUTOFMEMORY;
1093 obj->UnknownVtbl = &DirectMusicSegment8_Unknown_Vtbl;
1094 obj->SegmentVtbl = &DirectMusicSegment8_Segment_Vtbl;
1095 obj->ObjectVtbl = &DirectMusicSegment8_Object_Vtbl;
1096 obj->PersistStreamVtbl = &DirectMusicSegment8_PersistStream_Vtbl;
1097 obj->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
1098 DM_STRUCT_INIT(obj->pDesc);
1099 obj->pDesc->dwValidData |= DMUS_OBJ_CLASS;
1100 memcpy (&obj->pDesc->guidClass, &CLSID_DirectMusicSegment, sizeof (CLSID));
1101 obj->ref = 0; /* will be inited by QueryInterface */
1103 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&obj->UnknownVtbl, lpcGUID, ppobj);