kernelbase/tests: Fix the Sleep() test for non-default timer resolutions.
[wine.git] / dlls / dmime / timesigtrack.c
blobc34049beb184f7527a18571831c3e7f3852eb652
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"
21 #include "dmobject.h"
22 #include "wine/heap.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
26 /*****************************************************************************
27 * IDirectMusicTimeSigTrack implementation
29 typedef struct IDirectMusicTimeSigTrack {
30 IDirectMusicTrack IDirectMusicTrack_iface;
31 struct dmobject dmobj; /* IPersistStream only */
32 LONG ref;
34 DMUS_IO_TIMESIGNATURE_ITEM *items;
35 unsigned int count;
36 } IDirectMusicTimeSigTrack;
38 /* IDirectMusicTimeSigTrack IDirectMusicTrack8 part: */
39 static inline IDirectMusicTimeSigTrack *impl_from_IDirectMusicTrack(IDirectMusicTrack *iface)
41 return CONTAINING_RECORD(iface, IDirectMusicTimeSigTrack, IDirectMusicTrack_iface);
44 static inline IDirectMusicTimeSigTrack *impl_from_IPersistStream(IPersistStream *iface)
46 return CONTAINING_RECORD(iface, IDirectMusicTimeSigTrack, dmobj.IPersistStream_iface);
49 static HRESULT WINAPI IDirectMusicTrackImpl_QueryInterface(IDirectMusicTrack *iface, REFIID riid,
50 void **ret_iface)
52 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(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 *ret_iface = iface;
60 else if (IsEqualIID(riid, &IID_IPersistStream))
61 *ret_iface = &This->dmobj.IPersistStream_iface;
62 else {
63 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ret_iface);
64 return E_NOINTERFACE;
67 IUnknown_AddRef((IUnknown*)*ret_iface);
68 return S_OK;
71 static ULONG WINAPI IDirectMusicTrackImpl_AddRef(IDirectMusicTrack *iface)
73 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
74 LONG ref = InterlockedIncrement(&This->ref);
76 TRACE("(%p) ref=%d\n", This, ref);
78 return ref;
81 static ULONG WINAPI IDirectMusicTrackImpl_Release(IDirectMusicTrack *iface)
83 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
84 LONG ref = InterlockedDecrement(&This->ref);
86 TRACE("(%p) ref=%d\n", This, ref);
88 if (!ref) {
89 heap_free(This->items);
90 HeapFree(GetProcessHeap(), 0, This);
91 DMIME_UnlockModule();
94 return ref;
97 static HRESULT WINAPI IDirectMusicTrackImpl_Init(IDirectMusicTrack *iface,
98 IDirectMusicSegment *pSegment)
100 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
101 FIXME("(%p, %p): stub\n", This, pSegment);
102 return S_OK;
105 static HRESULT WINAPI IDirectMusicTrackImpl_InitPlay(IDirectMusicTrack *iface,
106 IDirectMusicSegmentState *pSegmentState, IDirectMusicPerformance *pPerformance,
107 void **ppStateData, DWORD dwVirtualTrack8ID, DWORD dwFlags)
109 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
110 FIXME("(%p, %p, %p, %p, %d, %d): stub\n", This, pSegmentState, pPerformance, ppStateData, dwVirtualTrack8ID, dwFlags);
111 return S_OK;
114 static HRESULT WINAPI IDirectMusicTrackImpl_EndPlay(IDirectMusicTrack *iface, void *pStateData)
116 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
117 FIXME("(%p, %p): stub\n", This, pStateData);
118 return S_OK;
121 static HRESULT WINAPI IDirectMusicTrackImpl_Play(IDirectMusicTrack *iface, void *pStateData,
122 MUSIC_TIME mtStart, MUSIC_TIME mtEnd, MUSIC_TIME mtOffset, DWORD dwFlags,
123 IDirectMusicPerformance *pPerf, IDirectMusicSegmentState *pSegSt, DWORD dwVirtualID)
125 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
126 FIXME("(%p, %p, %d, %d, %d, %d, %p, %p, %d): stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
127 return S_OK;
130 static HRESULT WINAPI IDirectMusicTrackImpl_GetParam(IDirectMusicTrack *iface, REFGUID type,
131 MUSIC_TIME time, MUSIC_TIME *next, void *param)
133 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
135 TRACE("(%p, %s, %d, %p, %p)\n", This, debugstr_dmguid(type), time, next, param);
137 if (IsEqualGUID(type, &GUID_TimeSignature)) {
138 FIXME("GUID_TimeSignature not handled yet\n");
139 return DMUS_E_NOT_FOUND;
142 return DMUS_E_GET_UNSUPPORTED;
145 static HRESULT WINAPI IDirectMusicTrackImpl_SetParam(IDirectMusicTrack *iface, REFGUID type,
146 MUSIC_TIME time, void *param)
148 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
150 TRACE("(%p, %s, %d, %p)\n", This, debugstr_dmguid(type), time, param);
152 if (IsEqualGUID(type, &GUID_DisableTimeSig)) {
153 FIXME("GUID_DisableTimeSig not handled yet\n");
154 return S_OK;
156 if (IsEqualGUID(type, &GUID_EnableTimeSig)) {
157 FIXME("GUID_EnableTimeSig not handled yet\n");
158 return S_OK;
161 return DMUS_E_SET_UNSUPPORTED;
164 static HRESULT WINAPI IDirectMusicTrackImpl_IsParamSupported(IDirectMusicTrack *iface,
165 REFGUID rguidType)
167 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
169 TRACE("(%p, %s)\n", This, debugstr_dmguid(rguidType));
170 if (IsEqualGUID (rguidType, &GUID_DisableTimeSig)
171 || IsEqualGUID (rguidType, &GUID_EnableTimeSig)
172 || IsEqualGUID (rguidType, &GUID_TimeSignature)) {
173 TRACE("param supported\n");
174 return S_OK;
176 TRACE("param unsupported\n");
177 return DMUS_E_TYPE_UNSUPPORTED;
180 static HRESULT WINAPI IDirectMusicTrackImpl_AddNotificationType(IDirectMusicTrack *iface,
181 REFGUID rguidNotificationType)
183 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
184 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
185 return S_OK;
188 static HRESULT WINAPI IDirectMusicTrackImpl_RemoveNotificationType(IDirectMusicTrack *iface,
189 REFGUID rguidNotificationType)
191 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
192 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
193 return S_OK;
196 static HRESULT WINAPI IDirectMusicTrackImpl_Clone(IDirectMusicTrack *iface, MUSIC_TIME mtStart,
197 MUSIC_TIME mtEnd, IDirectMusicTrack **ppTrack)
199 IDirectMusicTimeSigTrack *This = impl_from_IDirectMusicTrack(iface);
200 FIXME("(%p, %d, %d, %p): stub\n", This, mtStart, mtEnd, ppTrack);
201 return S_OK;
204 static const IDirectMusicTrackVtbl dmtack_vtbl = {
205 IDirectMusicTrackImpl_QueryInterface,
206 IDirectMusicTrackImpl_AddRef,
207 IDirectMusicTrackImpl_Release,
208 IDirectMusicTrackImpl_Init,
209 IDirectMusicTrackImpl_InitPlay,
210 IDirectMusicTrackImpl_EndPlay,
211 IDirectMusicTrackImpl_Play,
212 IDirectMusicTrackImpl_GetParam,
213 IDirectMusicTrackImpl_SetParam,
214 IDirectMusicTrackImpl_IsParamSupported,
215 IDirectMusicTrackImpl_AddNotificationType,
216 IDirectMusicTrackImpl_RemoveNotificationType,
217 IDirectMusicTrackImpl_Clone
220 static HRESULT parse_timetrack_list(IDirectMusicTimeSigTrack *This, IStream *stream,
221 struct chunk_entry *timesig)
223 HRESULT hr;
224 struct chunk_entry chunk = {.parent = timesig};
225 int i;
227 TRACE("Parsing segment form in %p: %s\n", stream, debugstr_chunk(timesig));
229 if (FAILED(hr = stream_next_chunk(stream, &chunk))) {
230 WARN("Failed to read data of %s\n", debugstr_chunk(&chunk));
231 return hr;
234 if (chunk.id != DMUS_FOURCC_TIMESIGNATURE_TRACK)
235 return DMUS_E_UNSUPPORTED_STREAM;
237 hr = stream_chunk_get_array(stream, &chunk, (void **)&This->items, &This->count,
238 sizeof(DMUS_IO_TIMESIGNATURE_ITEM));
239 if (FAILED(hr))
240 return hr;
242 for (i = 0; i < This->count; i++)
244 TRACE("Found DMUS_IO_TIMESIGNATURE_ITEM\n");
245 TRACE(" - lTime %d\n", This->items[i].lTime);
246 TRACE(" - bBeatsPerMeasure %d\n", This->items[i].bBeatsPerMeasure);
247 TRACE(" - bBeat %d\n", This->items[i].bBeat);
248 TRACE(" - wGridsPerBeat %d\n", This->items[i].wGridsPerBeat);
251 return S_OK;
254 static HRESULT WINAPI time_IPersistStream_Load(IPersistStream *iface, IStream *stream)
256 IDirectMusicTimeSigTrack *This = impl_from_IPersistStream(iface);
257 HRESULT hr;
258 struct chunk_entry chunk = {0};
260 TRACE("%p, %p\n", This, stream);
262 if (!stream)
263 return E_POINTER;
265 if ((hr = stream_get_chunk(stream, &chunk)) != S_OK)
266 return hr;
268 if (chunk.id == FOURCC_LIST && chunk.type == DMUS_FOURCC_TIMESIGTRACK_LIST)
269 hr = parse_timetrack_list(This, stream, &chunk);
270 else
271 hr = DMUS_E_UNSUPPORTED_STREAM;
273 return hr;
276 static const IPersistStreamVtbl persiststream_vtbl = {
277 dmobj_IPersistStream_QueryInterface,
278 dmobj_IPersistStream_AddRef,
279 dmobj_IPersistStream_Release,
280 dmobj_IPersistStream_GetClassID,
281 unimpl_IPersistStream_IsDirty,
282 time_IPersistStream_Load,
283 unimpl_IPersistStream_Save,
284 unimpl_IPersistStream_GetSizeMax
287 /* for ClassFactory */
288 HRESULT WINAPI create_dmtimesigtrack(REFIID lpcGUID, void **ppobj)
290 IDirectMusicTimeSigTrack *track;
291 HRESULT hr;
293 track = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*track));
294 if (!track) {
295 *ppobj = NULL;
296 return E_OUTOFMEMORY;
298 track->IDirectMusicTrack_iface.lpVtbl = &dmtack_vtbl;
299 track->ref = 1;
300 dmobject_init(&track->dmobj, &CLSID_DirectMusicTimeSigTrack,
301 (IUnknown *)&track->IDirectMusicTrack_iface);
302 track->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
304 DMIME_LockModule();
305 hr = IDirectMusicTrack_QueryInterface(&track->IDirectMusicTrack_iface, lpcGUID, ppobj);
306 IDirectMusicTrack_Release(&track->IDirectMusicTrack_iface);
308 return hr;