msvcr100: The msvcr100 debug channel is unused so remove it.
[wine/testsucceed.git] / dlls / dmband / bandtrack.c
blobe08a9e87ad10f54845533807d06b0486946da81c
1 /* IDirectMusicBandTrack Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "dmband_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(dmband);
23 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
25 /*****************************************************************************
26 * IDirectMusicBandTrack implementation
28 /* IDirectMusicBandTrack IUnknown part: */
29 static HRESULT WINAPI IDirectMusicBandTrack_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
30 ICOM_THIS_MULTI(IDirectMusicBandTrack, UnknownVtbl, iface);
31 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
33 if (IsEqualIID (riid, &IID_IUnknown)) {
34 *ppobj = &This->UnknownVtbl;
35 IUnknown_AddRef (iface);
36 return S_OK;
37 } else if (IsEqualIID (riid, &IID_IDirectMusicTrack)
38 || IsEqualIID (riid, &IID_IDirectMusicTrack8)) {
39 *ppobj = (LPDIRECTMUSICTRACK8)&This->TrackVtbl;
40 IUnknown_AddRef (iface);
41 return S_OK;
42 } else if (IsEqualIID (riid, &IID_IPersistStream)) {
43 *ppobj = &This->PersistStreamVtbl;
44 IUnknown_AddRef (iface);
45 return S_OK;
48 WARN("(%p, %s,%p): not found\n", This, debugstr_dmguid(riid), ppobj);
49 return E_NOINTERFACE;
52 static ULONG WINAPI IDirectMusicBandTrack_IUnknown_AddRef (LPUNKNOWN iface) {
53 ICOM_THIS_MULTI(IDirectMusicBandTrack, UnknownVtbl, iface);
54 ULONG ref = InterlockedIncrement(&This->ref);
56 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
58 DMBAND_LockModule();
60 return ref;
63 static ULONG WINAPI IDirectMusicBandTrack_IUnknown_Release (LPUNKNOWN iface) {
64 ICOM_THIS_MULTI(IDirectMusicBandTrack, UnknownVtbl, iface);
65 ULONG ref = InterlockedDecrement(&This->ref);
67 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
69 if (ref == 0) {
70 HeapFree(GetProcessHeap(), 0, This);
73 DMBAND_UnlockModule();
75 return ref;
78 static const IUnknownVtbl DirectMusicBandTrack_Unknown_Vtbl = {
79 IDirectMusicBandTrack_IUnknown_QueryInterface,
80 IDirectMusicBandTrack_IUnknown_AddRef,
81 IDirectMusicBandTrack_IUnknown_Release
84 /* IDirectMusicBandTrack IDirectMusicTrack8 part: */
85 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_QueryInterface (LPDIRECTMUSICTRACK8 iface, REFIID riid, LPVOID *ppobj) {
86 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
87 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
90 static ULONG WINAPI IDirectMusicBandTrack_IDirectMusicTrack_AddRef (LPDIRECTMUSICTRACK8 iface) {
91 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
92 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
95 static ULONG WINAPI IDirectMusicBandTrack_IDirectMusicTrack_Release (LPDIRECTMUSICTRACK8 iface) {
96 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
97 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
100 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_Init (LPDIRECTMUSICTRACK8 iface, IDirectMusicSegment* pSegment) {
101 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
102 FIXME("(%p, %p): stub\n", This, pSegment);
103 return S_OK;
106 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_InitPlay (LPDIRECTMUSICTRACK8 iface, IDirectMusicSegmentState* pSegmentState, IDirectMusicPerformance* pPerformance, void** ppStateData, DWORD dwVirtualTrack8ID, DWORD dwFlags) {
107 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
108 FIXME("(%p, %p, %p, %p, %d, %d): stub\n", This, pSegmentState, pPerformance, ppStateData, dwVirtualTrack8ID, dwFlags);
109 return S_OK;
112 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_EndPlay (LPDIRECTMUSICTRACK8 iface, void* pStateData) {
113 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
114 FIXME("(%p, %p): stub\n", This, pStateData);
115 return S_OK;
118 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_Play (LPDIRECTMUSICTRACK8 iface, void* pStateData, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, MUSIC_TIME mtOffset, DWORD dwFlags, IDirectMusicPerformance* pPerf, IDirectMusicSegmentState* pSegSt, DWORD dwVirtualID) {
119 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
121 FIXME("(%p, %p, %d, %d, %d, %d, %p, %p, %d): semi-stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
122 /* Sends following pMSG:
123 - DMUS_PATCH_PMSG
124 - DMUS_TRANSPOSE_PMSG
125 - DMUS_CHANNEL_PRIORITY_PMSG
126 - DMUS_MIDI_PMSG
129 return S_OK;
132 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_GetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
133 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
134 FIXME("(%p, %s, %d, %p, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pmtNext, pParam);
135 return S_OK;
138 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_SetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, void* pParam) {
139 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
140 FIXME("(%p, %s, %d, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pParam);
141 return S_OK;
144 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_IsParamSupported (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType) {
145 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
147 TRACE("(%p, %s)\n", This, debugstr_dmguid(rguidType));
148 if (IsEqualGUID (rguidType, &GUID_BandParam)
149 || IsEqualGUID (rguidType, &GUID_Clear_All_Bands)
150 || IsEqualGUID (rguidType, &GUID_ConnectToDLSCollection)
151 || IsEqualGUID (rguidType, &GUID_Disable_Auto_Download)
152 || IsEqualGUID (rguidType, &GUID_Download)
153 || IsEqualGUID (rguidType, &GUID_DownloadToAudioPath)
154 || IsEqualGUID (rguidType, &GUID_Enable_Auto_Download)
155 || IsEqualGUID (rguidType, &GUID_IDirectMusicBand)
156 || IsEqualGUID (rguidType, &GUID_StandardMIDIFile)
157 || IsEqualGUID (rguidType, &GUID_Unload)
158 || IsEqualGUID (rguidType, &GUID_UnloadFromAudioPath)) {
159 TRACE("param supported\n");
160 return S_OK;
163 TRACE("param unsupported\n");
164 return DMUS_E_TYPE_UNSUPPORTED;
167 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_AddNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
168 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
169 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
170 return S_OK;
173 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_RemoveNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
174 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
175 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
176 return S_OK;
179 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_Clone (LPDIRECTMUSICTRACK8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicTrack** ppTrack) {
180 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
181 FIXME("(%p, %d, %d, %p): stub\n", This, mtStart, mtEnd, ppTrack);
182 return S_OK;
185 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_PlayEx (LPDIRECTMUSICTRACK8 iface, void* pStateData, REFERENCE_TIME rtStart, REFERENCE_TIME rtEnd, REFERENCE_TIME rtOffset, DWORD dwFlags, IDirectMusicPerformance* pPerf, IDirectMusicSegmentState* pSegSt, DWORD dwVirtualID) {
186 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
187 FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %d, %p, %p, %d): stub\n", This, pStateData, wine_dbgstr_longlong(rtStart),
188 wine_dbgstr_longlong(rtEnd), wine_dbgstr_longlong(rtOffset), dwFlags, pPerf, pSegSt, dwVirtualID);
189 return S_OK;
192 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_GetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, REFERENCE_TIME* prtNext, void* pParam, void* pStateData, DWORD dwFlags) {
193 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
194 FIXME("(%p, %s, 0x%s, %p, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
195 wine_dbgstr_longlong(rtTime), prtNext, pParam, pStateData, dwFlags);
196 return S_OK;
199 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_SetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, void* pParam, void* pStateData, DWORD dwFlags) {
200 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
201 FIXME("(%p, %s, 0x%s, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
202 wine_dbgstr_longlong(rtTime), pParam, pStateData, dwFlags);
203 return S_OK;
206 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_Compose (LPDIRECTMUSICTRACK8 iface, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
207 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
208 FIXME("(%p, %p, %d, %p): stub\n", This, pContext, dwTrackGroup, ppResultTrack);
209 return S_OK;
212 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_Join (LPDIRECTMUSICTRACK8 iface, IDirectMusicTrack* pNewTrack, MUSIC_TIME mtJoin, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
213 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
214 FIXME("(%p, %p, %d, %p, %d, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
215 return S_OK;
218 static const IDirectMusicTrack8Vtbl DirectMusicBandTrack_DirectMusicTrack_Vtbl = {
219 IDirectMusicBandTrack_IDirectMusicTrack_QueryInterface,
220 IDirectMusicBandTrack_IDirectMusicTrack_AddRef,
221 IDirectMusicBandTrack_IDirectMusicTrack_Release,
222 IDirectMusicBandTrack_IDirectMusicTrack_Init,
223 IDirectMusicBandTrack_IDirectMusicTrack_InitPlay,
224 IDirectMusicBandTrack_IDirectMusicTrack_EndPlay,
225 IDirectMusicBandTrack_IDirectMusicTrack_Play,
226 IDirectMusicBandTrack_IDirectMusicTrack_GetParam,
227 IDirectMusicBandTrack_IDirectMusicTrack_SetParam,
228 IDirectMusicBandTrack_IDirectMusicTrack_IsParamSupported,
229 IDirectMusicBandTrack_IDirectMusicTrack_AddNotificationType,
230 IDirectMusicBandTrack_IDirectMusicTrack_RemoveNotificationType,
231 IDirectMusicBandTrack_IDirectMusicTrack_Clone,
232 IDirectMusicBandTrack_IDirectMusicTrack_PlayEx,
233 IDirectMusicBandTrack_IDirectMusicTrack_GetParamEx,
234 IDirectMusicBandTrack_IDirectMusicTrack_SetParamEx,
235 IDirectMusicBandTrack_IDirectMusicTrack_Compose,
236 IDirectMusicBandTrack_IDirectMusicTrack_Join
239 /* IDirectMusicBandTrack IPersistStream part: */
240 static HRESULT WINAPI IDirectMusicBandTrack_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
241 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
242 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
245 static ULONG WINAPI IDirectMusicBandTrack_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
246 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
247 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
250 static ULONG WINAPI IDirectMusicBandTrack_IPersistStream_Release (LPPERSISTSTREAM iface) {
251 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
252 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
255 static HRESULT WINAPI IDirectMusicBandTrack_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
256 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
257 TRACE("(%p, %p)\n", This, pClassID);
258 *pClassID = CLSID_DirectMusicBandTrack;
259 return S_OK;
262 static HRESULT WINAPI IDirectMusicBandTrack_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
263 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
264 FIXME("(%p): stub, always S_FALSE\n", This);
265 return S_FALSE;
268 static HRESULT IDirectMusicBandTrack_IPersistStream_LoadBand (LPPERSISTSTREAM iface, IStream* pClonedStream, IDirectMusicBand** ppBand,
269 DMUS_PRIVATE_BAND_ITEM_HEADER* pHeader) {
271 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
272 HRESULT hr = E_FAIL;
273 IPersistStream* pPersistStream = NULL;
275 hr = CoCreateInstance (&CLSID_DirectMusicBand, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicBand, (LPVOID*) ppBand);
276 if (FAILED(hr)) {
277 ERR(": could not create object\n");
278 return hr;
280 /* acquire PersistStream interface */
281 hr = IDirectMusicBand_QueryInterface (*ppBand, &IID_IPersistStream, (LPVOID*) &pPersistStream);
282 if (FAILED(hr)) {
283 ERR(": could not acquire IPersistStream\n");
284 return hr;
286 /* load */
287 hr = IPersistStream_Load (pPersistStream, pClonedStream);
288 if (FAILED(hr)) {
289 ERR(": failed to load object\n");
290 return hr;
293 /* release all loading-related stuff */
294 IPersistStream_Release (pPersistStream);
297 * @TODO insert pBand into This
299 if (SUCCEEDED(hr)) {
300 LPDMUS_PRIVATE_BAND pNewBand = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_BAND));
301 if (NULL == pNewBand) {
302 ERR(": no more memory\n");
303 return E_OUTOFMEMORY;
305 pNewBand->BandHeader = *pHeader;
306 pNewBand->pBand = (IDirectMusicBandImpl*)((char*)(*ppBand) - offsetof(IDirectMusicBandImpl,BandVtbl));
307 IDirectMusicBand_AddRef(*ppBand);
308 list_add_tail (&This->Bands, &pNewBand->entry);
311 return S_OK;
314 static HRESULT IDirectMusicBandTrack_IPersistStream_ParseBandsList (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
316 /*ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);*/
317 HRESULT hr = E_FAIL;
318 DMUS_PRIVATE_CHUNK Chunk;
319 DWORD StreamSize, ListSize[3], ListCount[3];
320 LARGE_INTEGER liMove; /* used when skipping chunks */
322 IDirectMusicBand* pBand = NULL;
323 DMUS_PRIVATE_BAND_ITEM_HEADER header;
325 memset(&header, 0, sizeof header);
327 if (pChunk->fccID != DMUS_FOURCC_BANDS_LIST) {
328 ERR_(dmfile)(": %s chunk should be a BANDS list\n", debugstr_fourcc (pChunk->fccID));
329 return E_FAIL;
332 ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
333 ListCount[0] = 0;
335 do {
336 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
337 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
338 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
339 switch (Chunk.fccID) {
340 case FOURCC_LIST: {
341 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
342 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
343 ListSize[1] = Chunk.dwSize - sizeof(FOURCC);
344 ListCount[1] = 0;
345 do {
346 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
347 ListCount[1] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
348 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
349 switch (Chunk.fccID) {
350 case DMUS_FOURCC_BANDITEM_CHUNK: {
351 DMUS_IO_BAND_ITEM_HEADER tmp_header;
352 TRACE_(dmfile)(": Band Item chunk v1\n");
354 IStream_Read (pStm, &tmp_header, sizeof(DMUS_IO_BAND_ITEM_HEADER), NULL);
355 TRACE_(dmfile)(" - lBandTime: %u\n", tmp_header.lBandTime);
357 header.dwVersion = 1;
358 header.lBandTime = tmp_header.lBandTime;
359 break;
361 case DMUS_FOURCC_BANDITEM_CHUNK2: {
362 DMUS_IO_BAND_ITEM_HEADER2 tmp_header2;
363 TRACE_(dmfile)(": Band Item chunk v2\n");
365 IStream_Read (pStm, &tmp_header2, sizeof(DMUS_IO_BAND_ITEM_HEADER2), NULL);
366 TRACE_(dmfile)(" - lBandTimeLogical: %u\n", tmp_header2.lBandTimeLogical);
367 TRACE_(dmfile)(" - lBandTimePhysical: %u\n", tmp_header2.lBandTimePhysical);
369 header.dwVersion = 2;
370 header.lBandTimeLogical = tmp_header2.lBandTimeLogical;
371 header.lBandTimePhysical = tmp_header2.lBandTimePhysical;
372 break;
374 case FOURCC_RIFF: {
375 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
376 TRACE_(dmfile)(": RIFF chunk of type %s\n", debugstr_fourcc(Chunk.fccID));
377 StreamSize = Chunk.dwSize - sizeof(FOURCC);
378 switch (Chunk.fccID) {
379 case DMUS_FOURCC_BAND_FORM: {
380 LPSTREAM pClonedStream = NULL;
381 TRACE_(dmfile)(": BAND RIFF\n");
383 IStream_Clone (pStm, &pClonedStream);
385 liMove.QuadPart = 0;
386 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
387 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
389 hr = IDirectMusicBandTrack_IPersistStream_LoadBand (iface, pClonedStream, &pBand, &header);
390 if (FAILED(hr)) {
391 ERR(": could not load track\n");
392 return hr;
394 IStream_Release (pClonedStream);
396 IDirectMusicTrack_Release(pBand); pBand = NULL; /* now we can release at as it inserted */
398 /** now safe move the cursor */
399 liMove.QuadPart = StreamSize;
400 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
401 break;
403 default: {
404 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
405 liMove.QuadPart = StreamSize;
406 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
407 break;
410 break;
412 default: {
413 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
414 liMove.QuadPart = Chunk.dwSize;
415 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
416 break;
419 TRACE_(dmfile)(": ListCount[1] = %d < ListSize[1] = %d\n", ListCount[1], ListSize[1]);
420 } while (ListCount[1] < ListSize[1]);
421 break;
423 default: {
424 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
425 liMove.QuadPart = Chunk.dwSize;
426 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
427 break;
430 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
431 } while (ListCount[0] < ListSize[0]);
433 return S_OK;
436 static HRESULT IDirectMusicBandTrack_IPersistStream_ParseBandTrackForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
438 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
439 HRESULT hr = E_FAIL;
440 DMUS_PRIVATE_CHUNK Chunk;
441 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
442 LARGE_INTEGER liMove; /* used when skipping chunks */
444 if (pChunk->fccID != DMUS_FOURCC_BANDTRACK_FORM) {
445 ERR_(dmfile)(": %s chunk should be a BANDTRACK form\n", debugstr_fourcc (pChunk->fccID));
446 return E_FAIL;
449 StreamSize = pChunk->dwSize - sizeof(FOURCC);
450 StreamCount = 0;
452 do {
453 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
454 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
455 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
457 hr = IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk, pStm, This->pDesc);
458 if (FAILED(hr)) return hr;
460 if (hr == S_FALSE) {
461 switch (Chunk.fccID) {
462 case DMUS_FOURCC_BANDTRACK_CHUNK: {
463 TRACE_(dmfile)(": BandTrack chunk\n");
464 IStream_Read (pStm, &This->header, sizeof(DMUS_IO_BAND_TRACK_HEADER), NULL);
465 TRACE_(dmfile)(" - bAutoDownload: %u\n", This->header.bAutoDownload);
466 break;
468 case FOURCC_LIST: {
469 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
470 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
471 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
472 ListCount[0] = 0;
473 switch (Chunk.fccID) {
474 case DMUS_FOURCC_UNFO_LIST: {
475 TRACE_(dmfile)(": UNFO list\n");
476 do {
477 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
478 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
479 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
481 hr = IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk, pStm, This->pDesc);
482 if (FAILED(hr)) return hr;
484 if (hr == S_FALSE) {
485 switch (Chunk.fccID) {
486 default: {
487 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
488 liMove.QuadPart = Chunk.dwSize;
489 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
490 break;
494 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
495 } while (ListCount[0] < ListSize[0]);
496 break;
498 case DMUS_FOURCC_BANDS_LIST: {
499 TRACE_(dmfile)(": TRACK list\n");
500 hr = IDirectMusicBandTrack_IPersistStream_ParseBandsList (iface, &Chunk, pStm);
501 if (FAILED(hr)) return hr;
502 break;
504 default: {
505 TRACE_(dmfile)(": unknown (skipping)\n");
506 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
507 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
508 break;
511 break;
513 default: {
514 TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
515 liMove.QuadPart = Chunk.dwSize;
516 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
517 break;
521 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
522 } while (StreamCount < StreamSize);
524 return S_OK;
528 static HRESULT WINAPI IDirectMusicBandTrack_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
529 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
531 DMUS_PRIVATE_CHUNK Chunk;
532 LARGE_INTEGER liMove;
533 HRESULT hr;
535 TRACE("(%p, %p): Loading\n", This, pStm);
537 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
538 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
539 switch (Chunk.fccID) {
540 case FOURCC_RIFF: {
541 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
542 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
543 switch (Chunk.fccID) {
544 case DMUS_FOURCC_BANDTRACK_FORM: {
545 TRACE_(dmfile)(": Band track form\n");
546 hr = IDirectMusicBandTrack_IPersistStream_ParseBandTrackForm (iface, &Chunk, pStm);
547 if (FAILED(hr)) return hr;
548 break;
550 default: {
551 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
552 liMove.QuadPart = Chunk.dwSize;
553 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
554 return E_FAIL;
557 TRACE_(dmfile)(": reading finished\n");
558 break;
560 default: {
561 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
562 liMove.QuadPart = Chunk.dwSize;
563 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
564 return E_FAIL;
568 return S_OK;
571 static HRESULT WINAPI IDirectMusicBandTrack_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
572 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
573 FIXME("(%p): Saving not implemented yet\n", This);
574 return E_NOTIMPL;
577 static HRESULT WINAPI IDirectMusicBandTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
578 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
579 FIXME("(%p, %p): stub\n", This, pcbSize);
580 return E_NOTIMPL;
583 static const IPersistStreamVtbl DirectMusicBandTrack_PerststStream_Vtbl = {
584 IDirectMusicBandTrack_IPersistStream_QueryInterface,
585 IDirectMusicBandTrack_IPersistStream_AddRef,
586 IDirectMusicBandTrack_IPersistStream_Release,
587 IDirectMusicBandTrack_IPersistStream_GetClassID,
588 IDirectMusicBandTrack_IPersistStream_IsDirty,
589 IDirectMusicBandTrack_IPersistStream_Load,
590 IDirectMusicBandTrack_IPersistStream_Save,
591 IDirectMusicBandTrack_IPersistStream_GetSizeMax
594 /* for ClassFactory */
595 HRESULT WINAPI DMUSIC_CreateDirectMusicBandTrack (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
596 IDirectMusicBandTrack* track;
598 track = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicBandTrack));
599 if (NULL == track) {
600 *ppobj = NULL;
601 return E_OUTOFMEMORY;
603 track->UnknownVtbl = &DirectMusicBandTrack_Unknown_Vtbl;
604 track->TrackVtbl = &DirectMusicBandTrack_DirectMusicTrack_Vtbl;
605 track->PersistStreamVtbl = &DirectMusicBandTrack_PerststStream_Vtbl;
606 track->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
607 DM_STRUCT_INIT(track->pDesc);
608 track->pDesc->dwValidData |= DMUS_OBJ_CLASS;
609 track->pDesc->guidClass = CLSID_DirectMusicBandTrack;
610 track->ref = 0; /* will be inited by QueryInterface */
611 list_init (&track->Bands);
613 return IDirectMusicBandTrack_IUnknown_QueryInterface ((LPUNKNOWN)&track->UnknownVtbl, lpcGUID, ppobj);