- fix DirectSound Creation by dmusic (fix recent Unreal2 regression)
[wine.git] / dlls / dmime / segment.c
blobf9c20a5e0e4607e81b75fffd37220ef3b0d0a2d6
1 /* IDirectMusicSegment8 Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "dmime_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
23 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
25 /*****************************************************************************
26 * IDirectMusicSegmentImpl implementation
28 /* IDirectMusicSegment IUnknown part: */
29 HRESULT WINAPI IDirectMusicSegment8Impl_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
30 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
31 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
33 if (IsEqualIID (riid, &IID_IUnknown)) {
34 *ppobj = (LPVOID)&This->UnknownVtbl;
35 IDirectMusicSegment8Impl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
36 return S_OK;
37 } else if (IsEqualIID (riid, &IID_IDirectMusicSegment)
38 || IsEqualIID (riid, &IID_IDirectMusicSegment2)
39 || IsEqualIID (riid, &IID_IDirectMusicSegment8)) {
40 *ppobj = (LPVOID)&This->SegmentVtbl;
41 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef ((LPDIRECTMUSICSEGMENT8)&This->SegmentVtbl);
42 return S_OK;
43 } else if (IsEqualIID (riid, &IID_IDirectMusicObject)) {
44 *ppobj = (LPVOID)&This->ObjectVtbl;
45 IDirectMusicSegment8Impl_IDirectMusicObject_AddRef ((LPDIRECTMUSICOBJECT)&This->ObjectVtbl);
46 return S_OK;
47 } else if (IsEqualIID (riid, &IID_IPersistStream)) {
48 *ppobj = (LPVOID)&This->PersistStreamVtbl;
49 IDirectMusicSegment8Impl_IPersistStream_AddRef ((LPPERSISTSTREAM)&This->PersistStreamVtbl);
50 return S_OK;
53 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
54 return E_NOINTERFACE;
57 ULONG WINAPI IDirectMusicSegment8Impl_IUnknown_AddRef (LPUNKNOWN iface) {
58 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
59 TRACE("(%p): AddRef from %ld\n", This, This->ref);
60 return ++(This->ref);
63 ULONG WINAPI IDirectMusicSegment8Impl_IUnknown_Release (LPUNKNOWN iface) {
64 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
65 ULONG ref = --This->ref;
66 TRACE("(%p): ReleaseRef to %ld\n", This, This->ref);
67 if (ref == 0) {
68 HeapFree(GetProcessHeap(), 0, This);
70 return ref;
73 ICOM_VTABLE(IUnknown) DirectMusicSegment8_Unknown_Vtbl = {
74 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
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 FIXME("(%p, %p): stub\n", This, pmtLength);
99 return S_OK;
102 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLength (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtLength) {
103 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
104 FIXME("(%p, %ld): stub\n", This, mtLength);
105 return S_OK;
108 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetRepeats (LPDIRECTMUSICSEGMENT8 iface, DWORD* pdwRepeats) {
109 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
110 FIXME("(%p, %p): stub\n", This, pdwRepeats);
111 return S_OK;
114 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetRepeats (LPDIRECTMUSICSEGMENT8 iface, DWORD dwRepeats) {
115 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
116 FIXME("(%p, %ld): stub\n", This, dwRepeats);
117 return S_OK;
120 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetDefaultResolution (LPDIRECTMUSICSEGMENT8 iface, DWORD* pdwResolution) {
121 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
122 FIXME("(%p, %p): stub\n", This, pdwResolution);
123 return S_OK;
126 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetDefaultResolution (LPDIRECTMUSICSEGMENT8 iface, DWORD dwResolution) {
127 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
128 FIXME("(%p, %ld): stub\n", This, dwResolution);
129 return S_OK;
132 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, IDirectMusicTrack** ppTrack) {
133 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
134 FIXME("(%p, %s, %ld, %ld, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, ppTrack);
135 return S_OK;
138 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrackGroup (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack, DWORD* pdwGroupBits) {
139 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
140 FIXME("(%p, %p, %p): stub\n", This, pTrack, pdwGroupBits);
141 return S_OK;
144 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack, DWORD dwGroupBits) {
145 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
146 FIXME("(%p, %p, %ld): stub\n", This, pTrack, dwGroupBits);
147 return S_OK;
150 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack) {
151 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
152 FIXME("(%p, %p): stub\n", This, pTrack);
153 return S_OK;
156 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicSegmentState** ppSegState, IDirectMusicPerformance* pPerformance, DWORD dwFlags) {
157 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
158 FIXME("(%p, %p, %p, %ld): stub\n", This, ppSegState, pPerformance, dwFlags);
159 return S_OK;
162 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicGraph** ppGraph) {
163 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
164 FIXME("(%p, %p): stub\n", This, ppGraph);
165 return S_OK;
168 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicGraph* pGraph) {
169 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
170 FIXME("(%p, %p): stub\n", This, pGraph);
171 return S_OK;
174 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidNotificationType) {
175 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
176 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
177 return S_OK;
180 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidNotificationType) {
181 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
182 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
183 return S_OK;
186 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
187 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
188 FIXME("(%p, %s, %ld, %ld, %ld, %p, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pmtNext, pParam);
189 return S_OK;
192 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, void* pParam) {
193 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
194 FIXME("(%p, %s, %ld, %ld, %ld, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pParam);
195 return S_OK;
198 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicSegment** ppSegment) {
199 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
200 FIXME("(%p, %ld, %ld, %p): stub\n", This, mtStart, mtEnd, ppSegment);
201 return S_OK;
204 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart) {
205 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
206 FIXME("(%p, %ld): stub\n", This, mtStart);
207 return S_OK;
210 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtStart) {
211 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
212 FIXME("(%p, %p): stub\n", This, pmtStart);
213 return S_OK;
216 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd) {
217 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
218 FIXME("(%p, %ld, %ld): stub\n", This, mtStart, mtEnd);
219 return S_OK;
222 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtStart, MUSIC_TIME* pmtEnd) {
223 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
224 FIXME("(%p, %p, %p): stub\n", This, pmtStart, pmtEnd);
225 return S_OK;
228 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed (LPDIRECTMUSICSEGMENT8 iface, DWORD dwNumPChannels, DWORD* paPChannels) {
229 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
230 FIXME("(%p, %ld, %p): stub\n", This, dwNumPChannels, paPChannels);
231 return S_OK;
234 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidTrackClassID, DWORD dwGroupBits, DWORD dwIndex, DWORD dwFlagsOn, DWORD dwFlagsOff) {
235 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
236 FIXME("(%p, %s, %ld, %ld, %ld, %ld): stub\n", This, debugstr_dmguid(rguidTrackClassID), dwGroupBits, dwIndex, dwFlagsOn, dwFlagsOff);
237 return S_OK;
240 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig (LPDIRECTMUSICSEGMENT8 iface, IUnknown** ppAudioPathConfig){
241 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
242 FIXME("(%p, %p): stub\n", This, ppAudioPathConfig);
243 return S_OK;
246 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtTime, IDirectMusicSegment* pFromSegment, IDirectMusicSegment* pToSegment, IDirectMusicSegment** ppComposedSegment) {
247 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
248 FIXME("(%p, %ld, %p, %p, %p): stub\n", This, mtTime, pFromSegment, pToSegment, ppComposedSegment);
249 return S_OK;
252 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Download (LPDIRECTMUSICSEGMENT8 iface, IUnknown *pAudioPath) {
253 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
254 FIXME("(%p, %p): stub\n", This, pAudioPath);
255 return S_OK;
258 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload (LPDIRECTMUSICSEGMENT8 iface, IUnknown *pAudioPath) {
259 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, SegmentVtbl, iface);
260 FIXME("(%p, %p): stub\n", This, pAudioPath);
261 return S_OK;
264 ICOM_VTABLE(IDirectMusicSegment8) DirectMusicSegment8_Segment_Vtbl = {
265 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
266 IDirectMusicSegment8Impl_IDirectMusicSegment8_QueryInterface,
267 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddRef,
268 IDirectMusicSegment8Impl_IDirectMusicSegment8_Release,
269 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLength,
270 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLength,
271 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetRepeats,
272 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetRepeats,
273 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetDefaultResolution,
274 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetDefaultResolution,
275 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrack,
276 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetTrackGroup,
277 IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack,
278 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveTrack,
279 IDirectMusicSegment8Impl_IDirectMusicSegment8_InitPlay,
280 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetGraph,
281 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetGraph,
282 IDirectMusicSegment8Impl_IDirectMusicSegment8_AddNotificationType,
283 IDirectMusicSegment8Impl_IDirectMusicSegment8_RemoveNotificationType,
284 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetParam,
285 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetParam,
286 IDirectMusicSegment8Impl_IDirectMusicSegment8_Clone,
287 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetStartPoint,
288 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetStartPoint,
289 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetLoopPoints,
290 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetLoopPoints,
291 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetPChannelsUsed,
292 IDirectMusicSegment8Impl_IDirectMusicSegment8_SetTrackConfig,
293 IDirectMusicSegment8Impl_IDirectMusicSegment8_GetAudioPathConfig,
294 IDirectMusicSegment8Impl_IDirectMusicSegment8_Compose,
295 IDirectMusicSegment8Impl_IDirectMusicSegment8_Download,
296 IDirectMusicSegment8Impl_IDirectMusicSegment8_Unload
299 /* IDirectMusicSegment8Impl IDirectMusicObject part: */
300 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) {
301 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
302 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
305 ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) {
306 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
307 return IDirectMusicSegment8Impl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
310 ULONG WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) {
311 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
312 return IDirectMusicSegment8Impl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
315 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
316 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
317 TRACE("(%p, %p)\n", This, pDesc);
318 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
319 memcpy (pDesc, This->pDesc, This->pDesc->dwSize);
320 return S_OK;
323 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
324 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
325 TRACE("(%p, %p): setting descriptor:\n%s\n", This, pDesc, debugstr_DMUS_OBJECTDESC (pDesc));
327 /* According to MSDN, we should copy only given values, not whole struct */
328 if (pDesc->dwValidData & DMUS_OBJ_OBJECT)
329 memcpy (&This->pDesc->guidObject, &pDesc->guidObject, sizeof (pDesc->guidObject));
330 if (pDesc->dwValidData & DMUS_OBJ_CLASS)
331 memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass));
332 if (pDesc->dwValidData & DMUS_OBJ_NAME)
333 strncpyW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
334 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
335 strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
336 if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
337 strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
338 if (pDesc->dwValidData & DMUS_OBJ_VERSION)
339 memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));
340 if (pDesc->dwValidData & DMUS_OBJ_DATE)
341 memcpy (&This->pDesc->ftDate, &pDesc->ftDate, sizeof (pDesc->ftDate));
342 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
343 memcpy (&This->pDesc->llMemLength, &pDesc->llMemLength, sizeof (pDesc->llMemLength));
344 memcpy (This->pDesc->pbMemData, pDesc->pbMemData, sizeof (pDesc->pbMemData));
346 if (pDesc->dwValidData & DMUS_OBJ_STREAM) {
347 /* according to MSDN, we copy the stream */
348 IStream_Clone (pDesc->pStream, &This->pDesc->pStream);
351 /* add new flags */
352 This->pDesc->dwValidData |= pDesc->dwValidData;
354 return S_OK;
357 HRESULT WINAPI IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc) {
358 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, ObjectVtbl, iface);
359 DMUS_PRIVATE_CHUNK Chunk;
360 DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
361 LARGE_INTEGER liMove; /* used when skipping chunks */
363 TRACE("(%p,%p, %p)\n", This, pStream, pDesc);
365 /* FIXME: should this be determined from stream? */
366 pDesc->dwValidData |= DMUS_OBJ_CLASS;
367 memcpy (&pDesc->guidClass, &CLSID_DirectMusicSegment, sizeof(CLSID));
369 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
370 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
371 switch (Chunk.fccID) {
372 case FOURCC_RIFF: {
373 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
374 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
375 StreamSize = Chunk.dwSize - sizeof(FOURCC);
376 StreamCount = 0;
377 if (Chunk.fccID == DMUS_FOURCC_SEGMENT_FORM) {
378 TRACE_(dmfile)(": segment form\n");
379 do {
380 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
381 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
382 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
383 switch (Chunk.fccID) {
384 case DMUS_FOURCC_GUID_CHUNK: {
385 TRACE_(dmfile)(": GUID chunk\n");
386 pDesc->dwValidData |= DMUS_OBJ_OBJECT;
387 IStream_Read (pStream, &pDesc->guidObject, Chunk.dwSize, NULL);
388 break;
390 case DMUS_FOURCC_VERSION_CHUNK: {
391 TRACE_(dmfile)(": version chunk\n");
392 pDesc->dwValidData |= DMUS_OBJ_VERSION;
393 IStream_Read (pStream, &pDesc->vVersion, Chunk.dwSize, NULL);
394 break;
396 case DMUS_FOURCC_CATEGORY_CHUNK: {
397 TRACE_(dmfile)(": category chunk\n");
398 pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
399 IStream_Read (pStream, pDesc->wszCategory, Chunk.dwSize, NULL);
400 break;
402 case FOURCC_LIST: {
403 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
404 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
405 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
406 ListCount[0] = 0;
407 switch (Chunk.fccID) {
408 /* evil M$ UNFO list, which can (!?) contain INFO elements */
409 case DMUS_FOURCC_UNFO_LIST: {
410 TRACE_(dmfile)(": UNFO list\n");
411 do {
412 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
413 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
414 TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
415 switch (Chunk.fccID) {
416 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
417 (though strings seem to be valid unicode) */
418 case mmioFOURCC('I','N','A','M'):
419 case DMUS_FOURCC_UNAM_CHUNK: {
420 TRACE_(dmfile)(": name chunk\n");
421 pDesc->dwValidData |= DMUS_OBJ_NAME;
422 IStream_Read (pStream, pDesc->wszName, Chunk.dwSize, NULL);
423 break;
425 case mmioFOURCC('I','A','R','T'):
426 case DMUS_FOURCC_UART_CHUNK: {
427 TRACE_(dmfile)(": artist chunk (ignored)\n");
428 liMove.QuadPart = Chunk.dwSize;
429 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
430 break;
432 case mmioFOURCC('I','C','O','P'):
433 case DMUS_FOURCC_UCOP_CHUNK: {
434 TRACE_(dmfile)(": copyright chunk (ignored)\n");
435 liMove.QuadPart = Chunk.dwSize;
436 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
437 break;
439 case mmioFOURCC('I','S','B','J'):
440 case DMUS_FOURCC_USBJ_CHUNK: {
441 TRACE_(dmfile)(": subject chunk (ignored)\n");
442 liMove.QuadPart = Chunk.dwSize;
443 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
444 break;
446 case mmioFOURCC('I','C','M','T'):
447 case DMUS_FOURCC_UCMT_CHUNK: {
448 TRACE_(dmfile)(": comment chunk (ignored)\n");
449 liMove.QuadPart = Chunk.dwSize;
450 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
451 break;
453 default: {
454 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
455 liMove.QuadPart = Chunk.dwSize;
456 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
457 break;
460 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
461 } while (ListCount[0] < ListSize[0]);
462 break;
464 case DMUS_FOURCC_TRACK_LIST: {
465 TRACE_(dmfile)(": TRACK list\n");
466 do {
467 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
468 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
469 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
470 switch (Chunk.fccID) {
471 default: {
472 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
473 liMove.QuadPart = Chunk.dwSize;
474 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
475 break;
478 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
479 } while (ListCount[0] < ListSize[0]);
480 break;
482 default: {
483 TRACE_(dmfile)(": unknown (skipping)\n");
484 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
485 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
486 break;
489 break;
491 default: {
492 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
493 liMove.QuadPart = Chunk.dwSize;
494 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
495 break;
498 TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
499 } while (StreamCount < StreamSize);
500 break;
501 } else if (Chunk.fccID == mmioFOURCC('W','A','V','E')) {
502 TRACE_(dmfile)(": wave form (loading not yet implemented)\n");
503 liMove.QuadPart = StreamSize;
504 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
505 } else {
506 TRACE_(dmfile)(": unexpected chunk (loading failed)\n");
507 liMove.QuadPart = StreamSize;
508 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
509 return E_FAIL;
512 TRACE_(dmfile)(": reading finished\n");
513 break;
515 default: {
516 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
517 liMove.QuadPart = Chunk.dwSize;
518 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
519 return DMUS_E_INVALIDFILE;
523 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc));
525 return S_OK;
528 ICOM_VTABLE(IDirectMusicObject) DirectMusicSegment8_Object_Vtbl = {
529 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
530 IDirectMusicSegment8Impl_IDirectMusicObject_QueryInterface,
531 IDirectMusicSegment8Impl_IDirectMusicObject_AddRef,
532 IDirectMusicSegment8Impl_IDirectMusicObject_Release,
533 IDirectMusicSegment8Impl_IDirectMusicObject_GetDescriptor,
534 IDirectMusicSegment8Impl_IDirectMusicObject_SetDescriptor,
535 IDirectMusicSegment8Impl_IDirectMusicObject_ParseDescriptor
538 /* IDirectMusicSegment8Impl IPersistStream part: */
539 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
540 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
541 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
544 ULONG WINAPI IDirectMusicSegment8Impl_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
545 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
546 return IDirectMusicSegment8Impl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
549 ULONG WINAPI IDirectMusicSegment8Impl_IPersistStream_Release (LPPERSISTSTREAM iface) {
550 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
551 return IDirectMusicSegment8Impl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
554 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
555 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
556 TRACE("(%p, %p)\n", This, pClassID);
557 memcpy(pClassID, &CLSID_DirectMusicContainer, sizeof(CLSID));
558 return S_OK;
561 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
562 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
563 FIXME("(%p): stub, always S_FALSE\n", This);
564 return S_FALSE;
568 static HRESULT IDirectMusicImpl_IPersistStream_ParseDescGeneric (DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, LPDMUS_OBJECTDESC pDesc) {
570 switch (pChunk->fccID) {
571 case DMUS_FOURCC_GUID_CHUNK: {
572 TRACE_(dmfile)(": GUID chunk\n");
573 pDesc->dwValidData |= DMUS_OBJ_OBJECT;
574 IStream_Read (pStm, &pDesc->guidObject, pChunk->dwSize, NULL);
575 break;
577 case DMUS_FOURCC_VERSION_CHUNK: {
578 TRACE_(dmfile)(": version chunk\n");
579 pDesc->dwValidData |= DMUS_OBJ_VERSION;
580 IStream_Read (pStm, &pDesc->vVersion, pChunk->dwSize, NULL);
581 break;
583 case DMUS_FOURCC_CATEGORY_CHUNK: {
584 TRACE_(dmfile)(": category chunk\n");
585 pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
586 IStream_Read (pStm, pDesc->wszCategory, pChunk->dwSize, NULL);
587 break;
589 default:
590 /* not handled */
591 return S_FALSE;
594 return S_OK;
597 static HRESULT IDirectMusicImpl_IPersistStream_ParseUNFOGeneric (DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, LPDMUS_OBJECTDESC pDesc) {
599 LARGE_INTEGER liMove; /* used when skipping chunks */
602 * don't ask me why, but M$ puts INFO elements in UNFO list sometimes
603 * (though strings seem to be valid unicode)
605 switch (pChunk->fccID) {
607 case mmioFOURCC('I','N','A','M'):
608 case DMUS_FOURCC_UNAM_CHUNK: {
609 TRACE_(dmfile)(": name chunk\n");
610 pDesc->dwValidData |= DMUS_OBJ_NAME;
611 IStream_Read (pStream, pDesc->wszName, Chunk.dwSize, NULL);
612 break;
615 case mmioFOURCC('I','A','R','T'):
616 case DMUS_FOURCC_UART_CHUNK: {
617 TRACE_(dmfile)(": artist chunk (ignored)\n");
618 liMove.QuadPart = pChunk->dwSize;
619 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
620 break;
622 case mmioFOURCC('I','C','O','P'):
623 case DMUS_FOURCC_UCOP_CHUNK: {
624 TRACE_(dmfile)(": copyright chunk (ignored)\n");
625 liMove.QuadPart = pChunk->dwSize;
626 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
627 break;
629 case mmioFOURCC('I','S','B','J'):
630 case DMUS_FOURCC_USBJ_CHUNK: {
631 TRACE_(dmfile)(": subject chunk (ignored)\n");
632 liMove.QuadPart = pChunk->dwSize;
633 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
634 break;
636 case mmioFOURCC('I','C','M','T'):
637 case DMUS_FOURCC_UCMT_CHUNK: {
638 TRACE_(dmfile)(": comment chunk (ignored)\n");
639 liMove.QuadPart = pChunk->dwSize;
640 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
641 break;
643 default:
644 /* not handled */
645 return S_FALSE;
648 return S_OK;
651 static HRESULT IDirectMusicSegment8Impl_IPersistStream_LoadTrack (LPPERSISTSTREAM iface, IStream* pClonedStream, IDirectMusicTrack** ppTrack,
652 DMUS_IO_TRACK_HEADER* pTrack_hdr) {
654 HRESULT hr = E_FAIL;
655 IPersistStream* pPersistStream = NULL;
657 hr = CoCreateInstance (&pTrack_hdr->guidClassID, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicTrack, (LPVOID*) ppTrack);
658 if (FAILED(hr)) {
659 ERR(": could not create object\n");
660 return hr;
662 /* acquire PersistStream interface */
663 hr = IDirectMusicTrack_QueryInterface (*ppTrack, &IID_IPersistStream, (LPVOID*) &pPersistStream);
664 if (FAILED(hr)) {
665 ERR(": could not acquire IPersistStream\n");
666 return hr;
668 /* load */
669 hr = IPersistStream_Load (pPersistStream, pClonedStream);
670 if (FAILED(hr)) {
671 ERR(": failed to load object\n");
672 return hr;
675 /* release all loading-related stuff */
676 IPersistStream_Release (pPersistStream);
678 return S_OK;
681 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicSegment8Impl* This) {
683 HRESULT hr = E_FAIL;
684 DMUS_PRIVATE_CHUNK Chunk;
685 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
686 LARGE_INTEGER liMove; /* used when skipping chunks */
688 DMUS_IO_TRACK_HEADER track_hdr;
689 DMUS_IO_TRACK_EXTRAS_HEADER track_xhdr;
690 IDirectMusicTrack* pTrack = NULL;
692 if (pChunk->fccID != DMUS_FOURCC_TRACK_FORM) {
693 ERR_(dmfile)(": %s chunk should be a TRACK form\n", debugstr_fourcc (pChunk->fccID));
694 return E_FAIL;
697 StreamSize = pChunk->dwSize - sizeof(FOURCC);
698 StreamCount = 0;
700 do {
701 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
702 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
703 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
705 switch (Chunk.fccID) {
706 case DMUS_FOURCC_TRACK_CHUNK: {
707 TRACE_(dmfile)(": track chunck\n");
708 IStream_Read (pStm, &track_hdr, sizeof(DMUS_IO_TRACK_HEADER), NULL);
709 TRACE_(dmfile)("class: %s\n", debugstr_guid (&track_hdr.guidClassID));
710 TRACE_(dmfile)("dwGroup: %ld\n", track_hdr.dwGroup);
711 TRACE_(dmfile)("ckid: %s\n", debugstr_fourcc (track_hdr.ckid));
712 TRACE_(dmfile)("fccType: %s\n", debugstr_fourcc (track_hdr.fccType));
713 break;
715 case DMUS_FOURCC_TRACK_EXTRAS_CHUNK: {
716 TRACE_(dmfile)(": track extras chunck\n");
717 IStream_Read (pStm, &track_xhdr, sizeof(DMUS_IO_TRACK_EXTRAS_HEADER), NULL);
718 break;
721 case DMUS_FOURCC_COMMANDTRACK_CHUNK: {
722 TRACE_(dmfile)(": COMMANDTRACK track\n");
723 liMove.QuadPart = Chunk.dwSize;
724 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
725 break;
728 case FOURCC_LIST: {
729 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
730 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
731 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
732 ListCount[0] = 0;
733 if (Chunk.fccID == track_hdr.fccType && 0 == track_hdr.ckid) {
734 LPSTREAM pClonedStream = NULL;
736 TRACE_(dmfile)(": TRACK list\n");
738 IStream_Clone (pStm, &pClonedStream);
740 liMove.QuadPart = 0;
741 liMove.QuadPart -= (sizeof(FOURCC) + sizeof(DWORD));
742 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
744 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
745 if (FAILED(hr)) {
746 ERR(": could not load track\n");
747 return hr;
750 IStream_Release (pClonedStream);
752 hr = IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack ((LPDIRECTMUSICSEGMENT8)This->SegmentVtbl, pTrack, track_hdr.dwGroup); /* at dsPosition */
753 if (FAILED(hr)) {
754 ERR(": could not insert track\n");
755 return hr;
757 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
759 liMove.QuadPart = Chunk.dwSize;
760 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
762 } else {
763 TRACE_(dmfile)(": unknown (skipping)\n");
764 liMove.QuadPart = Chunk.dwSize;
765 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
767 break;
770 case FOURCC_RIFF: {
771 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
772 FIXME_(dmfile)(": LIST chunk of type %s (behavior to check)", debugstr_fourcc(Chunk.fccID));
773 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
774 ListCount[0] = 0;
775 if (Chunk.fccID == track_hdr.fccType && 0 == track_hdr.ckid) {
776 TRACE_(dmfile)(": TRACK RIFF\n");
778 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pStm, &pTrack, &track_hdr);
779 if (FAILED(hr)) return hr;
781 liMove.QuadPart = Chunk.dwSize;
782 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
784 } else {
785 TRACE_(dmfile)(": unknown (skipping)\n");
786 liMove.QuadPart = Chunk.dwSize;
787 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
789 break;
792 default: {
793 if (0 == track_hdr.fccType && Chunk.fccID == track_hdr.ckid) {
794 LPSTREAM pClonedStream = NULL;
796 TRACE_(dmfile)(": TRACK solo\n");
798 IStream_Clone (pStm, &pClonedStream);
800 liMove.QuadPart = 0;
801 liMove.QuadPart -= (sizeof(FOURCC) + sizeof(DWORD));
802 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
804 hr = IDirectMusicSegment8Impl_IPersistStream_LoadTrack (iface, pClonedStream, &pTrack, &track_hdr);
805 if (FAILED(hr)) {
806 ERR(": could not load track\n");
807 return hr;
810 IStream_Release (pClonedStream);
812 hr = IDirectMusicSegment8Impl_IDirectMusicSegment8_InsertTrack ((LPDIRECTMUSICSEGMENT8)This->SegmentVtbl, pTrack, track_hdr.dwGroup); /* at dsPosition */
813 if (FAILED(hr)) {
814 ERR(": could not insert track\n");
815 return hr;
817 IDirectMusicTrack_Release(pTrack); pTrack = NULL; /* now we can release at as it inserted */
819 liMove.QuadPart = Chunk.dwSize;
820 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
822 break;
825 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
826 liMove.QuadPart = Chunk.dwSize;
827 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
828 break;
831 TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
832 } while (StreamCount < StreamSize);
834 return S_OK;
837 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicSegment8Impl* This) {
839 HRESULT hr = E_FAIL;
840 DMUS_PRIVATE_CHUNK Chunk;
841 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
842 LARGE_INTEGER liMove; /* used when skipping chunks */
844 if (pChunk->fccID != DMUS_FOURCC_TRACK_LIST) {
845 ERR_(dmfile)(": %s chunk should be a TRACK list\n", debugstr_fourcc (pChunk->fccID));
846 return E_FAIL;
849 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
850 ListCount[0] = 0;
852 do {
853 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
854 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
855 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
856 switch (Chunk.fccID) {
857 case FOURCC_RIFF: {
858 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
859 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
860 StreamSize = Chunk.dwSize - sizeof(FOURCC);
861 StreamCount = 0;
862 switch (Chunk.fccID) {
863 case DMUS_FOURCC_TRACK_FORM: {
864 TRACE_(dmfile)(": TRACK form\n");
865 hr = IDirectMusicSegment8Impl_IPersistStream_ParseTrackForm (iface, &Chunk, pStm, This);
866 if (FAILED(hr)) return hr;
867 break;
869 default: {
870 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
871 liMove.QuadPart = StreamSize;
872 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
873 break;
876 break;
878 default: {
879 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
880 liMove.QuadPart = Chunk.dwSize;
881 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
882 break;
885 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
886 } while (ListCount[0] < ListSize[0]);
888 return S_OK;
891 static HRESULT IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicSegment8Impl* This) {
893 HRESULT hr = E_FAIL;
894 DMUS_PRIVATE_CHUNK Chunk;
895 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
896 LARGE_INTEGER liMove; /* used when skipping chunks */
898 if (pChunk->fccID != DMUS_FOURCC_SEGMENT_FORM) {
899 ERR_(dmfile)(": %s chunk should be a segment form\n", debugstr_fourcc (pChunk->fccID));
900 return E_FAIL;
903 StreamSize = pChunk->dwSize - sizeof(FOURCC);
904 StreamCount = 0;
906 do {
907 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
908 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
909 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
911 hr = IDirectMusicImpl_IPersistStream_ParseDescGeneric(&Chunk, pStm, This->pDesc);
912 if (FAILED(hr)) return hr;
914 if (hr == S_FALSE) {
915 switch (Chunk.fccID) {
916 case DMUS_FOURCC_SEGMENT_CHUNK: {
917 FIXME_(dmfile)(": segment chunk\n");
918 liMove.QuadPart = Chunk.dwSize;
919 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
920 break;
922 case FOURCC_LIST: {
923 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
924 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
925 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
926 ListCount[0] = 0;
927 switch (Chunk.fccID) {
928 case DMUS_FOURCC_UNFO_LIST: {
929 TRACE_(dmfile)(": UNFO list\n");
930 do {
931 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
932 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
933 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
935 hr = IDirectMusicImpl_IPersistStream_ParseUNFOGeneric(&Chunk, pStm, This->pDesc);
936 if (FAILED(hr)) return hr;
938 if (hr == S_FALSE) {
939 switch (Chunk.fccID) {
940 default: {
941 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
942 liMove.QuadPart = Chunk.dwSize;
943 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
944 break;
949 TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
950 } while (ListCount[0] < ListSize[0]);
951 break;
953 case DMUS_FOURCC_TRACK_LIST: {
954 TRACE_(dmfile)(": TRACK list\n");
955 hr = IDirectMusicSegment8Impl_IPersistStream_ParseTrackList (iface, &Chunk, pStm, This);
956 if (FAILED(hr)) return hr;
957 break;
959 default: {
960 TRACE_(dmfile)(": unknown (skipping)\n");
961 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
962 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
963 break;
966 break;
968 default: {
969 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
970 liMove.QuadPart = Chunk.dwSize;
971 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
972 break;
976 TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
977 } while (StreamCount < StreamSize);
979 return S_OK;
982 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
983 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
985 HRESULT hr;
986 DMUS_PRIVATE_CHUNK Chunk;
987 DWORD StreamSize, StreamCount;
988 /*DWORD ListSize[3], ListCount[3];*/
989 LARGE_INTEGER liMove; /* used when skipping chunks */
992 FIXME("(%p, %p): Loading not implemented yet\n", This, pStm);
993 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
994 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
995 switch (Chunk.fccID) {
996 case FOURCC_RIFF: {
997 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
998 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
999 StreamSize = Chunk.dwSize - sizeof(FOURCC);
1000 StreamCount = 0;
1001 switch (Chunk.fccID) {
1002 case DMUS_FOURCC_SEGMENT_FORM: {
1003 TRACE_(dmfile)(": segment form\n");
1004 hr = IDirectMusicSegment8Impl_IPersistStream_ParseSegmentForm (iface, &Chunk, pStm, This);
1005 if (FAILED(hr)) return hr;
1006 break;
1008 case mmioFOURCC('W','A','V','E'): {
1009 FIXME_(dmfile)(": WAVE form (loading not yet implemented)\n");
1010 liMove.QuadPart = StreamSize;
1011 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1012 break;
1014 default: {
1015 TRACE_(dmfile)(": unexpected chunk (loading failed)\n");
1016 liMove.QuadPart = StreamSize;
1017 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1018 return E_FAIL;
1021 TRACE_(dmfile)(": reading finished\n");
1022 break;
1024 default: {
1025 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
1026 liMove.QuadPart = Chunk.dwSize;
1027 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
1028 return E_FAIL;
1032 return S_OK;
1035 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
1036 return E_NOTIMPL;
1039 HRESULT WINAPI IDirectMusicSegment8Impl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
1040 return E_NOTIMPL;
1043 ICOM_VTABLE(IPersistStream) DirectMusicSegment8_PersistStream_Vtbl = {
1044 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1045 IDirectMusicSegment8Impl_IPersistStream_QueryInterface,
1046 IDirectMusicSegment8Impl_IPersistStream_AddRef,
1047 IDirectMusicSegment8Impl_IPersistStream_Release,
1048 IDirectMusicSegment8Impl_IPersistStream_GetClassID,
1049 IDirectMusicSegment8Impl_IPersistStream_IsDirty,
1050 IDirectMusicSegment8Impl_IPersistStream_Load,
1051 IDirectMusicSegment8Impl_IPersistStream_Save,
1052 IDirectMusicSegment8Impl_IPersistStream_GetSizeMax
1055 /* for ClassFactory */
1056 HRESULT WINAPI DMUSIC_CreateDirectMusicSegmentImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
1057 IDirectMusicSegment8Impl* obj;
1059 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicSegment8Impl));
1060 if (NULL == obj) {
1061 *ppobj = (LPVOID) NULL;
1062 return E_OUTOFMEMORY;
1064 obj->UnknownVtbl = &DirectMusicSegment8_Unknown_Vtbl;
1065 obj->SegmentVtbl = &DirectMusicSegment8_Segment_Vtbl;
1066 obj->ObjectVtbl = &DirectMusicSegment8_Object_Vtbl;
1067 obj->PersistStreamVtbl = &DirectMusicSegment8_PersistStream_Vtbl;
1068 obj->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
1069 DM_STRUCT_INIT(obj->pDesc);
1070 obj->pDesc->dwValidData |= DMUS_OBJ_CLASS;
1071 memcpy (&obj->pDesc->guidClass, &CLSID_DirectMusicSegment, sizeof (CLSID));
1072 obj->ref = 0; /* will be inited by QueryInterface */
1074 return IDirectMusicSegment8Impl_IUnknown_QueryInterface ((LPUNKNOWN)&obj->UnknownVtbl, lpcGUID, ppobj);