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"
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 */
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
,
46 IDirectMusicChordTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
48 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ret_iface
);
52 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDirectMusicTrack
) ||
53 IsEqualIID(riid
, &IID_IDirectMusicTrack8
))
55 else if (IsEqualIID(riid
, &IID_IPersistStream
))
56 *ret_iface
= &This
->dmobj
.IPersistStream_iface
;
58 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ret_iface
);
62 IUnknown_AddRef((IUnknown
*)*ret_iface
);
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
);
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
);
84 HeapFree(GetProcessHeap(), 0, This
);
85 DMSTYLE_UnlockModule();
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
);
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
);
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
);
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
);
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
);
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
);
140 static HRESULT WINAPI
IDirectMusicTrack8Impl_IsParamSupported(IDirectMusicTrack8
*iface
,
143 IDirectMusicChordTrack
*This
= impl_from_IDirectMusicTrack8(iface
);
145 TRACE("(%p, %s)\n", This
, debugstr_dmguid(rguidType
));
150 if (IsEqualGUID (rguidType
, &GUID_BandParam
)
151 || IsEqualGUID (rguidType
, &GUID_ChordParam
)
152 || IsEqualGUID (rguidType
, &GUID_RhythmParam
)) {
153 TRACE("param supported\n");
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
));
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
));
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
);
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
);
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
);
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
);
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
);
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
);
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
,
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
));
264 ListSize
[0] = pChunk
->dwSize
- sizeof(FOURCC
);
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
);
278 case DMUS_FOURCC_CHORDTRACKBODY_CHUNK
: {
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
);
316 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
317 liMove
.QuadPart
= Chunk
.dwSize
;
318 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
322 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
323 } while (ListCount
[0] < ListSize
[0]);
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
;
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
) {
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
;
356 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
357 liMove
.QuadPart
= Chunk
.dwSize
;
358 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
362 TRACE_(dmfile
)(": reading finished\n");
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 */
376 static HRESULT WINAPI
IPersistStreamImpl_Save(IPersistStream
*iface
, IStream
*stream
,
379 IDirectMusicChordTrack
*This
= impl_from_IPersistStream(iface
);
381 FIXME("(%p, %p, %d): stub\n", This
, stream
, cleardirty
);
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
;
406 track
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*track
));
409 return E_OUTOFMEMORY
;
411 track
->IDirectMusicTrack8_iface
.lpVtbl
= &dmtrack8_vtbl
;
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
);