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_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 = &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 = &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 %d\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 %d\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, %d, %d): 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, %d, %d, %d, %d, %p, %p, %d): 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, %d, %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, %d, %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)\n", 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, %d, %d, %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, 0x%s, 0x%s, 0x%s, %d, %p, %p, %d): stub\n", This, pStateData, wine_dbgstr_longlong(rtStart),
180 wine_dbgstr_longlong(rtEnd), wine_dbgstr_longlong(rtOffset), dwFlags, pPerf, pSegSt, dwVirtualID);
184 static HRESULT WINAPI IDirectMusicCommandTrack_IDirectMusicTrack_GetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, REFERENCE_TIME* prtNext, void* pParam, void* pStateData, DWORD dwFlags) {
185 ICOM_THIS_MULTI(IDirectMusicCommandTrack, TrackVtbl, iface);
186 FIXME("(%p, %s, 0x%s, %p, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
187 wine_dbgstr_longlong(rtTime), prtNext, pParam, pStateData, dwFlags);
191 static HRESULT WINAPI IDirectMusicCommandTrack_IDirectMusicTrack_SetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, void* pParam, void* pStateData, DWORD dwFlags) {
192 ICOM_THIS_MULTI(IDirectMusicCommandTrack, TrackVtbl, iface);
193 FIXME("(%p, %s, 0x%s, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
194 wine_dbgstr_longlong(rtTime), pParam, pStateData, dwFlags);
198 static HRESULT WINAPI IDirectMusicCommandTrack_IDirectMusicTrack_Compose (LPDIRECTMUSICTRACK8 iface, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
199 ICOM_THIS_MULTI(IDirectMusicCommandTrack, TrackVtbl, iface);
200 FIXME("(%p, %p, %d, %p): stub\n", This, pContext, dwTrackGroup, ppResultTrack);
204 static HRESULT WINAPI IDirectMusicCommandTrack_IDirectMusicTrack_Join (LPDIRECTMUSICTRACK8 iface, IDirectMusicTrack* pNewTrack, MUSIC_TIME mtJoin, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack) {
205 ICOM_THIS_MULTI(IDirectMusicCommandTrack, TrackVtbl, iface);
206 FIXME("(%p, %p, %d, %p, %d, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
210 static const IDirectMusicTrack8Vtbl DirectMusicCommandTrack_Track_Vtbl = {
211 IDirectMusicCommandTrack_IDirectMusicTrack_QueryInterface,
212 IDirectMusicCommandTrack_IDirectMusicTrack_AddRef,
213 IDirectMusicCommandTrack_IDirectMusicTrack_Release,
214 IDirectMusicCommandTrack_IDirectMusicTrack_Init,
215 IDirectMusicCommandTrack_IDirectMusicTrack_InitPlay,
216 IDirectMusicCommandTrack_IDirectMusicTrack_EndPlay,
217 IDirectMusicCommandTrack_IDirectMusicTrack_Play,
218 IDirectMusicCommandTrack_IDirectMusicTrack_GetParam,
219 IDirectMusicCommandTrack_IDirectMusicTrack_SetParam,
220 IDirectMusicCommandTrack_IDirectMusicTrack_IsParamSupported,
221 IDirectMusicCommandTrack_IDirectMusicTrack_AddNotificationType,
222 IDirectMusicCommandTrack_IDirectMusicTrack_RemoveNotificationType,
223 IDirectMusicCommandTrack_IDirectMusicTrack_Clone,
224 IDirectMusicCommandTrack_IDirectMusicTrack_PlayEx,
225 IDirectMusicCommandTrack_IDirectMusicTrack_GetParamEx,
226 IDirectMusicCommandTrack_IDirectMusicTrack_SetParamEx,
227 IDirectMusicCommandTrack_IDirectMusicTrack_Compose,
228 IDirectMusicCommandTrack_IDirectMusicTrack_Join
231 /* IDirectMusicCommandTrack IPersistStream part: */
232 static HRESULT WINAPI IDirectMusicCommandTrack_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
233 ICOM_THIS_MULTI(IDirectMusicCommandTrack, PersistStreamVtbl, iface);
234 return IDirectMusicCommandTrack_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
237 static ULONG WINAPI IDirectMusicCommandTrack_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
238 ICOM_THIS_MULTI(IDirectMusicCommandTrack, PersistStreamVtbl, iface);
239 return IDirectMusicCommandTrack_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
242 static ULONG WINAPI IDirectMusicCommandTrack_IPersistStream_Release (LPPERSISTSTREAM iface) {
243 ICOM_THIS_MULTI(IDirectMusicCommandTrack, PersistStreamVtbl, iface);
244 return IDirectMusicCommandTrack_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
247 static HRESULT WINAPI IDirectMusicCommandTrack_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
251 static HRESULT WINAPI IDirectMusicCommandTrack_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
255 static HRESULT WINAPI IDirectMusicCommandTrack_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
256 ICOM_THIS_MULTI(IDirectMusicCommandTrack, PersistStreamVtbl, iface);
258 DWORD chunkSize, dwSizeOfStruct, nrCommands;
259 LARGE_INTEGER liMove; /* used when skipping chunks */
261 IStream_Read (pStm, &chunkID, sizeof(FOURCC), NULL);
262 IStream_Read (pStm, &chunkSize, sizeof(DWORD), NULL);
263 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (chunkID), chunkSize);
265 case DMUS_FOURCC_COMMANDTRACK_CHUNK: {
267 TRACE_(dmfile)(": command track chunk\n");
268 IStream_Read (pStm, &dwSizeOfStruct, sizeof(DWORD), NULL);
269 if (dwSizeOfStruct != sizeof(DMUS_IO_COMMAND)) {
270 TRACE_(dmfile)(": declared size of struct (=%d) != actual size; indicates older direct music version\n", dwSizeOfStruct);
272 chunkSize -= sizeof(DWORD); /* now chunk size is one DWORD shorter */
273 nrCommands = chunkSize/dwSizeOfStruct; /* and this is the number of commands */
274 /* load each command separately in new entry */
275 for (count = 0; count < nrCommands; count++) {
276 LPDMUS_PRIVATE_COMMAND pNewCommand = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_COMMAND));
277 IStream_Read (pStm, &pNewCommand->pCommand, dwSizeOfStruct, NULL);
278 list_add_tail (&This->Commands, &pNewCommand->entry);
280 TRACE_(dmfile)(": reading finished\n");
281 This->pDesc->dwValidData |= DMUS_OBJ_LOADED;
285 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
286 liMove.QuadPart = chunkSize;
287 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
292 /* DEBUG: dumps whole band track object tree: */
293 if (TRACE_ON(dmstyle)) {
295 DMUS_PRIVATE_COMMAND *tmpEntry;
296 struct list *listEntry;
297 TRACE("*** IDirectMusicCommandTrack (%p) ***\n", This->TrackVtbl);
298 TRACE(" - Commands:\n");
299 LIST_FOR_EACH (listEntry, &This->Commands) {
300 tmpEntry = LIST_ENTRY (listEntry, DMUS_PRIVATE_COMMAND, entry);
301 TRACE(" - Command[%i]:\n", r);
302 TRACE(" - mtTime = %i\n", tmpEntry->pCommand.mtTime);
303 TRACE(" - wMeasure = %d\n", tmpEntry->pCommand.wMeasure);
304 TRACE(" - bBeat = %i\n", tmpEntry->pCommand.bBeat);
305 TRACE(" - bCommand = %i\n", tmpEntry->pCommand.bCommand);
306 TRACE(" - bGrooveLevel = %i\n", tmpEntry->pCommand.bGrooveLevel);
307 TRACE(" - bGrooveRange = %i\n", tmpEntry->pCommand.bGrooveRange);
308 TRACE(" - bRepeatMode = %i\n", tmpEntry->pCommand.bRepeatMode);
316 static HRESULT WINAPI IDirectMusicCommandTrack_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
320 static HRESULT WINAPI IDirectMusicCommandTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
324 static const IPersistStreamVtbl DirectMusicCommandTrack_PersistStream_Vtbl = {
325 IDirectMusicCommandTrack_IPersistStream_QueryInterface,
326 IDirectMusicCommandTrack_IPersistStream_AddRef,
327 IDirectMusicCommandTrack_IPersistStream_Release,
328 IDirectMusicCommandTrack_IPersistStream_GetClassID,
329 IDirectMusicCommandTrack_IPersistStream_IsDirty,
330 IDirectMusicCommandTrack_IPersistStream_Load,
331 IDirectMusicCommandTrack_IPersistStream_Save,
332 IDirectMusicCommandTrack_IPersistStream_GetSizeMax
335 /* for ClassFactory */
336 HRESULT WINAPI DMUSIC_CreateDirectMusicCommandTrack (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
337 IDirectMusicCommandTrack* track;
339 track = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicCommandTrack));
342 return E_OUTOFMEMORY;
344 track->UnknownVtbl = &DirectMusicCommandTrack_Unknown_Vtbl;
345 track->TrackVtbl = &DirectMusicCommandTrack_Track_Vtbl;
346 track->PersistStreamVtbl = &DirectMusicCommandTrack_PersistStream_Vtbl;
347 track->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
348 DM_STRUCT_INIT(track->pDesc);
349 track->pDesc->dwValidData |= DMUS_OBJ_CLASS;
350 track->pDesc->guidClass = CLSID_DirectMusicCommandTrack;
351 track->ref = 0; /* will be inited by QueryInterface */
352 list_init (&track->Commands);
354 return IDirectMusicCommandTrack_IUnknown_QueryInterface ((LPUNKNOWN)&track->UnknownVtbl, lpcGUID, ppobj);