2003-07-22 00:10:14 +02:00
|
|
|
/* IDirectMusicBand Implementation
|
|
|
|
*
|
2004-01-20 01:21:40 +01:00
|
|
|
* Copyright (C) 2003-2004 Rok Mandeljc
|
2003-07-22 00:10:14 +02:00
|
|
|
*
|
2007-05-30 12:54:07 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2003-07-22 00:10:14 +02:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-05-30 12:54:07 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2003-07-22 00:10:14 +02:00
|
|
|
*
|
2007-05-30 12:54:07 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-07-22 00:10:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dmband_private.h"
|
2015-06-15 01:07:17 +02:00
|
|
|
#include "dmobject.h"
|
2003-07-22 00:10:14 +02:00
|
|
|
|
2003-08-23 01:53:27 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dmband);
|
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(dmfile);
|
2003-07-22 00:10:14 +02:00
|
|
|
|
2004-01-20 01:21:40 +01:00
|
|
|
|
2003-08-23 01:53:27 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectMusicBandImpl implementation
|
|
|
|
*/
|
2014-06-09 13:28:01 +02:00
|
|
|
typedef struct IDirectMusicBandImpl {
|
|
|
|
IDirectMusicBand IDirectMusicBand_iface;
|
2015-06-15 01:07:17 +02:00
|
|
|
struct dmobject dmobj;
|
2014-06-09 13:28:01 +02:00
|
|
|
LONG ref;
|
|
|
|
struct list Instruments;
|
|
|
|
} IDirectMusicBandImpl;
|
|
|
|
|
2014-01-30 01:04:58 +01:00
|
|
|
static inline IDirectMusicBandImpl *impl_from_IDirectMusicBand(IDirectMusicBand *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IDirectMusicBandImpl, IDirectMusicBand_iface);
|
|
|
|
}
|
|
|
|
|
2014-01-30 01:06:43 +01:00
|
|
|
/* DirectMusicBandImpl IDirectMusicBand part: */
|
|
|
|
static HRESULT WINAPI IDirectMusicBandImpl_QueryInterface(IDirectMusicBand *iface, REFIID riid,
|
|
|
|
void **ret_iface)
|
|
|
|
{
|
|
|
|
IDirectMusicBandImpl *This = impl_from_IDirectMusicBand(iface);
|
2005-01-21 11:18:16 +01:00
|
|
|
|
2014-01-30 01:06:43 +01:00
|
|
|
TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ret_iface);
|
2005-01-31 21:40:26 +01:00
|
|
|
|
2014-01-30 01:06:43 +01:00
|
|
|
*ret_iface = NULL;
|
2003-07-22 00:10:14 +02:00
|
|
|
|
2014-01-30 01:06:43 +01:00
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDirectMusicBand))
|
|
|
|
*ret_iface = iface;
|
|
|
|
else if (IsEqualIID(riid, &IID_IDirectMusicObject))
|
2015-06-15 01:07:17 +02:00
|
|
|
*ret_iface = &This->dmobj.IDirectMusicObject_iface;
|
2014-01-30 01:06:43 +01:00
|
|
|
else if (IsEqualIID(riid, &IID_IPersistStream))
|
2015-06-15 01:07:17 +02:00
|
|
|
*ret_iface = &This->dmobj.IPersistStream_iface;
|
2014-01-30 01:06:43 +01:00
|
|
|
else {
|
|
|
|
WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ret_iface);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
2003-07-22 00:10:14 +02:00
|
|
|
|
2014-01-30 01:06:43 +01:00
|
|
|
IDirectMusicBand_AddRef((IUnknown*)*ret_iface);
|
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2014-01-30 01:01:06 +01:00
|
|
|
static ULONG WINAPI IDirectMusicBandImpl_AddRef(IDirectMusicBand *iface)
|
|
|
|
{
|
2014-01-30 01:04:58 +01:00
|
|
|
IDirectMusicBandImpl *This = impl_from_IDirectMusicBand(iface);
|
2014-01-30 01:06:43 +01:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2022-02-08 23:14:51 +01:00
|
|
|
TRACE("(%p) ref=%ld\n", This, ref);
|
2014-01-30 01:06:43 +01:00
|
|
|
|
|
|
|
return ref;
|
2004-01-20 01:21:40 +01:00
|
|
|
}
|
2003-07-22 00:10:14 +02:00
|
|
|
|
2014-01-30 01:01:06 +01:00
|
|
|
static ULONG WINAPI IDirectMusicBandImpl_Release(IDirectMusicBand *iface)
|
|
|
|
{
|
2014-01-30 01:04:58 +01:00
|
|
|
IDirectMusicBandImpl *This = impl_from_IDirectMusicBand(iface);
|
2014-01-30 01:06:43 +01:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2022-02-08 23:14:51 +01:00
|
|
|
TRACE("(%p) ref=%ld\n", This, ref);
|
2014-01-30 01:06:43 +01:00
|
|
|
|
|
|
|
if (!ref) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
DMBAND_UnlockModule();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
2004-01-20 01:21:40 +01:00
|
|
|
}
|
2003-07-22 00:10:14 +02:00
|
|
|
|
2014-01-30 01:01:06 +01:00
|
|
|
static HRESULT WINAPI IDirectMusicBandImpl_CreateSegment(IDirectMusicBand *iface,
|
2020-09-18 22:42:17 +02:00
|
|
|
IDirectMusicSegment **segment)
|
2014-01-30 01:01:06 +01:00
|
|
|
{
|
2020-09-18 22:42:17 +02:00
|
|
|
IDirectMusicBandImpl *This = impl_from_IDirectMusicBand(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
DMUS_BAND_PARAM bandparam;
|
|
|
|
|
|
|
|
FIXME("(%p, %p): semi-stub\n", This, segment);
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_DirectMusicSegment, NULL, CLSCTX_INPROC,
|
|
|
|
&IID_IDirectMusicSegment, (void**)segment);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
bandparam.mtTimePhysical = 0;
|
|
|
|
bandparam.pBand = &This->IDirectMusicBand_iface;
|
|
|
|
IDirectMusicBand_AddRef(bandparam.pBand);
|
|
|
|
hr = IDirectMusicSegment_SetParam(*segment, &GUID_BandParam, 0xffffffff, DMUS_SEG_ALLTRACKS,
|
|
|
|
0, &bandparam);
|
|
|
|
IDirectMusicBand_Release(bandparam.pBand);
|
|
|
|
|
|
|
|
return hr;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2014-01-30 01:01:06 +01:00
|
|
|
static HRESULT WINAPI IDirectMusicBandImpl_Download(IDirectMusicBand *iface,
|
|
|
|
IDirectMusicPerformance *pPerformance)
|
|
|
|
{
|
2014-01-30 01:04:58 +01:00
|
|
|
IDirectMusicBandImpl *This = impl_from_IDirectMusicBand(iface);
|
2003-07-22 00:10:14 +02:00
|
|
|
FIXME("(%p, %p): stub\n", This, pPerformance);
|
2004-01-20 01:21:40 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2003-07-22 00:10:14 +02:00
|
|
|
|
2014-01-30 01:01:06 +01:00
|
|
|
static HRESULT WINAPI IDirectMusicBandImpl_Unload(IDirectMusicBand *iface,
|
|
|
|
IDirectMusicPerformance *pPerformance)
|
|
|
|
{
|
2014-01-30 01:04:58 +01:00
|
|
|
IDirectMusicBandImpl *This = impl_from_IDirectMusicBand(iface);
|
2004-01-20 01:21:40 +01:00
|
|
|
FIXME("(%p, %p): stub\n", This, pPerformance);
|
2003-07-22 00:10:14 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-30 01:04:58 +01:00
|
|
|
static const IDirectMusicBandVtbl dmband_vtbl = {
|
2014-01-30 01:01:06 +01:00
|
|
|
IDirectMusicBandImpl_QueryInterface,
|
|
|
|
IDirectMusicBandImpl_AddRef,
|
|
|
|
IDirectMusicBandImpl_Release,
|
|
|
|
IDirectMusicBandImpl_CreateSegment,
|
|
|
|
IDirectMusicBandImpl_Download,
|
|
|
|
IDirectMusicBandImpl_Unload
|
2003-07-22 00:10:14 +02:00
|
|
|
};
|
|
|
|
|
2004-01-20 01:21:40 +01:00
|
|
|
/* IDirectMusicBandImpl IDirectMusicObject part: */
|
2018-07-15 21:08:45 +02:00
|
|
|
static HRESULT WINAPI band_IDirectMusicObject_ParseDescriptor(IDirectMusicObject *iface,
|
|
|
|
IStream *stream, DMUS_OBJECTDESC *desc)
|
2015-06-15 01:07:17 +02:00
|
|
|
{
|
2018-07-15 21:08:45 +02:00
|
|
|
struct chunk_entry riff = {0};
|
|
|
|
STATSTG stat;
|
|
|
|
HRESULT hr;
|
2004-01-20 01:21:40 +01:00
|
|
|
|
2018-07-15 21:08:45 +02:00
|
|
|
TRACE("(%p, %p, %p)\n", iface, stream, desc);
|
2008-02-19 23:03:43 +01:00
|
|
|
|
2018-07-15 21:08:45 +02:00
|
|
|
if (!stream || !desc)
|
|
|
|
return E_POINTER;
|
2008-02-19 23:03:43 +01:00
|
|
|
|
2018-07-15 21:08:45 +02:00
|
|
|
if ((hr = stream_get_chunk(stream, &riff)) != S_OK)
|
|
|
|
return hr;
|
|
|
|
if (riff.id != FOURCC_RIFF || riff.type != DMUS_FOURCC_BAND_FORM) {
|
|
|
|
TRACE("loading failed: unexpected %s\n", debugstr_chunk(&riff));
|
|
|
|
stream_skip_chunk(stream, &riff);
|
|
|
|
return DMUS_E_INVALID_BAND;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = dmobj_parsedescriptor(stream, &riff, desc,
|
|
|
|
DMUS_OBJ_OBJECT|DMUS_OBJ_NAME|DMUS_OBJ_NAME_INAM|DMUS_OBJ_CATEGORY|DMUS_OBJ_VERSION);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
desc->guidClass = CLSID_DirectMusicBand;
|
|
|
|
desc->dwValidData |= DMUS_OBJ_CLASS;
|
|
|
|
|
|
|
|
if (desc->dwValidData & DMUS_OBJ_CATEGORY) {
|
|
|
|
IStream_Stat(stream, &stat, STATFLAG_NONAME);
|
|
|
|
desc->ftDate = stat.mtime;
|
|
|
|
desc->dwValidData |= DMUS_OBJ_DATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("returning descriptor:\n");
|
2019-12-12 01:10:58 +01:00
|
|
|
dump_DMUS_OBJECTDESC(desc);
|
2018-07-15 21:08:45 +02:00
|
|
|
return S_OK;
|
2004-01-20 01:21:40 +01:00
|
|
|
}
|
|
|
|
|
2015-06-15 01:07:17 +02:00
|
|
|
static const IDirectMusicObjectVtbl dmobject_vtbl = {
|
|
|
|
dmobj_IDirectMusicObject_QueryInterface,
|
|
|
|
dmobj_IDirectMusicObject_AddRef,
|
|
|
|
dmobj_IDirectMusicObject_Release,
|
|
|
|
dmobj_IDirectMusicObject_GetDescriptor,
|
|
|
|
dmobj_IDirectMusicObject_SetDescriptor,
|
2018-07-15 21:08:45 +02:00
|
|
|
band_IDirectMusicObject_ParseDescriptor
|
2004-01-20 01:21:40 +01:00
|
|
|
};
|
|
|
|
|
2019-11-08 22:32:56 +01:00
|
|
|
#define DMUS_IO_INSTRUMENT_DX7_SIZE offsetof(DMUS_IO_INSTRUMENT, nPitchBendRange)
|
|
|
|
|
2004-01-20 01:21:40 +01:00
|
|
|
/* IDirectMusicBandImpl IPersistStream part: */
|
2015-06-15 01:04:41 +02:00
|
|
|
static HRESULT parse_instrument(IDirectMusicBandImpl *This, DMUS_PRIVATE_CHUNK *pChunk,
|
|
|
|
IStream *pStm)
|
|
|
|
{
|
2004-05-13 01:58:05 +02:00
|
|
|
DMUS_PRIVATE_CHUNK Chunk;
|
|
|
|
DWORD ListSize[3], ListCount[3];
|
|
|
|
LARGE_INTEGER liMove; /* used when skipping chunks */
|
2004-05-13 07:19:47 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
DMUS_IO_INSTRUMENT inst;
|
|
|
|
LPDMUS_PRIVATE_INSTRUMENT pNewInstrument;
|
|
|
|
IDirectMusicObject* pObject = NULL;
|
2004-05-13 01:58:05 +02:00
|
|
|
|
|
|
|
if (pChunk->fccID != DMUS_FOURCC_INSTRUMENT_LIST) {
|
2005-03-23 14:15:18 +01:00
|
|
|
ERR_(dmfile)(": %s chunk should be an INSTRUMENT list\n", debugstr_fourcc (pChunk->fccID));
|
2004-05-13 01:58:05 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
|
|
|
|
ListCount[0] = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
|
|
|
|
ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
|
2022-02-08 23:14:51 +01:00
|
|
|
TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
|
2004-05-13 01:58:05 +02:00
|
|
|
switch (Chunk.fccID) {
|
|
|
|
case DMUS_FOURCC_INSTRUMENT_CHUNK: {
|
|
|
|
TRACE_(dmfile)(": Instrument chunk\n");
|
2019-11-08 22:32:56 +01:00
|
|
|
if (Chunk.dwSize != sizeof(DMUS_IO_INSTRUMENT) && Chunk.dwSize != DMUS_IO_INSTRUMENT_DX7_SIZE) {
|
2022-02-08 23:14:51 +01:00
|
|
|
ERR_(dmfile)("unexpected size %ld\n", Chunk.dwSize);
|
2019-11-08 22:32:56 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
IStream_Read (pStm, &inst, Chunk.dwSize, NULL);
|
|
|
|
if (Chunk.dwSize != sizeof(DMUS_IO_INSTRUMENT))
|
|
|
|
inst.nPitchBendRange = 0;
|
|
|
|
|
2022-02-08 23:14:51 +01:00
|
|
|
TRACE_(dmfile)(" - dwPatch: %lu\n", inst.dwPatch);
|
|
|
|
TRACE_(dmfile)(" - dwAssignPatch: %lu\n", inst.dwAssignPatch);
|
|
|
|
TRACE_(dmfile)(" - dwNoteRanges[0]: %lu\n", inst.dwNoteRanges[0]);
|
|
|
|
TRACE_(dmfile)(" - dwNoteRanges[1]: %lu\n", inst.dwNoteRanges[1]);
|
|
|
|
TRACE_(dmfile)(" - dwNoteRanges[2]: %lu\n", inst.dwNoteRanges[2]);
|
|
|
|
TRACE_(dmfile)(" - dwNoteRanges[3]: %lu\n", inst.dwNoteRanges[3]);
|
|
|
|
TRACE_(dmfile)(" - dwPChannel: %lu\n", inst.dwPChannel);
|
|
|
|
TRACE_(dmfile)(" - dwFlags: %lx\n", inst.dwFlags);
|
2004-05-13 01:58:05 +02:00
|
|
|
TRACE_(dmfile)(" - bPan: %u\n", inst.bPan);
|
|
|
|
TRACE_(dmfile)(" - bVolume: %u\n", inst.bVolume);
|
|
|
|
TRACE_(dmfile)(" - nTranspose: %d\n", inst.nTranspose);
|
2022-02-08 23:14:51 +01:00
|
|
|
TRACE_(dmfile)(" - dwChannelPriority: %lu\n", inst.dwChannelPriority);
|
2004-05-13 01:58:05 +02:00
|
|
|
TRACE_(dmfile)(" - nPitchBendRange: %d\n", inst.nPitchBendRange);
|
|
|
|
break;
|
2004-05-13 07:19:47 +02:00
|
|
|
}
|
|
|
|
case FOURCC_LIST: {
|
|
|
|
IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
|
|
|
|
TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
|
|
|
|
ListSize[1] = Chunk.dwSize - sizeof(FOURCC);
|
|
|
|
ListCount[1] = 0;
|
|
|
|
switch (Chunk.fccID) {
|
|
|
|
case DMUS_FOURCC_REF_LIST: {
|
|
|
|
FIXME_(dmfile)(": DMRF (DM References) list\n");
|
2015-06-15 01:07:17 +02:00
|
|
|
hr = IDirectMusicUtils_IPersistStream_ParseReference(&This->dmobj.IPersistStream_iface,
|
2015-06-15 01:04:41 +02:00
|
|
|
&Chunk, pStm, &pObject);
|
2004-05-13 07:19:47 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
ERR(": could not load Reference\n");
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
TRACE_(dmfile)(": unknown (skipping)\n");
|
|
|
|
liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-05-13 01:58:05 +02:00
|
|
|
}
|
|
|
|
default: {
|
2011-07-30 12:03:08 +02:00
|
|
|
TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
|
2004-05-13 01:58:05 +02:00
|
|
|
liMove.QuadPart = Chunk.dwSize;
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-02-08 23:14:51 +01:00
|
|
|
TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
|
2004-05-13 01:58:05 +02:00
|
|
|
} while (ListCount[0] < ListSize[0]);
|
|
|
|
|
2004-05-13 07:19:47 +02:00
|
|
|
/*
|
|
|
|
* @TODO insert pNewInstrument into This
|
|
|
|
*/
|
|
|
|
pNewInstrument = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_INSTRUMENT));
|
|
|
|
if (NULL == pNewInstrument) {
|
|
|
|
ERR(": no more memory\n");
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
memcpy(&pNewInstrument->pInstrument, &inst, sizeof(DMUS_IO_INSTRUMENT));
|
|
|
|
pNewInstrument->ppReferenceCollection = NULL;
|
|
|
|
if (NULL != pObject) {
|
|
|
|
IDirectMusicCollection* pCol = NULL;
|
|
|
|
hr = IDirectMusicObject_QueryInterface (pObject, &IID_IDirectMusicCollection, (void**) &pCol);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
ERR(": failed to get IDirectMusicCollection Interface from DMObject\n");
|
2007-09-18 23:58:29 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, pNewInstrument);
|
|
|
|
|
2004-05-13 07:19:47 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
pNewInstrument->ppReferenceCollection = pCol;
|
|
|
|
IDirectMusicObject_Release(pObject);
|
|
|
|
}
|
|
|
|
list_add_tail (&This->Instruments, &pNewInstrument->entry);
|
|
|
|
|
2004-05-13 01:58:05 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-15 01:04:41 +02:00
|
|
|
static HRESULT parse_instruments_list(IDirectMusicBandImpl *This, DMUS_PRIVATE_CHUNK *pChunk,
|
|
|
|
IStream *pStm)
|
|
|
|
{
|
2004-05-13 01:58:05 +02:00
|
|
|
HRESULT hr;
|
|
|
|
DMUS_PRIVATE_CHUNK Chunk;
|
|
|
|
DWORD ListSize[3], ListCount[3];
|
|
|
|
LARGE_INTEGER liMove; /* used when skipping chunks */
|
|
|
|
|
|
|
|
if (pChunk->fccID != DMUS_FOURCC_INSTRUMENTS_LIST) {
|
2005-03-23 14:15:18 +01:00
|
|
|
ERR_(dmfile)(": %s chunk should be an INSTRUMENTS list\n", debugstr_fourcc (pChunk->fccID));
|
2004-05-13 01:58:05 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
|
|
|
|
ListCount[0] = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
|
|
|
|
ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
|
2022-02-08 23:14:51 +01:00
|
|
|
TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
|
2004-05-13 01:58:05 +02:00
|
|
|
switch (Chunk.fccID) {
|
|
|
|
case FOURCC_LIST: {
|
|
|
|
IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
|
|
|
|
TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
|
|
|
|
ListSize[1] = Chunk.dwSize - sizeof(FOURCC);
|
|
|
|
ListCount[1] = 0;
|
|
|
|
switch (Chunk.fccID) {
|
|
|
|
case DMUS_FOURCC_INSTRUMENT_LIST: {
|
|
|
|
TRACE_(dmfile)(": Instrument list\n");
|
2015-06-15 01:04:41 +02:00
|
|
|
hr = parse_instrument(This, &Chunk, pStm);
|
2004-05-13 01:58:05 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2011-07-30 12:03:08 +02:00
|
|
|
TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
|
2004-05-13 01:58:05 +02:00
|
|
|
liMove.QuadPart = ListSize[1];
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2011-07-30 12:03:08 +02:00
|
|
|
TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
|
2004-05-13 01:58:05 +02:00
|
|
|
liMove.QuadPart = Chunk.dwSize;
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-02-08 23:14:51 +01:00
|
|
|
TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
|
2004-05-13 01:58:05 +02:00
|
|
|
} while (ListCount[0] < ListSize[0]);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-15 01:04:41 +02:00
|
|
|
static HRESULT parse_band_form(IDirectMusicBandImpl *This, DMUS_PRIVATE_CHUNK *pChunk,
|
|
|
|
IStream *pStm)
|
|
|
|
{
|
2004-05-13 01:58:05 +02:00
|
|
|
HRESULT hr = E_FAIL;
|
|
|
|
DMUS_PRIVATE_CHUNK Chunk;
|
|
|
|
DWORD StreamSize, StreamCount, ListSize[3], ListCount[3];
|
|
|
|
LARGE_INTEGER liMove; /* used when skipping chunks */
|
|
|
|
|
|
|
|
GUID tmp_guid;
|
|
|
|
|
|
|
|
if (pChunk->fccID != DMUS_FOURCC_BAND_FORM) {
|
|
|
|
ERR_(dmfile)(": %s chunk should be a BAND form\n", debugstr_fourcc (pChunk->fccID));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamSize = pChunk->dwSize - sizeof(FOURCC);
|
|
|
|
StreamCount = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
|
|
|
|
StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
|
2022-02-08 23:14:51 +01:00
|
|
|
TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
|
2004-05-13 07:19:47 +02:00
|
|
|
|
2015-06-15 01:07:17 +02:00
|
|
|
hr = IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk, pStm, &This->dmobj.desc);
|
2004-05-13 07:19:47 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
if (hr == S_FALSE) {
|
2004-05-13 01:58:05 +02:00
|
|
|
switch (Chunk.fccID) {
|
2004-05-13 07:19:47 +02:00
|
|
|
case DMUS_FOURCC_GUID_CHUNK: {
|
|
|
|
TRACE_(dmfile)(": GUID\n");
|
|
|
|
IStream_Read (pStm, &tmp_guid, sizeof(GUID), NULL);
|
|
|
|
TRACE_(dmfile)(" - guid: %s\n", debugstr_dmguid(&tmp_guid));
|
2004-05-13 01:58:05 +02:00
|
|
|
break;
|
|
|
|
}
|
2004-05-13 07:19:47 +02:00
|
|
|
case FOURCC_LIST: {
|
|
|
|
IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
|
|
|
|
TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
|
|
|
|
ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
|
|
|
|
ListCount[0] = 0;
|
|
|
|
switch (Chunk.fccID) {
|
|
|
|
case DMUS_FOURCC_UNFO_LIST: {
|
|
|
|
TRACE_(dmfile)(": UNFO list\n");
|
|
|
|
do {
|
|
|
|
IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
|
|
|
|
ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
|
2022-02-08 23:14:51 +01:00
|
|
|
TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
|
2015-06-15 01:07:17 +02:00
|
|
|
|
|
|
|
hr = IDirectMusicUtils_IPersistStream_ParseUNFOGeneric(&Chunk, pStm, &This->dmobj.desc);
|
2004-05-13 07:19:47 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
if (hr == S_FALSE) {
|
|
|
|
switch (Chunk.fccID) {
|
|
|
|
default: {
|
2011-07-30 12:03:08 +02:00
|
|
|
TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
|
2004-05-13 07:19:47 +02:00
|
|
|
liMove.QuadPart = Chunk.dwSize;
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-08 23:14:51 +01:00
|
|
|
TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
|
2004-05-13 07:19:47 +02:00
|
|
|
} while (ListCount[0] < ListSize[0]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DMUS_FOURCC_INSTRUMENTS_LIST: {
|
|
|
|
TRACE_(dmfile)(": INSTRUMENTS list\n");
|
2015-06-15 01:04:41 +02:00
|
|
|
hr = parse_instruments_list(This, &Chunk, pStm);
|
2004-05-13 07:19:47 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
TRACE_(dmfile)(": unknown (skipping)\n");
|
|
|
|
liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-05-13 01:58:05 +02:00
|
|
|
}
|
|
|
|
default: {
|
2011-07-30 12:03:08 +02:00
|
|
|
TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
|
2004-05-13 07:19:47 +02:00
|
|
|
liMove.QuadPart = Chunk.dwSize;
|
2004-05-13 01:58:05 +02:00
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-08 23:14:51 +01:00
|
|
|
TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
|
2004-05-13 01:58:05 +02:00
|
|
|
} while (StreamCount < StreamSize);
|
|
|
|
|
|
|
|
return S_OK;
|
2004-01-20 01:21:40 +01:00
|
|
|
}
|
|
|
|
|
2015-06-15 01:07:17 +02:00
|
|
|
static inline IDirectMusicBandImpl *impl_from_IPersistStream(IPersistStream *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IDirectMusicBandImpl, dmobj.IPersistStream_iface);
|
|
|
|
}
|
2004-05-13 01:58:05 +02:00
|
|
|
|
2015-06-15 01:07:17 +02:00
|
|
|
static HRESULT WINAPI IPersistStreamImpl_Load(IPersistStream *iface, IStream *pStm)
|
|
|
|
{
|
|
|
|
IDirectMusicBandImpl *This = impl_from_IPersistStream(iface);
|
2004-05-13 01:58:05 +02:00
|
|
|
DMUS_PRIVATE_CHUNK Chunk;
|
|
|
|
LARGE_INTEGER liMove;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2004-05-13 07:19:47 +02:00
|
|
|
TRACE("(%p,%p): loading\n", This, pStm);
|
2004-05-13 01:58:05 +02:00
|
|
|
|
|
|
|
IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
|
2022-02-08 23:14:51 +01:00
|
|
|
TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
|
2004-05-13 01:58:05 +02:00
|
|
|
switch (Chunk.fccID) {
|
|
|
|
case FOURCC_RIFF: {
|
|
|
|
IStream_Read (pStm, &Chunk.fccID, sizeof(FOURCC), NULL);
|
2022-02-08 23:14:51 +01:00
|
|
|
TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
|
2004-05-13 01:58:05 +02:00
|
|
|
switch (Chunk.fccID) {
|
|
|
|
case DMUS_FOURCC_BAND_FORM: {
|
|
|
|
TRACE_(dmfile)(": Band form\n");
|
2015-06-15 01:04:41 +02:00
|
|
|
hr = parse_band_form(This, &Chunk, pStm);
|
2004-05-13 01:58:05 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
|
|
|
|
liMove.QuadPart = Chunk.dwSize;
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TRACE_(dmfile)(": reading finished\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
|
|
|
|
liMove.QuadPart = Chunk.dwSize;
|
|
|
|
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2003-08-23 01:53:27 +02:00
|
|
|
}
|
|
|
|
|
2015-06-15 01:07:17 +02:00
|
|
|
static const IPersistStreamVtbl persiststream_vtbl = {
|
|
|
|
dmobj_IPersistStream_QueryInterface,
|
|
|
|
dmobj_IPersistStream_AddRef,
|
|
|
|
dmobj_IPersistStream_Release,
|
|
|
|
unimpl_IPersistStream_GetClassID,
|
|
|
|
unimpl_IPersistStream_IsDirty,
|
|
|
|
IPersistStreamImpl_Load,
|
|
|
|
unimpl_IPersistStream_Save,
|
|
|
|
unimpl_IPersistStream_GetSizeMax
|
2003-08-23 01:53:27 +02:00
|
|
|
};
|
2004-01-20 01:21:40 +01:00
|
|
|
|
|
|
|
/* for ClassFactory */
|
2014-01-30 00:46:19 +01:00
|
|
|
HRESULT WINAPI create_dmband(REFIID lpcGUID, void **ppobj)
|
|
|
|
{
|
2004-05-13 01:58:05 +02:00
|
|
|
IDirectMusicBandImpl* obj;
|
2014-01-30 01:06:43 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2004-05-13 01:58:05 +02:00
|
|
|
obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicBandImpl));
|
|
|
|
if (NULL == obj) {
|
2004-12-22 16:13:20 +01:00
|
|
|
*ppobj = NULL;
|
2004-05-13 01:58:05 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2014-01-30 01:04:58 +01:00
|
|
|
obj->IDirectMusicBand_iface.lpVtbl = &dmband_vtbl;
|
2014-01-30 01:06:43 +01:00
|
|
|
obj->ref = 1;
|
2015-06-15 01:07:17 +02:00
|
|
|
dmobject_init(&obj->dmobj, &CLSID_DirectMusicBand, (IUnknown *)&obj->IDirectMusicBand_iface);
|
|
|
|
obj->dmobj.IDirectMusicObject_iface.lpVtbl = &dmobject_vtbl;
|
|
|
|
obj->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
|
2004-05-13 01:58:05 +02:00
|
|
|
list_init (&obj->Instruments);
|
2008-02-19 23:03:43 +01:00
|
|
|
|
2014-01-30 01:06:43 +01:00
|
|
|
DMBAND_LockModule();
|
|
|
|
hr = IDirectMusicBand_QueryInterface(&obj->IDirectMusicBand_iface, lpcGUID, ppobj);
|
|
|
|
IDirectMusicBand_Release(&obj->IDirectMusicBand_iface);
|
|
|
|
|
|
|
|
return hr;
|
2004-01-20 01:21:40 +01:00
|
|
|
}
|