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 modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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
14 * GNU Library General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 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 IDirectMusicTempoTrack_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
38 } else if (IsEqualIID (riid, &IID_IDirectMusicTrack)
39 || IsEqualIID (riid, &IID_IDirectMusicTrack8)) {
40 *ppobj = (LPDIRECTMUSICTRACK8)&This->TrackVtbl;
41 IDirectMusicTempoTrack_IDirectMusicTrack_AddRef ((LPDIRECTMUSICTRACK8)&This->TrackVtbl);
43 } else if (IsEqualIID (riid, &IID_IPersistStream)) {
44 *ppobj = (LPPERSISTSTREAM)&This->PersistStreamVtbl;
45 IDirectMusicTempoTrack_IPersistStream_AddRef ((LPPERSISTSTREAM)&This->PersistStreamVtbl);
49 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
53 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 %ld\n", This, ref - 1);
64 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 %ld\n", This, ref);
70 HeapFree(GetProcessHeap(), 0, This);
78 IUnknownVtbl DirectMusicTempoTrack_Unknown_Vtbl = {
79 IDirectMusicTempoTrack_IUnknown_QueryInterface,
80 IDirectMusicTempoTrack_IUnknown_AddRef,
81 IDirectMusicTempoTrack_IUnknown_Release
84 /* IDirectMusicTempoTrack IDirectMusicTrack8 part: */
85 HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_QueryInterface (LPDIRECTMUSICTRACK8 iface, REFIID riid, LPVOID *ppobj) {
86 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
87 return IDirectMusicTempoTrack_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
90 ULONG WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_AddRef (LPDIRECTMUSICTRACK8 iface) {
91 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
92 return IDirectMusicTempoTrack_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
95 ULONG WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Release (LPDIRECTMUSICTRACK8 iface) {
96 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
97 return IDirectMusicTempoTrack_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
100 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 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, %ld, %ld): 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 usefull datas */
122 *ppStateData = pState;
126 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 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, %ld, %p, %p, %ld): stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
146 /** should use IDirectMusicPerformance_SendPMsg here */
150 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 = IDirectMusicTempoTrack_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 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 HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_IsParamSupported (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType) {
206 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
208 TRACE("(%p, %s): ", 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 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 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 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 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, %lli, %lli, %lli, %ld, %p, %p, %ld): stub\n", This, pStateData, rtStart, rtEnd, rtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
246 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, %lli, %p, %p, %p, %ld): stub\n", This, debugstr_dmguid(rguidType), rtTime, prtNext, pParam, pStateData, dwFlags);
252 HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_SetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, void* pParam, void* pStateData, DWORD dwFlags) {
253 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
254 FIXME("(%p, %s, %lli, %p, %p, %ld): stub\n", This, debugstr_dmguid(rguidType), rtTime, pParam, pStateData, dwFlags);
258 HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Compose (LPDIRECTMUSICTRACK8 iface, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
259 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
260 FIXME("(%p, %p, %ld, %p): stub\n", This, pContext, dwTrackGroup, ppResultTrack);
264 HRESULT WINAPI IDirectMusicTempoTrack_IDirectMusicTrack_Join (LPDIRECTMUSICTRACK8 iface, IDirectMusicTrack* pNewTrack, MUSIC_TIME mtJoin, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
265 ICOM_THIS_MULTI(IDirectMusicTempoTrack, TrackVtbl, iface);
266 FIXME("(%p, %p, %ld, %p, %ld, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
270 IDirectMusicTrack8Vtbl DirectMusicTempoTrack_Track_Vtbl = {
271 IDirectMusicTempoTrack_IDirectMusicTrack_QueryInterface,
272 IDirectMusicTempoTrack_IDirectMusicTrack_AddRef,
273 IDirectMusicTempoTrack_IDirectMusicTrack_Release,
274 IDirectMusicTempoTrack_IDirectMusicTrack_Init,
275 IDirectMusicTempoTrack_IDirectMusicTrack_InitPlay,
276 IDirectMusicTempoTrack_IDirectMusicTrack_EndPlay,
277 IDirectMusicTempoTrack_IDirectMusicTrack_Play,
278 IDirectMusicTempoTrack_IDirectMusicTrack_GetParam,
279 IDirectMusicTempoTrack_IDirectMusicTrack_SetParam,
280 IDirectMusicTempoTrack_IDirectMusicTrack_IsParamSupported,
281 IDirectMusicTempoTrack_IDirectMusicTrack_AddNotificationType,
282 IDirectMusicTempoTrack_IDirectMusicTrack_RemoveNotificationType,
283 IDirectMusicTempoTrack_IDirectMusicTrack_Clone,
284 IDirectMusicTempoTrack_IDirectMusicTrack_PlayEx,
285 IDirectMusicTempoTrack_IDirectMusicTrack_GetParamEx,
286 IDirectMusicTempoTrack_IDirectMusicTrack_SetParamEx,
287 IDirectMusicTempoTrack_IDirectMusicTrack_Compose,
288 IDirectMusicTempoTrack_IDirectMusicTrack_Join
291 /* IDirectMusicTempoTrack IPersistStream part: */
292 HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
293 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
294 return IDirectMusicTempoTrack_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
297 ULONG WINAPI IDirectMusicTempoTrack_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
298 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
299 return IDirectMusicTempoTrack_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
302 ULONG WINAPI IDirectMusicTempoTrack_IPersistStream_Release (LPPERSISTSTREAM iface) {
303 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
304 return IDirectMusicTempoTrack_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
307 HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
308 ICOM_THIS_MULTI(IDirectMusicSegment8Impl, PersistStreamVtbl, iface);
309 TRACE("(%p, %p)\n", This, pClassID);
310 memcpy(pClassID, &CLSID_DirectMusicTempoTrack, sizeof(CLSID));
314 HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
315 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
316 FIXME("(%p): stub, always S_FALSE\n", This);
320 HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
321 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
322 DMUS_PRIVATE_CHUNK Chunk;
323 DWORD StreamSize, StreamCount;
324 LARGE_INTEGER liMove;
325 DMUS_IO_TEMPO_ITEM item;
326 LPDMUS_PRIVATE_TEMPO_ITEM pNewItem = NULL;
328 FIXME("(%p, %p): Loading not fully implemented yet\n", This, pStm);
331 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
332 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
333 switch (Chunk.fccID) {
334 case DMUS_FOURCC_TEMPO_TRACK: {
335 TRACE_(dmfile)(": Tempo track\n");
337 IStream_Read (pStm, &StreamSize, sizeof(DWORD), NULL);
338 StreamSize -= sizeof(DWORD);
340 TRACE_(dmfile)(" - sizeof(DMUS_IO_TEMPO_ITEM): %lu (chunkSize = %lu)\n", StreamSize, Chunk.dwSize - sizeof(DWORD));
342 IStream_Read (pStm, &item, sizeof(item), NULL);
344 TRACE_(dmfile)("DMUS_IO_TEMPO_ITEM #%ld\n", nItem);
345 TRACE_(dmfile)(" - lTime = %lu\n", item.lTime);
346 TRACE_(dmfile)(" - dblTempo = %g\n", item.dblTempo);
347 pNewItem = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_TEMPO_ITEM));
348 if (NULL == pNewItem) {
349 ERR(": no more memory\n");
350 return E_OUTOFMEMORY;
352 memcpy(&pNewItem->item, &item, sizeof(DMUS_IO_TEMPO_ITEM));
353 list_add_tail (&This->Items, &pNewItem->entry);
355 StreamCount += sizeof(item);
356 TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
357 } while (StreamCount < StreamSize);
359 liMove.QuadPart = Chunk.dwSize;
360 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
365 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
366 liMove.QuadPart = Chunk.dwSize;
367 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
376 HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
377 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
378 FIXME("(%p): Saving not implemented yet\n", This);
382 HRESULT WINAPI IDirectMusicTempoTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
383 ICOM_THIS_MULTI(IDirectMusicTempoTrack, PersistStreamVtbl, iface);
384 FIXME("(%p, %p): stub\n", This, pcbSize);
388 IPersistStreamVtbl DirectMusicTempoTrack_PersistStream_Vtbl = {
389 IDirectMusicTempoTrack_IPersistStream_QueryInterface,
390 IDirectMusicTempoTrack_IPersistStream_AddRef,
391 IDirectMusicTempoTrack_IPersistStream_Release,
392 IDirectMusicTempoTrack_IPersistStream_GetClassID,
393 IDirectMusicTempoTrack_IPersistStream_IsDirty,
394 IDirectMusicTempoTrack_IPersistStream_Load,
395 IDirectMusicTempoTrack_IPersistStream_Save,
396 IDirectMusicTempoTrack_IPersistStream_GetSizeMax
399 /* for ClassFactory */
400 HRESULT WINAPI DMUSIC_CreateDirectMusicTempoTrack (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
401 IDirectMusicTempoTrack* track;
403 track = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicTempoTrack));
406 return E_OUTOFMEMORY;
408 track->UnknownVtbl = &DirectMusicTempoTrack_Unknown_Vtbl;
409 track->TrackVtbl = &DirectMusicTempoTrack_Track_Vtbl;
410 track->PersistStreamVtbl = &DirectMusicTempoTrack_PersistStream_Vtbl;
411 track->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
412 DM_STRUCT_INIT(track->pDesc);
413 track->pDesc->dwValidData |= DMUS_OBJ_CLASS;
414 memcpy (&track->pDesc->guidClass, &CLSID_DirectMusicTempoTrack, sizeof (CLSID));
415 track->ref = 0; /* will be inited by QueryInterface */
416 track->enabled = TRUE;
417 list_init (&track->Items);
419 return IDirectMusicTempoTrack_IUnknown_QueryInterface ((LPUNKNOWN)&track->UnknownVtbl, lpcGUID, ppobj);