wined3d: Introduce wined3d_texture_use_pbo().
[wine.git] / dlls / dmstyle / chordtrack.c
blobfd290bf7a9e23bc3fd7b2b36fd469e1cebddf05b
1 /* IDirectMusicChordTrack Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
4 * Copyright (C) 2003-2004 Raphael Junqueira
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "dmstyle_private.h"
22 #include "dmobject.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(dmstyle);
25 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
27 /*****************************************************************************
28 * IDirectMusicChordTrack implementation
30 typedef struct IDirectMusicChordTrack {
31 IDirectMusicTrack8 IDirectMusicTrack8_iface;
32 struct dmobject dmobj; /* IPersistStream only */
33 LONG ref;
34 DWORD dwScale;
35 } IDirectMusicChordTrack;
37 /* IDirectMusicChordTrack IDirectMusicTrack8 part: */
38 static inline IDirectMusicChordTrack *impl_from_IDirectMusicTrack8(IDirectMusicTrack8 *iface)
40 return CONTAINING_RECORD(iface, IDirectMusicChordTrack, IDirectMusicTrack8_iface);
43 static HRESULT WINAPI IDirectMusicTrack8Impl_QueryInterface(IDirectMusicTrack8 *iface, REFIID riid,
44 void **ret_iface)
46 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
48 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ret_iface);
50 *ret_iface = NULL;
52 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDirectMusicTrack) ||
53 IsEqualIID(riid, &IID_IDirectMusicTrack8))
54 *ret_iface = iface;
55 else if (IsEqualIID(riid, &IID_IPersistStream))
56 *ret_iface = &This->dmobj.IPersistStream_iface;
57 else {
58 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ret_iface);
59 return E_NOINTERFACE;
62 IUnknown_AddRef((IUnknown*)*ret_iface);
63 return S_OK;
66 static ULONG WINAPI IDirectMusicTrack8Impl_AddRef(IDirectMusicTrack8 *iface)
68 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
69 LONG ref = InterlockedIncrement(&This->ref);
71 TRACE("(%p) ref=%d\n", This, ref);
73 return ref;
76 static ULONG WINAPI IDirectMusicTrack8Impl_Release(IDirectMusicTrack8 *iface)
78 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
79 LONG ref = InterlockedDecrement(&This->ref);
81 TRACE("(%p) ref=%d\n", This, ref);
83 if (!ref) {
84 HeapFree(GetProcessHeap(), 0, This);
85 DMSTYLE_UnlockModule();
88 return ref;
91 static HRESULT WINAPI IDirectMusicTrack8Impl_Init(IDirectMusicTrack8 *iface,
92 IDirectMusicSegment *pSegment)
94 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
95 FIXME("(%p, %p): stub\n", This, pSegment);
96 return S_OK;
99 static HRESULT WINAPI IDirectMusicTrack8Impl_InitPlay(IDirectMusicTrack8 *iface,
100 IDirectMusicSegmentState *pSegmentState, IDirectMusicPerformance *pPerformance,
101 void **ppStateData, DWORD dwVirtualTrack8ID, DWORD dwFlags)
103 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
104 FIXME("(%p, %p, %p, %p, %d, %d): stub\n", This, pSegmentState, pPerformance, ppStateData, dwVirtualTrack8ID, dwFlags);
105 return S_OK;
108 static HRESULT WINAPI IDirectMusicTrack8Impl_EndPlay(IDirectMusicTrack8 *iface, void *pStateData)
110 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
111 FIXME("(%p, %p): stub\n", This, pStateData);
112 return S_OK;
115 static HRESULT WINAPI IDirectMusicTrack8Impl_Play(IDirectMusicTrack8 *iface, void *pStateData,
116 MUSIC_TIME mtStart, MUSIC_TIME mtEnd, MUSIC_TIME mtOffset, DWORD dwFlags,
117 IDirectMusicPerformance *pPerf, IDirectMusicSegmentState *pSegSt, DWORD dwVirtualID)
119 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
120 FIXME("(%p, %p, %d, %d, %d, %d, %p, %p, %d): stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
121 return S_OK;
124 static HRESULT WINAPI IDirectMusicTrack8Impl_GetParam(IDirectMusicTrack8 *iface, REFGUID rguidType,
125 MUSIC_TIME mtTime, MUSIC_TIME *pmtNext, void *pParam)
127 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
128 FIXME("(%p, %s, %d, %p, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pmtNext, pParam);
129 return S_OK;
132 static HRESULT WINAPI IDirectMusicTrack8Impl_SetParam(IDirectMusicTrack8 *iface, REFGUID rguidType,
133 MUSIC_TIME mtTime, void *pParam)
135 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
136 FIXME("(%p, %s, %d, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pParam);
137 return S_OK;
140 static HRESULT WINAPI IDirectMusicTrack8Impl_IsParamSupported(IDirectMusicTrack8 *iface,
141 REFGUID rguidType)
143 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
145 TRACE("(%p, %s)\n", This, debugstr_dmguid(rguidType));
147 if (!rguidType)
148 return E_POINTER;
150 if (IsEqualGUID (rguidType, &GUID_BandParam)
151 || IsEqualGUID (rguidType, &GUID_ChordParam)
152 || IsEqualGUID (rguidType, &GUID_RhythmParam)) {
153 TRACE("param supported\n");
154 return S_OK;
156 TRACE("param unsupported\n");
157 return DMUS_E_TYPE_UNSUPPORTED;
160 static HRESULT WINAPI IDirectMusicTrack8Impl_AddNotificationType(IDirectMusicTrack8 *iface,
161 REFGUID rguidNotificationType)
163 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
164 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
165 return S_OK;
168 static HRESULT WINAPI IDirectMusicTrack8Impl_RemoveNotificationType(IDirectMusicTrack8 *iface,
169 REFGUID rguidNotificationType)
171 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
172 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
173 return S_OK;
176 static HRESULT WINAPI IDirectMusicTrack8Impl_Clone(IDirectMusicTrack8 *iface, MUSIC_TIME mtStart,
177 MUSIC_TIME mtEnd, IDirectMusicTrack **ppTrack)
179 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
180 FIXME("(%p, %d, %d, %p): stub\n", This, mtStart, mtEnd, ppTrack);
181 return S_OK;
184 static HRESULT WINAPI IDirectMusicTrack8Impl_PlayEx(IDirectMusicTrack8 *iface, void *pStateData,
185 REFERENCE_TIME rtStart, REFERENCE_TIME rtEnd, REFERENCE_TIME rtOffset, DWORD dwFlags,
186 IDirectMusicPerformance *pPerf, IDirectMusicSegmentState *pSegSt, DWORD dwVirtualID)
188 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
189 FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %d, %p, %p, %d): stub\n", This, pStateData, wine_dbgstr_longlong(rtStart),
190 wine_dbgstr_longlong(rtEnd), wine_dbgstr_longlong(rtOffset), dwFlags, pPerf, pSegSt, dwVirtualID);
191 return S_OK;
194 static HRESULT WINAPI IDirectMusicTrack8Impl_GetParamEx(IDirectMusicTrack8 *iface,
195 REFGUID rguidType, REFERENCE_TIME rtTime, REFERENCE_TIME *prtNext, void *pParam,
196 void *pStateData, DWORD dwFlags)
198 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
199 FIXME("(%p, %s, 0x%s, %p, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
200 wine_dbgstr_longlong(rtTime), prtNext, pParam, pStateData, dwFlags);
201 return S_OK;
204 static HRESULT WINAPI IDirectMusicTrack8Impl_SetParamEx(IDirectMusicTrack8 *iface,
205 REFGUID rguidType, REFERENCE_TIME rtTime, void *pParam, void *pStateData, DWORD dwFlags)
207 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
208 FIXME("(%p, %s, 0x%s, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
209 wine_dbgstr_longlong(rtTime), pParam, pStateData, dwFlags);
210 return S_OK;
213 static HRESULT WINAPI IDirectMusicTrack8Impl_Compose(IDirectMusicTrack8 *iface, IUnknown *context,
214 DWORD trackgroup, IDirectMusicTrack **track)
216 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
218 TRACE("(%p, %p, %d, %p): method not implemented\n", This, context, trackgroup, track);
219 return E_NOTIMPL;
222 static HRESULT WINAPI IDirectMusicTrack8Impl_Join(IDirectMusicTrack8 *iface,
223 IDirectMusicTrack *pNewTrack, MUSIC_TIME mtJoin, IUnknown *pContext, DWORD dwTrackGroup,
224 IDirectMusicTrack **ppResultTrack)
226 IDirectMusicChordTrack *This = impl_from_IDirectMusicTrack8(iface);
227 FIXME("(%p, %p, %d, %p, %d, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
228 return S_OK;
231 static const IDirectMusicTrack8Vtbl dmtrack8_vtbl = {
232 IDirectMusicTrack8Impl_QueryInterface,
233 IDirectMusicTrack8Impl_AddRef,
234 IDirectMusicTrack8Impl_Release,
235 IDirectMusicTrack8Impl_Init,
236 IDirectMusicTrack8Impl_InitPlay,
237 IDirectMusicTrack8Impl_EndPlay,
238 IDirectMusicTrack8Impl_Play,
239 IDirectMusicTrack8Impl_GetParam,
240 IDirectMusicTrack8Impl_SetParam,
241 IDirectMusicTrack8Impl_IsParamSupported,
242 IDirectMusicTrack8Impl_AddNotificationType,
243 IDirectMusicTrack8Impl_RemoveNotificationType,
244 IDirectMusicTrack8Impl_Clone,
245 IDirectMusicTrack8Impl_PlayEx,
246 IDirectMusicTrack8Impl_GetParamEx,
247 IDirectMusicTrack8Impl_SetParamEx,
248 IDirectMusicTrack8Impl_Compose,
249 IDirectMusicTrack8Impl_Join
252 static HRESULT parse_chordtrack_list(IDirectMusicChordTrack *This, DMUS_PRIVATE_CHUNK *pChunk,
253 IStream *pStm)
255 DMUS_PRIVATE_CHUNK Chunk;
256 DWORD ListSize[3], ListCount[3];
257 LARGE_INTEGER liMove; /* used when skipping chunks */
259 if (pChunk->fccID != DMUS_FOURCC_CHORDTRACK_LIST) {
260 ERR_(dmfile)(": %s chunk should be a CHORDTRACK list\n", debugstr_fourcc (pChunk->fccID));
261 return E_FAIL;
264 ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
265 ListCount[0] = 0;
267 do {
268 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
269 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
270 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
271 switch (Chunk.fccID) {
272 case DMUS_FOURCC_CHORDTRACKHEADER_CHUNK: {
273 TRACE_(dmfile)(": Chord track header chunk\n");
274 IStream_Read (pStm, &This->dwScale, sizeof(DWORD), NULL);
275 TRACE_(dmfile)(" - dwScale: %d\n", This->dwScale);
276 break;
278 case DMUS_FOURCC_CHORDTRACKBODY_CHUNK: {
279 DWORD sz;
280 DWORD it;
281 DWORD num;
282 DMUS_IO_CHORD body;
283 DMUS_IO_SUBCHORD subchords;
285 TRACE_(dmfile)(": Chord track body chunk\n");
287 IStream_Read (pStm, &sz, sizeof(DWORD), NULL);
288 TRACE_(dmfile)(" - sizeof(DMUS_IO_CHORD): %d\n", sz);
289 if (sz != sizeof(DMUS_IO_CHORD)) return E_FAIL;
290 IStream_Read (pStm, &body, sizeof(DMUS_IO_CHORD), NULL);
291 TRACE_(dmfile)(" - wszName: %s\n", debugstr_w(body.wszName));
292 TRACE_(dmfile)(" - mtTime: %u\n", body.mtTime);
293 TRACE_(dmfile)(" - wMeasure: %u\n", body.wMeasure);
294 TRACE_(dmfile)(" - bBeat: %u\n", body.bBeat);
295 TRACE_(dmfile)(" - bFlags: 0x%02x\n", body.bFlags);
297 IStream_Read (pStm, &num, sizeof(DWORD), NULL);
298 TRACE_(dmfile)(" - # DMUS_IO_SUBCHORDS: %d\n", num);
299 IStream_Read (pStm, &sz, sizeof(DWORD), NULL);
300 TRACE_(dmfile)(" - sizeof(DMUS_IO_SUBCHORDS): %d\n", sz);
301 if (sz != sizeof(DMUS_IO_SUBCHORD)) return E_FAIL;
303 for (it = 0; it < num; ++it) {
304 IStream_Read (pStm, &subchords, sizeof(DMUS_IO_SUBCHORD), NULL);
305 TRACE_(dmfile)("DMUS_IO_SUBCHORD #%d\n", it+1);
306 TRACE_(dmfile)(" - dwChordPattern: %u\n", subchords.dwChordPattern);
307 TRACE_(dmfile)(" - dwScalePattern: %u\n", subchords.dwScalePattern);
308 TRACE_(dmfile)(" - dwInversionPoints: %u\n", subchords.dwInversionPoints);
309 TRACE_(dmfile)(" - dwLevels: %u\n", subchords.dwLevels);
310 TRACE_(dmfile)(" - bChordRoot: %u\n", subchords.bChordRoot);
311 TRACE_(dmfile)(" - bScaleRoot: %u\n", subchords.bScaleRoot);
313 break;
315 default: {
316 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
317 liMove.QuadPart = Chunk.dwSize;
318 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
319 break;
322 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
323 } while (ListCount[0] < ListSize[0]);
325 return S_OK;
328 static inline IDirectMusicChordTrack *impl_from_IPersistStream(IPersistStream *iface)
330 return CONTAINING_RECORD(iface, IDirectMusicChordTrack, dmobj.IPersistStream_iface);
333 static HRESULT WINAPI IPersistStreamImpl_Load(IPersistStream *iface, IStream *pStm)
335 IDirectMusicChordTrack *This = impl_from_IPersistStream(iface);
336 DMUS_PRIVATE_CHUNK Chunk;
337 LARGE_INTEGER liMove;
338 HRESULT hr;
340 TRACE("(%p, %p): Loading\n", This, pStm);
342 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
343 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
344 switch (Chunk.fccID) {
345 case FOURCC_LIST: {
346 IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
347 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
348 switch (Chunk.fccID) {
349 case DMUS_FOURCC_CHORDTRACK_LIST: {
350 TRACE_(dmfile)(": Chord track list\n");
351 hr = parse_chordtrack_list(This, &Chunk, pStm);
352 if (FAILED(hr)) return hr;
353 break;
355 default: {
356 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
357 liMove.QuadPart = Chunk.dwSize;
358 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
359 return E_FAIL;
362 TRACE_(dmfile)(": reading finished\n");
363 break;
365 default: {
366 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
367 liMove.QuadPart = Chunk.dwSize;
368 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
369 return E_FAIL;
373 return S_OK;
376 static HRESULT WINAPI IPersistStreamImpl_Save(IPersistStream *iface, IStream *stream,
377 BOOL cleardirty)
379 IDirectMusicChordTrack *This = impl_from_IPersistStream(iface);
381 FIXME("(%p, %p, %d): stub\n", This, stream, cleardirty);
383 if (!stream)
384 return E_POINTER;
386 return E_NOTIMPL;
389 static const IPersistStreamVtbl persiststream_vtbl = {
390 dmobj_IPersistStream_QueryInterface,
391 dmobj_IPersistStream_AddRef,
392 dmobj_IPersistStream_Release,
393 dmobj_IPersistStream_GetClassID,
394 unimpl_IPersistStream_IsDirty,
395 IPersistStreamImpl_Load,
396 IPersistStreamImpl_Save,
397 unimpl_IPersistStream_GetSizeMax
400 /* for ClassFactory */
401 HRESULT WINAPI create_dmchordtrack(REFIID lpcGUID, void **ppobj)
403 IDirectMusicChordTrack *track;
404 HRESULT hr;
406 track = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*track));
407 if (!track) {
408 *ppobj = NULL;
409 return E_OUTOFMEMORY;
411 track->IDirectMusicTrack8_iface.lpVtbl = &dmtrack8_vtbl;
412 track->ref = 1;
413 dmobject_init(&track->dmobj, &CLSID_DirectMusicChordTrack,
414 (IUnknown *)&track->IDirectMusicTrack8_iface);
415 track->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
417 DMSTYLE_LockModule();
418 hr = IDirectMusicTrack8_QueryInterface(&track->IDirectMusicTrack8_iface, lpcGUID, ppobj);
419 IDirectMusicTrack8_Release(&track->IDirectMusicTrack8_iface);
421 return hr;