wineps: Handle EMR_INVERTRGN record in spool files.
[wine.git] / dlls / dmstyle / styletrack.c
blob83b03807ddf01db143a217a414fa618f0394de7f
1 /* IDirectMusicStyleTrack 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 #include "wine/heap.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(dmstyle);
27 /*****************************************************************************
28 * IDirectMusicStyleTrack implementation
30 struct style_item {
31 struct list entry;
32 DWORD timestamp;
33 IDirectMusicStyle8 *dmstyle;
36 typedef struct IDirectMusicStyleTrack {
37 IDirectMusicTrack8 IDirectMusicTrack8_iface;
38 struct dmobject dmobj; /* IPersistStream only */
39 LONG ref;
40 struct list Items;
41 } IDirectMusicStyleTrack;
43 /* IDirectMusicStyleTrack IDirectMusicTrack8 part: */
44 static inline IDirectMusicStyleTrack *impl_from_IDirectMusicTrack8(IDirectMusicTrack8 *iface)
46 return CONTAINING_RECORD(iface, IDirectMusicStyleTrack, IDirectMusicTrack8_iface);
49 static HRESULT WINAPI style_track_QueryInterface(IDirectMusicTrack8 *iface, REFIID riid,
50 void **ret_iface)
52 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
54 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ret_iface);
56 *ret_iface = NULL;
58 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDirectMusicTrack) ||
59 IsEqualIID(riid, &IID_IDirectMusicTrack8))
60 *ret_iface = iface;
61 else if (IsEqualIID(riid, &IID_IPersistStream))
62 *ret_iface = &This->dmobj.IPersistStream_iface;
63 else {
64 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ret_iface);
65 return E_NOINTERFACE;
68 IUnknown_AddRef((IUnknown*)*ret_iface);
69 return S_OK;
72 static ULONG WINAPI style_track_AddRef(IDirectMusicTrack8 *iface)
74 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
75 LONG ref = InterlockedIncrement(&This->ref);
77 TRACE("(%p) ref=%ld\n", This, ref);
79 return ref;
82 static ULONG WINAPI style_track_Release(IDirectMusicTrack8 *iface)
84 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
85 LONG ref = InterlockedDecrement(&This->ref);
87 TRACE("(%p) ref=%ld\n", This, ref);
89 if (!ref) {
90 struct style_item *item, *item2;
92 LIST_FOR_EACH_ENTRY_SAFE(item, item2, &This->Items, struct style_item, entry) {
93 list_remove(&item->entry);
94 IDirectMusicStyle8_Release(item->dmstyle);
95 free(item);
98 heap_free(This);
99 DMSTYLE_UnlockModule();
102 return ref;
105 static HRESULT WINAPI style_track_Init(IDirectMusicTrack8 *iface, IDirectMusicSegment *pSegment)
107 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
108 FIXME("(%p, %p): stub\n", This, pSegment);
109 return S_OK;
112 static HRESULT WINAPI style_track_InitPlay(IDirectMusicTrack8 *iface,
113 IDirectMusicSegmentState *pSegmentState, IDirectMusicPerformance *pPerformance,
114 void **ppStateData, DWORD dwVirtualTrack8ID, DWORD dwFlags)
116 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
117 FIXME("(%p, %p, %p, %p, %ld, %ld): stub\n", This, pSegmentState, pPerformance, ppStateData, dwVirtualTrack8ID, dwFlags);
118 return S_OK;
121 static HRESULT WINAPI style_track_EndPlay(IDirectMusicTrack8 *iface, void *pStateData)
123 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
124 FIXME("(%p, %p): stub\n", This, pStateData);
125 return S_OK;
128 static HRESULT WINAPI style_track_Play(IDirectMusicTrack8 *iface, void *pStateData,
129 MUSIC_TIME mtStart, MUSIC_TIME mtEnd, MUSIC_TIME mtOffset, DWORD dwFlags,
130 IDirectMusicPerformance *pPerf, IDirectMusicSegmentState *pSegSt, DWORD dwVirtualID)
132 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
133 FIXME("(%p, %p, %ld, %ld, %ld, %ld, %p, %p, %ld): stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
134 return S_OK;
137 static HRESULT WINAPI style_track_GetParam(IDirectMusicTrack8 *iface, REFGUID type,
138 MUSIC_TIME time, MUSIC_TIME *next, void *param)
140 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
141 struct style_item *item;
143 TRACE("(%p, %s, %ld, %p, %p):\n", This, debugstr_dmguid(type), time, next, param);
145 if (!type)
146 return E_POINTER;
148 if (IsEqualGUID(&GUID_IDirectMusicStyle, type)) {
149 LIST_FOR_EACH_ENTRY(item, &This->Items, struct style_item, entry) {
150 IDirectMusicStyle8_AddRef(item->dmstyle);
151 *((IDirectMusicStyle8 **)param) = item->dmstyle;
153 return S_OK;
156 return DMUS_E_NOT_FOUND;
157 } else if (IsEqualGUID(&GUID_TimeSignature, type)) {
158 FIXME("GUID_TimeSignature not handled yet\n");
159 return S_OK;
162 return DMUS_E_GET_UNSUPPORTED;
165 static HRESULT WINAPI style_track_SetParam(IDirectMusicTrack8 *iface, REFGUID type, MUSIC_TIME time,
166 void *param)
168 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
170 TRACE("(%p, %s, %ld, %p)\n", This, debugstr_dmguid(type), time, param);
172 if (!type)
173 return E_POINTER;
175 if (IsEqualGUID(type, &GUID_DisableTimeSig)) {
176 FIXME("GUID_DisableTimeSig not handled yet\n");
177 return S_OK;
178 } else if (IsEqualGUID(type, &GUID_EnableTimeSig)) {
179 FIXME("GUID_EnableTimeSig not handled yet\n");
180 return S_OK;
181 } else if (IsEqualGUID(type, &GUID_IDirectMusicStyle)) {
182 FIXME("GUID_IDirectMusicStyle not handled yet\n");
183 return S_OK;
184 } else if (IsEqualGUID(type, &GUID_SeedVariations)) {
185 FIXME("GUID_SeedVariations not handled yet\n");
186 return S_OK;
189 return DMUS_E_SET_UNSUPPORTED;
192 static HRESULT WINAPI style_track_IsParamSupported(IDirectMusicTrack8 *iface, REFGUID rguidType)
194 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
196 TRACE("(%p, %s)\n", This, debugstr_dmguid(rguidType));
198 if (!rguidType)
199 return E_POINTER;
201 if (IsEqualGUID (rguidType, &GUID_DisableTimeSig)
202 || IsEqualGUID (rguidType, &GUID_EnableTimeSig)
203 || IsEqualGUID (rguidType, &GUID_IDirectMusicStyle)
204 || IsEqualGUID (rguidType, &GUID_SeedVariations)
205 || IsEqualGUID (rguidType, &GUID_TimeSignature)) {
206 TRACE("param supported\n");
207 return S_OK;
209 TRACE("param unsupported\n");
210 return DMUS_E_TYPE_UNSUPPORTED;
213 static HRESULT WINAPI style_track_AddNotificationType(IDirectMusicTrack8 *iface,
214 REFGUID rguidNotificationType)
216 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
217 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
218 return S_OK;
221 static HRESULT WINAPI style_track_RemoveNotificationType(IDirectMusicTrack8 *iface,
222 REFGUID rguidNotificationType)
224 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
225 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
226 return S_OK;
229 static HRESULT WINAPI style_track_Clone(IDirectMusicTrack8 *iface, MUSIC_TIME mtStart,
230 MUSIC_TIME mtEnd, IDirectMusicTrack **ppTrack)
232 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
233 FIXME("(%p, %ld, %ld, %p): stub\n", This, mtStart, mtEnd, ppTrack);
234 return S_OK;
237 static HRESULT WINAPI style_track_PlayEx(IDirectMusicTrack8 *iface, void *pStateData,
238 REFERENCE_TIME rtStart, REFERENCE_TIME rtEnd, REFERENCE_TIME rtOffset, DWORD dwFlags,
239 IDirectMusicPerformance *pPerf, IDirectMusicSegmentState *pSegSt, DWORD dwVirtualID)
241 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
242 FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %ld, %p, %p, %ld): stub\n", This, pStateData, wine_dbgstr_longlong(rtStart),
243 wine_dbgstr_longlong(rtEnd), wine_dbgstr_longlong(rtOffset), dwFlags, pPerf, pSegSt, dwVirtualID);
244 return S_OK;
247 static HRESULT WINAPI style_track_GetParamEx(IDirectMusicTrack8 *iface, REFGUID rguidType,
248 REFERENCE_TIME rtTime, REFERENCE_TIME *prtNext, void *pParam, void *pStateData,
249 DWORD dwFlags)
251 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
252 FIXME("(%p, %s, 0x%s, %p, %p, %p, %ld): stub\n", This, debugstr_dmguid(rguidType),
253 wine_dbgstr_longlong(rtTime), prtNext, pParam, pStateData, dwFlags);
254 return S_OK;
257 static HRESULT WINAPI style_track_SetParamEx(IDirectMusicTrack8 *iface, REFGUID rguidType,
258 REFERENCE_TIME rtTime, void *pParam, void *pStateData, DWORD dwFlags)
260 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
261 FIXME("(%p, %s, 0x%s, %p, %p, %ld): stub\n", This, debugstr_dmguid(rguidType),
262 wine_dbgstr_longlong(rtTime), pParam, pStateData, dwFlags);
263 return S_OK;
266 static HRESULT WINAPI style_track_Compose(IDirectMusicTrack8 *iface, IUnknown *context,
267 DWORD trackgroup, IDirectMusicTrack **track)
269 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
271 TRACE("(%p, %p, %ld, %p): method not implemented\n", This, context, trackgroup, track);
272 return E_NOTIMPL;
275 static HRESULT WINAPI style_track_Join(IDirectMusicTrack8 *iface, IDirectMusicTrack *pNewTrack,
276 MUSIC_TIME mtJoin, IUnknown *pContext, DWORD dwTrackGroup,
277 IDirectMusicTrack **ppResultTrack)
279 IDirectMusicStyleTrack *This = impl_from_IDirectMusicTrack8(iface);
280 FIXME("(%p, %p, %ld, %p, %ld, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
281 return S_OK;
284 static const IDirectMusicTrack8Vtbl dmtrack8_vtbl = {
285 style_track_QueryInterface,
286 style_track_AddRef,
287 style_track_Release,
288 style_track_Init,
289 style_track_InitPlay,
290 style_track_EndPlay,
291 style_track_Play,
292 style_track_GetParam,
293 style_track_SetParam,
294 style_track_IsParamSupported,
295 style_track_AddNotificationType,
296 style_track_RemoveNotificationType,
297 style_track_Clone,
298 style_track_PlayEx,
299 style_track_GetParamEx,
300 style_track_SetParamEx,
301 style_track_Compose,
302 style_track_Join
305 static HRESULT parse_style_ref(IDirectMusicStyleTrack *This, IStream *stream, const struct chunk_entry *strf)
307 struct chunk_entry chunk = {.parent = strf};
308 IDirectMusicObject *dmobj;
309 struct style_item *item;
310 HRESULT hr;
312 /* First chunk is a timestamp */
313 if (stream_get_chunk(stream, &chunk) != S_OK || chunk.id != DMUS_FOURCC_TIME_STAMP_CHUNK)
314 return DMUS_E_CHUNKNOTFOUND;
315 if (!(item = malloc(sizeof(*item))))
316 return E_OUTOFMEMORY;
317 hr = stream_chunk_get_data(stream, &chunk, &item->timestamp, sizeof(item->timestamp));
318 if (FAILED(hr))
319 goto error;
321 /* Second chunk is a reference list */
322 if (stream_next_chunk(stream, &chunk) != S_OK || chunk.id != FOURCC_LIST ||
323 chunk.type != DMUS_FOURCC_REF_LIST) {
324 hr = DMUS_E_INVALID_SEGMENTTRIGGERTRACK;
325 goto error;
327 if (FAILED(hr = dmobj_parsereference(stream, &chunk, &dmobj))) {
328 WARN("Failed to load reference: %#lx\n", hr);
329 goto error;
331 hr = IDirectMusicObject_QueryInterface(dmobj, &IID_IDirectMusicStyle8, (void **)&item->dmstyle);
332 if (FAILED(hr)) {
333 WARN("Reference not an IDirectMusicStyle8\n");
334 IDirectMusicObject_Release(dmobj);
335 goto error;
338 list_add_tail(&This->Items, &item->entry);
339 TRACE("Found reference to style %p with timestamp %lu\n", item->dmstyle, item->timestamp);
341 return S_OK;
343 error:
344 free(item);
345 return hr;
348 static inline IDirectMusicStyleTrack *impl_from_IPersistStream(IPersistStream *iface)
350 return CONTAINING_RECORD(iface, IDirectMusicStyleTrack, dmobj.IPersistStream_iface);
353 static HRESULT WINAPI IPersistStreamImpl_Load(IPersistStream *iface, IStream *stream)
355 IDirectMusicStyleTrack *This = impl_from_IPersistStream(iface);
356 struct chunk_entry track = {0};
357 struct chunk_entry chunk = {.parent = &track};
358 HRESULT hr;
360 TRACE("(%p, %p): Loading\n", This, stream);
362 if (!stream)
363 return E_POINTER;
365 if (stream_get_chunk(stream, &track) != S_OK || track.id != FOURCC_LIST ||
366 track.type != DMUS_FOURCC_STYLE_TRACK_LIST)
367 return DMUS_E_TRACK_NOT_FOUND;
369 while ((hr = stream_next_chunk(stream, &chunk)) == S_OK)
370 if (chunk.id == FOURCC_LIST && chunk.type == DMUS_FOURCC_STYLE_REF_LIST)
371 if (FAILED(hr = parse_style_ref(This, stream, &chunk)))
372 break;
374 return SUCCEEDED(hr) ? S_OK : hr;
377 static const IPersistStreamVtbl persiststream_vtbl = {
378 dmobj_IPersistStream_QueryInterface,
379 dmobj_IPersistStream_AddRef,
380 dmobj_IPersistStream_Release,
381 dmobj_IPersistStream_GetClassID,
382 unimpl_IPersistStream_IsDirty,
383 IPersistStreamImpl_Load,
384 unimpl_IPersistStream_Save,
385 unimpl_IPersistStream_GetSizeMax
388 /* for ClassFactory */
389 HRESULT create_dmstyletrack(REFIID lpcGUID, void **ppobj)
391 IDirectMusicStyleTrack *track;
392 HRESULT hr;
394 track = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*track));
395 if (!track) {
396 *ppobj = NULL;
397 return E_OUTOFMEMORY;
399 track->IDirectMusicTrack8_iface.lpVtbl = &dmtrack8_vtbl;
400 track->ref = 1;
401 dmobject_init(&track->dmobj, &CLSID_DirectMusicStyleTrack,
402 (IUnknown *)&track->IDirectMusicTrack8_iface);
403 track->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
404 list_init (&track->Items);
406 DMSTYLE_LockModule();
407 hr = IDirectMusicTrack8_QueryInterface(&track->IDirectMusicTrack8_iface, lpcGUID, ppobj);
408 IDirectMusicTrack8_Release(&track->IDirectMusicTrack8_iface);
410 return hr;