1 /* IDirectMusicChordMap 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 "dmcompos_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(dmcompos
);
24 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
26 /*****************************************************************************
27 * IDirectMusicChordMapImpl implementation
29 typedef struct IDirectMusicChordMapImpl
{
30 IDirectMusicChordMap IDirectMusicChordMap_iface
;
31 struct dmobject dmobj
;
33 } IDirectMusicChordMapImpl
;
35 /* IDirectMusicChordMapImpl IDirectMusicChordMap part: */
36 static inline IDirectMusicChordMapImpl
*impl_from_IDirectMusicChordMap(IDirectMusicChordMap
*iface
)
38 return CONTAINING_RECORD(iface
, IDirectMusicChordMapImpl
, IDirectMusicChordMap_iface
);
41 static HRESULT WINAPI
IDirectMusicChordMapImpl_QueryInterface(IDirectMusicChordMap
*iface
,
42 REFIID riid
, void **ret_iface
)
44 IDirectMusicChordMapImpl
*This
= impl_from_IDirectMusicChordMap(iface
);
46 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ret_iface
);
50 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDirectMusicChordMap
))
52 else if (IsEqualIID(riid
, &IID_IDirectMusicObject
))
53 *ret_iface
= &This
->dmobj
.IDirectMusicObject_iface
;
54 else if (IsEqualIID(riid
, &IID_IPersistStream
))
55 *ret_iface
= &This
->dmobj
.IPersistStream_iface
;
57 WARN("(%p, %s, %p): not found\n", This
, debugstr_dmguid(riid
), ret_iface
);
61 IUnknown_AddRef((IUnknown
*)*ret_iface
);
65 static ULONG WINAPI
IDirectMusicChordMapImpl_AddRef(IDirectMusicChordMap
*iface
)
67 IDirectMusicChordMapImpl
*This
= impl_from_IDirectMusicChordMap(iface
);
68 LONG ref
= InterlockedIncrement(&This
->ref
);
70 TRACE("(%p) ref=%d\n", This
, ref
);
75 static ULONG WINAPI
IDirectMusicChordMapImpl_Release(IDirectMusicChordMap
*iface
)
77 IDirectMusicChordMapImpl
*This
= impl_from_IDirectMusicChordMap(iface
);
78 LONG ref
= InterlockedDecrement(&This
->ref
);
80 TRACE("(%p) ref=%d\n", This
, ref
);
83 HeapFree(GetProcessHeap(), 0, This
);
84 DMCOMPOS_UnlockModule();
90 static HRESULT WINAPI
IDirectMusicChordMapImpl_GetScale(IDirectMusicChordMap
*iface
,
93 IDirectMusicChordMapImpl
*This
= impl_from_IDirectMusicChordMap(iface
);
94 FIXME("(%p, %p): stub\n", This
, pdwScale
);
98 static const IDirectMusicChordMapVtbl dmchordmap_vtbl
= {
99 IDirectMusicChordMapImpl_QueryInterface
,
100 IDirectMusicChordMapImpl_AddRef
,
101 IDirectMusicChordMapImpl_Release
,
102 IDirectMusicChordMapImpl_GetScale
105 /* IDirectMusicChordMapImpl IDirectMusicObject part: */
106 static HRESULT WINAPI
IDirectMusicObjectImpl_ParseDescriptor(IDirectMusicObject
*iface
,
107 IStream
*pStream
, DMUS_OBJECTDESC
*pDesc
)
109 DMUS_PRIVATE_CHUNK Chunk
;
110 DWORD StreamSize
, StreamCount
, ListSize
[1], ListCount
[1];
111 LARGE_INTEGER liMove
; /* used when skipping chunks */
113 TRACE("(%p, %p)\n", pStream
, pDesc
);
115 /* FIXME: should this be determined from stream? */
116 pDesc
->dwValidData
|= DMUS_OBJ_CLASS
;
117 pDesc
->guidClass
= CLSID_DirectMusicChordMap
;
119 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
120 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
121 switch (Chunk
.fccID
) {
123 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
124 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
125 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
127 if (Chunk
.fccID
== DMUS_FOURCC_CHORDMAP_FORM
) {
128 TRACE_(dmfile
)(": chord map form\n");
130 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
131 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
132 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
133 switch (Chunk
.fccID
) {
134 case DMUS_FOURCC_GUID_CHUNK
: {
135 TRACE_(dmfile
)(": GUID chunk\n");
136 pDesc
->dwValidData
|= DMUS_OBJ_OBJECT
;
137 IStream_Read (pStream
, &pDesc
->guidObject
, Chunk
.dwSize
, NULL
);
140 case DMUS_FOURCC_VERSION_CHUNK
: {
141 TRACE_(dmfile
)(": version chunk\n");
142 pDesc
->dwValidData
|= DMUS_OBJ_VERSION
;
143 IStream_Read (pStream
, &pDesc
->vVersion
, Chunk
.dwSize
, NULL
);
146 case DMUS_FOURCC_CATEGORY_CHUNK
: {
147 TRACE_(dmfile
)(": category chunk\n");
148 pDesc
->dwValidData
|= DMUS_OBJ_CATEGORY
;
149 IStream_Read (pStream
, pDesc
->wszCategory
, Chunk
.dwSize
, NULL
);
153 IStream_Read (pStream
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
154 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
155 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
157 switch (Chunk
.fccID
) {
158 /* evil M$ UNFO list, which can (!?) contain INFO elements */
159 case DMUS_FOURCC_UNFO_LIST
: {
160 TRACE_(dmfile
)(": UNFO list\n");
162 IStream_Read (pStream
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
163 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
164 TRACE_(dmfile
)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
165 switch (Chunk
.fccID
) {
166 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
167 (though strings seem to be valid unicode) */
168 case mmioFOURCC('I','N','A','M'):
169 case DMUS_FOURCC_UNAM_CHUNK
: {
170 TRACE_(dmfile
)(": name chunk\n");
171 pDesc
->dwValidData
|= DMUS_OBJ_NAME
;
172 IStream_Read (pStream
, pDesc
->wszName
, Chunk
.dwSize
, NULL
);
175 case mmioFOURCC('I','A','R','T'):
176 case DMUS_FOURCC_UART_CHUNK
: {
177 TRACE_(dmfile
)(": artist chunk (ignored)\n");
178 liMove
.QuadPart
= Chunk
.dwSize
;
179 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
182 case mmioFOURCC('I','C','O','P'):
183 case DMUS_FOURCC_UCOP_CHUNK
: {
184 TRACE_(dmfile
)(": copyright chunk (ignored)\n");
185 liMove
.QuadPart
= Chunk
.dwSize
;
186 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
189 case mmioFOURCC('I','S','B','J'):
190 case DMUS_FOURCC_USBJ_CHUNK
: {
191 TRACE_(dmfile
)(": subject chunk (ignored)\n");
192 liMove
.QuadPart
= Chunk
.dwSize
;
193 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
196 case mmioFOURCC('I','C','M','T'):
197 case DMUS_FOURCC_UCMT_CHUNK
: {
198 TRACE_(dmfile
)(": comment chunk (ignored)\n");
199 liMove
.QuadPart
= Chunk
.dwSize
;
200 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
204 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
205 liMove
.QuadPart
= Chunk
.dwSize
;
206 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
210 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
211 } while (ListCount
[0] < ListSize
[0]);
215 TRACE_(dmfile
)(": unknown (skipping)\n");
216 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
217 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
224 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
225 liMove
.QuadPart
= Chunk
.dwSize
;
226 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
);
230 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
231 } while (StreamCount
< StreamSize
);
233 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
234 liMove
.QuadPart
= StreamSize
;
235 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
239 TRACE_(dmfile
)(": reading finished\n");
243 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
244 liMove
.QuadPart
= Chunk
.dwSize
;
245 IStream_Seek (pStream
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
246 return DMUS_E_INVALIDFILE
;
250 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc
));
255 static const IDirectMusicObjectVtbl dmobject_vtbl
= {
256 dmobj_IDirectMusicObject_QueryInterface
,
257 dmobj_IDirectMusicObject_AddRef
,
258 dmobj_IDirectMusicObject_Release
,
259 dmobj_IDirectMusicObject_GetDescriptor
,
260 dmobj_IDirectMusicObject_SetDescriptor
,
261 IDirectMusicObjectImpl_ParseDescriptor
264 /* IDirectMusicChordMapImpl IPersistStream part: */
265 static inline IDirectMusicChordMapImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
267 return CONTAINING_RECORD(iface
, IDirectMusicChordMapImpl
, dmobj
.IPersistStream_iface
);
270 static HRESULT WINAPI
IPersistStreamImpl_Load(IPersistStream
*iface
, IStream
*pStm
)
272 IDirectMusicChordMapImpl
*This
= impl_from_IPersistStream(iface
);
274 DWORD chunkSize
, StreamSize
, StreamCount
, ListSize
[3], ListCount
[3];
275 LARGE_INTEGER liMove
; /* used when skipping chunks */
277 FIXME("(%p, %p): Loading not implemented yet\n", This
, pStm
);
278 IStream_Read (pStm
, &chunkID
, sizeof(FOURCC
), NULL
);
279 IStream_Read (pStm
, &chunkSize
, sizeof(DWORD
), NULL
);
280 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (chunkID
), chunkSize
);
283 IStream_Read (pStm
, &chunkID
, sizeof(FOURCC
), NULL
);
284 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(chunkID
));
285 StreamSize
= chunkSize
- sizeof(FOURCC
);
288 case DMUS_FOURCC_CHORDMAP_FORM
: {
289 TRACE_(dmfile
)(": chordmap form\n");
291 IStream_Read (pStm
, &chunkID
, sizeof(FOURCC
), NULL
);
292 IStream_Read (pStm
, &chunkSize
, sizeof(FOURCC
), NULL
);
293 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + chunkSize
;
294 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (chunkID
), chunkSize
);
296 case DMUS_FOURCC_GUID_CHUNK
: {
297 TRACE_(dmfile
)(": GUID chunk\n");
298 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_OBJECT
;
299 IStream_Read (pStm
, &This
->dmobj
.desc
.guidObject
, chunkSize
, NULL
);
302 case DMUS_FOURCC_VERSION_CHUNK
: {
303 TRACE_(dmfile
)(": version chunk\n");
304 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_VERSION
;
305 IStream_Read (pStm
, &This
->dmobj
.desc
.vVersion
, chunkSize
, NULL
);
308 case DMUS_FOURCC_CATEGORY_CHUNK
: {
309 TRACE_(dmfile
)(": category chunk\n");
310 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_CATEGORY
;
311 IStream_Read (pStm
, This
->dmobj
.desc
.wszCategory
, chunkSize
, NULL
);
315 IStream_Read (pStm
, &chunkID
, sizeof(FOURCC
), NULL
);
316 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(chunkID
));
317 ListSize
[0] = chunkSize
- sizeof(FOURCC
);
320 case DMUS_FOURCC_UNFO_LIST
: {
321 TRACE_(dmfile
)(": UNFO list\n");
323 IStream_Read (pStm
, &chunkID
, sizeof(FOURCC
), NULL
);
324 IStream_Read (pStm
, &chunkSize
, sizeof(FOURCC
), NULL
);
325 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + chunkSize
;
326 TRACE_(dmfile
)(": %s chunk (size = %d)", debugstr_fourcc (chunkID
), chunkSize
);
328 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
329 (though strings seem to be valid unicode) */
330 case mmioFOURCC('I','N','A','M'):
331 case DMUS_FOURCC_UNAM_CHUNK
: {
332 TRACE_(dmfile
)(": name chunk\n");
333 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_NAME
;
334 IStream_Read (pStm
, This
->dmobj
.desc
.wszName
, chunkSize
, NULL
);
337 case mmioFOURCC('I','A','R','T'):
338 case DMUS_FOURCC_UART_CHUNK
: {
339 TRACE_(dmfile
)(": artist chunk (ignored)\n");
340 liMove
.QuadPart
= chunkSize
;
341 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
344 case mmioFOURCC('I','C','O','P'):
345 case DMUS_FOURCC_UCOP_CHUNK
: {
346 TRACE_(dmfile
)(": copyright chunk (ignored)\n");
347 liMove
.QuadPart
= chunkSize
;
348 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
351 case mmioFOURCC('I','S','B','J'):
352 case DMUS_FOURCC_USBJ_CHUNK
: {
353 TRACE_(dmfile
)(": subject chunk (ignored)\n");
354 liMove
.QuadPart
= chunkSize
;
355 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
358 case mmioFOURCC('I','C','M','T'):
359 case DMUS_FOURCC_UCMT_CHUNK
: {
360 TRACE_(dmfile
)(": comment chunk (ignored)\n");
361 liMove
.QuadPart
= chunkSize
;
362 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
366 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
367 liMove
.QuadPart
= chunkSize
;
368 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
372 TRACE_(dmfile
)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount
[0], ListSize
[0]);
373 } while (ListCount
[0] < ListSize
[0]);
377 TRACE_(dmfile
)(": unknown (skipping)\n");
378 liMove
.QuadPart
= chunkSize
- sizeof(FOURCC
);
379 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
386 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
387 liMove
.QuadPart
= chunkSize
;
388 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
392 TRACE_(dmfile
)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount
, StreamSize
);
393 } while (StreamCount
< StreamSize
);
397 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
398 liMove
.QuadPart
= StreamSize
;
399 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
403 TRACE_(dmfile
)(": reading finished\n");
407 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
408 liMove
.QuadPart
= chunkSize
;
409 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
417 static const IPersistStreamVtbl persiststream_vtbl
= {
418 dmobj_IPersistStream_QueryInterface
,
419 dmobj_IPersistStream_AddRef
,
420 dmobj_IPersistStream_Release
,
421 dmobj_IPersistStream_GetClassID
,
422 unimpl_IPersistStream_IsDirty
,
423 IPersistStreamImpl_Load
,
424 unimpl_IPersistStream_Save
,
425 unimpl_IPersistStream_GetSizeMax
428 /* for ClassFactory */
429 HRESULT WINAPI
create_dmchordmap(REFIID lpcGUID
, void **ppobj
)
431 IDirectMusicChordMapImpl
* obj
;
434 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicChordMapImpl
));
437 return E_OUTOFMEMORY
;
439 obj
->IDirectMusicChordMap_iface
.lpVtbl
= &dmchordmap_vtbl
;
441 dmobject_init(&obj
->dmobj
, &CLSID_DirectMusicChordMap
,
442 (IUnknown
*)&obj
->IDirectMusicChordMap_iface
);
443 obj
->dmobj
.IDirectMusicObject_iface
.lpVtbl
= &dmobject_vtbl
;
444 obj
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
446 DMCOMPOS_LockModule();
447 hr
= IDirectMusicChordMap_QueryInterface(&obj
->IDirectMusicChordMap_iface
, lpcGUID
, ppobj
);
448 IDirectMusicChordMap_Release(&obj
->IDirectMusicChordMap_iface
);