1 /* IDirectMusicCommandTrack Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (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
13 * GNU Library General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * 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"
22 WINE_DEFAULT_DEBUG_CHANNEL(dmstyle
);
23 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
25 static ULONG WINAPI
IDirectMusicCommandTrack_IUnknown_AddRef (LPUNKNOWN iface
);
26 static ULONG WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_AddRef (LPDIRECTMUSICTRACK8 iface
);
27 static ULONG WINAPI
IDirectMusicCommandTrack_IPersistStream_AddRef (LPPERSISTSTREAM iface
);
29 /*****************************************************************************
30 * IDirectMusicCommandTrack implementation
32 /* IDirectMusicCommandTrack IUnknown part: */
33 static HRESULT WINAPI
IDirectMusicCommandTrack_IUnknown_QueryInterface (LPUNKNOWN iface
, REFIID riid
, LPVOID
*ppobj
) {
34 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, UnknownVtbl
, iface
);
35 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ppobj
);
37 if (IsEqualIID (riid
, &IID_IUnknown
)) {
38 *ppobj
= (LPUNKNOWN
)&This
->UnknownVtbl
;
39 IDirectMusicCommandTrack_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
41 } else if (IsEqualIID (riid
, &IID_IDirectMusicTrack
)
42 || IsEqualIID (riid
, &IID_IDirectMusicTrack8
)) {
43 *ppobj
= (LPDIRECTMUSICTRACK8
)&This
->TrackVtbl
;
44 IDirectMusicCommandTrack_IDirectMusicTrack_AddRef ((LPDIRECTMUSICTRACK8
)&This
->TrackVtbl
);
46 } else if (IsEqualIID (riid
, &IID_IPersistStream
)) {
47 *ppobj
= (LPPERSISTSTREAM
)&This
->PersistStreamVtbl
;
48 IDirectMusicCommandTrack_IPersistStream_AddRef ((LPPERSISTSTREAM
)&This
->PersistStreamVtbl
);
52 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ppobj
);
56 static ULONG WINAPI
IDirectMusicCommandTrack_IUnknown_AddRef (LPUNKNOWN iface
) {
57 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, UnknownVtbl
, iface
);
58 ULONG ref
= InterlockedIncrement(&This
->ref
);
60 TRACE("(%p): AddRef from %ld\n", This
, ref
- 1);
67 static ULONG WINAPI
IDirectMusicCommandTrack_IUnknown_Release (LPUNKNOWN iface
) {
68 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, UnknownVtbl
, iface
);
69 ULONG ref
= InterlockedDecrement(&This
->ref
);
71 TRACE("(%p): ReleaseRef to %ld\n", This
, ref
);
74 HeapFree(GetProcessHeap(), 0, This
);
77 DMSTYLE_UnlockModule();
82 static const IUnknownVtbl DirectMusicCommandTrack_Unknown_Vtbl
= {
83 IDirectMusicCommandTrack_IUnknown_QueryInterface
,
84 IDirectMusicCommandTrack_IUnknown_AddRef
,
85 IDirectMusicCommandTrack_IUnknown_Release
88 /* IDirectMusicCommandTrack IDirectMusicTrack8 part: */
89 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_QueryInterface (LPDIRECTMUSICTRACK8 iface
, REFIID riid
, LPVOID
*ppobj
) {
90 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
91 return IDirectMusicCommandTrack_IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
94 static ULONG WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_AddRef (LPDIRECTMUSICTRACK8 iface
) {
95 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
96 return IDirectMusicCommandTrack_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
99 static ULONG WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_Release (LPDIRECTMUSICTRACK8 iface
) {
100 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
101 return IDirectMusicCommandTrack_IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
104 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_Init (LPDIRECTMUSICTRACK8 iface
, IDirectMusicSegment
* pSegment
)
106 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
107 FIXME("(%p, %p): stub\n", This
, pSegment
);
111 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_InitPlay (LPDIRECTMUSICTRACK8 iface
, IDirectMusicSegmentState
* pSegmentState
, IDirectMusicPerformance
* pPerformance
, void** ppStateData
, DWORD dwVirtualTrack8ID
, DWORD dwFlags
)
113 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
114 FIXME("(%p, %p, %p, %p, %ld, %ld): stub\n", This
, pSegmentState
, pPerformance
, ppStateData
, dwVirtualTrack8ID
, dwFlags
);
118 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_EndPlay (LPDIRECTMUSICTRACK8 iface
, void* pStateData
)
120 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
121 FIXME("(%p, %p): stub\n", This
, pStateData
);
125 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_Play (LPDIRECTMUSICTRACK8 iface
, void* pStateData
, MUSIC_TIME mtStart
, MUSIC_TIME mtEnd
, MUSIC_TIME mtOffset
, DWORD dwFlags
, IDirectMusicPerformance
* pPerf
, IDirectMusicSegmentState
* pSegSt
, DWORD dwVirtualID
)
127 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
128 FIXME("(%p, %p, %ld, %ld, %ld, %ld, %p, %p, %ld): stub\n", This
, pStateData
, mtStart
, mtEnd
, mtOffset
, dwFlags
, pPerf
, pSegSt
, dwVirtualID
);
132 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_GetParam (LPDIRECTMUSICTRACK8 iface
, REFGUID rguidType
, MUSIC_TIME mtTime
, MUSIC_TIME
* pmtNext
, void* pParam
) {
133 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
134 FIXME("(%p, %s, %ld, %p, %p): stub\n", This
, debugstr_dmguid(rguidType
), mtTime
, pmtNext
, pParam
);
138 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_SetParam (LPDIRECTMUSICTRACK8 iface
, REFGUID rguidType
, MUSIC_TIME mtTime
, void* pParam
) {
139 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
140 FIXME("(%p, %s, %ld, %p): stub\n", This
, debugstr_dmguid(rguidType
), mtTime
, pParam
);
144 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_IsParamSupported (LPDIRECTMUSICTRACK8 iface
, REFGUID rguidType
) {
145 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
147 TRACE("(%p, %s): ", This
, debugstr_dmguid(rguidType
));
148 if (IsEqualGUID (rguidType
, &GUID_CommandParam
)
149 || IsEqualGUID (rguidType
, &GUID_CommandParam2
)
150 || IsEqualGUID (rguidType
, &GUID_CommandParamNext
)) {
151 TRACE("param supported\n");
155 TRACE("param unsupported\n");
156 return DMUS_E_TYPE_UNSUPPORTED
;
159 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_AddNotificationType (LPDIRECTMUSICTRACK8 iface
, REFGUID rguidNotificationType
) {
160 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
161 FIXME("(%p, %s): stub\n", This
, debugstr_dmguid(rguidNotificationType
));
165 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_RemoveNotificationType (LPDIRECTMUSICTRACK8 iface
, REFGUID rguidNotificationType
) {
166 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
167 FIXME("(%p, %s): stub\n", This
, debugstr_dmguid(rguidNotificationType
));
171 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_Clone (LPDIRECTMUSICTRACK8 iface
, MUSIC_TIME mtStart
, MUSIC_TIME mtEnd
, IDirectMusicTrack
** ppTrack
) {
172 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
173 FIXME("(%p, %ld, %ld, %p): stub\n", This
, mtStart
, mtEnd
, ppTrack
);
177 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_PlayEx (LPDIRECTMUSICTRACK8 iface
, void* pStateData
, REFERENCE_TIME rtStart
, REFERENCE_TIME rtEnd
, REFERENCE_TIME rtOffset
, DWORD dwFlags
, IDirectMusicPerformance
* pPerf
, IDirectMusicSegmentState
* pSegSt
, DWORD dwVirtualID
) {
178 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
179 FIXME("(%p, %p, %lli, %lli, %lli, %ld, %p, %p, %ld): stub\n", This
, pStateData
, rtStart
, rtEnd
, rtOffset
, dwFlags
, pPerf
, pSegSt
, dwVirtualID
);
183 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_GetParamEx (LPDIRECTMUSICTRACK8 iface
, REFGUID rguidType
, REFERENCE_TIME rtTime
, REFERENCE_TIME
* prtNext
, void* pParam
, void* pStateData
, DWORD dwFlags
) {
184 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
185 FIXME("(%p, %s, %lli, %p, %p, %p, %ld): stub\n", This
, debugstr_dmguid(rguidType
), rtTime
, prtNext
, pParam
, pStateData
, dwFlags
);
189 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_SetParamEx (LPDIRECTMUSICTRACK8 iface
, REFGUID rguidType
, REFERENCE_TIME rtTime
, void* pParam
, void* pStateData
, DWORD dwFlags
) {
190 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
191 FIXME("(%p, %s, %lli, %p, %p, %ld): stub\n", This
, debugstr_dmguid(rguidType
), rtTime
, pParam
, pStateData
, dwFlags
);
195 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_Compose (LPDIRECTMUSICTRACK8 iface
, IUnknown
* pContext
, DWORD dwTrackGroup
, IDirectMusicTrack
** ppResultTrack
) {
196 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
197 FIXME("(%p, %p, %ld, %p): stub\n", This
, pContext
, dwTrackGroup
, ppResultTrack
);
201 static HRESULT WINAPI
IDirectMusicCommandTrack_IDirectMusicTrack_Join (LPDIRECTMUSICTRACK8 iface
, IDirectMusicTrack
* pNewTrack
, MUSIC_TIME mtJoin
, IUnknown
* pContext
, DWORD dwTrackGroup
, IDirectMusicTrack
** ppResultTrack
) {
202 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, TrackVtbl
, iface
);
203 FIXME("(%p, %p, %ld, %p, %ld, %p): stub\n", This
, pNewTrack
, mtJoin
, pContext
, dwTrackGroup
, ppResultTrack
);
207 static const IDirectMusicTrack8Vtbl DirectMusicCommandTrack_Track_Vtbl
= {
208 IDirectMusicCommandTrack_IDirectMusicTrack_QueryInterface
,
209 IDirectMusicCommandTrack_IDirectMusicTrack_AddRef
,
210 IDirectMusicCommandTrack_IDirectMusicTrack_Release
,
211 IDirectMusicCommandTrack_IDirectMusicTrack_Init
,
212 IDirectMusicCommandTrack_IDirectMusicTrack_InitPlay
,
213 IDirectMusicCommandTrack_IDirectMusicTrack_EndPlay
,
214 IDirectMusicCommandTrack_IDirectMusicTrack_Play
,
215 IDirectMusicCommandTrack_IDirectMusicTrack_GetParam
,
216 IDirectMusicCommandTrack_IDirectMusicTrack_SetParam
,
217 IDirectMusicCommandTrack_IDirectMusicTrack_IsParamSupported
,
218 IDirectMusicCommandTrack_IDirectMusicTrack_AddNotificationType
,
219 IDirectMusicCommandTrack_IDirectMusicTrack_RemoveNotificationType
,
220 IDirectMusicCommandTrack_IDirectMusicTrack_Clone
,
221 IDirectMusicCommandTrack_IDirectMusicTrack_PlayEx
,
222 IDirectMusicCommandTrack_IDirectMusicTrack_GetParamEx
,
223 IDirectMusicCommandTrack_IDirectMusicTrack_SetParamEx
,
224 IDirectMusicCommandTrack_IDirectMusicTrack_Compose
,
225 IDirectMusicCommandTrack_IDirectMusicTrack_Join
228 /* IDirectMusicCommandTrack IPersistStream part: */
229 static HRESULT WINAPI
IDirectMusicCommandTrack_IPersistStream_QueryInterface (LPPERSISTSTREAM iface
, REFIID riid
, LPVOID
*ppobj
) {
230 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, PersistStreamVtbl
, iface
);
231 return IDirectMusicCommandTrack_IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
234 static ULONG WINAPI
IDirectMusicCommandTrack_IPersistStream_AddRef (LPPERSISTSTREAM iface
) {
235 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, PersistStreamVtbl
, iface
);
236 return IDirectMusicCommandTrack_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
239 static ULONG WINAPI
IDirectMusicCommandTrack_IPersistStream_Release (LPPERSISTSTREAM iface
) {
240 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, PersistStreamVtbl
, iface
);
241 return IDirectMusicCommandTrack_IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
244 static HRESULT WINAPI
IDirectMusicCommandTrack_IPersistStream_GetClassID (LPPERSISTSTREAM iface
, CLSID
* pClassID
) {
248 static HRESULT WINAPI
IDirectMusicCommandTrack_IPersistStream_IsDirty (LPPERSISTSTREAM iface
) {
252 static HRESULT WINAPI
IDirectMusicCommandTrack_IPersistStream_Load (LPPERSISTSTREAM iface
, IStream
* pStm
) {
253 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, PersistStreamVtbl
, iface
);
255 DWORD chunkSize
, dwSizeOfStruct
, nrCommands
;
256 LARGE_INTEGER liMove
; /* used when skipping chunks */
258 IStream_Read (pStm
, &chunkID
, sizeof(FOURCC
), NULL
);
259 IStream_Read (pStm
, &chunkSize
, sizeof(DWORD
), NULL
);
260 TRACE_(dmfile
)(": %s chunk (size = %ld)", debugstr_fourcc (chunkID
), chunkSize
);
262 case DMUS_FOURCC_COMMANDTRACK_CHUNK
: {
264 TRACE_(dmfile
)(": command track chunk\n");
265 IStream_Read (pStm
, &dwSizeOfStruct
, sizeof(DWORD
), NULL
);
266 if (dwSizeOfStruct
!= sizeof(DMUS_IO_COMMAND
)) {
267 TRACE_(dmfile
)(": declared size of struct (=%ld) != actual size; indicates older direct music version\n", dwSizeOfStruct
);
269 chunkSize
-= sizeof(DWORD
); /* now chunk size is one DWORD shorter */
270 nrCommands
= chunkSize
/dwSizeOfStruct
; /* and this is the number of commands */
271 /* load each command seperately in new entry */
272 for (count
= 0; count
< nrCommands
; count
++) {
273 LPDMUS_PRIVATE_COMMAND pNewCommand
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_COMMAND
));
274 IStream_Read (pStm
, &pNewCommand
->pCommand
, dwSizeOfStruct
, NULL
);
275 list_add_tail (&This
->Commands
, &pNewCommand
->entry
);
277 TRACE_(dmfile
)(": reading finished\n");
278 This
->pDesc
->dwValidData
|= DMUS_OBJ_LOADED
;
282 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
283 liMove
.QuadPart
= chunkSize
;
284 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
289 /* DEBUG: dumps whole band track object tree: */
290 if (TRACE_ON(dmstyle
)) {
292 DMUS_PRIVATE_COMMAND
*tmpEntry
;
293 struct list
*listEntry
;
294 TRACE("*** IDirectMusicCommandTrack (%p) ***\n", This
->TrackVtbl
);
295 TRACE(" - Commands:\n");
296 LIST_FOR_EACH (listEntry
, &This
->Commands
) {
297 tmpEntry
= LIST_ENTRY (listEntry
, DMUS_PRIVATE_COMMAND
, entry
);
298 TRACE(" - Command[%i]:\n", r
);
299 TRACE(" - mtTime = %li\n", tmpEntry
->pCommand
.mtTime
);
300 TRACE(" - wMeasure = %d\n", tmpEntry
->pCommand
.wMeasure
);
301 TRACE(" - bBeat = %i\n", tmpEntry
->pCommand
.bBeat
);
302 TRACE(" - bCommand = %i\n", tmpEntry
->pCommand
.bCommand
);
303 TRACE(" - bGrooveLevel = %i\n", tmpEntry
->pCommand
.bGrooveLevel
);
304 TRACE(" - bGrooveRange = %i\n", tmpEntry
->pCommand
.bGrooveRange
);
305 TRACE(" - bRepeatMode = %i\n", tmpEntry
->pCommand
.bRepeatMode
);
313 static HRESULT WINAPI
IDirectMusicCommandTrack_IPersistStream_Save (LPPERSISTSTREAM iface
, IStream
* pStm
, BOOL fClearDirty
) {
317 static HRESULT WINAPI
IDirectMusicCommandTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface
, ULARGE_INTEGER
* pcbSize
) {
321 static const IPersistStreamVtbl DirectMusicCommandTrack_PersistStream_Vtbl
= {
322 IDirectMusicCommandTrack_IPersistStream_QueryInterface
,
323 IDirectMusicCommandTrack_IPersistStream_AddRef
,
324 IDirectMusicCommandTrack_IPersistStream_Release
,
325 IDirectMusicCommandTrack_IPersistStream_GetClassID
,
326 IDirectMusicCommandTrack_IPersistStream_IsDirty
,
327 IDirectMusicCommandTrack_IPersistStream_Load
,
328 IDirectMusicCommandTrack_IPersistStream_Save
,
329 IDirectMusicCommandTrack_IPersistStream_GetSizeMax
332 /* for ClassFactory */
333 HRESULT WINAPI
DMUSIC_CreateDirectMusicCommandTrack (LPCGUID lpcGUID
, LPVOID
*ppobj
, LPUNKNOWN pUnkOuter
) {
334 IDirectMusicCommandTrack
* track
;
336 track
= HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicCommandTrack
));
339 return E_OUTOFMEMORY
;
341 track
->UnknownVtbl
= &DirectMusicCommandTrack_Unknown_Vtbl
;
342 track
->TrackVtbl
= &DirectMusicCommandTrack_Track_Vtbl
;
343 track
->PersistStreamVtbl
= &DirectMusicCommandTrack_PersistStream_Vtbl
;
344 track
->pDesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DMUS_OBJECTDESC
));
345 DM_STRUCT_INIT(track
->pDesc
);
346 track
->pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
347 memcpy (&track
->pDesc
->guidClass
, &CLSID_DirectMusicCommandTrack
, sizeof (CLSID
));
348 track
->ref
= 0; /* will be inited by QueryInterface */
349 list_init (&track
->Commands
);
351 return IDirectMusicCommandTrack_IUnknown_QueryInterface ((LPUNKNOWN
)&track
->UnknownVtbl
, lpcGUID
, ppobj
);