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"
24 #include "wine/heap.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(dmime
);
27 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
29 /*****************************************************************************
30 * IDirectMusicTempoTrack implementation
32 typedef struct IDirectMusicTempoTrack
{
33 IDirectMusicTrack8 IDirectMusicTrack8_iface
;
34 struct dmobject dmobj
; /* IPersistStream only */
37 } IDirectMusicTempoTrack
;
39 /* IDirectMusicTempoTrack IDirectMusicTrack8 part: */
40 static inline IDirectMusicTempoTrack
*impl_from_IDirectMusicTrack8(IDirectMusicTrack8
*iface
)
42 return CONTAINING_RECORD(iface
, IDirectMusicTempoTrack
, IDirectMusicTrack8_iface
);
45 static HRESULT WINAPI
tempo_track_QueryInterface(IDirectMusicTrack8
*iface
, REFIID riid
,
48 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
50 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ret_iface
);
54 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDirectMusicTrack
) ||
55 IsEqualIID(riid
, &IID_IDirectMusicTrack8
))
57 else if (IsEqualIID(riid
, &IID_IPersistStream
))
58 *ret_iface
= &This
->dmobj
.IPersistStream_iface
;
60 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ret_iface
);
64 IUnknown_AddRef((IUnknown
*)*ret_iface
);
68 static ULONG WINAPI
tempo_track_AddRef(IDirectMusicTrack8
*iface
)
70 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
71 LONG ref
= InterlockedIncrement(&This
->ref
);
73 TRACE("(%p) ref=%d\n", This
, ref
);
78 static ULONG WINAPI
tempo_track_Release(IDirectMusicTrack8
*iface
)
80 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
81 LONG ref
= InterlockedDecrement(&This
->ref
);
83 TRACE("(%p) ref=%d\n", This
, ref
);
86 struct list
*cursor
, *cursor2
;
87 DMUS_PRIVATE_TEMPO_ITEM
*item
;
89 LIST_FOR_EACH_SAFE(cursor
, cursor2
, &This
->Items
) {
90 item
= LIST_ENTRY(cursor
, DMUS_PRIVATE_TEMPO_ITEM
, entry
);
103 static HRESULT WINAPI
tempo_track_Init(IDirectMusicTrack8
*iface
, IDirectMusicSegment
*pSegment
)
105 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
106 TRACE("(%p, %p): nothing to do here\n", This
, pSegment
);
110 static HRESULT WINAPI
tempo_track_InitPlay(IDirectMusicTrack8
*iface
,
111 IDirectMusicSegmentState
*pSegmentState
, IDirectMusicPerformance
*pPerformance
,
112 void **ppStateData
, DWORD dwVirtualTrack8ID
, DWORD dwFlags
)
114 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
116 LPDMUS_PRIVATE_TEMPO_PLAY_STATE pState
= NULL
;
118 FIXME("(%p, %p, %p, %p, %d, %d): semi-stub\n", This
, pSegmentState
, pPerformance
, ppStateData
, dwVirtualTrack8ID
, dwFlags
);
120 pState
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_TEMPO_PLAY_STATE
));
122 return E_OUTOFMEMORY
;
124 /** TODO real fill useful data */
126 *ppStateData
= pState
;
130 static HRESULT WINAPI
tempo_track_EndPlay(IDirectMusicTrack8
*iface
, void *pStateData
)
132 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
134 LPDMUS_PRIVATE_TEMPO_PLAY_STATE pState
= pStateData
;
136 FIXME("(%p, %p): semi-stub\n", This
, pStateData
);
138 if (NULL
== pStateData
) {
141 /** TODO real clean up */
142 HeapFree(GetProcessHeap(), 0, pState
);
146 static HRESULT WINAPI
tempo_track_Play(IDirectMusicTrack8
*iface
, void *pStateData
,
147 MUSIC_TIME mtStart
, MUSIC_TIME mtEnd
, MUSIC_TIME mtOffset
, DWORD dwFlags
,
148 IDirectMusicPerformance
*pPerf
, IDirectMusicSegmentState
*pSegSt
, DWORD dwVirtualID
)
150 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
151 FIXME("(%p, %p, %d, %d, %d, %d, %p, %p, %d): stub\n", This
, pStateData
, mtStart
, mtEnd
, mtOffset
, dwFlags
, pPerf
, pSegSt
, dwVirtualID
);
152 /** should use IDirectMusicPerformance_SendPMsg here */
156 static HRESULT WINAPI
tempo_track_GetParam(IDirectMusicTrack8
*iface
, REFGUID type
, MUSIC_TIME time
,
157 MUSIC_TIME
*next
, void *param
)
159 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
160 DMUS_PRIVATE_TEMPO_ITEM
*item
= NULL
;
161 DMUS_TEMPO_PARAM
*prm
= param
;
163 TRACE("(%p, %s, %d, %p, %p)\n", This
, debugstr_dmguid(type
), time
, next
, param
);
167 if (!IsEqualGUID(type
, &GUID_TempoParam
))
168 return DMUS_E_GET_UNSUPPORTED
;
170 FIXME("Partial support for GUID_TempoParam\n");
175 prm
->dblTempo
= 0.123456;
177 LIST_FOR_EACH_ENTRY(item
, &This
->Items
, DMUS_PRIVATE_TEMPO_ITEM
, entry
) {
178 if (item
->item
.lTime
<= time
) {
179 MUSIC_TIME ofs
= item
->item
.lTime
- time
;
180 if (ofs
> prm
->mtTime
) {
182 prm
->dblTempo
= item
->item
.dblTempo
;
184 if (next
&& item
->item
.lTime
> time
&& item
->item
.lTime
< *next
)
185 *next
= item
->item
.lTime
;
189 if (0.123456 == prm
->dblTempo
)
190 return DMUS_E_NOT_FOUND
;
195 static HRESULT WINAPI
tempo_track_SetParam(IDirectMusicTrack8
*iface
, REFGUID type
, MUSIC_TIME time
,
198 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
200 TRACE("(%p, %s, %d, %p)\n", This
, debugstr_dmguid(type
), time
, param
);
202 if (IsEqualGUID(type
, &GUID_DisableTempo
)) {
204 return DMUS_E_TYPE_DISABLED
;
205 FIXME("GUID_DisableTempo not handled yet\n");
208 if (IsEqualGUID(type
, &GUID_EnableTempo
)) {
210 return DMUS_E_TYPE_DISABLED
;
211 FIXME("GUID_EnableTempo not handled yet\n");
214 if (IsEqualGUID(type
, &GUID_TempoParam
)) {
217 FIXME("GUID_TempoParam not handled yet\n");
221 return DMUS_E_SET_UNSUPPORTED
;
224 static HRESULT WINAPI
tempo_track_IsParamSupported(IDirectMusicTrack8
*iface
, REFGUID rguidType
)
226 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
228 TRACE("(%p, %s)\n", This
, debugstr_dmguid(rguidType
));
229 if (IsEqualGUID (rguidType
, &GUID_DisableTempo
)
230 || IsEqualGUID (rguidType
, &GUID_EnableTempo
)
231 || IsEqualGUID (rguidType
, &GUID_TempoParam
)) {
232 TRACE("param supported\n");
235 TRACE("param unsupported\n");
236 return DMUS_E_TYPE_UNSUPPORTED
;
239 static HRESULT WINAPI
tempo_track_AddNotificationType(IDirectMusicTrack8
*iface
, REFGUID notiftype
)
241 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
243 TRACE("(%p, %s): method not implemented\n", This
, debugstr_dmguid(notiftype
));
247 static HRESULT WINAPI
tempo_track_RemoveNotificationType(IDirectMusicTrack8
*iface
,
250 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
252 TRACE("(%p, %s): method not implemented\n", This
, debugstr_dmguid(notiftype
));
256 static HRESULT WINAPI
tempo_track_Clone(IDirectMusicTrack8
*iface
, MUSIC_TIME mtStart
,
257 MUSIC_TIME mtEnd
, IDirectMusicTrack
**ppTrack
)
259 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
260 FIXME("(%p, %d, %d, %p): stub\n", This
, mtStart
, mtEnd
, ppTrack
);
264 static HRESULT WINAPI
tempo_track_PlayEx(IDirectMusicTrack8
*iface
, void *pStateData
,
265 REFERENCE_TIME rtStart
, REFERENCE_TIME rtEnd
, REFERENCE_TIME rtOffset
, DWORD dwFlags
,
266 IDirectMusicPerformance
*pPerf
, IDirectMusicSegmentState
*pSegSt
, DWORD dwVirtualID
)
268 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
269 FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %d, %p, %p, %d): stub\n", This
, pStateData
, wine_dbgstr_longlong(rtStart
),
270 wine_dbgstr_longlong(rtEnd
), wine_dbgstr_longlong(rtOffset
), dwFlags
, pPerf
, pSegSt
, dwVirtualID
);
274 static HRESULT WINAPI
tempo_track_GetParamEx(IDirectMusicTrack8
*iface
, REFGUID rguidType
,
275 REFERENCE_TIME rtTime
, REFERENCE_TIME
*prtNext
, void *pParam
, void *pStateData
,
278 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
279 FIXME("(%p, %s, 0x%s, %p, %p, %p, %d): stub\n", This
, debugstr_dmguid(rguidType
),
280 wine_dbgstr_longlong(rtTime
), prtNext
, pParam
, pStateData
, dwFlags
);
284 static HRESULT WINAPI
tempo_track_SetParamEx(IDirectMusicTrack8
*iface
, REFGUID rguidType
,
285 REFERENCE_TIME rtTime
, void *pParam
, void *pStateData
, DWORD dwFlags
)
287 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
288 FIXME("(%p, %s, 0x%s, %p, %p, %d): stub\n", This
, debugstr_dmguid(rguidType
),
289 wine_dbgstr_longlong(rtTime
), pParam
, pStateData
, dwFlags
);
293 static HRESULT WINAPI
tempo_track_Compose(IDirectMusicTrack8
*iface
, IUnknown
*context
,
294 DWORD trackgroup
, IDirectMusicTrack
**track
)
296 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
298 TRACE("(%p, %p, %d, %p): method not implemented\n", This
, context
, trackgroup
, track
);
302 static HRESULT WINAPI
tempo_track_Join(IDirectMusicTrack8
*iface
, IDirectMusicTrack
*pNewTrack
,
303 MUSIC_TIME mtJoin
, IUnknown
*pContext
, DWORD dwTrackGroup
,
304 IDirectMusicTrack
**ppResultTrack
)
306 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
307 FIXME("(%p, %p, %d, %p, %d, %p): stub\n", This
, pNewTrack
, mtJoin
, pContext
, dwTrackGroup
, ppResultTrack
);
311 static const IDirectMusicTrack8Vtbl dmtrack8_vtbl
= {
312 tempo_track_QueryInterface
,
316 tempo_track_InitPlay
,
319 tempo_track_GetParam
,
320 tempo_track_SetParam
,
321 tempo_track_IsParamSupported
,
322 tempo_track_AddNotificationType
,
323 tempo_track_RemoveNotificationType
,
326 tempo_track_GetParamEx
,
327 tempo_track_SetParamEx
,
332 static inline IDirectMusicTempoTrack
*impl_from_IPersistStream(IPersistStream
*iface
)
334 return CONTAINING_RECORD(iface
, IDirectMusicTempoTrack
, dmobj
.IPersistStream_iface
);
337 static HRESULT WINAPI
tempo_IPersistStream_Load(IPersistStream
*iface
, IStream
*pStm
)
339 IDirectMusicTempoTrack
*This
= impl_from_IPersistStream(iface
);
340 DMUS_PRIVATE_CHUNK Chunk
;
341 DWORD StreamSize
, StreamCount
;
342 LARGE_INTEGER liMove
;
343 DMUS_IO_TEMPO_ITEM item
;
344 LPDMUS_PRIVATE_TEMPO_ITEM pNewItem
= NULL
;
346 FIXME("(%p, %p): Loading not fully implemented yet\n", This
, pStm
);
348 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
349 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
350 switch (Chunk
.fccID
) {
351 case DMUS_FOURCC_TEMPO_TRACK
: {
352 TRACE_(dmfile
)(": Tempo track\n");
353 IStream_Read (pStm
, &StreamSize
, sizeof(DWORD
), NULL
);
354 StreamSize
-= sizeof(DWORD
);
356 TRACE_(dmfile
)(" - sizeof(DMUS_IO_TEMPO_ITEM): %u (chunkSize = %u)\n", StreamSize
, Chunk
.dwSize
);
358 IStream_Read (pStm
, &item
, sizeof(item
), NULL
);
360 TRACE_(dmfile
)("DMUS_IO_TEMPO_ITEM #%d\n", nItem
);
361 TRACE_(dmfile
)(" - lTime = %u\n", item
.lTime
);
362 TRACE_(dmfile
)(" - dblTempo = %g\n", item
.dblTempo
);
363 pNewItem
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_TEMPO_ITEM
));
364 if (NULL
== pNewItem
)
365 return E_OUTOFMEMORY
;
367 pNewItem
->item
= item
;
368 list_add_tail (&This
->Items
, &pNewItem
->entry
);
370 StreamCount
+= sizeof(item
);
371 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
372 } while (StreamCount
< StreamSize
);
376 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
377 liMove
.QuadPart
= Chunk
.dwSize
;
378 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
386 static const IPersistStreamVtbl persiststream_vtbl
= {
387 dmobj_IPersistStream_QueryInterface
,
388 dmobj_IPersistStream_AddRef
,
389 dmobj_IPersistStream_Release
,
390 dmobj_IPersistStream_GetClassID
,
391 unimpl_IPersistStream_IsDirty
,
392 tempo_IPersistStream_Load
,
393 unimpl_IPersistStream_Save
,
394 unimpl_IPersistStream_GetSizeMax
397 /* for ClassFactory */
398 HRESULT WINAPI
create_dmtempotrack(REFIID lpcGUID
, void **ppobj
)
400 IDirectMusicTempoTrack
*track
;
403 track
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*track
));
406 return E_OUTOFMEMORY
;
408 track
->IDirectMusicTrack8_iface
.lpVtbl
= &dmtrack8_vtbl
;
410 dmobject_init(&track
->dmobj
, &CLSID_DirectMusicTempoTrack
,
411 (IUnknown
*)&track
->IDirectMusicTrack8_iface
);
412 track
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
413 list_init(&track
->Items
);
416 hr
= IDirectMusicTrack8_QueryInterface(&track
->IDirectMusicTrack8_iface
, lpcGUID
, ppobj
);
417 IDirectMusicTrack8_Release(&track
->IDirectMusicTrack8_iface
);