1 /* IDirectMusicTempoTrack Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
4 * Copyright (C) 2004 Raphael Junqueira
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "dmime_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
24 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
26 /*****************************************************************************
27 * IDirectMusicTempoTrack implementation
29 /* IDirectMusicTempoTrack IUnknown part: */
30 static HRESULT WINAPI IDirectMusicTempoTrack_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
31 ICOM_THIS_MULTI(IDirectMusicTempoTrack, UnknownVtbl, iface);
32 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
34 if (IsEqualIID (riid, &IID_IUnknown)) {
35 *ppobj = (LPUNKNOWN)&This->UnknownVtbl;
36 IUnknown_AddRef (iface);
38 } else if (IsEqualIID (riid, &IID_IDirectMusicTrack)
39 || IsEqualIID (riid, &IID_IDirectMusicTrack8)) {
40 *ppobj = (LPDIRECTMUSICTRACK8)&This->TrackVtbl;
41 IUnknown_AddRef (iface);
43 } else if (IsEqualIID (riid, &IID_IPersistStream)) {
44 *ppobj = (LPPERSISTSTREAM)&This->PersistStreamVtbl;
45 IUnknown_AddRef (iface);
49 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
53 static ULONG WINAPI IDirectMusicTempoTrack_IUnknown_AddRef (LPUNKNOWN iface) {
54 ICOM_THIS_MULTI(IDirectMusicTempoTrack, UnknownVtbl, iface);
55 ULONG ref = InterlockedIncrement(&This->ref);
57 TRACE("(%p): AddRef from %d\n", This, ref - 1);
64 static ULONG WINAPI IDirectMusicTempoTrack_IUnknown_Release (LPUNKNOWN iface) {
65 ICOM_THIS_MULTI(IDirectMusicTempoTrack, UnknownVtbl, iface);
66 ULONG ref = InterlockedDecrement(&This->ref);
67 TRACE("(%p): ReleaseRef to %d\n", This, ref);
70 HeapFree(GetProcessHeap(), 0, This);
78 static const IUnknownVtbl DirectMusicTempoTrack_Unknown_Vtbl = {
79 IDirectMusicTempoTrack_IUnknown_QueryInterface,
80 IDirectMusicTempoTrack_IUnknown_AddRef,
81 IDirectMusicTempoTrack_IUnknown_Release
84 /* IDirectMusicTempoTrack IDirectMusicTrack8 part: */
85 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_QueryInterface (LPDIRECTMUSICTRACK8 iface, REFIID riid, LPVOID *ppobj) {
86 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
87 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
90 static ULONG WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_AddRef (LPDIRECTMUSICTRACK8 iface) {
91 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
92 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
95 static ULONG WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Release (LPDIRECTMUSICTRACK8 iface) {
96 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
97 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
100 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Init (LPDIRECTMUSICTRACK8 iface, IDirectMusicSegment* pSegment)
102 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
103 TRACE("(%p, %p): nothing to do here\n", This, pSegment);
107 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_InitPlay (LPDIRECTMUSICTRACK8 iface, IDirectMusicSegmentState* pSegmentState, IDirectMusicPerformance* pPerformance, void** ppStateData, DWORD dwVirtualTrack8ID, DWORD dwFlags)
109 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
111 LPDMUS_PRIVATE_TEMPO_PLAY_STATE pState = NULL;
113 FIXME("(%p, %p, %p, %p, %d, %d): semi-stub\n", This, pSegmentState, pPerformance, ppStateData, dwVirtualTrack8ID, dwFlags);
115 pState = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_TEMPO_PLAY_STATE));
116 if (NULL == pState) {
117 ERR(": no more memory\n");
118 return E_OUTOFMEMORY;
120 /** TODO real fill useful data */
122 *ppStateData = pState;
126 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_EndPlay (LPDIRECTMUSICTRACK8 iface, void* pStateData)
128 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
130 LPDMUS_PRIVATE_TEMPO_PLAY_STATE pState = pStateData;
132 FIXME("(%p, %p): semi-stub\n", This, pStateData);
134 if (NULL == pStateData) {
137 /** TODO real clean up */
138 HeapFree(GetProcessHeap(), 0, pState);
142 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Play (LPDIRECTMUSICTRACK8 iface, void* pStateData, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, MUSIC_TIME mtOffset, DWORD dwFlags, IDirectMusicPerformance* pPerf, IDirectMusicSegmentState* pSegSt, DWORD dwVirtualID)
144 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
145 FIXME("(%p, %p, %ld, %ld, %ld, %d, %p, %p, %d): stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
146 /** should use IDirectMusicPerformance_SendPMsg here */
150 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_GetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
151 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
154 struct list* pEntry = NULL;
155 LPDMUS_PRIVATE_TEMPO_ITEM pIt = NULL;
156 DMUS_TEMPO_PARAM* prm = pParam;
158 FIXME("(%p, %s, %ld, %p, %p): almost stub\n", This, debugstr_dmguid(rguidType), mtTime, pmtNext, pParam);
160 if (NULL == pParam) {
164 hr = IDirectMusicTrack_IsParamSupported (iface, rguidType);
168 if (FALSE == This->enabled) {
169 return DMUS_E_TYPE_DISABLED;
172 if (NULL != pmtNext) *pmtNext = 0;
174 prm->dblTempo = 0.123456;
176 LIST_FOR_EACH (pEntry, &This->Items) {
177 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_TEMPO_ITEM, entry);
178 /*TRACE(" - %p -> 0x%lx,%p\n", pIt, pIt->item.lTime, pIt->item.dblTempo);*/
179 if (pIt->item.lTime <= mtTime) {
180 MUSIC_TIME ofs = pIt->item.lTime - mtTime;
181 if (ofs > prm->mtTime) {
183 prm->dblTempo = pIt->item.dblTempo;
185 if (NULL != pmtNext && pIt->item.lTime > mtTime) {
186 if (pIt->item.lTime < *pmtNext) {
187 *pmtNext = pIt->item.lTime;
193 if (0.123456 == prm->dblTempo) {
194 return DMUS_E_NOT_FOUND;
199 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_SetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, void* pParam) {
200 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
201 FIXME("(%p, %s, %ld, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pParam);
205 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_IsParamSupported (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType) {
206 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
208 TRACE("(%p, %s)\n", This, debugstr_dmguid(rguidType));
209 if (IsEqualGUID (rguidType, &GUID_DisableTempo)
210 || IsEqualGUID (rguidType, &GUID_EnableTempo)
211 || IsEqualGUID (rguidType, &GUID_TempoParam)) {
212 TRACE("param supported\n");
215 if (FALSE == This->enabled) {
216 return DMUS_E_TYPE_DISABLED;
218 TRACE("param unsupported\n");
219 return DMUS_E_TYPE_UNSUPPORTED;
222 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_AddNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
223 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
224 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
228 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_RemoveNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
229 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
230 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
234 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Clone (LPDIRECTMUSICTRACK8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicTrack** ppTrack) {
235 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
236 FIXME("(%p, %ld, %ld, %p): stub\n", This, mtStart, mtEnd, ppTrack);
240 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_PlayEx (LPDIRECTMUSICTRACK8 iface, void* pStateData, REFERENCE_TIME rtStart, REFERENCE_TIME rtEnd, REFERENCE_TIME rtOffset, DWORD dwFlags, IDirectMusicPerformance* pPerf, IDirectMusicSegmentState* pSegSt, DWORD dwVirtualID) {
241 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
242 FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %d, %p, %p, %d): stub\n", This, pStateData, wine_dbgstr_longlong(rtStart),
243 wine_dbgstr_longlong(rtEnd), wine_dbgstr_longlong(rtOffset), dwFlags, pPerf, pSegSt, dwVirtualID);
247 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_GetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, REFERENCE_TIME* prtNext, void* pParam, void* pStateData, DWORD dwFlags) {
248 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
249 FIXME("(%p, %s, 0x%s, %p, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
250 wine_dbgstr_longlong(rtTime), prtNext, pParam, pStateData, dwFlags);
254 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_SetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, void* pParam, void* pStateData, DWORD dwFlags) {
255 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
256 FIXME("(%p, %s, 0x%s, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
257 wine_dbgstr_longlong(rtTime), pParam, pStateData, dwFlags);
261 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Compose (LPDIRECTMUSICTRACK8 iface, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
262 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
263 FIXME("(%p, %p, %d, %p): stub\n", This, pContext, dwTrackGroup, ppResultTrack);
267 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Join (LPDIRECTMUSICTRACK8 iface, IDirectMusicTrack* pNewTrack, MUSIC_TIME mtJoin, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
268 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
269 FIXME("(%p, %p, %ld, %p, %d, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
273 static const IDirectMusicTrack8Vtbl DirectMusicTempoTrack_Track_Vtbl = {
274 IDirectMusicTempoTrack_IDirectMusicTrack_QueryInterface,
275 IDirectMusicTempoTrack_IDirectMusicTrack_AddRef,
276 IDirectMusicTempoTrack_IDirectMusicTrack_Release,
277 IDirectMusicTempoTrack_IDirectMusicTrack_Init,
278 IDirectMusicTempoTrack_IDirectMusicTrack_InitPlay,
279 IDirectMusicTempoTrack_IDirectMusicTrack_EndPlay,
280 IDirectMusicTempoTrack_IDirectMusicTrack_Play,
281 IDirectMusicTempoTrack_IDirectMusicTrack_GetParam,
282 IDirectMusicTempoTrack_IDirectMusicTrack_SetParam,
283 IDirectMusicTempoTrack_IDirectMusicTrack_IsParamSupported,
284 IDirectMusicTempoTrack_IDirectMusicTrack_AddNotificationType,
285 IDirectMusicTempoTrack_IDirectMusicTrack_RemoveNotificationType,
286 IDirectMusicTempoTrack_IDirectMusicTrack_Clone,
287 IDirectMusicTempoTrack_IDirectMusicTrack_PlayEx,
288 IDirectMusicTempoTrack_IDirectMusicTrack_GetParamEx,
289 IDirectMusicTempoTrack_IDirectMusicTrack_SetParamEx,
290 IDirectMusicTempoTrack_IDirectMusicTrack_Compose,
291 IDirectMusicTempoTrack_IDirectMusicTrack_Join
294 /* IDirectMusicTempoTrack IPersistStream part: */
295 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
296 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
297 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
300 static ULONG WINAPI IDirectMusicTempoTrack_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
301 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
302 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
305 static ULONG WINAPI IDirectMusicTempoTrack_IPersistStream_Release (LPPERSISTSTREAM iface) {
306 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
307 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
310 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
311 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
312 TRACE("(%p, %p)\n", This, pClassID);
313 *pClassID = CLSID_DirectMusicTempoTrack;
317 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
318 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
319 FIXME("(%p): stub, always S_FALSE\n", This);
323 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
324 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
325 DMUS_PRIVATE_CHUNK Chunk;
326 DWORD StreamSize, StreamCount;
327 LARGE_INTEGER liMove;
328 DMUS_IO_TEMPO_ITEM item;
329 LPDMUS_PRIVATE_TEMPO_ITEM pNewItem = NULL;
331 FIXME("(%p, %p): Loading not fully implemented yet\n", This, pStm);
334 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
335 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
336 switch (Chunk.fccID) {
337 case DMUS_FOURCC_TEMPO_TRACK: {
338 TRACE_(dmfile)(": Tempo track\n");
340 IStream_Read (pStm, &StreamSize, sizeof(DWORD), NULL);
341 StreamSize -= sizeof(DWORD);
343 TRACE_(dmfile)(" - sizeof(DMUS_IO_TEMPO_ITEM): %u (chunkSize = %u)\n", StreamSize, Chunk.dwSize);
345 IStream_Read (pStm, &item, sizeof(item), NULL);
347 TRACE_(dmfile)("DMUS_IO_TEMPO_ITEM #%d\n", nItem);
348 TRACE_(dmfile)(" - lTime = %lu\n", item.lTime);
349 TRACE_(dmfile)(" - dblTempo = %g\n", item.dblTempo);
350 pNewItem = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_TEMPO_ITEM));
351 if (NULL == pNewItem) {
352 ERR(": no more memory\n");
353 return E_OUTOFMEMORY;
355 pNewItem->item = item;
356 list_add_tail (&This->Items, &pNewItem->entry);
358 StreamCount += sizeof(item);
359 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
360 } while (StreamCount < StreamSize);
362 liMove.QuadPart = Chunk.dwSize;
363 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
368 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
369 liMove.QuadPart = Chunk.dwSize;
370 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
379 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
380 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
381 FIXME("(%p): Saving not implemented yet\n", This);
385 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
386 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
387 FIXME("(%p, %p): stub\n", This, pcbSize);
391 static const IPersistStreamVtbl DirectMusicTempoTrack_PersistStream_Vtbl = {
392 IDirectMusicTempoTrack_IPersistStream_QueryInterface,
393 IDirectMusicTempoTrack_IPersistStream_AddRef,
394 IDirectMusicTempoTrack_IPersistStream_Release,
395 IDirectMusicTempoTrack_IPersistStream_GetClassID,
396 IDirectMusicTempoTrack_IPersistStream_IsDirty,
397 IDirectMusicTempoTrack_IPersistStream_Load,
398 IDirectMusicTempoTrack_IPersistStream_Save,
399 IDirectMusicTempoTrack_IPersistStream_GetSizeMax
402 /* for ClassFactory */
403 HRESULT WINAPI DMUSIC_CreateDirectMusicTempoTrack (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
404 IDirectMusicTempoTrack* track;
406 track = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicTempoTrack));
409 return E_OUTOFMEMORY;
411 track->UnknownVtbl = &DirectMusicTempoTrack_Unknown_Vtbl;
412 track->TrackVtbl = &DirectMusicTempoTrack_Track_Vtbl;
413 track->PersistStreamVtbl = &DirectMusicTempoTrack_PersistStream_Vtbl;
414 track->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
415 DM_STRUCT_INIT(track->pDesc);
416 track->pDesc->dwValidData |= DMUS_OBJ_CLASS;
417 track->pDesc->guidClass = CLSID_DirectMusicTempoTrack;
418 track->ref = 0; /* will be inited by QueryInterface */
419 track->enabled = TRUE;
420 list_init (&track->Items);
422 return IDirectMusicTempoTrack_IUnknown_QueryInterface ((LPUNKNOWN)&track->UnknownVtbl, lpcGUID, ppobj);