rsaenh/tests: Add more AES encrypt/decrypt tests.
[wine.git] / dlls / dmband / bandtrack.c
blob14e368ded46f81fe66819c692840de5f3a77aaf1
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 typedef struct IDirectMusicBandTrack {
29 const IUnknownVtbl *UnknownVtbl;
30 const IDirectMusicTrack8Vtbl *TrackVtbl;
31 const IPersistStreamVtbl *PersistStreamVtbl;
32 LONG ref;
33 DMUS_OBJECTDESC *pDesc;
34 DMUS_IO_BAND_TRACK_HEADER header;
35 struct list Bands;
36 } IDirectMusicBandTrack;
38 static HRESULT WINAPI IDirectMusicBandTrack_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
39 ICOM_THIS_MULTI(IDirectMusicBandTrack, UnknownVtbl, iface);
40 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
42 if (IsEqualIID (riid, &IID_IUnknown)) {
43 *ppobj = &This->UnknownVtbl;
44 IUnknown_AddRef (iface);
45 return S_OK;
46 } else if (IsEqualIID (riid, &IID_IDirectMusicTrack)
47 || IsEqualIID (riid, &IID_IDirectMusicTrack8)) {
48 *ppobj = (LPDIRECTMUSICTRACK8)&This->TrackVtbl;
49 IUnknown_AddRef (iface);
50 return S_OK;
51 } else if (IsEqualIID (riid, &IID_IPersistStream)) {
52 *ppobj = &This->PersistStreamVtbl;
53 IUnknown_AddRef (iface);
54 return S_OK;
57 WARN("(%p, %s,%p): not found\n", This, debugstr_dmguid(riid), ppobj);
58 return E_NOINTERFACE;
61 static ULONG WINAPI IDirectMusicBandTrack_IUnknown_AddRef (LPUNKNOWN iface) {
62 ICOM_THIS_MULTI(IDirectMusicBandTrack, UnknownVtbl, iface);
63 ULONG ref = InterlockedIncrement(&This->ref);
65 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
67 DMBAND_LockModule();
69 return ref;
72 static ULONG WINAPI IDirectMusicBandTrack_IUnknown_Release (LPUNKNOWN iface) {
73 ICOM_THIS_MULTI(IDirectMusicBandTrack, UnknownVtbl, iface);
74 ULONG ref = InterlockedDecrement(&This->ref);
76 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
78 if (ref == 0) {
79 HeapFree(GetProcessHeap(), 0, This);
82 DMBAND_UnlockModule();
84 return ref;
87 static const IUnknownVtbl DirectMusicBandTrack_Unknown_Vtbl = {
88 IDirectMusicBandTrack_IUnknown_QueryInterface,
89 IDirectMusicBandTrack_IUnknown_AddRef,
90 IDirectMusicBandTrack_IUnknown_Release
93 /* IDirectMusicBandTrack IDirectMusicTrack8 part: */
94 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_QueryInterface (LPDIRECTMUSICTRACK8 iface, REFIID riid, LPVOID *ppobj) {
95 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
96 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
99 static ULONG WINAPI IDirectMusicBandTrack_IDirectMusicTrack_AddRef (LPDIRECTMUSICTRACK8 iface) {
100 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
101 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
104 static ULONG WINAPI IDirectMusicBandTrack_IDirectMusicTrack_Release (LPDIRECTMUSICTRACK8 iface) {
105 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
106 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
109 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_Init (LPDIRECTMUSICTRACK8 iface, IDirectMusicSegment* pSegment) {
110 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
111 FIXME("(%p, %p): stub\n", This, pSegment);
112 return S_OK;
115 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_InitPlay(LPDIRECTMUSICTRACK8 iface, IDirectMusicSegmentState* segment_state, IDirectMusicPerformance* performance, void** state_data, DWORD virtual_track8id, DWORD flags)
117 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
119 FIXME("(%p, %p, %p, %p, %d, %x): stub\n", This, segment_state, performance, state_data, virtual_track8id, flags);
121 return S_OK;
124 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_EndPlay (LPDIRECTMUSICTRACK8 iface, void* pStateData) {
125 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
126 FIXME("(%p, %p): stub\n", This, pStateData);
127 return S_OK;
130 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_Play(LPDIRECTMUSICTRACK8 iface, void* state_data, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, MUSIC_TIME mtOffset, DWORD flags, IDirectMusicPerformance* performance, IDirectMusicSegmentState* segment_state, DWORD virtual_id)
132 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
134 FIXME("(%p, %p, %d, %d, %d, %x, %p, %p, %d): semi-stub\n", This, state_data, mtStart, mtEnd, mtOffset, flags, performance, segment_state, virtual_id);
136 /* Sends following pMSG:
137 - DMUS_PATCH_PMSG
138 - DMUS_TRANSPOSE_PMSG
139 - DMUS_CHANNEL_PRIORITY_PMSG
140 - DMUS_MIDI_PMSG
143 return S_OK;
146 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_GetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
147 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
148 FIXME("(%p, %s, %d, %p, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pmtNext, pParam);
149 return S_OK;
152 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_SetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, void* pParam) {
153 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
154 FIXME("(%p, %s, %d, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pParam);
155 return S_OK;
158 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_IsParamSupported (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType) {
159 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
161 TRACE("(%p, %s)\n", This, debugstr_dmguid(rguidType));
162 if (IsEqualGUID (rguidType, &GUID_BandParam)
163 || IsEqualGUID (rguidType, &GUID_Clear_All_Bands)
164 || IsEqualGUID (rguidType, &GUID_ConnectToDLSCollection)
165 || IsEqualGUID (rguidType, &GUID_Disable_Auto_Download)
166 || IsEqualGUID (rguidType, &GUID_Download)
167 || IsEqualGUID (rguidType, &GUID_DownloadToAudioPath)
168 || IsEqualGUID (rguidType, &GUID_Enable_Auto_Download)
169 || IsEqualGUID (rguidType, &GUID_IDirectMusicBand)
170 || IsEqualGUID (rguidType, &GUID_StandardMIDIFile)
171 || IsEqualGUID (rguidType, &GUID_Unload)
172 || IsEqualGUID (rguidType, &GUID_UnloadFromAudioPath)) {
173 TRACE("param supported\n");
174 return S_OK;
177 TRACE("param unsupported\n");
178 return DMUS_E_TYPE_UNSUPPORTED;
181 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_AddNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
182 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
183 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
184 return S_OK;
187 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_RemoveNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
188 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
189 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
190 return S_OK;
193 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_Clone (LPDIRECTMUSICTRACK8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicTrack** ppTrack) {
194 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
195 FIXME("(%p, %d, %d, %p): stub\n", This, mtStart, mtEnd, ppTrack);
196 return S_OK;
199 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_PlayEx(LPDIRECTMUSICTRACK8 iface, void* state_data, REFERENCE_TIME rtStart, REFERENCE_TIME rtEnd, REFERENCE_TIME rtOffset, DWORD flags, IDirectMusicPerformance* performance, IDirectMusicSegmentState* segment_state, DWORD virtual_id)
201 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
203 FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %x, %p, %p, %d): stub\n", This, state_data, wine_dbgstr_longlong(rtStart),
204 wine_dbgstr_longlong(rtEnd), wine_dbgstr_longlong(rtOffset), flags, performance, segment_state, virtual_id);
206 return S_OK;
209 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_GetParamEx(LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, REFERENCE_TIME* rtNext, void* param, void* state_data, DWORD flags)
211 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
213 FIXME("(%p, %s, 0x%s, %p, %p, %p, %x): stub\n", This, debugstr_dmguid(rguidType),
214 wine_dbgstr_longlong(rtTime), rtNext, param, state_data, flags);
216 return S_OK;
219 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_SetParamEx(LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, void* param, void* state_data, DWORD flags)
221 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
223 FIXME("(%p, %s, 0x%s, %p, %p, %x): stub\n", This, debugstr_dmguid(rguidType),
224 wine_dbgstr_longlong(rtTime), param, state_data, flags);
226 return S_OK;
229 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_Compose (LPDIRECTMUSICTRACK8 iface, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
230 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
231 FIXME("(%p, %p, %d, %p): stub\n", This, pContext, dwTrackGroup, ppResultTrack);
232 return S_OK;
235 static HRESULT WINAPI IDirectMusicBandTrack_IDirectMusicTrack_Join (LPDIRECTMUSICTRACK8 iface, IDirectMusicTrack* pNewTrack, MUSIC_TIME mtJoin, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
236 ICOM_THIS_MULTI(IDirectMusicBandTrack, TrackVtbl, iface);
237 FIXME("(%p, %p, %d, %p, %d, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
238 return S_OK;
241 static const IDirectMusicTrack8Vtbl DirectMusicBandTrack_DirectMusicTrack_Vtbl = {
242 IDirectMusicBandTrack_IDirectMusicTrack_QueryInterface,
243 IDirectMusicBandTrack_IDirectMusicTrack_AddRef,
244 IDirectMusicBandTrack_IDirectMusicTrack_Release,
245 IDirectMusicBandTrack_IDirectMusicTrack_Init,
246 IDirectMusicBandTrack_IDirectMusicTrack_InitPlay,
247 IDirectMusicBandTrack_IDirectMusicTrack_EndPlay,
248 IDirectMusicBandTrack_IDirectMusicTrack_Play,
249 IDirectMusicBandTrack_IDirectMusicTrack_GetParam,
250 IDirectMusicBandTrack_IDirectMusicTrack_SetParam,
251 IDirectMusicBandTrack_IDirectMusicTrack_IsParamSupported,
252 IDirectMusicBandTrack_IDirectMusicTrack_AddNotificationType,
253 IDirectMusicBandTrack_IDirectMusicTrack_RemoveNotificationType,
254 IDirectMusicBandTrack_IDirectMusicTrack_Clone,
255 IDirectMusicBandTrack_IDirectMusicTrack_PlayEx,
256 IDirectMusicBandTrack_IDirectMusicTrack_GetParamEx,
257 IDirectMusicBandTrack_IDirectMusicTrack_SetParamEx,
258 IDirectMusicBandTrack_IDirectMusicTrack_Compose,
259 IDirectMusicBandTrack_IDirectMusicTrack_Join
262 /* IDirectMusicBandTrack IPersistStream part: */
263 static HRESULT WINAPI IDirectMusicBandTrack_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
264 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
265 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
268 static ULONG WINAPI IDirectMusicBandTrack_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
269 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
270 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
273 static ULONG WINAPI IDirectMusicBandTrack_IPersistStream_Release (LPPERSISTSTREAM iface) {
274 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
275 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
278 static HRESULT WINAPI IDirectMusicBandTrack_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
279 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
280 TRACE("(%p, %p)\n", This, pClassID);
281 *pClassID = CLSID_DirectMusicBandTrack;
282 return S_OK;
285 static HRESULT WINAPI IDirectMusicBandTrack_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
286 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
287 FIXME("(%p): stub, always S_FALSE\n", This);
288 return S_FALSE;
291 static HRESULT IDirectMusicBandTrack_IPersistStream_LoadBand (LPPERSISTSTREAM iface, IStream* pClonedStream, IDirectMusicBand** ppBand,
292 DMUS_PRIVATE_BAND_ITEM_HEADER* pHeader) {
294 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
295 HRESULT hr = E_FAIL;
296 IPersistStream* pPersistStream = NULL;
298 hr = CoCreateInstance (&CLSID_DirectMusicBand, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicBand, (LPVOID*) ppBand);
299 if (FAILED(hr)) {
300 ERR(": could not create object\n");
301 return hr;
303 /* acquire PersistStream interface */
304 hr = IDirectMusicBand_QueryInterface (*ppBand, &IID_IPersistStream, (LPVOID*) &pPersistStream);
305 if (FAILED(hr)) {
306 ERR(": could not acquire IPersistStream\n");
307 return hr;
309 /* load */
310 hr = IPersistStream_Load (pPersistStream, pClonedStream);
311 if (FAILED(hr)) {
312 ERR(": failed to load object\n");
313 return hr;
316 /* release all loading-related stuff */
317 IPersistStream_Release (pPersistStream);
320 * @TODO insert pBand into This
322 if (SUCCEEDED(hr)) {
323 LPDMUS_PRIVATE_BAND pNewBand = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_BAND));
324 if (NULL == pNewBand) {
325 ERR(": no more memory\n");
326 return E_OUTOFMEMORY;
328 pNewBand->BandHeader = *pHeader;
329 pNewBand->band = *ppBand;
330 IDirectMusicBand_AddRef(*ppBand);
331 list_add_tail (&This->Bands, &pNewBand->entry);
334 return S_OK;
337 static HRESULT IDirectMusicBandTrack_IPersistStream_ParseBandsList (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
339 /*ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);*/
340 HRESULT hr = E_FAIL;
341 DMUS_PRIVATE_CHUNK Chunk;
342 DWORD StreamSize, ListSize[3], ListCount[3];
343 LARGE_INTEGER liMove; /* used when skipping chunks */
345 IDirectMusicBand* pBand = NULL;
346 DMUS_PRIVATE_BAND_ITEM_HEADER header;
348 memset(&header, 0, sizeof header);
350 if (pChunk->fccID != DMUS_FOURCC_BANDS_LIST) {
351 ERR_(dmfile)(": %s chunk should be a BANDS list\n", debugstr_fourcc (pChunk->fccID));
352 return E_FAIL;
355 ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
356 ListCount[0] = 0;
358 do {
359 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
360 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
361 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
362 switch (Chunk.fccID) {
363 case FOURCC_LIST: {
364 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
365 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
366 ListSize[1] = Chunk.dwSize - sizeof(FOURCC);
367 ListCount[1] = 0;
368 do {
369 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
370 ListCount[1] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
371 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
372 switch (Chunk.fccID) {
373 case DMUS_FOURCC_BANDITEM_CHUNK: {
374 DMUS_IO_BAND_ITEM_HEADER tmp_header;
375 TRACE_(dmfile)(": Band Item chunk v1\n");
377 IStream_Read (pStm, &tmp_header, sizeof(DMUS_IO_BAND_ITEM_HEADER), NULL);
378 TRACE_(dmfile)(" - lBandTime: %u\n", tmp_header.lBandTime);
380 header.dwVersion = 1;
381 header.lBandTime = tmp_header.lBandTime;
382 break;
384 case DMUS_FOURCC_BANDITEM_CHUNK2: {
385 DMUS_IO_BAND_ITEM_HEADER2 tmp_header2;
386 TRACE_(dmfile)(": Band Item chunk v2\n");
388 IStream_Read (pStm, &tmp_header2, sizeof(DMUS_IO_BAND_ITEM_HEADER2), NULL);
389 TRACE_(dmfile)(" - lBandTimeLogical: %u\n", tmp_header2.lBandTimeLogical);
390 TRACE_(dmfile)(" - lBandTimePhysical: %u\n", tmp_header2.lBandTimePhysical);
392 header.dwVersion = 2;
393 header.lBandTimeLogical = tmp_header2.lBandTimeLogical;
394 header.lBandTimePhysical = tmp_header2.lBandTimePhysical;
395 break;
397 case FOURCC_RIFF: {
398 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
399 TRACE_(dmfile)(": RIFF chunk of type %s\n", debugstr_fourcc(Chunk.fccID));
400 StreamSize = Chunk.dwSize - sizeof(FOURCC);
401 switch (Chunk.fccID) {
402 case DMUS_FOURCC_BAND_FORM: {
403 LPSTREAM pClonedStream = NULL;
404 TRACE_(dmfile)(": BAND RIFF\n");
406 IStream_Clone (pStm, &pClonedStream);
408 liMove.QuadPart = 0;
409 liMove.QuadPart -= sizeof(FOURCC) + (sizeof(FOURCC)+sizeof(DWORD));
410 IStream_Seek (pClonedStream, liMove, STREAM_SEEK_CUR, NULL);
412 hr = IDirectMusicBandTrack_IPersistStream_LoadBand (iface, pClonedStream, &pBand, &header);
413 if (FAILED(hr)) {
414 ERR(": could not load track\n");
415 return hr;
417 IStream_Release (pClonedStream);
419 IDirectMusicTrack_Release(pBand); pBand = NULL; /* now we can release at as it inserted */
421 /** now safe move the cursor */
422 liMove.QuadPart = StreamSize;
423 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
424 break;
426 default: {
427 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
428 liMove.QuadPart = StreamSize;
429 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
430 break;
433 break;
435 default: {
436 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
437 liMove.QuadPart = Chunk.dwSize;
438 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
439 break;
442 TRACE_(dmfile)(": ListCount[1] = %d < ListSize[1] = %d\n", ListCount[1], ListSize[1]);
443 } while (ListCount[1] < ListSize[1]);
444 break;
446 default: {
447 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
448 liMove.QuadPart = Chunk.dwSize;
449 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
450 break;
453 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
454 } while (ListCount[0] < ListSize[0]);
456 return S_OK;
459 static HRESULT IDirectMusicBandTrack_IPersistStream_ParseBandTrackForm (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm) {
461 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
462 HRESULT hr = E_FAIL;
463 DMUS_PRIVATE_CHUNK Chunk;
464 DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
465 LARGE_INTEGER liMove; /* used when skipping chunks */
467 if (pChunk->fccID != DMUS_FOURCC_BANDTRACK_FORM) {
468 ERR_(dmfile)(": %s chunk should be a BANDTRACK form\n", debugstr_fourcc (pChunk->fccID));
469 return E_FAIL;
472 StreamSize = pChunk->dwSize - sizeof(FOURCC);
473 StreamCount = 0;
475 do {
476 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
477 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
478 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
480 hr = IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk, pStm, This->pDesc);
481 if (FAILED(hr)) return hr;
483 if (hr == S_FALSE) {
484 switch (Chunk.fccID) {
485 case DMUS_FOURCC_BANDTRACK_CHUNK: {
486 TRACE_(dmfile)(": BandTrack chunk\n");
487 IStream_Read (pStm, &This->header, sizeof(DMUS_IO_BAND_TRACK_HEADER), NULL);
488 TRACE_(dmfile)(" - bAutoDownload: %u\n", This->header.bAutoDownload);
489 break;
491 case FOURCC_LIST: {
492 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
493 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
494 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
495 ListCount[0] = 0;
496 switch (Chunk.fccID) {
497 case DMUS_FOURCC_UNFO_LIST: {
498 TRACE_(dmfile)(": UNFO list\n");
499 do {
500 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
501 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
502 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
504 hr = IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk, pStm, This->pDesc);
505 if (FAILED(hr)) return hr;
507 if (hr == S_FALSE) {
508 switch (Chunk.fccID) {
509 default: {
510 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
511 liMove.QuadPart = Chunk.dwSize;
512 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
513 break;
517 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
518 } while (ListCount[0] < ListSize[0]);
519 break;
521 case DMUS_FOURCC_BANDS_LIST: {
522 TRACE_(dmfile)(": TRACK list\n");
523 hr = IDirectMusicBandTrack_IPersistStream_ParseBandsList (iface, &Chunk, pStm);
524 if (FAILED(hr)) return hr;
525 break;
527 default: {
528 TRACE_(dmfile)(": unknown (skipping)\n");
529 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
530 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
531 break;
534 break;
536 default: {
537 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
538 liMove.QuadPart = Chunk.dwSize;
539 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
540 break;
544 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
545 } while (StreamCount < StreamSize);
547 return S_OK;
551 static HRESULT WINAPI IDirectMusicBandTrack_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
552 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
554 DMUS_PRIVATE_CHUNK Chunk;
555 LARGE_INTEGER liMove;
556 HRESULT hr;
558 TRACE("(%p, %p): Loading\n", This, pStm);
560 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
561 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
562 switch (Chunk.fccID) {
563 case FOURCC_RIFF: {
564 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
565 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
566 switch (Chunk.fccID) {
567 case DMUS_FOURCC_BANDTRACK_FORM: {
568 TRACE_(dmfile)(": Band track form\n");
569 hr = IDirectMusicBandTrack_IPersistStream_ParseBandTrackForm (iface, &Chunk, pStm);
570 if (FAILED(hr)) return hr;
571 break;
573 default: {
574 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
575 liMove.QuadPart = Chunk.dwSize;
576 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
577 return E_FAIL;
580 TRACE_(dmfile)(": reading finished\n");
581 break;
583 default: {
584 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
585 liMove.QuadPart = Chunk.dwSize;
586 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
587 return E_FAIL;
591 return S_OK;
594 static HRESULT WINAPI IDirectMusicBandTrack_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
595 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
596 FIXME("(%p): Saving not implemented yet\n", This);
597 return E_NOTIMPL;
600 static HRESULT WINAPI IDirectMusicBandTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
601 ICOM_THIS_MULTI(IDirectMusicBandTrack, PersistStreamVtbl, iface);
602 FIXME("(%p, %p): stub\n", This, pcbSize);
603 return E_NOTIMPL;
606 static const IPersistStreamVtbl DirectMusicBandTrack_PerststStream_Vtbl = {
607 IDirectMusicBandTrack_IPersistStream_QueryInterface,
608 IDirectMusicBandTrack_IPersistStream_AddRef,
609 IDirectMusicBandTrack_IPersistStream_Release,
610 IDirectMusicBandTrack_IPersistStream_GetClassID,
611 IDirectMusicBandTrack_IPersistStream_IsDirty,
612 IDirectMusicBandTrack_IPersistStream_Load,
613 IDirectMusicBandTrack_IPersistStream_Save,
614 IDirectMusicBandTrack_IPersistStream_GetSizeMax
617 /* for ClassFactory */
618 HRESULT WINAPI create_dmbandtrack(REFIID lpcGUID, void **ppobj)
620 IDirectMusicBandTrack* track;
622 track = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicBandTrack));
623 if (NULL == track) {
624 *ppobj = NULL;
625 return E_OUTOFMEMORY;
627 track->UnknownVtbl = &DirectMusicBandTrack_Unknown_Vtbl;
628 track->TrackVtbl = &DirectMusicBandTrack_DirectMusicTrack_Vtbl;
629 track->PersistStreamVtbl = &DirectMusicBandTrack_PerststStream_Vtbl;
630 track->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
631 DM_STRUCT_INIT(track->pDesc);
632 track->pDesc->dwValidData |= DMUS_OBJ_CLASS;
633 track->pDesc->guidClass = CLSID_DirectMusicBandTrack;
634 track->ref = 0; /* will be inited by QueryInterface */
635 list_init (&track->Bands);
637 return IDirectMusicBandTrack_IUnknown_QueryInterface ((LPUNKNOWN)&track->UnknownVtbl, lpcGUID, ppobj);