1 /* IDirectMusicCommandTrack Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "dmstyle_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(dmstyle
);
24 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
26 /*****************************************************************************
27 * IDirectMusicCommandTrack implementation
29 typedef struct IDirectMusicCommandTrack
{
30 IDirectMusicTrack8 IDirectMusicTrack8_iface
;
31 struct dmobject dmobj
; /* IPersistStream only */
34 } IDirectMusicCommandTrack
;
36 /* IDirectMusicCommandTrack IDirectMusicTrack8 part: */
37 static inline IDirectMusicCommandTrack
*impl_from_IDirectMusicTrack8(IDirectMusicTrack8
*iface
)
39 return CONTAINING_RECORD(iface
, IDirectMusicCommandTrack
, IDirectMusicTrack8_iface
);
42 static HRESULT WINAPI
command_track_QueryInterface(IDirectMusicTrack8
*iface
, REFIID riid
,
45 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
47 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ret_iface
);
51 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDirectMusicTrack
) ||
52 IsEqualIID(riid
, &IID_IDirectMusicTrack8
))
54 else if (IsEqualIID(riid
, &IID_IPersistStream
))
55 *ret_iface
= &This
->dmobj
.IPersistStream_iface
;
57 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ret_iface
);
61 IUnknown_AddRef((IUnknown
*)*ret_iface
);
65 static ULONG WINAPI
command_track_AddRef(IDirectMusicTrack8
*iface
)
67 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
68 LONG ref
= InterlockedIncrement(&This
->ref
);
70 TRACE("(%p) ref=%ld\n", This
, ref
);
75 static ULONG WINAPI
command_track_Release(IDirectMusicTrack8
*iface
)
77 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
78 LONG ref
= InterlockedDecrement(&This
->ref
);
80 TRACE("(%p) ref=%ld\n", This
, ref
);
87 static HRESULT WINAPI
command_track_Init(IDirectMusicTrack8
*iface
, IDirectMusicSegment
*pSegment
)
89 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
90 FIXME("(%p, %p): stub\n", This
, pSegment
);
94 static HRESULT WINAPI
command_track_InitPlay(IDirectMusicTrack8
*iface
,
95 IDirectMusicSegmentState
*pSegmentState
, IDirectMusicPerformance
*pPerformance
,
96 void **ppStateData
, DWORD dwVirtualTrack8ID
, DWORD dwFlags
)
98 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
99 FIXME("(%p, %p, %p, %p, %ld, %ld): stub\n", This
, pSegmentState
, pPerformance
, ppStateData
, dwVirtualTrack8ID
, dwFlags
);
103 static HRESULT WINAPI
command_track_EndPlay(IDirectMusicTrack8
*iface
, void *pStateData
)
105 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
106 FIXME("(%p, %p): stub\n", This
, pStateData
);
110 static HRESULT WINAPI
command_track_Play(IDirectMusicTrack8
*iface
, void *pStateData
,
111 MUSIC_TIME mtStart
, MUSIC_TIME mtEnd
, MUSIC_TIME mtOffset
, DWORD dwFlags
,
112 IDirectMusicPerformance
*pPerf
, IDirectMusicSegmentState
*pSegSt
, DWORD dwVirtualID
)
114 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
115 FIXME("(%p, %p, %ld, %ld, %ld, %ld, %p, %p, %ld): stub\n", This
, pStateData
, mtStart
, mtEnd
, mtOffset
, dwFlags
, pPerf
, pSegSt
, dwVirtualID
);
119 static HRESULT WINAPI
command_track_GetParam(IDirectMusicTrack8
*iface
, REFGUID type
,
120 MUSIC_TIME time
, MUSIC_TIME
*next
, void *param
)
122 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
124 TRACE("(%p, %s, %ld, %p, %p):\n", This
, debugstr_dmguid(type
), time
, next
, param
);
129 if (IsEqualGUID(type
, &GUID_CommandParam
)) {
130 FIXME("GUID_CommandParam not handled yet\n");
132 } else if (IsEqualGUID(type
, &GUID_CommandParam2
)) {
133 FIXME("GUID_CommandParam2 not handled yet\n");
135 } else if (IsEqualGUID(type
, &GUID_CommandParamNext
)) {
136 FIXME("GUID_CommandParamNext not handled yet\n");
140 return DMUS_E_GET_UNSUPPORTED
;
143 static HRESULT WINAPI
command_track_SetParam(IDirectMusicTrack8
*iface
, REFGUID type
,
144 MUSIC_TIME time
, void *param
)
146 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
148 TRACE("(%p, %s, %ld, %p)\n", This
, debugstr_dmguid(type
), time
, param
);
153 if (IsEqualGUID(type
, &GUID_CommandParam
)) {
154 FIXME("GUID_CommandParam not handled yet\n");
156 } else if (IsEqualGUID(type
, &GUID_CommandParamNext
)) {
157 FIXME("GUID_CommandParamNext not handled yet\n");
161 return DMUS_E_SET_UNSUPPORTED
;
164 static HRESULT WINAPI
command_track_IsParamSupported(IDirectMusicTrack8
*iface
, REFGUID rguidType
)
166 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
168 TRACE("(%p, %s)\n", This
, debugstr_dmguid(rguidType
));
173 if (IsEqualGUID (rguidType
, &GUID_CommandParam
)
174 || IsEqualGUID (rguidType
, &GUID_CommandParam2
)
175 || IsEqualGUID (rguidType
, &GUID_CommandParamNext
)) {
176 TRACE("param supported\n");
180 TRACE("param unsupported\n");
181 return DMUS_E_TYPE_UNSUPPORTED
;
184 static HRESULT WINAPI
command_track_AddNotificationType(IDirectMusicTrack8
*iface
,
185 REFGUID rguidNotificationType
)
187 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
188 FIXME("(%p, %s): stub\n", This
, debugstr_dmguid(rguidNotificationType
));
192 static HRESULT WINAPI
command_track_RemoveNotificationType(IDirectMusicTrack8
*iface
,
193 REFGUID rguidNotificationType
)
195 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
196 FIXME("(%p, %s): stub\n", This
, debugstr_dmguid(rguidNotificationType
));
200 static HRESULT WINAPI
command_track_Clone(IDirectMusicTrack8
*iface
, MUSIC_TIME mtStart
,
201 MUSIC_TIME mtEnd
, IDirectMusicTrack
**ppTrack
)
203 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
204 FIXME("(%p, %ld, %ld, %p): stub\n", This
, mtStart
, mtEnd
, ppTrack
);
208 static HRESULT WINAPI
command_track_PlayEx(IDirectMusicTrack8
*iface
, void *pStateData
,
209 REFERENCE_TIME rtStart
, REFERENCE_TIME rtEnd
, REFERENCE_TIME rtOffset
, DWORD dwFlags
,
210 IDirectMusicPerformance
*pPerf
, IDirectMusicSegmentState
*pSegSt
, DWORD dwVirtualID
)
212 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
213 FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %ld, %p, %p, %ld): stub\n", This
, pStateData
, wine_dbgstr_longlong(rtStart
),
214 wine_dbgstr_longlong(rtEnd
), wine_dbgstr_longlong(rtOffset
), dwFlags
, pPerf
, pSegSt
, dwVirtualID
);
218 static HRESULT WINAPI
command_track_GetParamEx(IDirectMusicTrack8
*iface
, REFGUID rguidType
,
219 REFERENCE_TIME rtTime
, REFERENCE_TIME
*prtNext
, void *pParam
,
220 void *pStateData
, DWORD dwFlags
)
222 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
223 FIXME("(%p, %s, 0x%s, %p, %p, %p, %ld): stub\n", This
, debugstr_dmguid(rguidType
),
224 wine_dbgstr_longlong(rtTime
), prtNext
, pParam
, pStateData
, dwFlags
);
228 static HRESULT WINAPI
command_track_SetParamEx(IDirectMusicTrack8
*iface
, REFGUID rguidType
,
229 REFERENCE_TIME rtTime
, void *pParam
, void *pStateData
, DWORD dwFlags
)
231 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
232 FIXME("(%p, %s, 0x%s, %p, %p, %ld): stub\n", This
, debugstr_dmguid(rguidType
),
233 wine_dbgstr_longlong(rtTime
), pParam
, pStateData
, dwFlags
);
237 static HRESULT WINAPI
command_track_Compose(IDirectMusicTrack8
*iface
, IUnknown
*context
,
238 DWORD trackgroup
, IDirectMusicTrack
**track
)
240 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
242 TRACE("(%p, %p, %ld, %p): method not implemented\n", This
, context
, trackgroup
, track
);
246 static HRESULT WINAPI
command_track_Join(IDirectMusicTrack8
*iface
, IDirectMusicTrack
*pNewTrack
,
247 MUSIC_TIME mtJoin
, IUnknown
*pContext
, DWORD dwTrackGroup
,
248 IDirectMusicTrack
**ppResultTrack
)
250 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
251 FIXME("(%p, %p, %ld, %p, %ld, %p): stub\n", This
, pNewTrack
, mtJoin
, pContext
, dwTrackGroup
, ppResultTrack
);
255 static const IDirectMusicTrack8Vtbl dmtrack8_vtbl
= {
256 command_track_QueryInterface
,
257 command_track_AddRef
,
258 command_track_Release
,
260 command_track_InitPlay
,
261 command_track_EndPlay
,
263 command_track_GetParam
,
264 command_track_SetParam
,
265 command_track_IsParamSupported
,
266 command_track_AddNotificationType
,
267 command_track_RemoveNotificationType
,
269 command_track_PlayEx
,
270 command_track_GetParamEx
,
271 command_track_SetParamEx
,
272 command_track_Compose
,
276 static inline IDirectMusicCommandTrack
*impl_from_IPersistStream(IPersistStream
*iface
)
278 return CONTAINING_RECORD(iface
, IDirectMusicCommandTrack
, dmobj
.IPersistStream_iface
);
281 static HRESULT WINAPI
IPersistStreamImpl_Load(IPersistStream
*iface
, IStream
*pStm
)
283 IDirectMusicCommandTrack
*This
= impl_from_IPersistStream(iface
);
285 DWORD chunkSize
, dwSizeOfStruct
, nrCommands
;
286 LARGE_INTEGER liMove
; /* used when skipping chunks */
288 IStream_Read (pStm
, &chunkID
, sizeof(FOURCC
), NULL
);
289 IStream_Read (pStm
, &chunkSize
, sizeof(DWORD
), NULL
);
290 TRACE_(dmfile
)(": %s chunk (size = %ld)", debugstr_fourcc (chunkID
), chunkSize
);
292 case DMUS_FOURCC_COMMANDTRACK_CHUNK
: {
294 TRACE_(dmfile
)(": command track chunk\n");
295 IStream_Read (pStm
, &dwSizeOfStruct
, sizeof(DWORD
), NULL
);
296 if (dwSizeOfStruct
!= sizeof(DMUS_IO_COMMAND
)) {
297 TRACE_(dmfile
)(": declared size of struct (=%ld) != actual size; indicates older direct music version\n", dwSizeOfStruct
);
299 chunkSize
-= sizeof(DWORD
); /* now chunk size is one DWORD shorter */
300 nrCommands
= chunkSize
/dwSizeOfStruct
; /* and this is the number of commands */
301 /* load each command separately in new entry */
302 for (count
= 0; count
< nrCommands
; count
++) {
303 LPDMUS_PRIVATE_COMMAND pNewCommand
= calloc(1, sizeof(*pNewCommand
));
304 IStream_Read (pStm
, &pNewCommand
->pCommand
, dwSizeOfStruct
, NULL
);
305 list_add_tail (&This
->Commands
, &pNewCommand
->entry
);
307 TRACE_(dmfile
)(": reading finished\n");
308 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_LOADED
;
312 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
313 liMove
.QuadPart
= chunkSize
;
314 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
319 /* DEBUG: dumps whole band track object tree: */
320 if (TRACE_ON(dmstyle
)) {
322 DMUS_PRIVATE_COMMAND
*tmpEntry
;
323 struct list
*listEntry
;
324 TRACE("*** IDirectMusicCommandTrack (%p) ***\n", This
);
325 TRACE(" - Commands:\n");
326 LIST_FOR_EACH (listEntry
, &This
->Commands
) {
327 tmpEntry
= LIST_ENTRY (listEntry
, DMUS_PRIVATE_COMMAND
, entry
);
328 TRACE(" - Command[%i]:\n", r
);
329 TRACE(" - mtTime = %li\n", tmpEntry
->pCommand
.mtTime
);
330 TRACE(" - wMeasure = %d\n", tmpEntry
->pCommand
.wMeasure
);
331 TRACE(" - bBeat = %i\n", tmpEntry
->pCommand
.bBeat
);
332 TRACE(" - bCommand = %i\n", tmpEntry
->pCommand
.bCommand
);
333 TRACE(" - bGrooveLevel = %i\n", tmpEntry
->pCommand
.bGrooveLevel
);
334 TRACE(" - bGrooveRange = %i\n", tmpEntry
->pCommand
.bGrooveRange
);
335 TRACE(" - bRepeatMode = %i\n", tmpEntry
->pCommand
.bRepeatMode
);
343 static HRESULT WINAPI
IPersistStreamImpl_Save(IPersistStream
*iface
, IStream
*stream
,
346 IDirectMusicCommandTrack
*This
= impl_from_IPersistStream(iface
);
348 FIXME("(%p, %p, %d): stub\n", This
, stream
, cleardirty
);
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 IPersistStreamImpl_Load
,
363 IPersistStreamImpl_Save
,
364 unimpl_IPersistStream_GetSizeMax
367 /* for ClassFactory */
368 HRESULT
create_dmcommandtrack(REFIID lpcGUID
, void **ppobj
)
370 IDirectMusicCommandTrack
*track
;
374 if (!(track
= calloc(1, sizeof(*track
)))) return E_OUTOFMEMORY
;
375 track
->IDirectMusicTrack8_iface
.lpVtbl
= &dmtrack8_vtbl
;
377 dmobject_init(&track
->dmobj
, &CLSID_DirectMusicCommandTrack
,
378 (IUnknown
*)&track
->IDirectMusicTrack8_iface
);
379 track
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
380 list_init (&track
->Commands
);
382 hr
= IDirectMusicTrack8_QueryInterface(&track
->IDirectMusicTrack8_iface
,
384 IDirectMusicTrack8_Release(&track
->IDirectMusicTrack8_iface
);