winecoreaudio: Use mmdevapi's session_wrapper_create.
[wine.git] / dlls / dmstyle / commandtrack.c
blob32e0bbe8c0d300eaa9bf6df4619e60349db9ea47
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"
21 #include "dmobject.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 */
32 LONG ref;
33 struct list Commands;
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,
43 void **ret_iface)
45 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
47 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ret_iface);
49 *ret_iface = NULL;
51 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDirectMusicTrack) ||
52 IsEqualIID(riid, &IID_IDirectMusicTrack8))
53 *ret_iface = iface;
54 else if (IsEqualIID(riid, &IID_IPersistStream))
55 *ret_iface = &This->dmobj.IPersistStream_iface;
56 else {
57 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ret_iface);
58 return E_NOINTERFACE;
61 IUnknown_AddRef((IUnknown*)*ret_iface);
62 return S_OK;
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);
72 return 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);
82 if (!ref) {
83 HeapFree(GetProcessHeap(), 0, This);
84 DMSTYLE_UnlockModule();
87 return ref;
90 static HRESULT WINAPI command_track_Init(IDirectMusicTrack8 *iface, IDirectMusicSegment *pSegment)
92 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
93 FIXME("(%p, %p): stub\n", This, pSegment);
94 return S_OK;
97 static HRESULT WINAPI command_track_InitPlay(IDirectMusicTrack8 *iface,
98 IDirectMusicSegmentState *pSegmentState, IDirectMusicPerformance *pPerformance,
99 void **ppStateData, DWORD dwVirtualTrack8ID, DWORD dwFlags)
101 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
102 FIXME("(%p, %p, %p, %p, %ld, %ld): stub\n", This, pSegmentState, pPerformance, ppStateData, dwVirtualTrack8ID, dwFlags);
103 return S_OK;
106 static HRESULT WINAPI command_track_EndPlay(IDirectMusicTrack8 *iface, void *pStateData)
108 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
109 FIXME("(%p, %p): stub\n", This, pStateData);
110 return S_OK;
113 static HRESULT WINAPI command_track_Play(IDirectMusicTrack8 *iface, void *pStateData,
114 MUSIC_TIME mtStart, MUSIC_TIME mtEnd, MUSIC_TIME mtOffset, DWORD dwFlags,
115 IDirectMusicPerformance *pPerf, IDirectMusicSegmentState *pSegSt, DWORD dwVirtualID)
117 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
118 FIXME("(%p, %p, %ld, %ld, %ld, %ld, %p, %p, %ld): stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
119 return S_OK;
122 static HRESULT WINAPI command_track_GetParam(IDirectMusicTrack8 *iface, REFGUID type,
123 MUSIC_TIME time, MUSIC_TIME *next, void *param)
125 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
127 TRACE("(%p, %s, %ld, %p, %p):\n", This, debugstr_dmguid(type), time, next, param);
129 if (!type)
130 return E_POINTER;
132 if (IsEqualGUID(type, &GUID_CommandParam)) {
133 FIXME("GUID_CommandParam not handled yet\n");
134 return S_OK;
135 } else if (IsEqualGUID(type, &GUID_CommandParam2)) {
136 FIXME("GUID_CommandParam2 not handled yet\n");
137 return S_OK;
138 } else if (IsEqualGUID(type, &GUID_CommandParamNext)) {
139 FIXME("GUID_CommandParamNext not handled yet\n");
140 return S_OK;
143 return DMUS_E_GET_UNSUPPORTED;
146 static HRESULT WINAPI command_track_SetParam(IDirectMusicTrack8 *iface, REFGUID type,
147 MUSIC_TIME time, void *param)
149 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
151 TRACE("(%p, %s, %ld, %p)\n", This, debugstr_dmguid(type), time, param);
153 if (!type)
154 return E_POINTER;
156 if (IsEqualGUID(type, &GUID_CommandParam)) {
157 FIXME("GUID_CommandParam not handled yet\n");
158 return S_OK;
159 } else if (IsEqualGUID(type, &GUID_CommandParamNext)) {
160 FIXME("GUID_CommandParamNext not handled yet\n");
161 return S_OK;
164 return DMUS_E_SET_UNSUPPORTED;
167 static HRESULT WINAPI command_track_IsParamSupported(IDirectMusicTrack8 *iface, REFGUID rguidType)
169 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
171 TRACE("(%p, %s)\n", This, debugstr_dmguid(rguidType));
173 if (!rguidType)
174 return E_POINTER;
176 if (IsEqualGUID (rguidType, &GUID_CommandParam)
177 || IsEqualGUID (rguidType, &GUID_CommandParam2)
178 || IsEqualGUID (rguidType, &GUID_CommandParamNext)) {
179 TRACE("param supported\n");
180 return S_OK;
183 TRACE("param unsupported\n");
184 return DMUS_E_TYPE_UNSUPPORTED;
187 static HRESULT WINAPI command_track_AddNotificationType(IDirectMusicTrack8 *iface,
188 REFGUID rguidNotificationType)
190 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
191 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
192 return S_OK;
195 static HRESULT WINAPI command_track_RemoveNotificationType(IDirectMusicTrack8 *iface,
196 REFGUID rguidNotificationType)
198 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
199 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
200 return S_OK;
203 static HRESULT WINAPI command_track_Clone(IDirectMusicTrack8 *iface, MUSIC_TIME mtStart,
204 MUSIC_TIME mtEnd, IDirectMusicTrack **ppTrack)
206 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
207 FIXME("(%p, %ld, %ld, %p): stub\n", This, mtStart, mtEnd, ppTrack);
208 return S_OK;
211 static HRESULT WINAPI command_track_PlayEx(IDirectMusicTrack8 *iface, void *pStateData,
212 REFERENCE_TIME rtStart, REFERENCE_TIME rtEnd, REFERENCE_TIME rtOffset, DWORD dwFlags,
213 IDirectMusicPerformance *pPerf, IDirectMusicSegmentState *pSegSt, DWORD dwVirtualID)
215 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
216 FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %ld, %p, %p, %ld): stub\n", This, pStateData, wine_dbgstr_longlong(rtStart),
217 wine_dbgstr_longlong(rtEnd), wine_dbgstr_longlong(rtOffset), dwFlags, pPerf, pSegSt, dwVirtualID);
218 return S_OK;
221 static HRESULT WINAPI command_track_GetParamEx(IDirectMusicTrack8 *iface, REFGUID rguidType,
222 REFERENCE_TIME rtTime, REFERENCE_TIME *prtNext, void *pParam,
223 void *pStateData, DWORD dwFlags)
225 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
226 FIXME("(%p, %s, 0x%s, %p, %p, %p, %ld): stub\n", This, debugstr_dmguid(rguidType),
227 wine_dbgstr_longlong(rtTime), prtNext, pParam, pStateData, dwFlags);
228 return S_OK;
231 static HRESULT WINAPI command_track_SetParamEx(IDirectMusicTrack8 *iface, REFGUID rguidType,
232 REFERENCE_TIME rtTime, void *pParam, void *pStateData, DWORD dwFlags)
234 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
235 FIXME("(%p, %s, 0x%s, %p, %p, %ld): stub\n", This, debugstr_dmguid(rguidType),
236 wine_dbgstr_longlong(rtTime), pParam, pStateData, dwFlags);
237 return S_OK;
240 static HRESULT WINAPI command_track_Compose(IDirectMusicTrack8 *iface, IUnknown *context,
241 DWORD trackgroup, IDirectMusicTrack **track)
243 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
245 TRACE("(%p, %p, %ld, %p): method not implemented\n", This, context, trackgroup, track);
246 return E_NOTIMPL;
249 static HRESULT WINAPI command_track_Join(IDirectMusicTrack8 *iface, IDirectMusicTrack *pNewTrack,
250 MUSIC_TIME mtJoin, IUnknown *pContext, DWORD dwTrackGroup,
251 IDirectMusicTrack **ppResultTrack)
253 IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
254 FIXME("(%p, %p, %ld, %p, %ld, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
255 return S_OK;
258 static const IDirectMusicTrack8Vtbl dmtrack8_vtbl = {
259 command_track_QueryInterface,
260 command_track_AddRef,
261 command_track_Release,
262 command_track_Init,
263 command_track_InitPlay,
264 command_track_EndPlay,
265 command_track_Play,
266 command_track_GetParam,
267 command_track_SetParam,
268 command_track_IsParamSupported,
269 command_track_AddNotificationType,
270 command_track_RemoveNotificationType,
271 command_track_Clone,
272 command_track_PlayEx,
273 command_track_GetParamEx,
274 command_track_SetParamEx,
275 command_track_Compose,
276 command_track_Join
279 static inline IDirectMusicCommandTrack *impl_from_IPersistStream(IPersistStream *iface)
281 return CONTAINING_RECORD(iface, IDirectMusicCommandTrack, dmobj.IPersistStream_iface);
284 static HRESULT WINAPI IPersistStreamImpl_Load(IPersistStream *iface, IStream *pStm)
286 IDirectMusicCommandTrack *This = impl_from_IPersistStream(iface);
287 FOURCC chunkID;
288 DWORD chunkSize, dwSizeOfStruct, nrCommands;
289 LARGE_INTEGER liMove; /* used when skipping chunks */
291 IStream_Read (pStm, &chunkID, sizeof(FOURCC), NULL);
292 IStream_Read (pStm, &chunkSize, sizeof(DWORD), NULL);
293 TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (chunkID), chunkSize);
294 switch (chunkID) {
295 case DMUS_FOURCC_COMMANDTRACK_CHUNK: {
296 DWORD count;
297 TRACE_(dmfile)(": command track chunk\n");
298 IStream_Read (pStm, &dwSizeOfStruct, sizeof(DWORD), NULL);
299 if (dwSizeOfStruct != sizeof(DMUS_IO_COMMAND)) {
300 TRACE_(dmfile)(": declared size of struct (=%ld) != actual size; indicates older direct music version\n", dwSizeOfStruct);
302 chunkSize -= sizeof(DWORD); /* now chunk size is one DWORD shorter */
303 nrCommands = chunkSize/dwSizeOfStruct; /* and this is the number of commands */
304 /* load each command separately in new entry */
305 for (count = 0; count < nrCommands; count++) {
306 LPDMUS_PRIVATE_COMMAND pNewCommand = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_COMMAND));
307 IStream_Read (pStm, &pNewCommand->pCommand, dwSizeOfStruct, NULL);
308 list_add_tail (&This->Commands, &pNewCommand->entry);
310 TRACE_(dmfile)(": reading finished\n");
311 This->dmobj.desc.dwValidData |= DMUS_OBJ_LOADED;
312 break;
314 default: {
315 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
316 liMove.QuadPart = chunkSize;
317 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
318 return E_FAIL;
322 /* DEBUG: dumps whole band track object tree: */
323 if (TRACE_ON(dmstyle)) {
324 int r = 0;
325 DMUS_PRIVATE_COMMAND *tmpEntry;
326 struct list *listEntry;
327 TRACE("*** IDirectMusicCommandTrack (%p) ***\n", This);
328 TRACE(" - Commands:\n");
329 LIST_FOR_EACH (listEntry, &This->Commands) {
330 tmpEntry = LIST_ENTRY (listEntry, DMUS_PRIVATE_COMMAND, entry);
331 TRACE(" - Command[%i]:\n", r);
332 TRACE(" - mtTime = %li\n", tmpEntry->pCommand.mtTime);
333 TRACE(" - wMeasure = %d\n", tmpEntry->pCommand.wMeasure);
334 TRACE(" - bBeat = %i\n", tmpEntry->pCommand.bBeat);
335 TRACE(" - bCommand = %i\n", tmpEntry->pCommand.bCommand);
336 TRACE(" - bGrooveLevel = %i\n", tmpEntry->pCommand.bGrooveLevel);
337 TRACE(" - bGrooveRange = %i\n", tmpEntry->pCommand.bGrooveRange);
338 TRACE(" - bRepeatMode = %i\n", tmpEntry->pCommand.bRepeatMode);
339 r++;
343 return S_OK;
346 static HRESULT WINAPI IPersistStreamImpl_Save(IPersistStream *iface, IStream *stream,
347 BOOL cleardirty)
349 IDirectMusicCommandTrack *This = impl_from_IPersistStream(iface);
351 FIXME("(%p, %p, %d): stub\n", This, stream, cleardirty);
353 if (!stream)
354 return E_POINTER;
356 return E_NOTIMPL;
359 static const IPersistStreamVtbl persiststream_vtbl = {
360 dmobj_IPersistStream_QueryInterface,
361 dmobj_IPersistStream_AddRef,
362 dmobj_IPersistStream_Release,
363 dmobj_IPersistStream_GetClassID,
364 unimpl_IPersistStream_IsDirty,
365 IPersistStreamImpl_Load,
366 IPersistStreamImpl_Save,
367 unimpl_IPersistStream_GetSizeMax
370 /* for ClassFactory */
371 HRESULT create_dmcommandtrack(REFIID lpcGUID, void **ppobj)
373 IDirectMusicCommandTrack *track;
374 HRESULT hr;
376 track = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*track));
377 if (!track) {
378 *ppobj = NULL;
379 return E_OUTOFMEMORY;
381 track->IDirectMusicTrack8_iface.lpVtbl = &dmtrack8_vtbl;
382 track->ref = 1;
383 dmobject_init(&track->dmobj, &CLSID_DirectMusicCommandTrack,
384 (IUnknown *)&track->IDirectMusicTrack8_iface);
385 track->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
386 list_init (&track->Commands);
388 DMSTYLE_LockModule();
389 hr = IDirectMusicTrack8_QueryInterface(&track->IDirectMusicTrack8_iface,
390 lpcGUID, ppobj);
391 IDirectMusicTrack8_Release(&track->IDirectMusicTrack8_iface);
393 return hr;