comctl32/tests: Use CRT allocation functions.
[wine.git] / dlls / dmime / timesigtrack.c
blob0ebf5e4256e3637f20e3f8700bbfe7e75b03de03
1 /* IDirectMusicTimeSigTrack 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 "dmime_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
24 /*****************************************************************************
25 * IDirectMusicTimeSigTrack implementation
27 typedef struct IDirectMusicTimeSigTrack {
28 IDirectMusicTrack IDirectMusicTrack_iface;
29 struct dmobject dmobj; /* IPersistStream only */
30 LONG ref;
32 DMUS_IO_TIMESIGNATURE_ITEM *items;
33 unsigned int count;
34 } IDirectMusicTimeSigTrack;
36 /* IDirectMusicTimeSigTrack IDirectMusicTrack8 part: */
37 static inline IDirectMusicTimeSigTrack *impl_from_IDirectMusicTrack(IDirectMusicTrack *iface)
39 return CONTAINING_RECORD(iface, IDirectMusicTimeSigTrack, IDirectMusicTrack_iface);
42 static inline IDirectMusicTimeSigTrack *impl_from_IPersistStream(IPersistStream *iface)
44 return CONTAINING_RECORD(iface, IDirectMusicTimeSigTrack, dmobj.IPersistStream_iface);
47 static HRESULT WINAPI IDirectMusicTrackImpl_QueryInterface(IDirectMusicTrack *iface, REFIID riid,
48 void **ret_iface)
50 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
52 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ret_iface);
54 *ret_iface = NULL;
56 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDirectMusicTrack))
57 *ret_iface = iface;
58 else if (IsEqualIID(riid, &IID_IPersistStream))
59 *ret_iface = &This->dmobj.IPersistStream_iface;
60 else {
61 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ret_iface);
62 return E_NOINTERFACE;
65 IUnknown_AddRef((IUnknown*)*ret_iface);
66 return S_OK;
69 static ULONG WINAPI IDirectMusicTrackImpl_AddRef(IDirectMusicTrack *iface)
71 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
72 LONG ref = InterlockedIncrement(&This->ref);
74 TRACE("(%p) ref=%ld\n", This, ref);
76 return ref;
79 static ULONG WINAPI IDirectMusicTrackImpl_Release(IDirectMusicTrack *iface)
81 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
82 LONG ref = InterlockedDecrement(&This->ref);
84 TRACE("(%p) ref=%ld\n", This, ref);
86 if (!ref) {
87 free(This->items);
88 free(This);
91 return ref;
94 static HRESULT WINAPI IDirectMusicTrackImpl_Init(IDirectMusicTrack *iface,
95 IDirectMusicSegment *pSegment)
97 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
98 FIXME("(%p, %p): stub\n", This, pSegment);
99 return S_OK;
102 static HRESULT WINAPI IDirectMusicTrackImpl_InitPlay(IDirectMusicTrack *iface,
103 IDirectMusicSegmentState *pSegmentState, IDirectMusicPerformance *pPerformance,
104 void **ppStateData, DWORD dwVirtualTrack8ID, DWORD dwFlags)
106 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
107 FIXME("(%p, %p, %p, %p, %ld, %ld): stub\n", This, pSegmentState, pPerformance, ppStateData, dwVirtualTrack8ID, dwFlags);
108 return S_OK;
111 static HRESULT WINAPI IDirectMusicTrackImpl_EndPlay(IDirectMusicTrack *iface, void *pStateData)
113 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
114 FIXME("(%p, %p): stub\n", This, pStateData);
115 return S_OK;
118 static HRESULT WINAPI IDirectMusicTrackImpl_Play(IDirectMusicTrack *iface, void *pStateData,
119 MUSIC_TIME mtStart, MUSIC_TIME mtEnd, MUSIC_TIME mtOffset, DWORD dwFlags,
120 IDirectMusicPerformance *pPerf, IDirectMusicSegmentState *pSegSt, DWORD dwVirtualID)
122 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
123 FIXME("(%p, %p, %ld, %ld, %ld, %ld, %p, %p, %ld): stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
124 return S_OK;
127 static HRESULT WINAPI IDirectMusicTrackImpl_GetParam(IDirectMusicTrack *iface, REFGUID type,
128 MUSIC_TIME time, MUSIC_TIME *next, void *param)
130 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
132 TRACE("(%p, %s, %ld, %p, %p)\n", This, debugstr_dmguid(type), time, next, param);
134 if (IsEqualGUID(type, &GUID_TimeSignature)) {
135 FIXME("GUID_TimeSignature not handled yet\n");
136 return DMUS_E_NOT_FOUND;
139 return DMUS_E_GET_UNSUPPORTED;
142 static HRESULT WINAPI IDirectMusicTrackImpl_SetParam(IDirectMusicTrack *iface, REFGUID type,
143 MUSIC_TIME time, void *param)
145 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
147 TRACE("(%p, %s, %ld, %p)\n", This, debugstr_dmguid(type), time, param);
149 if (IsEqualGUID(type, &GUID_DisableTimeSig)) {
150 FIXME("GUID_DisableTimeSig not handled yet\n");
151 return S_OK;
153 if (IsEqualGUID(type, &GUID_EnableTimeSig)) {
154 FIXME("GUID_EnableTimeSig not handled yet\n");
155 return S_OK;
158 return DMUS_E_SET_UNSUPPORTED;
161 static HRESULT WINAPI IDirectMusicTrackImpl_IsParamSupported(IDirectMusicTrack *iface,
162 REFGUID rguidType)
164 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
166 TRACE("(%p, %s)\n", This, debugstr_dmguid(rguidType));
167 if (IsEqualGUID (rguidType, &GUID_DisableTimeSig)
168 || IsEqualGUID (rguidType, &GUID_EnableTimeSig)
169 || IsEqualGUID (rguidType, &GUID_TimeSignature)) {
170 TRACE("param supported\n");
171 return S_OK;
173 TRACE("param unsupported\n");
174 return DMUS_E_TYPE_UNSUPPORTED;
177 static HRESULT WINAPI IDirectMusicTrackImpl_AddNotificationType(IDirectMusicTrack *iface,
178 REFGUID rguidNotificationType)
180 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
181 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
182 return S_OK;
185 static HRESULT WINAPI IDirectMusicTrackImpl_RemoveNotificationType(IDirectMusicTrack *iface,
186 REFGUID rguidNotificationType)
188 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
189 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
190 return S_OK;
193 static HRESULT WINAPI IDirectMusicTrackImpl_Clone(IDirectMusicTrack *iface, MUSIC_TIME mtStart,
194 MUSIC_TIME mtEnd, IDirectMusicTrack **ppTrack)
196 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
197 FIXME("(%p, %ld, %ld, %p): stub\n", This, mtStart, mtEnd, ppTrack);
198 return S_OK;
201 static const IDirectMusicTrackVtbl dmtack_vtbl = {
202 IDirectMusicTrackImpl_QueryInterface,
203 IDirectMusicTrackImpl_AddRef,
204 IDirectMusicTrackImpl_Release,
205 IDirectMusicTrackImpl_Init,
206 IDirectMusicTrackImpl_InitPlay,
207 IDirectMusicTrackImpl_EndPlay,
208 IDirectMusicTrackImpl_Play,
209 IDirectMusicTrackImpl_GetParam,
210 IDirectMusicTrackImpl_SetParam,
211 IDirectMusicTrackImpl_IsParamSupported,
212 IDirectMusicTrackImpl_AddNotificationType,
213 IDirectMusicTrackImpl_RemoveNotificationType,
214 IDirectMusicTrackImpl_Clone
217 static HRESULT parse_timetrack_list(IDirectMusicTimeSigTrack *This, IStream *stream,
218 struct chunk_entry *timesig)
220 HRESULT hr;
221 struct chunk_entry chunk = {.parent = timesig};
222 int i;
224 TRACE("Parsing segment form in %p: %s\n", stream, debugstr_chunk(timesig));
226 if (FAILED(hr = stream_next_chunk(stream, &chunk))) {
227 WARN("Failed to read data of %s\n", debugstr_chunk(&chunk));
228 return hr;
231 if (chunk.id != DMUS_FOURCC_TIMESIGNATURE_TRACK)
232 return DMUS_E_UNSUPPORTED_STREAM;
234 hr = stream_chunk_get_array(stream, &chunk, (void **)&This->items, &This->count,
235 sizeof(DMUS_IO_TIMESIGNATURE_ITEM));
236 if (FAILED(hr))
237 return hr;
239 for (i = 0; i < This->count; i++)
241 TRACE("Found DMUS_IO_TIMESIGNATURE_ITEM\n");
242 TRACE(" - lTime %ld\n", This->items[i].lTime);
243 TRACE(" - bBeatsPerMeasure %d\n", This->items[i].bBeatsPerMeasure);
244 TRACE(" - bBeat %d\n", This->items[i].bBeat);
245 TRACE(" - wGridsPerBeat %d\n", This->items[i].wGridsPerBeat);
248 return S_OK;
251 static HRESULT WINAPI time_IPersistStream_Load(IPersistStream *iface, IStream *stream)
253 IDirectMusicTimeSigTrack *This = impl_from_IPersistStream(iface);
254 HRESULT hr;
255 struct chunk_entry chunk = {0};
257 TRACE("%p, %p\n", This, stream);
259 if (!stream)
260 return E_POINTER;
262 if ((hr = stream_get_chunk(stream, &chunk)) != S_OK)
263 return hr;
265 if (chunk.id == FOURCC_LIST && chunk.type == DMUS_FOURCC_TIMESIGTRACK_LIST)
266 hr = parse_timetrack_list(This, stream, &chunk);
267 else
268 hr = DMUS_E_UNSUPPORTED_STREAM;
270 return hr;
273 static const IPersistStreamVtbl persiststream_vtbl = {
274 dmobj_IPersistStream_QueryInterface,
275 dmobj_IPersistStream_AddRef,
276 dmobj_IPersistStream_Release,
277 dmobj_IPersistStream_GetClassID,
278 unimpl_IPersistStream_IsDirty,
279 time_IPersistStream_Load,
280 unimpl_IPersistStream_Save,
281 unimpl_IPersistStream_GetSizeMax
284 /* for ClassFactory */
285 HRESULT create_dmtimesigtrack(REFIID lpcGUID, void **ppobj)
287 IDirectMusicTimeSigTrack *track;
288 HRESULT hr;
290 *ppobj = NULL;
291 if (!(track = calloc(1, sizeof(*track)))) return E_OUTOFMEMORY;
292 track->IDirectMusicTrack_iface.lpVtbl = &dmtack_vtbl;
293 track->ref = 1;
294 dmobject_init(&track->dmobj, &CLSID_DirectMusicTimeSigTrack,
295 (IUnknown *)&track->IDirectMusicTrack_iface);
296 track->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
298 hr = IDirectMusicTrack_QueryInterface(&track->IDirectMusicTrack_iface, lpcGUID, ppobj);
299 IDirectMusicTrack_Release(&track->IDirectMusicTrack_iface);
301 return hr;