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 WINE_DEFAULT_DEBUG_CHANNEL(dmime
);
25 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
27 /*****************************************************************************
28 * IDirectMusicTempoTrack implementation
31 typedef struct IDirectMusicTempoTrack
{
32 IDirectMusicTrack8 IDirectMusicTrack8_iface
;
33 struct dmobject dmobj
; /* IPersistStream only */
35 DMUS_IO_TEMPO_ITEM
*items
;
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=%ld\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=%ld\n", This
, ref
);
93 static HRESULT WINAPI
tempo_track_Init(IDirectMusicTrack8
*iface
, IDirectMusicSegment
*pSegment
)
95 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
96 TRACE("(%p, %p): nothing to do here\n", This
, pSegment
);
100 static HRESULT WINAPI
tempo_track_InitPlay(IDirectMusicTrack8
*iface
,
101 IDirectMusicSegmentState
*pSegmentState
, IDirectMusicPerformance
*pPerformance
,
102 void **ppStateData
, DWORD dwVirtualTrack8ID
, DWORD dwFlags
)
104 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
106 LPDMUS_PRIVATE_TEMPO_PLAY_STATE pState
= NULL
;
108 FIXME("(%p, %p, %p, %p, %ld, %ld): semi-stub\n", This
, pSegmentState
, pPerformance
, ppStateData
, dwVirtualTrack8ID
, dwFlags
);
110 if (!(pState
= calloc(1, sizeof(*pState
)))) return E_OUTOFMEMORY
;
112 /** TODO real fill useful data */
114 *ppStateData
= pState
;
118 static HRESULT WINAPI
tempo_track_EndPlay(IDirectMusicTrack8
*iface
, void *pStateData
)
120 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
122 LPDMUS_PRIVATE_TEMPO_PLAY_STATE pState
= pStateData
;
124 FIXME("(%p, %p): semi-stub\n", This
, pStateData
);
126 if (NULL
== pStateData
) {
129 /** TODO real clean up */
134 static HRESULT WINAPI
tempo_track_Play(IDirectMusicTrack8
*iface
, void *pStateData
,
135 MUSIC_TIME mtStart
, MUSIC_TIME mtEnd
, MUSIC_TIME mtOffset
, DWORD dwFlags
,
136 IDirectMusicPerformance
*pPerf
, IDirectMusicSegmentState
*pSegSt
, DWORD dwVirtualID
)
138 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
139 FIXME("(%p, %p, %ld, %ld, %ld, %ld, %p, %p, %ld): stub\n", This
, pStateData
, mtStart
, mtEnd
, mtOffset
, dwFlags
, pPerf
, pSegSt
, dwVirtualID
);
140 /** should use IDirectMusicPerformance_SendPMsg here */
144 static HRESULT WINAPI
tempo_track_GetParam(IDirectMusicTrack8
*iface
, REFGUID type
, MUSIC_TIME time
,
145 MUSIC_TIME
*next
, void *param
)
147 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
148 DMUS_TEMPO_PARAM
*prm
= param
;
151 TRACE("(%p, %s, %ld, %p, %p)\n", This
, debugstr_dmguid(type
), time
, next
, param
);
155 if (!IsEqualGUID(type
, &GUID_TempoParam
))
156 return DMUS_E_GET_UNSUPPORTED
;
158 FIXME("Partial support for GUID_TempoParam\n");
163 prm
->dblTempo
= 0.123456;
165 for (i
= 0; i
< This
->count
; i
++) {
166 if (This
->items
[i
].lTime
<= time
) {
167 MUSIC_TIME ofs
= This
->items
[i
].lTime
- time
;
168 if (ofs
> prm
->mtTime
) {
170 prm
->dblTempo
= This
->items
[i
].dblTempo
;
172 if (next
&& This
->items
[i
].lTime
> time
&& This
->items
[i
].lTime
< *next
)
173 *next
= This
->items
[i
].lTime
;
177 if (0.123456 == prm
->dblTempo
)
178 return DMUS_E_NOT_FOUND
;
183 static HRESULT WINAPI
tempo_track_SetParam(IDirectMusicTrack8
*iface
, REFGUID type
, MUSIC_TIME time
,
186 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
188 TRACE("(%p, %s, %ld, %p)\n", This
, debugstr_dmguid(type
), time
, param
);
190 if (IsEqualGUID(type
, &GUID_DisableTempo
)) {
192 return DMUS_E_TYPE_DISABLED
;
193 FIXME("GUID_DisableTempo not handled yet\n");
196 if (IsEqualGUID(type
, &GUID_EnableTempo
)) {
198 return DMUS_E_TYPE_DISABLED
;
199 FIXME("GUID_EnableTempo not handled yet\n");
202 if (IsEqualGUID(type
, &GUID_TempoParam
)) {
205 FIXME("GUID_TempoParam not handled yet\n");
209 return DMUS_E_SET_UNSUPPORTED
;
212 static HRESULT WINAPI
tempo_track_IsParamSupported(IDirectMusicTrack8
*iface
, REFGUID rguidType
)
214 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
216 TRACE("(%p, %s)\n", This
, debugstr_dmguid(rguidType
));
217 if (IsEqualGUID (rguidType
, &GUID_DisableTempo
)
218 || IsEqualGUID (rguidType
, &GUID_EnableTempo
)
219 || IsEqualGUID (rguidType
, &GUID_TempoParam
)) {
220 TRACE("param supported\n");
223 TRACE("param unsupported\n");
224 return DMUS_E_TYPE_UNSUPPORTED
;
227 static HRESULT WINAPI
tempo_track_AddNotificationType(IDirectMusicTrack8
*iface
, REFGUID notiftype
)
229 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
231 TRACE("(%p, %s): method not implemented\n", This
, debugstr_dmguid(notiftype
));
235 static HRESULT WINAPI
tempo_track_RemoveNotificationType(IDirectMusicTrack8
*iface
,
238 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
240 TRACE("(%p, %s): method not implemented\n", This
, debugstr_dmguid(notiftype
));
244 static HRESULT WINAPI
tempo_track_Clone(IDirectMusicTrack8
*iface
, MUSIC_TIME mtStart
,
245 MUSIC_TIME mtEnd
, IDirectMusicTrack
**ppTrack
)
247 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
248 FIXME("(%p, %ld, %ld, %p): stub\n", This
, mtStart
, mtEnd
, ppTrack
);
252 static HRESULT WINAPI
tempo_track_PlayEx(IDirectMusicTrack8
*iface
, void *pStateData
,
253 REFERENCE_TIME rtStart
, REFERENCE_TIME rtEnd
, REFERENCE_TIME rtOffset
, DWORD dwFlags
,
254 IDirectMusicPerformance
*pPerf
, IDirectMusicSegmentState
*pSegSt
, DWORD dwVirtualID
)
256 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
257 FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %ld, %p, %p, %ld): stub\n", This
, pStateData
, wine_dbgstr_longlong(rtStart
),
258 wine_dbgstr_longlong(rtEnd
), wine_dbgstr_longlong(rtOffset
), dwFlags
, pPerf
, pSegSt
, dwVirtualID
);
262 static HRESULT WINAPI
tempo_track_GetParamEx(IDirectMusicTrack8
*iface
, REFGUID rguidType
,
263 REFERENCE_TIME rtTime
, REFERENCE_TIME
*prtNext
, void *pParam
, void *pStateData
,
266 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
267 FIXME("(%p, %s, 0x%s, %p, %p, %p, %ld): stub\n", This
, debugstr_dmguid(rguidType
),
268 wine_dbgstr_longlong(rtTime
), prtNext
, pParam
, pStateData
, dwFlags
);
272 static HRESULT WINAPI
tempo_track_SetParamEx(IDirectMusicTrack8
*iface
, REFGUID rguidType
,
273 REFERENCE_TIME rtTime
, void *pParam
, void *pStateData
, DWORD dwFlags
)
275 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
276 FIXME("(%p, %s, 0x%s, %p, %p, %ld): stub\n", This
, debugstr_dmguid(rguidType
),
277 wine_dbgstr_longlong(rtTime
), pParam
, pStateData
, dwFlags
);
281 static HRESULT WINAPI
tempo_track_Compose(IDirectMusicTrack8
*iface
, IUnknown
*context
,
282 DWORD trackgroup
, IDirectMusicTrack
**track
)
284 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
286 TRACE("(%p, %p, %ld, %p): method not implemented\n", This
, context
, trackgroup
, track
);
290 static HRESULT WINAPI
tempo_track_Join(IDirectMusicTrack8
*iface
, IDirectMusicTrack
*pNewTrack
,
291 MUSIC_TIME mtJoin
, IUnknown
*pContext
, DWORD dwTrackGroup
,
292 IDirectMusicTrack
**ppResultTrack
)
294 IDirectMusicTempoTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
295 FIXME("(%p, %p, %ld, %p, %ld, %p): stub\n", This
, pNewTrack
, mtJoin
, pContext
, dwTrackGroup
, ppResultTrack
);
299 static const IDirectMusicTrack8Vtbl dmtrack8_vtbl
= {
300 tempo_track_QueryInterface
,
304 tempo_track_InitPlay
,
307 tempo_track_GetParam
,
308 tempo_track_SetParam
,
309 tempo_track_IsParamSupported
,
310 tempo_track_AddNotificationType
,
311 tempo_track_RemoveNotificationType
,
314 tempo_track_GetParamEx
,
315 tempo_track_SetParamEx
,
320 static inline IDirectMusicTempoTrack
*impl_from_IPersistStream(IPersistStream
*iface
)
322 return CONTAINING_RECORD(iface
, IDirectMusicTempoTrack
, dmobj
.IPersistStream_iface
);
325 static HRESULT WINAPI
tempo_IPersistStream_Load(IPersistStream
*iface
, IStream
*stream
)
327 IDirectMusicTempoTrack
*This
= impl_from_IPersistStream(iface
);
328 struct chunk_entry chunk
= {0};
332 TRACE("%p, %p\n", This
, stream
);
337 if ((hr
= stream_get_chunk(stream
, &chunk
)) != S_OK
)
339 if (chunk
.id
!= DMUS_FOURCC_TEMPO_TRACK
)
340 return DMUS_E_UNSUPPORTED_STREAM
;
342 hr
= stream_chunk_get_array(stream
, &chunk
, (void **)&This
->items
, &This
->count
,
343 sizeof(DMUS_IO_TEMPO_ITEM
));
347 for (i
= 0; i
< This
->count
; i
++) {
348 TRACE_(dmfile
)("DMUS_IO_TEMPO_ITEM #%u\n", i
);
349 TRACE_(dmfile
)(" - lTime = %lu\n", This
->items
[i
].lTime
);
350 TRACE_(dmfile
)(" - dblTempo = %g\n", This
->items
[i
].dblTempo
);
356 static const IPersistStreamVtbl persiststream_vtbl
= {
357 dmobj_IPersistStream_QueryInterface
,
358 dmobj_IPersistStream_AddRef
,
359 dmobj_IPersistStream_Release
,
360 dmobj_IPersistStream_GetClassID
,
361 unimpl_IPersistStream_IsDirty
,
362 tempo_IPersistStream_Load
,
363 unimpl_IPersistStream_Save
,
364 unimpl_IPersistStream_GetSizeMax
367 /* for ClassFactory */
368 HRESULT
create_dmtempotrack(REFIID lpcGUID
, void **ppobj
)
370 IDirectMusicTempoTrack
*track
;
374 if (!(track
= calloc(1, sizeof(*track
)))) return E_OUTOFMEMORY
;
375 track
->IDirectMusicTrack8_iface
.lpVtbl
= &dmtrack8_vtbl
;
377 dmobject_init(&track
->dmobj
, &CLSID_DirectMusicTempoTrack
,
378 (IUnknown
*)&track
->IDirectMusicTrack8_iface
);
379 track
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
381 hr
= IDirectMusicTrack8_QueryInterface(&track
->IDirectMusicTrack8_iface
, lpcGUID
, ppobj
);
382 IDirectMusicTrack8_Release(&track
->IDirectMusicTrack8_iface
);