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 = &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 = &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));
117 return E_OUTOFMEMORY;
119 /** TODO real fill useful data */
121 *ppStateData = pState;
125 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_EndPlay (LPDIRECTMUSICTRACK8 iface, void* pStateData)
127 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
129 LPDMUS_PRIVATE_TEMPO_PLAY_STATE pState = pStateData;
131 FIXME("(%p, %p): semi-stub\n", This, pStateData);
133 if (NULL == pStateData) {
136 /** TODO real clean up */
137 HeapFree(GetProcessHeap(), 0, pState);
141 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)
143 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
144 FIXME("(%p, %p, %d, %d, %d, %d, %p, %p, %d): stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
145 /** should use IDirectMusicPerformance_SendPMsg here */
149 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_GetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
150 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
153 struct list* pEntry = NULL;
154 LPDMUS_PRIVATE_TEMPO_ITEM pIt = NULL;
155 DMUS_TEMPO_PARAM* prm = pParam;
157 FIXME("(%p, %s, %d, %p, %p): almost stub\n", This, debugstr_dmguid(rguidType), mtTime, pmtNext, pParam);
159 if (NULL == pParam) {
163 hr = IDirectMusicTrack_IsParamSupported (iface, rguidType);
167 if (FALSE == This->enabled) {
168 return DMUS_E_TYPE_DISABLED;
171 if (NULL != pmtNext) *pmtNext = 0;
173 prm->dblTempo = 0.123456;
175 LIST_FOR_EACH (pEntry, &This->Items) {
176 pIt = LIST_ENTRY(pEntry, DMUS_PRIVATE_TEMPO_ITEM, entry);
177 /*TRACE(" - %p -> 0x%lx,%p\n", pIt, pIt->item.lTime, pIt->item.dblTempo);*/
178 if (pIt->item.lTime <= mtTime) {
179 MUSIC_TIME ofs = pIt->item.lTime - mtTime;
180 if (ofs > prm->mtTime) {
182 prm->dblTempo = pIt->item.dblTempo;
184 if (NULL != pmtNext && pIt->item.lTime > mtTime) {
185 if (pIt->item.lTime < *pmtNext) {
186 *pmtNext = pIt->item.lTime;
192 if (0.123456 == prm->dblTempo) {
193 return DMUS_E_NOT_FOUND;
198 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_SetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, void* pParam) {
199 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
200 FIXME("(%p, %s, %d, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pParam);
204 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_IsParamSupported (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType) {
205 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
207 TRACE("(%p, %s)\n", This, debugstr_dmguid(rguidType));
208 if (IsEqualGUID (rguidType, &GUID_DisableTempo)
209 || IsEqualGUID (rguidType, &GUID_EnableTempo)
210 || IsEqualGUID (rguidType, &GUID_TempoParam)) {
211 TRACE("param supported\n");
214 if (FALSE == This->enabled) {
215 return DMUS_E_TYPE_DISABLED;
217 TRACE("param unsupported\n");
218 return DMUS_E_TYPE_UNSUPPORTED;
221 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_AddNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
222 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
223 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
227 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_RemoveNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType) {
228 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
229 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
233 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Clone (LPDIRECTMUSICTRACK8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicTrack** ppTrack) {
234 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
235 FIXME("(%p, %d, %d, %p): stub\n", This, mtStart, mtEnd, ppTrack);
239 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) {
240 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
241 FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %d, %p, %p, %d): stub\n", This, pStateData, wine_dbgstr_longlong(rtStart),
242 wine_dbgstr_longlong(rtEnd), wine_dbgstr_longlong(rtOffset), dwFlags, pPerf, pSegSt, dwVirtualID);
246 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_GetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, REFERENCE_TIME* prtNext, void* pParam, void* pStateData, DWORD dwFlags) {
247 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
248 FIXME("(%p, %s, 0x%s, %p, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
249 wine_dbgstr_longlong(rtTime), prtNext, pParam, pStateData, dwFlags);
253 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_SetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, void* pParam, void* pStateData, DWORD dwFlags) {
254 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
255 FIXME("(%p, %s, 0x%s, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
256 wine_dbgstr_longlong(rtTime), pParam, pStateData, dwFlags);
260 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Compose (LPDIRECTMUSICTRACK8 iface, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
261 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
262 FIXME("(%p, %p, %d, %p): stub\n", This, pContext, dwTrackGroup, ppResultTrack);
266 static HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Join (LPDIRECTMUSICTRACK8 iface, IDirectMusicTrack* pNewTrack, MUSIC_TIME mtJoin, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
267 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
268 FIXME("(%p, %p, %d, %p, %d, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
272 static const IDirectMusicTrack8Vtbl DirectMusicTempoTrack_Track_Vtbl = {
273 IDirectMusicTempoTrack_IDirectMusicTrack_QueryInterface,
274 IDirectMusicTempoTrack_IDirectMusicTrack_AddRef,
275 IDirectMusicTempoTrack_IDirectMusicTrack_Release,
276 IDirectMusicTempoTrack_IDirectMusicTrack_Init,
277 IDirectMusicTempoTrack_IDirectMusicTrack_InitPlay,
278 IDirectMusicTempoTrack_IDirectMusicTrack_EndPlay,
279 IDirectMusicTempoTrack_IDirectMusicTrack_Play,
280 IDirectMusicTempoTrack_IDirectMusicTrack_GetParam,
281 IDirectMusicTempoTrack_IDirectMusicTrack_SetParam,
282 IDirectMusicTempoTrack_IDirectMusicTrack_IsParamSupported,
283 IDirectMusicTempoTrack_IDirectMusicTrack_AddNotificationType,
284 IDirectMusicTempoTrack_IDirectMusicTrack_RemoveNotificationType,
285 IDirectMusicTempoTrack_IDirectMusicTrack_Clone,
286 IDirectMusicTempoTrack_IDirectMusicTrack_PlayEx,
287 IDirectMusicTempoTrack_IDirectMusicTrack_GetParamEx,
288 IDirectMusicTempoTrack_IDirectMusicTrack_SetParamEx,
289 IDirectMusicTempoTrack_IDirectMusicTrack_Compose,
290 IDirectMusicTempoTrack_IDirectMusicTrack_Join
293 /* IDirectMusicTempoTrack IPersistStream part: */
294 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
295 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
296 return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
299 static ULONG WINAPI IDirectMusicTempoTrack_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
300 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
301 return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
304 static ULONG WINAPI IDirectMusicTempoTrack_IPersistStream_Release (LPPERSISTSTREAM iface) {
305 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
306 return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
309 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
310 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
311 TRACE("(%p, %p)\n", This, pClassID);
312 *pClassID = CLSID_DirectMusicTempoTrack;
316 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
317 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
318 FIXME("(%p): stub, always S_FALSE\n", This);
322 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
323 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
324 DMUS_PRIVATE_CHUNK Chunk;
325 DWORD StreamSize, StreamCount;
326 LARGE_INTEGER liMove;
327 DMUS_IO_TEMPO_ITEM item;
328 LPDMUS_PRIVATE_TEMPO_ITEM pNewItem = NULL;
330 FIXME("(%p, %p): Loading not fully implemented yet\n", This, pStm);
333 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
334 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
335 switch (Chunk.fccID) {
336 case DMUS_FOURCC_TEMPO_TRACK: {
337 TRACE_(dmfile)(": Tempo track\n");
339 IStream_Read (pStm, &StreamSize, sizeof(DWORD), NULL);
340 StreamSize -= sizeof(DWORD);
342 TRACE_(dmfile)(" - sizeof(DMUS_IO_TEMPO_ITEM): %u (chunkSize = %u)\n", StreamSize, Chunk.dwSize);
344 IStream_Read (pStm, &item, sizeof(item), NULL);
346 TRACE_(dmfile)("DMUS_IO_TEMPO_ITEM #%d\n", nItem);
347 TRACE_(dmfile)(" - lTime = %u\n", item.lTime);
348 TRACE_(dmfile)(" - dblTempo = %g\n", item.dblTempo);
349 pNewItem = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_TEMPO_ITEM));
350 if (NULL == pNewItem)
351 return E_OUTOFMEMORY;
353 pNewItem->item = item;
354 list_add_tail (&This->Items, &pNewItem->entry);
356 StreamCount += sizeof(item);
357 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
358 } while (StreamCount < StreamSize);
360 liMove.QuadPart = Chunk.dwSize;
361 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
366 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
367 liMove.QuadPart = Chunk.dwSize;
368 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
377 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
378 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
379 FIXME("(%p): Saving not implemented yet\n", This);
383 static HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
384 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
385 FIXME("(%p, %p): stub\n", This, pcbSize);
389 static const IPersistStreamVtbl DirectMusicTempoTrack_PersistStream_Vtbl = {
390 IDirectMusicTempoTrack_IPersistStream_QueryInterface,
391 IDirectMusicTempoTrack_IPersistStream_AddRef,
392 IDirectMusicTempoTrack_IPersistStream_Release,
393 IDirectMusicTempoTrack_IPersistStream_GetClassID,
394 IDirectMusicTempoTrack_IPersistStream_IsDirty,
395 IDirectMusicTempoTrack_IPersistStream_Load,
396 IDirectMusicTempoTrack_IPersistStream_Save,
397 IDirectMusicTempoTrack_IPersistStream_GetSizeMax
400 /* for ClassFactory */
401 HRESULT WINAPI DMUSIC_CreateDirectMusicTempoTrack (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
402 IDirectMusicTempoTrack* track;
404 track = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicTempoTrack));
407 return E_OUTOFMEMORY;
409 track->UnknownVtbl = &DirectMusicTempoTrack_Unknown_Vtbl;
410 track->TrackVtbl = &DirectMusicTempoTrack_Track_Vtbl;
411 track->PersistStreamVtbl = &DirectMusicTempoTrack_PersistStream_Vtbl;
412 track->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
413 DM_STRUCT_INIT(track->pDesc);
414 track->pDesc->dwValidData |= DMUS_OBJ_CLASS;
415 track->pDesc->guidClass = CLSID_DirectMusicTempoTrack;
416 track->ref = 0; /* will be inited by QueryInterface */
417 track->enabled = TRUE;
418 list_init (&track->Items);
420 return IDirectMusicTempoTrack_IUnknown_QueryInterface ((LPUNKNOWN)&track->UnknownVtbl, lpcGUID, ppobj);