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"
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_IPersistStream_AddRef (LPPERSISTSTREAM iface
);
28 /*****************************************************************************
29 * IDirectMusicCommandTrack implementation
31 typedef struct IDirectMusicCommandTrack
{
32 const IUnknownVtbl
*UnknownVtbl
;
33 IDirectMusicTrack8 IDirectMusicTrack8_iface
;
34 const IPersistStreamVtbl
*PersistStreamVtbl
;
36 DMUS_OBJECTDESC
*pDesc
;
38 } IDirectMusicCommandTrack
;
40 /* IDirectMusicCommandTrack IUnknown part: */
41 static HRESULT WINAPI
IDirectMusicCommandTrack_IUnknown_QueryInterface (LPUNKNOWN iface
, REFIID riid
, LPVOID
*ppobj
) {
42 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, UnknownVtbl
, iface
);
43 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ppobj
);
45 if (IsEqualIID (riid
, &IID_IUnknown
)) {
46 *ppobj
= &This
->UnknownVtbl
;
47 IDirectMusicCommandTrack_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
49 } else if (IsEqualIID (riid
, &IID_IDirectMusicTrack
)
50 || IsEqualIID (riid
, &IID_IDirectMusicTrack8
)) {
51 *ppobj
= &This
->IDirectMusicTrack8_iface
;
52 IDirectMusicTrack8_AddRef (&This
->IDirectMusicTrack8_iface
);
54 } else if (IsEqualIID (riid
, &IID_IPersistStream
)) {
55 *ppobj
= &This
->PersistStreamVtbl
;
56 IDirectMusicCommandTrack_IPersistStream_AddRef ((LPPERSISTSTREAM
)&This
->PersistStreamVtbl
);
60 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ppobj
);
64 static ULONG WINAPI
IDirectMusicCommandTrack_IUnknown_AddRef (LPUNKNOWN iface
) {
65 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, UnknownVtbl
, iface
);
66 ULONG ref
= InterlockedIncrement(&This
->ref
);
68 TRACE("(%p): AddRef from %d\n", This
, ref
- 1);
75 static ULONG WINAPI
IDirectMusicCommandTrack_IUnknown_Release (LPUNKNOWN iface
) {
76 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, UnknownVtbl
, iface
);
77 ULONG ref
= InterlockedDecrement(&This
->ref
);
79 TRACE("(%p): ReleaseRef to %d\n", This
, ref
);
82 HeapFree(GetProcessHeap(), 0, This
);
85 DMSTYLE_UnlockModule();
90 static const IUnknownVtbl DirectMusicCommandTrack_Unknown_Vtbl
= {
91 IDirectMusicCommandTrack_IUnknown_QueryInterface
,
92 IDirectMusicCommandTrack_IUnknown_AddRef
,
93 IDirectMusicCommandTrack_IUnknown_Release
96 /* IDirectMusicCommandTrack IDirectMusicTrack8 part: */
97 static inline IDirectMusicCommandTrack
*impl_from_IDirectMusicTrack8(IDirectMusicTrack8
*iface
)
99 return CONTAINING_RECORD(iface
, IDirectMusicCommandTrack
, IDirectMusicTrack8_iface
);
102 static HRESULT WINAPI
IDirectMusicTrack8Impl_QueryInterface(IDirectMusicTrack8
*iface
, REFIID riid
,
105 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
106 return IDirectMusicCommandTrack_IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
109 static ULONG WINAPI
IDirectMusicTrack8Impl_AddRef(IDirectMusicTrack8
*iface
)
111 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
112 return IDirectMusicCommandTrack_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
115 static ULONG WINAPI
IDirectMusicTrack8Impl_Release(IDirectMusicTrack8
*iface
)
117 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
118 return IDirectMusicCommandTrack_IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
121 static HRESULT WINAPI
IDirectMusicTrack8Impl_Init(IDirectMusicTrack8
*iface
,
122 IDirectMusicSegment
*pSegment
)
124 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
125 FIXME("(%p, %p): stub\n", This
, pSegment
);
129 static HRESULT WINAPI
IDirectMusicTrack8Impl_InitPlay(IDirectMusicTrack8
*iface
,
130 IDirectMusicSegmentState
*pSegmentState
, IDirectMusicPerformance
*pPerformance
,
131 void **ppStateData
, DWORD dwVirtualTrack8ID
, DWORD dwFlags
)
133 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
134 FIXME("(%p, %p, %p, %p, %d, %d): stub\n", This
, pSegmentState
, pPerformance
, ppStateData
, dwVirtualTrack8ID
, dwFlags
);
138 static HRESULT WINAPI
IDirectMusicTrack8Impl_EndPlay(IDirectMusicTrack8
*iface
, void *pStateData
)
140 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
141 FIXME("(%p, %p): stub\n", This
, pStateData
);
145 static HRESULT WINAPI
IDirectMusicTrack8Impl_Play(IDirectMusicTrack8
*iface
, void *pStateData
,
146 MUSIC_TIME mtStart
, MUSIC_TIME mtEnd
, MUSIC_TIME mtOffset
, DWORD dwFlags
,
147 IDirectMusicPerformance
*pPerf
, IDirectMusicSegmentState
*pSegSt
, DWORD dwVirtualID
)
149 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
150 FIXME("(%p, %p, %d, %d, %d, %d, %p, %p, %d): stub\n", This
, pStateData
, mtStart
, mtEnd
, mtOffset
, dwFlags
, pPerf
, pSegSt
, dwVirtualID
);
154 static HRESULT WINAPI
IDirectMusicTrack8Impl_GetParam(IDirectMusicTrack8
*iface
, REFGUID rguidType
,
155 MUSIC_TIME mtTime
, MUSIC_TIME
*pmtNext
, void *pParam
)
157 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
158 FIXME("(%p, %s, %d, %p, %p): stub\n", This
, debugstr_dmguid(rguidType
), mtTime
, pmtNext
, pParam
);
162 static HRESULT WINAPI
IDirectMusicTrack8Impl_SetParam(IDirectMusicTrack8
*iface
, REFGUID rguidType
,
163 MUSIC_TIME mtTime
, void *pParam
)
165 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
166 FIXME("(%p, %s, %d, %p): stub\n", This
, debugstr_dmguid(rguidType
), mtTime
, pParam
);
170 static HRESULT WINAPI
IDirectMusicTrack8Impl_IsParamSupported(IDirectMusicTrack8
*iface
,
173 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
175 TRACE("(%p, %s)\n", This
, debugstr_dmguid(rguidType
));
180 if (IsEqualGUID (rguidType
, &GUID_CommandParam
)
181 || IsEqualGUID (rguidType
, &GUID_CommandParam2
)
182 || IsEqualGUID (rguidType
, &GUID_CommandParamNext
)) {
183 TRACE("param supported\n");
187 TRACE("param unsupported\n");
188 return DMUS_E_TYPE_UNSUPPORTED
;
191 static HRESULT WINAPI
IDirectMusicTrack8Impl_AddNotificationType(IDirectMusicTrack8
*iface
,
192 REFGUID rguidNotificationType
)
194 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
195 FIXME("(%p, %s): stub\n", This
, debugstr_dmguid(rguidNotificationType
));
199 static HRESULT WINAPI
IDirectMusicTrack8Impl_RemoveNotificationType(IDirectMusicTrack8
*iface
,
200 REFGUID rguidNotificationType
)
202 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
203 FIXME("(%p, %s): stub\n", This
, debugstr_dmguid(rguidNotificationType
));
207 static HRESULT WINAPI
IDirectMusicTrack8Impl_Clone(IDirectMusicTrack8
*iface
, MUSIC_TIME mtStart
,
208 MUSIC_TIME mtEnd
, IDirectMusicTrack
**ppTrack
)
210 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
211 FIXME("(%p, %d, %d, %p): stub\n", This
, mtStart
, mtEnd
, ppTrack
);
215 static HRESULT WINAPI
IDirectMusicTrack8Impl_PlayEx(IDirectMusicTrack8
*iface
, void *pStateData
,
216 REFERENCE_TIME rtStart
, REFERENCE_TIME rtEnd
, REFERENCE_TIME rtOffset
, DWORD dwFlags
,
217 IDirectMusicPerformance
*pPerf
, IDirectMusicSegmentState
*pSegSt
, DWORD dwVirtualID
)
219 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
220 FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %d, %p, %p, %d): stub\n", This
, pStateData
, wine_dbgstr_longlong(rtStart
),
221 wine_dbgstr_longlong(rtEnd
), wine_dbgstr_longlong(rtOffset
), dwFlags
, pPerf
, pSegSt
, dwVirtualID
);
225 static HRESULT WINAPI
IDirectMusicTrack8Impl_GetParamEx(IDirectMusicTrack8
*iface
,
226 REFGUID rguidType
, REFERENCE_TIME rtTime
, REFERENCE_TIME
*prtNext
, void *pParam
,
227 void *pStateData
, DWORD dwFlags
)
229 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
230 FIXME("(%p, %s, 0x%s, %p, %p, %p, %d): stub\n", This
, debugstr_dmguid(rguidType
),
231 wine_dbgstr_longlong(rtTime
), prtNext
, pParam
, pStateData
, dwFlags
);
235 static HRESULT WINAPI
IDirectMusicTrack8Impl_SetParamEx(IDirectMusicTrack8
*iface
,
236 REFGUID rguidType
, REFERENCE_TIME rtTime
, void *pParam
, void *pStateData
, DWORD dwFlags
)
238 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
239 FIXME("(%p, %s, 0x%s, %p, %p, %d): stub\n", This
, debugstr_dmguid(rguidType
),
240 wine_dbgstr_longlong(rtTime
), pParam
, pStateData
, dwFlags
);
244 static HRESULT WINAPI
IDirectMusicTrack8Impl_Compose(IDirectMusicTrack8
*iface
, IUnknown
*context
,
245 DWORD trackgroup
, IDirectMusicTrack
**track
)
247 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
249 TRACE("(%p, %p, %d, %p): method not implemented\n", This
, context
, trackgroup
, track
);
253 static HRESULT WINAPI
IDirectMusicTrack8Impl_Join(IDirectMusicTrack8
*iface
,
254 IDirectMusicTrack
*pNewTrack
, MUSIC_TIME mtJoin
, IUnknown
*pContext
, DWORD dwTrackGroup
,
255 IDirectMusicTrack
**ppResultTrack
)
257 IDirectMusicCommandTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
258 FIXME("(%p, %p, %d, %p, %d, %p): stub\n", This
, pNewTrack
, mtJoin
, pContext
, dwTrackGroup
, ppResultTrack
);
262 static const IDirectMusicTrack8Vtbl dmtrack8_vtbl
= {
263 IDirectMusicTrack8Impl_QueryInterface
,
264 IDirectMusicTrack8Impl_AddRef
,
265 IDirectMusicTrack8Impl_Release
,
266 IDirectMusicTrack8Impl_Init
,
267 IDirectMusicTrack8Impl_InitPlay
,
268 IDirectMusicTrack8Impl_EndPlay
,
269 IDirectMusicTrack8Impl_Play
,
270 IDirectMusicTrack8Impl_GetParam
,
271 IDirectMusicTrack8Impl_SetParam
,
272 IDirectMusicTrack8Impl_IsParamSupported
,
273 IDirectMusicTrack8Impl_AddNotificationType
,
274 IDirectMusicTrack8Impl_RemoveNotificationType
,
275 IDirectMusicTrack8Impl_Clone
,
276 IDirectMusicTrack8Impl_PlayEx
,
277 IDirectMusicTrack8Impl_GetParamEx
,
278 IDirectMusicTrack8Impl_SetParamEx
,
279 IDirectMusicTrack8Impl_Compose
,
280 IDirectMusicTrack8Impl_Join
283 /* IDirectMusicCommandTrack IPersistStream part: */
284 static HRESULT WINAPI
IDirectMusicCommandTrack_IPersistStream_QueryInterface (LPPERSISTSTREAM iface
, REFIID riid
, LPVOID
*ppobj
) {
285 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, PersistStreamVtbl
, iface
);
286 return IDirectMusicCommandTrack_IUnknown_QueryInterface ((LPUNKNOWN
)&This
->UnknownVtbl
, riid
, ppobj
);
289 static ULONG WINAPI
IDirectMusicCommandTrack_IPersistStream_AddRef (LPPERSISTSTREAM iface
) {
290 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, PersistStreamVtbl
, iface
);
291 return IDirectMusicCommandTrack_IUnknown_AddRef ((LPUNKNOWN
)&This
->UnknownVtbl
);
294 static ULONG WINAPI
IDirectMusicCommandTrack_IPersistStream_Release (LPPERSISTSTREAM iface
) {
295 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, PersistStreamVtbl
, iface
);
296 return IDirectMusicCommandTrack_IUnknown_Release ((LPUNKNOWN
)&This
->UnknownVtbl
);
299 static HRESULT WINAPI
IDirectMusicCommandTrack_IPersistStream_GetClassID (LPPERSISTSTREAM iface
, CLSID
* pClassID
) {
303 static HRESULT WINAPI
IDirectMusicCommandTrack_IPersistStream_IsDirty (LPPERSISTSTREAM iface
) {
307 static HRESULT WINAPI
IDirectMusicCommandTrack_IPersistStream_Load (LPPERSISTSTREAM iface
, IStream
* pStm
) {
308 ICOM_THIS_MULTI(IDirectMusicCommandTrack
, PersistStreamVtbl
, iface
);
310 DWORD chunkSize
, dwSizeOfStruct
, nrCommands
;
311 LARGE_INTEGER liMove
; /* used when skipping chunks */
313 IStream_Read (pStm
, &chunkID
, sizeof(FOURCC
), NULL
);
314 IStream_Read (pStm
, &chunkSize
, sizeof(DWORD
), NULL
);
315 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (chunkID
), chunkSize
);
317 case DMUS_FOURCC_COMMANDTRACK_CHUNK
: {
319 TRACE_(dmfile
)(": command track chunk\n");
320 IStream_Read (pStm
, &dwSizeOfStruct
, sizeof(DWORD
), NULL
);
321 if (dwSizeOfStruct
!= sizeof(DMUS_IO_COMMAND
)) {
322 TRACE_(dmfile
)(": declared size of struct (=%d) != actual size; indicates older direct music version\n", dwSizeOfStruct
);
324 chunkSize
-= sizeof(DWORD
); /* now chunk size is one DWORD shorter */
325 nrCommands
= chunkSize
/dwSizeOfStruct
; /* and this is the number of commands */
326 /* load each command separately in new entry */
327 for (count
= 0; count
< nrCommands
; count
++) {
328 LPDMUS_PRIVATE_COMMAND pNewCommand
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(DMUS_PRIVATE_COMMAND
));
329 IStream_Read (pStm
, &pNewCommand
->pCommand
, dwSizeOfStruct
, NULL
);
330 list_add_tail (&This
->Commands
, &pNewCommand
->entry
);
332 TRACE_(dmfile
)(": reading finished\n");
333 This
->pDesc
->dwValidData
|= DMUS_OBJ_LOADED
;
337 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
338 liMove
.QuadPart
= chunkSize
;
339 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
344 /* DEBUG: dumps whole band track object tree: */
345 if (TRACE_ON(dmstyle
)) {
347 DMUS_PRIVATE_COMMAND
*tmpEntry
;
348 struct list
*listEntry
;
349 TRACE("*** IDirectMusicCommandTrack (%p) ***\n", This
);
350 TRACE(" - Commands:\n");
351 LIST_FOR_EACH (listEntry
, &This
->Commands
) {
352 tmpEntry
= LIST_ENTRY (listEntry
, DMUS_PRIVATE_COMMAND
, entry
);
353 TRACE(" - Command[%i]:\n", r
);
354 TRACE(" - mtTime = %i\n", tmpEntry
->pCommand
.mtTime
);
355 TRACE(" - wMeasure = %d\n", tmpEntry
->pCommand
.wMeasure
);
356 TRACE(" - bBeat = %i\n", tmpEntry
->pCommand
.bBeat
);
357 TRACE(" - bCommand = %i\n", tmpEntry
->pCommand
.bCommand
);
358 TRACE(" - bGrooveLevel = %i\n", tmpEntry
->pCommand
.bGrooveLevel
);
359 TRACE(" - bGrooveRange = %i\n", tmpEntry
->pCommand
.bGrooveRange
);
360 TRACE(" - bRepeatMode = %i\n", tmpEntry
->pCommand
.bRepeatMode
);
368 static HRESULT WINAPI
IDirectMusicCommandTrack_IPersistStream_Save (LPPERSISTSTREAM iface
, IStream
* pStm
, BOOL fClearDirty
) {
372 static HRESULT WINAPI
IDirectMusicCommandTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface
, ULARGE_INTEGER
* pcbSize
) {
376 static const IPersistStreamVtbl DirectMusicCommandTrack_PersistStream_Vtbl
= {
377 IDirectMusicCommandTrack_IPersistStream_QueryInterface
,
378 IDirectMusicCommandTrack_IPersistStream_AddRef
,
379 IDirectMusicCommandTrack_IPersistStream_Release
,
380 IDirectMusicCommandTrack_IPersistStream_GetClassID
,
381 IDirectMusicCommandTrack_IPersistStream_IsDirty
,
382 IDirectMusicCommandTrack_IPersistStream_Load
,
383 IDirectMusicCommandTrack_IPersistStream_Save
,
384 IDirectMusicCommandTrack_IPersistStream_GetSizeMax
387 /* for ClassFactory */
388 HRESULT WINAPI
create_dmcommandtrack(REFIID lpcGUID
, void **ppobj
)
390 IDirectMusicCommandTrack
* track
;
392 track
= HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicCommandTrack
));
395 return E_OUTOFMEMORY
;
397 track
->UnknownVtbl
= &DirectMusicCommandTrack_Unknown_Vtbl
;
398 track
->IDirectMusicTrack8_iface
.lpVtbl
= &dmtrack8_vtbl
;
399 track
->PersistStreamVtbl
= &DirectMusicCommandTrack_PersistStream_Vtbl
;
400 track
->pDesc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DMUS_OBJECTDESC
));
401 DM_STRUCT_INIT(track
->pDesc
);
402 track
->pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
403 track
->pDesc
->guidClass
= CLSID_DirectMusicCommandTrack
;
404 track
->ref
= 0; /* will be inited by QueryInterface */
405 list_init (&track
->Commands
);
407 return IDirectMusicCommandTrack_IUnknown_QueryInterface ((LPUNKNOWN
)&track
->UnknownVtbl
, lpcGUID
, ppobj
);