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
IDirectMusicTrack8Impl_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
IDirectMusicTrack8Impl_AddRef(IDirectMusicTrack8
*iface
)
67 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
68 LONG ref
= InterlockedIncrement(&This
->ref
);
70 TRACE("(%p) ref=%d\n", This
, ref
);
75 static ULONG WINAPI
IDirectMusicTrack8Impl_Release(IDirectMusicTrack8
*iface
)
77 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
78 LONG ref
= InterlockedDecrement(&This
->ref
);
80 TRACE("(%p) ref=%d\n", This
, ref
);
83 HeapFree(GetProcessHeap(), 0, This
);
84 DMSTYLE_UnlockModule();
90 static HRESULT WINAPI
IDirectMusicTrack8Impl_Init(IDirectMusicTrack8
*iface
,
91 IDirectMusicSegment
*pSegment
)
93 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
94 FIXME("(%p, %p): stub\n", This
, pSegment
);
98 static HRESULT WINAPI
IDirectMusicTrack8Impl_InitPlay(IDirectMusicTrack8
*iface
,
99 IDirectMusicSegmentState
*pSegmentState
, IDirectMusicPerformance
*pPerformance
,
100 void **ppStateData
, DWORD dwVirtualTrack8ID
, DWORD dwFlags
)
102 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
103 FIXME("(%p, %p, %p, %p, %d, %d): stub\n", This
, pSegmentState
, pPerformance
, ppStateData
, dwVirtualTrack8ID
, dwFlags
);
107 static HRESULT WINAPI
IDirectMusicTrack8Impl_EndPlay(IDirectMusicTrack8
*iface
, void *pStateData
)
109 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
110 FIXME("(%p, %p): stub\n", This
, pStateData
);
114 static HRESULT WINAPI
IDirectMusicTrack8Impl_Play(IDirectMusicTrack8
*iface
, void *pStateData
,
115 MUSIC_TIME mtStart
, MUSIC_TIME mtEnd
, MUSIC_TIME mtOffset
, DWORD dwFlags
,
116 IDirectMusicPerformance
*pPerf
, IDirectMusicSegmentState
*pSegSt
, DWORD dwVirtualID
)
118 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
119 FIXME("(%p, %p, %d, %d, %d, %d, %p, %p, %d): stub\n", This
, pStateData
, mtStart
, mtEnd
, mtOffset
, dwFlags
, pPerf
, pSegSt
, dwVirtualID
);
123 static HRESULT WINAPI
IDirectMusicTrack8Impl_GetParam(IDirectMusicTrack8
*iface
, REFGUID rguidType
,
124 MUSIC_TIME mtTime
, MUSIC_TIME
*pmtNext
, void *pParam
)
126 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
127 FIXME("(%p, %s, %d, %p, %p): stub\n", This
, debugstr_dmguid(rguidType
), mtTime
, pmtNext
, pParam
);
131 static HRESULT WINAPI
IDirectMusicTrack8Impl_SetParam(IDirectMusicTrack8
*iface
, REFGUID rguidType
,
132 MUSIC_TIME mtTime
, void *pParam
)
134 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
135 FIXME("(%p, %s, %d, %p): stub\n", This
, debugstr_dmguid(rguidType
), mtTime
, pParam
);
139 static HRESULT WINAPI
IDirectMusicTrack8Impl_IsParamSupported(IDirectMusicTrack8
*iface
,
142 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
144 TRACE("(%p, %s)\n", This
, debugstr_dmguid(rguidType
));
149 if (IsEqualGUID (rguidType
, &GUID_CommandParam
)
150 || IsEqualGUID (rguidType
, &GUID_CommandParam2
)
151 || IsEqualGUID (rguidType
, &GUID_CommandParamNext
)) {
152 TRACE("param supported\n");
156 TRACE("param unsupported\n");
157 return DMUS_E_TYPE_UNSUPPORTED
;
160 static HRESULT WINAPI
IDirectMusicTrack8Impl_AddNotificationType(IDirectMusicTrack8
*iface
,
161 REFGUID rguidNotificationType
)
163 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
164 FIXME("(%p, %s): stub\n", This
, debugstr_dmguid(rguidNotificationType
));
168 static HRESULT WINAPI
IDirectMusicTrack8Impl_RemoveNotificationType(IDirectMusicTrack8
*iface
,
169 REFGUID rguidNotificationType
)
171 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
172 FIXME("(%p, %s): stub\n", This
, debugstr_dmguid(rguidNotificationType
));
176 static HRESULT WINAPI
IDirectMusicTrack8Impl_Clone(IDirectMusicTrack8
*iface
, MUSIC_TIME mtStart
,
177 MUSIC_TIME mtEnd
, IDirectMusicTrack
**ppTrack
)
179 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
180 FIXME("(%p, %d, %d, %p): stub\n", This
, mtStart
, mtEnd
, ppTrack
);
184 static HRESULT WINAPI
IDirectMusicTrack8Impl_PlayEx(IDirectMusicTrack8
*iface
, void *pStateData
,
185 REFERENCE_TIME rtStart
, REFERENCE_TIME rtEnd
, REFERENCE_TIME rtOffset
, DWORD dwFlags
,
186 IDirectMusicPerformance
*pPerf
, IDirectMusicSegmentState
*pSegSt
, DWORD dwVirtualID
)
188 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
189 FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %d, %p, %p, %d): stub\n", This
, pStateData
, wine_dbgstr_longlong(rtStart
),
190 wine_dbgstr_longlong(rtEnd
), wine_dbgstr_longlong(rtOffset
), dwFlags
, pPerf
, pSegSt
, dwVirtualID
);
194 static HRESULT WINAPI
IDirectMusicTrack8Impl_GetParamEx(IDirectMusicTrack8
*iface
,
195 REFGUID rguidType
, REFERENCE_TIME rtTime
, REFERENCE_TIME
*prtNext
, void *pParam
,
196 void *pStateData
, DWORD dwFlags
)
198 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
199 FIXME("(%p, %s, 0x%s, %p, %p, %p, %d): stub\n", This
, debugstr_dmguid(rguidType
),
200 wine_dbgstr_longlong(rtTime
), prtNext
, pParam
, pStateData
, dwFlags
);
204 static HRESULT WINAPI
IDirectMusicTrack8Impl_SetParamEx(IDirectMusicTrack8
*iface
,
205 REFGUID rguidType
, REFERENCE_TIME rtTime
, void *pParam
, void *pStateData
, DWORD dwFlags
)
207 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
208 FIXME("(%p, %s, 0x%s, %p, %p, %d): stub\n", This
, debugstr_dmguid(rguidType
),
209 wine_dbgstr_longlong(rtTime
), pParam
, pStateData
, dwFlags
);
213 static HRESULT WINAPI
IDirectMusicTrack8Impl_Compose(IDirectMusicTrack8
*iface
, IUnknown
*context
,
214 DWORD trackgroup
, IDirectMusicTrack
**track
)
216 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
218 TRACE("(%p, %p, %d, %p): method not implemented\n", This
, context
, trackgroup
, track
);
222 static HRESULT WINAPI
IDirectMusicTrack8Impl_Join(IDirectMusicTrack8
*iface
,
223 IDirectMusicTrack
*pNewTrack
, MUSIC_TIME mtJoin
, IUnknown
*pContext
, DWORD dwTrackGroup
,
224 IDirectMusicTrack
**ppResultTrack
)
226 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
227 FIXME("(%p, %p, %d, %p, %d, %p): stub\n", This
, pNewTrack
, mtJoin
, pContext
, dwTrackGroup
, ppResultTrack
);
231 static const IDirectMusicTrack8Vtbl dmtrack8_vtbl
= {
232 IDirectMusicTrack8Impl_QueryInterface
,
233 IDirectMusicTrack8Impl_AddRef
,
234 IDirectMusicTrack8Impl_Release
,
235 IDirectMusicTrack8Impl_Init
,
236 IDirectMusicTrack8Impl_InitPlay
,
237 IDirectMusicTrack8Impl_EndPlay
,
238 IDirectMusicTrack8Impl_Play
,
239 IDirectMusicTrack8Impl_GetParam
,
240 IDirectMusicTrack8Impl_SetParam
,
241 IDirectMusicTrack8Impl_IsParamSupported
,
242 IDirectMusicTrack8Impl_AddNotificationType
,
243 IDirectMusicTrack8Impl_RemoveNotificationType
,
244 IDirectMusicTrack8Impl_Clone
,
245 IDirectMusicTrack8Impl_PlayEx
,
246 IDirectMusicTrack8Impl_GetParamEx
,
247 IDirectMusicTrack8Impl_SetParamEx
,
248 IDirectMusicTrack8Impl_Compose
,
249 IDirectMusicTrack8Impl_Join
252 static inline IDirectMusicCommandTrack
*impl_from_IPersistStream(IPersistStream
*iface
)
254 return CONTAINING_RECORD(iface
, IDirectMusicCommandTrack
, dmobj
.IPersistStream_iface
);
257 static HRESULT WINAPI
IPersistStreamImpl_Load(IPersistStream
*iface
, IStream
*pStm
)
259 IDirectMusicCommandTrack
*This
= impl_from_IPersistStream(iface
);
261 DWORD chunkSize
, dwSizeOfStruct
, nrCommands
;
262 LARGE_INTEGER liMove
; /* used when skipping chunks */
264 IStream_Read (pStm
, &chunkID
, sizeof(FOURCC
), NULL
);
265 IStream_Read (pStm
, &chunkSize
, sizeof(DWORD
), NULL
);
266 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (chunkID
), chunkSize
);
268 case DMUS_FOURCC_COMMANDTRACK_CHUNK
: {
270 TRACE_(dmfile
)(": command track chunk\n");
271 IStream_Read (pStm
, &dwSizeOfStruct
, sizeof(DWORD
), NULL
);
272 if (dwSizeOfStruct
!= sizeof(DMUS_IO_COMMAND
)) {
273 TRACE_(dmfile
)(": declared size of struct (=%d) != actual size; indicates older direct music version\n", dwSizeOfStruct
);
275 chunkSize
-= sizeof(DWORD
); /* now chunk size is one DWORD shorter */
276 nrCommands
= chunkSize
/dwSizeOfStruct
; /* and this is the number of commands */
277 /* load each command separately in new entry */
278 for (count
= 0; count
< nrCommands
; count
++) {
279 LPDMUS_PRIVATE_COMMAND pNewCommand
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_COMMAND
));
280 IStream_Read (pStm
, &pNewCommand
->pCommand
, dwSizeOfStruct
, NULL
);
281 list_add_tail (&This
->Commands
, &pNewCommand
->entry
);
283 TRACE_(dmfile
)(": reading finished\n");
284 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_LOADED
;
288 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
289 liMove
.QuadPart
= chunkSize
;
290 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
295 /* DEBUG: dumps whole band track object tree: */
296 if (TRACE_ON(dmstyle
)) {
298 DMUS_PRIVATE_COMMAND
*tmpEntry
;
299 struct list
*listEntry
;
300 TRACE("*** IDirectMusicCommandTrack (%p) ***\n", This
);
301 TRACE(" - Commands:\n");
302 LIST_FOR_EACH (listEntry
, &This
->Commands
) {
303 tmpEntry
= LIST_ENTRY (listEntry
, DMUS_PRIVATE_COMMAND
, entry
);
304 TRACE(" - Command[%i]:\n", r
);
305 TRACE(" - mtTime = %i\n", tmpEntry
->pCommand
.mtTime
);
306 TRACE(" - wMeasure = %d\n", tmpEntry
->pCommand
.wMeasure
);
307 TRACE(" - bBeat = %i\n", tmpEntry
->pCommand
.bBeat
);
308 TRACE(" - bCommand = %i\n", tmpEntry
->pCommand
.bCommand
);
309 TRACE(" - bGrooveLevel = %i\n", tmpEntry
->pCommand
.bGrooveLevel
);
310 TRACE(" - bGrooveRange = %i\n", tmpEntry
->pCommand
.bGrooveRange
);
311 TRACE(" - bRepeatMode = %i\n", tmpEntry
->pCommand
.bRepeatMode
);
319 static HRESULT WINAPI
IPersistStreamImpl_Save(IPersistStream
*iface
, IStream
*stream
,
322 IDirectMusicCommandTrack
*This
= impl_from_IPersistStream(iface
);
324 FIXME("(%p, %p, %d): stub\n", This
, stream
, cleardirty
);
332 static const IPersistStreamVtbl persiststream_vtbl
= {
333 dmobj_IPersistStream_QueryInterface
,
334 dmobj_IPersistStream_AddRef
,
335 dmobj_IPersistStream_Release
,
336 dmobj_IPersistStream_GetClassID
,
337 unimpl_IPersistStream_IsDirty
,
338 IPersistStreamImpl_Load
,
339 IPersistStreamImpl_Save
,
340 unimpl_IPersistStream_GetSizeMax
343 /* for ClassFactory */
344 HRESULT WINAPI
create_dmcommandtrack(REFIID lpcGUID
, void **ppobj
)
346 IDirectMusicCommandTrack
*track
;
349 track
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*track
));
352 return E_OUTOFMEMORY
;
354 track
->IDirectMusicTrack8_iface
.lpVtbl
= &dmtrack8_vtbl
;
356 dmobject_init(&track
->dmobj
, &CLSID_DirectMusicCommandTrack
,
357 (IUnknown
*)&track
->IDirectMusicTrack8_iface
);
358 track
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
359 list_init (&track
->Commands
);
361 DMSTYLE_LockModule();
362 hr
= IDirectMusicTrack8_QueryInterface(&track
->IDirectMusicTrack8_iface
,
364 IDirectMusicTrack8_Release(&track
->IDirectMusicTrack8_iface
);