Sweden-Number/dlls/dmband/band.c

412 lines
17 KiB
C
Raw Normal View History

2003-07-22 00:10:14 +02:00
/* IDirectMusicBand Implementation
*
* Copyright (C) 2003-2004 Rok Mandeljc
2003-07-22 00:10:14 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "dmband_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmband);
WINE_DECLARE_DEBUG_CHANNEL(dmfile);
2003-07-22 00:10:14 +02:00
const GUID IID_IDirectMusicBandPRIVATE = {0xda54db81,0x837d,0x11d1,{0x86,0xbc,0x00,0xc0,0x4f,0xbf,0x8f,0xef}};
/*****************************************************************************
* IDirectMusicBandImpl implementation
*/
/* IDirectMusicBandImpl IUnknown part: */
HRESULT WINAPI IDirectMusicBandImpl_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, UnknownVtbl, iface);
TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
if (IsEqualIID (riid, &IID_IUnknown)) {
*ppobj = (LPVOID)&This->UnknownVtbl;
IDirectMusicBandImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
return S_OK;
} else if (IsEqualIID (riid, &IID_IDirectMusicBand)) {
*ppobj = (LPVOID)&This->BandVtbl;
IDirectMusicBandImpl_IDirectMusicBand_AddRef ((LPDIRECTMUSICBAND)&This->BandVtbl);
return S_OK;
} else if (IsEqualIID (riid, &IID_IDirectMusicObject)) {
*ppobj = (LPVOID)&This->ObjectVtbl;
IDirectMusicBandImpl_IDirectMusicObject_AddRef ((LPDIRECTMUSICOBJECT)&This->ObjectVtbl);
return S_OK;
} else if (IsEqualIID (riid, &IID_IPersistStream)) {
*ppobj = (LPVOID)&This->PersistStreamVtbl;
IDirectMusicBandImpl_IPersistStream_AddRef ((LPPERSISTSTREAM)&This->PersistStreamVtbl);
2003-07-22 00:10:14 +02:00
return S_OK;
}
WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
2003-07-22 00:10:14 +02:00
return E_NOINTERFACE;
}
ULONG WINAPI IDirectMusicBandImpl_IUnknown_AddRef (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, UnknownVtbl, iface);
2003-07-22 00:10:14 +02:00
TRACE("(%p) : AddRef from %ld\n", This, This->ref);
return ++(This->ref);
}
ULONG WINAPI IDirectMusicBandImpl_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, UnknownVtbl, iface);
2003-07-22 00:10:14 +02:00
ULONG ref = --This->ref;
TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
2003-10-28 22:08:55 +01:00
if (ref == 0) {
2003-07-22 00:10:14 +02:00
HeapFree(GetProcessHeap(), 0, This);
}
return ref;
}
ICOM_VTABLE(IUnknown) DirectMusicBand_Unknown_Vtbl = {
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
IDirectMusicBandImpl_IUnknown_QueryInterface,
IDirectMusicBandImpl_IUnknown_AddRef,
IDirectMusicBandImpl_IUnknown_Release
};
2003-07-22 00:10:14 +02:00
/* IDirectMusicBandImpl IDirectMusicBand part: */
HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicBand_QueryInterface (LPDIRECTMUSICBAND iface, REFIID riid, LPVOID *ppobj) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, BandVtbl, iface);
return IDirectMusicBandImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
2003-07-22 00:10:14 +02:00
}
ULONG WINAPI IDirectMusicBandImpl_IDirectMusicBand_AddRef (LPDIRECTMUSICBAND iface) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, BandVtbl, iface);
return IDirectMusicBandImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
}
2003-07-22 00:10:14 +02:00
ULONG WINAPI IDirectMusicBandImpl_IDirectMusicBand_Release (LPDIRECTMUSICBAND iface) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, BandVtbl, iface);
return IDirectMusicBandImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
}
2003-07-22 00:10:14 +02:00
HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicBand_CreateSegment (LPDIRECTMUSICBAND iface, IDirectMusicSegment** ppSegment) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, BandVtbl, iface);
FIXME("(%p, %p): stub\n", This, ppSegment);
2003-07-22 00:10:14 +02:00
return S_OK;
}
HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicBand_Download (LPDIRECTMUSICBAND iface, IDirectMusicPerformance* pPerformance) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, BandVtbl, iface);
2003-07-22 00:10:14 +02:00
FIXME("(%p, %p): stub\n", This, pPerformance);
return S_OK;
}
2003-07-22 00:10:14 +02:00
HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicBand_Unload (LPDIRECTMUSICBAND iface, IDirectMusicPerformance* pPerformance) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, BandVtbl, iface);
FIXME("(%p, %p): stub\n", This, pPerformance);
2003-07-22 00:10:14 +02:00
return S_OK;
}
ICOM_VTABLE(IDirectMusicBand) DirectMusicBand_Band_Vtbl = {
2003-07-22 00:10:14 +02:00
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
IDirectMusicBandImpl_IDirectMusicBand_QueryInterface,
IDirectMusicBandImpl_IDirectMusicBand_AddRef,
IDirectMusicBandImpl_IDirectMusicBand_Release,
IDirectMusicBandImpl_IDirectMusicBand_CreateSegment,
IDirectMusicBandImpl_IDirectMusicBand_Download,
IDirectMusicBandImpl_IDirectMusicBand_Unload
2003-07-22 00:10:14 +02:00
};
/* IDirectMusicBandImpl IDirectMusicObject part: */
HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, ObjectVtbl, iface);
return IDirectMusicBandImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
2003-07-22 00:10:14 +02:00
}
ULONG WINAPI IDirectMusicBandImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, ObjectVtbl, iface);
return IDirectMusicBandImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
}
ULONG WINAPI IDirectMusicBandImpl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, ObjectVtbl, iface);
return IDirectMusicBandImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
}
HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, ObjectVtbl, iface);
TRACE("(%p, %p)\n", This, pDesc);
/* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
memcpy (pDesc, This->pDesc, This->pDesc->dwSize);
return S_OK;
}
HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, ObjectVtbl, iface);
TRACE("(%p, %p): setting descriptor:\n%s\n", This, pDesc, debugstr_DMUS_OBJECTDESC (pDesc));
/* According to MSDN, we should copy only given values, not whole struct */
if (pDesc->dwValidData & DMUS_OBJ_OBJECT)
memcpy (&This->pDesc->guidObject, &pDesc->guidObject, sizeof (pDesc->guidObject));
if (pDesc->dwValidData & DMUS_OBJ_CLASS)
memcpy (&This->pDesc->guidClass, &pDesc->guidClass, sizeof (pDesc->guidClass));
if (pDesc->dwValidData & DMUS_OBJ_NAME)
strncpyW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
strncpyW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
strncpyW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
if (pDesc->dwValidData & DMUS_OBJ_VERSION)
memcpy (&This->pDesc->vVersion, &pDesc->vVersion, sizeof (pDesc->vVersion));
if (pDesc->dwValidData & DMUS_OBJ_DATE)
memcpy (&This->pDesc->ftDate, &pDesc->ftDate, sizeof (pDesc->ftDate));
if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
memcpy (&This->pDesc->llMemLength, &pDesc->llMemLength, sizeof (pDesc->llMemLength));
memcpy (This->pDesc->pbMemData, pDesc->pbMemData, sizeof (pDesc->pbMemData));
}
if (pDesc->dwValidData & DMUS_OBJ_STREAM) {
/* according to MSDN, we copy the stream */
IStream_Clone (pDesc->pStream, &This->pDesc->pStream);
}
/* add new flags */
This->pDesc->dwValidData |= pDesc->dwValidData;
return S_OK;
}
HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc) {
DMUS_PRIVATE_CHUNK Chunk;
DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
LARGE_INTEGER liMove; /* used when skipping chunks */
TRACE("(%p, %p)\n", pStream, pDesc);
/* FIXME: should this be determined from stream? */
pDesc->dwValidData |= DMUS_OBJ_CLASS;
memcpy (&pDesc->guidClass, &CLSID_DirectMusicBand, sizeof(CLSID));
IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
switch (Chunk.fccID) {
case FOURCC_RIFF: {
IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
StreamSize = Chunk.dwSize - sizeof(FOURCC);
StreamCount = 0;
if (Chunk.fccID == DMUS_FOURCC_BAND_FORM) {
TRACE_(dmfile)(": band form\n");
do {
IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
switch (Chunk.fccID) {
case DMUS_FOURCC_GUID_CHUNK: {
TRACE_(dmfile)(": GUID chunk\n");
pDesc->dwValidData |= DMUS_OBJ_OBJECT;
IStream_Read (pStream, &pDesc->guidObject, Chunk.dwSize, NULL);
break;
}
case DMUS_FOURCC_VERSION_CHUNK: {
TRACE_(dmfile)(": version chunk\n");
pDesc->dwValidData |= DMUS_OBJ_VERSION;
IStream_Read (pStream, &pDesc->vVersion, Chunk.dwSize, NULL);
break;
}
case DMUS_FOURCC_CATEGORY_CHUNK: {
TRACE_(dmfile)(": category chunk\n");
pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
IStream_Read (pStream, pDesc->wszCategory, Chunk.dwSize, NULL);
break;
}
case FOURCC_LIST: {
IStream_Read (pStream, &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) {
/* evil M$ UNFO list, which can (!?) contain INFO elements */
case DMUS_FOURCC_UNFO_LIST: {
TRACE_(dmfile)(": UNFO list\n");
do {
IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
TRACE_(dmfile)(": %s chunk (size = 0x%04lx)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
switch (Chunk.fccID) {
/* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
(though strings seem to be valid unicode) */
case mmioFOURCC('I','N','A','M'):
case DMUS_FOURCC_UNAM_CHUNK: {
TRACE_(dmfile)(": name chunk\n");
pDesc->dwValidData |= DMUS_OBJ_NAME;
IStream_Read (pStream, pDesc->wszName, Chunk.dwSize, NULL);
break;
}
case mmioFOURCC('I','A','R','T'):
case DMUS_FOURCC_UART_CHUNK: {
TRACE_(dmfile)(": artist chunk (ignored)\n");
liMove.QuadPart = Chunk.dwSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
break;
}
case mmioFOURCC('I','C','O','P'):
case DMUS_FOURCC_UCOP_CHUNK: {
TRACE_(dmfile)(": copyright chunk (ignored)\n");
liMove.QuadPart = Chunk.dwSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
break;
}
case mmioFOURCC('I','S','B','J'):
case DMUS_FOURCC_USBJ_CHUNK: {
TRACE_(dmfile)(": subject chunk (ignored)\n");
liMove.QuadPart = Chunk.dwSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
break;
}
case mmioFOURCC('I','C','M','T'):
case DMUS_FOURCC_UCMT_CHUNK: {
TRACE_(dmfile)(": comment chunk (ignored)\n");
liMove.QuadPart = Chunk.dwSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
break;
}
default: {
TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
liMove.QuadPart = Chunk.dwSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
break;
}
}
TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
} while (ListCount[0] < ListSize[0]);
break;
}
default: {
TRACE_(dmfile)(": unknown (skipping)\n");
liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
break;
}
}
break;
}
default: {
TRACE_(dmfile)(": unknown chunk (irrevelant & skipping)\n");
liMove.QuadPart = Chunk.dwSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
break;
}
}
TRACE_(dmfile)(": StreamCount[0] = %ld < StreamSize[0] = %ld\n", StreamCount, StreamSize);
} while (StreamCount < StreamSize);
break;
} else {
TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
liMove.QuadPart = StreamSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
return E_FAIL;
}
TRACE_(dmfile)(": reading finished\n");
break;
}
default: {
TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
liMove.QuadPart = Chunk.dwSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
return DMUS_E_INVALIDFILE;
}
}
TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc));
return S_OK;
}
ICOM_VTABLE(IDirectMusicObject) DirectMusicBand_Object_Vtbl = {
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
IDirectMusicBandImpl_IDirectMusicObject_QueryInterface,
IDirectMusicBandImpl_IDirectMusicObject_AddRef,
IDirectMusicBandImpl_IDirectMusicObject_Release,
IDirectMusicBandImpl_IDirectMusicObject_GetDescriptor,
IDirectMusicBandImpl_IDirectMusicObject_SetDescriptor,
IDirectMusicBandImpl_IDirectMusicObject_ParseDescriptor
};
/* IDirectMusicBandImpl IPersistStream part: */
HRESULT WINAPI IDirectMusicBandImpl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);
return IDirectMusicBandImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
}
2003-10-28 22:08:55 +01:00
ULONG WINAPI IDirectMusicBandImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);
return IDirectMusicBandImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
}
ULONG WINAPI IDirectMusicBandImpl_IPersistStream_Release (LPPERSISTSTREAM iface) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);
return IDirectMusicBandImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
}
HRESULT WINAPI IDirectMusicBandImpl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
return E_NOTIMPL;
}
HRESULT WINAPI IDirectMusicBandImpl_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
return E_NOTIMPL;
}
HRESULT WINAPI IDirectMusicBandImpl_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface);
FIXME("(%p,%p): loading not implemented yet\n", This, pStm);
return S_OK;
}
HRESULT WINAPI IDirectMusicBandImpl_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
return E_NOTIMPL;
}
HRESULT WINAPI IDirectMusicBandImpl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
return E_NOTIMPL;
}
ICOM_VTABLE(IPersistStream) DirectMusicBand_PersistStream_Vtbl = {
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
IDirectMusicBandImpl_IPersistStream_QueryInterface,
IDirectMusicBandImpl_IPersistStream_AddRef,
IDirectMusicBandImpl_IPersistStream_Release,
IDirectMusicBandImpl_IPersistStream_GetClassID,
IDirectMusicBandImpl_IPersistStream_IsDirty,
IDirectMusicBandImpl_IPersistStream_Load,
IDirectMusicBandImpl_IPersistStream_Save,
IDirectMusicBandImpl_IPersistStream_GetSizeMax
};
/* for ClassFactory */
HRESULT WINAPI DMUSIC_CreateDirectMusicBandImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
IDirectMusicBandImpl* obj;
obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicBandImpl));
if (NULL == obj) {
*ppobj = (LPVOID) NULL;
return E_OUTOFMEMORY;
}
obj->UnknownVtbl = &DirectMusicBand_Unknown_Vtbl;
obj->BandVtbl = &DirectMusicBand_Band_Vtbl;
obj->ObjectVtbl = &DirectMusicBand_Object_Vtbl;
obj->PersistStreamVtbl = &DirectMusicBand_PersistStream_Vtbl;
obj->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
DM_STRUCT_INIT(obj->pDesc);
obj->pDesc->dwValidData |= DMUS_OBJ_CLASS;
memcpy (&obj->pDesc->guidClass, &CLSID_DirectMusicBand, sizeof (CLSID));
obj->ref = 0; /* will be inited by QueryInterface */
list_init (&obj->Instruments);
return IDirectMusicBandImpl_IUnknown_QueryInterface ((LPUNKNOWN)&obj->UnknownVtbl, lpcGUID, ppobj);
}