2003-07-22 00:10:14 +02:00
|
|
|
/* IDirectMusicInstrument 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 "dmusic_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
|
|
|
|
|
2005-06-01 21:57:42 +02:00
|
|
|
static const GUID IID_IDirectMusicInstrumentPRIVATE = {0xbcb20080,0xa40c,0x11d1,{0x86,0xbc,0x00,0xc0,0x4f,0xbf,0x8f,0xef}};
|
2003-07-22 00:10:14 +02:00
|
|
|
|
2006-06-10 11:57:22 +02:00
|
|
|
static ULONG WINAPI IDirectMusicInstrumentImpl_IUnknown_AddRef (LPUNKNOWN iface);
|
|
|
|
static ULONG WINAPI IDirectMusicInstrumentImpl_IDirectMusicInstrument_AddRef (LPDIRECTMUSICINSTRUMENT iface);
|
|
|
|
|
2004-01-20 01:21:40 +01:00
|
|
|
/* IDirectMusicInstrument IUnknown part: */
|
2006-06-10 11:57:22 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicInstrumentImpl_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
|
2004-01-20 01:21:40 +01:00
|
|
|
ICOM_THIS_MULTI(IDirectMusicInstrumentImpl, UnknownVtbl, iface);
|
2004-02-25 02:30:03 +01:00
|
|
|
TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
|
2004-01-20 01:21:40 +01:00
|
|
|
|
|
|
|
if (IsEqualIID (riid, &IID_IUnknown)) {
|
2009-01-13 10:57:20 +01:00
|
|
|
*ppobj = &This->UnknownVtbl;
|
2004-01-20 01:21:40 +01:00
|
|
|
IDirectMusicInstrumentImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
|
|
|
|
return S_OK;
|
|
|
|
} else if (IsEqualIID (riid, &IID_IDirectMusicInstrument)) {
|
2009-01-13 10:57:20 +01:00
|
|
|
*ppobj = &This->InstrumentVtbl;
|
2004-01-20 01:21:40 +01:00
|
|
|
IDirectMusicInstrumentImpl_IDirectMusicInstrument_AddRef ((LPDIRECTMUSICINSTRUMENT)&This->InstrumentVtbl);
|
2003-07-22 00:10:14 +02:00
|
|
|
return S_OK;
|
2004-01-20 01:21:40 +01:00
|
|
|
} else if (IsEqualIID (riid, &IID_IDirectMusicInstrumentPRIVATE)) {
|
|
|
|
/* it seems to me that this interface is only basic IUnknown, without any
|
|
|
|
other inherited functions... *sigh* this is the worst scenario, since it means
|
|
|
|
that whoever calls it knows the layout of original implementation table and therefore
|
|
|
|
tries to get data by direct access... expect crashes */
|
|
|
|
FIXME("*sigh*... requested private/unspecified interface\n");
|
2009-01-13 10:57:20 +01:00
|
|
|
*ppobj = &This->UnknownVtbl;
|
2004-01-20 01:21:40 +01:00
|
|
|
IDirectMusicInstrumentImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
|
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
2004-01-20 01:21:40 +01:00
|
|
|
|
2004-02-25 02:30:03 +01:00
|
|
|
WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
|
2003-07-22 00:10:14 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2006-06-10 11:57:22 +02:00
|
|
|
static ULONG WINAPI IDirectMusicInstrumentImpl_IUnknown_AddRef (LPUNKNOWN iface) {
|
2004-01-20 01:21:40 +01:00
|
|
|
ICOM_THIS_MULTI(IDirectMusicInstrumentImpl, UnknownVtbl, iface);
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedIncrement(&This->ref);
|
|
|
|
|
2006-10-12 21:34:50 +02:00
|
|
|
TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
2005-01-26 20:41:43 +01:00
|
|
|
DMUSIC_LockModule();
|
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
return refCount;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:57:22 +02:00
|
|
|
static ULONG WINAPI IDirectMusicInstrumentImpl_IUnknown_Release (LPUNKNOWN iface) {
|
2004-01-20 01:21:40 +01:00
|
|
|
ICOM_THIS_MULTI(IDirectMusicInstrumentImpl, UnknownVtbl, iface);
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->ref);
|
|
|
|
|
2006-10-12 21:34:50 +02:00
|
|
|
TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
|
|
|
if (!refCount) {
|
2003-07-22 00:10:14 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
2005-01-26 20:41:43 +01:00
|
|
|
|
|
|
|
DMUSIC_UnlockModule();
|
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
return refCount;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2005-06-01 21:57:42 +02:00
|
|
|
static const IUnknownVtbl DirectMusicInstrument_Unknown_Vtbl = {
|
2004-01-20 01:21:40 +01:00
|
|
|
IDirectMusicInstrumentImpl_IUnknown_QueryInterface,
|
|
|
|
IDirectMusicInstrumentImpl_IUnknown_AddRef,
|
|
|
|
IDirectMusicInstrumentImpl_IUnknown_Release
|
|
|
|
};
|
|
|
|
|
|
|
|
/* IDirectMusicInstrumentImpl IDirectMusicInstrument part: */
|
2006-06-10 11:57:22 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicInstrumentImpl_IDirectMusicInstrument_QueryInterface (LPDIRECTMUSICINSTRUMENT iface, REFIID riid, LPVOID *ppobj) {
|
2004-01-20 01:21:40 +01:00
|
|
|
ICOM_THIS_MULTI(IDirectMusicInstrumentImpl, InstrumentVtbl, iface);
|
|
|
|
return IDirectMusicInstrumentImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
|
|
|
|
}
|
2003-07-22 00:10:14 +02:00
|
|
|
|
2006-06-10 11:57:22 +02:00
|
|
|
static ULONG WINAPI IDirectMusicInstrumentImpl_IDirectMusicInstrument_AddRef (LPDIRECTMUSICINSTRUMENT iface) {
|
2004-01-20 01:21:40 +01:00
|
|
|
ICOM_THIS_MULTI(IDirectMusicInstrumentImpl, InstrumentVtbl, iface);
|
|
|
|
return IDirectMusicInstrumentImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:57:22 +02:00
|
|
|
static ULONG WINAPI IDirectMusicInstrumentImpl_IDirectMusicInstrument_Release (LPDIRECTMUSICINSTRUMENT iface) {
|
2004-01-20 01:21:40 +01:00
|
|
|
ICOM_THIS_MULTI(IDirectMusicInstrumentImpl, InstrumentVtbl, iface);
|
|
|
|
return IDirectMusicInstrumentImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
|
|
|
|
}
|
2003-07-22 00:10:14 +02:00
|
|
|
|
2006-06-10 11:57:22 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicInstrumentImpl_IDirectMusicInstrument_GetPatch (LPDIRECTMUSICINSTRUMENT iface, DWORD* pdwPatch) {
|
2004-01-20 01:21:40 +01:00
|
|
|
ICOM_THIS_MULTI(IDirectMusicInstrumentImpl, InstrumentVtbl, iface);
|
|
|
|
TRACE("(%p, %p)\n", This, pdwPatch);
|
|
|
|
*pdwPatch = MIDILOCALE2Patch(&This->pHeader->Locale);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2003-07-22 00:10:14 +02:00
|
|
|
|
2006-06-10 11:57:22 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicInstrumentImpl_IDirectMusicInstrument_SetPatch (LPDIRECTMUSICINSTRUMENT iface, DWORD dwPatch) {
|
2004-01-20 01:21:40 +01:00
|
|
|
ICOM_THIS_MULTI(IDirectMusicInstrumentImpl, InstrumentVtbl, iface);
|
2006-10-12 21:34:50 +02:00
|
|
|
TRACE("(%p, %d): stub\n", This, dwPatch);
|
2004-01-20 01:21:40 +01:00
|
|
|
Patch2MIDILOCALE(dwPatch, &This->pHeader->Locale);
|
2003-07-22 00:10:14 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-01 21:57:42 +02:00
|
|
|
static const IDirectMusicInstrumentVtbl DirectMusicInstrument_Instrument_Vtbl = {
|
2004-01-20 01:21:40 +01:00
|
|
|
IDirectMusicInstrumentImpl_IDirectMusicInstrument_QueryInterface,
|
|
|
|
IDirectMusicInstrumentImpl_IDirectMusicInstrument_AddRef,
|
|
|
|
IDirectMusicInstrumentImpl_IDirectMusicInstrument_Release,
|
|
|
|
IDirectMusicInstrumentImpl_IDirectMusicInstrument_GetPatch,
|
|
|
|
IDirectMusicInstrumentImpl_IDirectMusicInstrument_SetPatch
|
2003-07-22 00:10:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* for ClassFactory */
|
2004-01-20 01:21:40 +01:00
|
|
|
HRESULT WINAPI DMUSIC_CreateDirectMusicInstrumentImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
|
|
|
|
IDirectMusicInstrumentImpl* dminst;
|
|
|
|
|
|
|
|
dminst = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicInstrumentImpl));
|
|
|
|
if (NULL == dminst) {
|
2004-12-22 16:13:20 +01:00
|
|
|
*ppobj = NULL;
|
2004-01-20 01:21:40 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
dminst->UnknownVtbl = &DirectMusicInstrument_Unknown_Vtbl;
|
|
|
|
dminst->InstrumentVtbl = &DirectMusicInstrument_Instrument_Vtbl;
|
|
|
|
dminst->ref = 0; /* will be inited by QueryInterface */
|
|
|
|
|
|
|
|
return IDirectMusicInstrumentImpl_IUnknown_QueryInterface ((LPUNKNOWN)&dminst->UnknownVtbl, lpcGUID, ppobj);
|
|
|
|
}
|
|
|
|
|
2012-03-30 15:38:41 +02:00
|
|
|
static HRESULT read_from_stream(IStream *stream, void *data, ULONG size)
|
|
|
|
{
|
|
|
|
ULONG readed;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IStream_Read(stream, data, size, &readed);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
TRACE("IStream_Read failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
if(readed < size){
|
|
|
|
TRACE("Didn't read full chunk: %u < %u\n", readed, size);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline DWORD subtract_bytes(DWORD len, DWORD bytes)
|
|
|
|
{
|
|
|
|
if(bytes > len){
|
|
|
|
TRACE("Apparent mismatch in chunk lengths? %u bytes remaining, %u bytes read\n", len, bytes);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return len - bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT load_instrument(IDirectMusicInstrumentImpl *This, IStream *stream, DWORD length)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
FOURCC fourcc;
|
|
|
|
DWORD bytes;
|
|
|
|
LARGE_INTEGER move;
|
|
|
|
|
|
|
|
while(length){
|
|
|
|
hr = read_from_stream(stream, &fourcc, sizeof(fourcc));
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = read_from_stream(stream, &bytes, sizeof(bytes));
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
length = subtract_bytes(length, sizeof(fourcc) + sizeof(bytes));
|
|
|
|
|
|
|
|
switch(fourcc){
|
|
|
|
case FOURCC_INSH:
|
|
|
|
TRACE("INSH chunk: %u bytes\n", bytes);
|
|
|
|
hr = read_from_stream(stream, This->pHeader, sizeof(*This->pHeader));
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
move.QuadPart = bytes - sizeof(*This->pHeader);
|
|
|
|
hr = IStream_Seek(stream, move, STREAM_SEEK_CUR, NULL);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
WARN("IStream_Seek failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = subtract_bytes(length, bytes);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FOURCC_DLID:
|
|
|
|
TRACE("DLID chunk: %u bytes\n", bytes);
|
|
|
|
hr = read_from_stream(stream, This->pInstrumentID, sizeof(*This->pInstrumentID));
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
move.QuadPart = bytes - sizeof(*This->pInstrumentID);
|
|
|
|
hr = IStream_Seek(stream, move, STREAM_SEEK_CUR, NULL);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
WARN("IStream_Seek failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = subtract_bytes(length, bytes);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
TRACE("Unknown chunk %s: %u bytes\n", debugstr_fourcc(fourcc), bytes);
|
|
|
|
|
|
|
|
move.QuadPart = bytes;
|
|
|
|
hr = IStream_Seek(stream, move, STREAM_SEEK_CUR, NULL);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
WARN("IStream_Seek failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = subtract_bytes(length, bytes);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-20 01:21:40 +01:00
|
|
|
/* aux. function that completely loads instrument; my tests indicate that it's
|
|
|
|
called somewhere around IDirectMusicCollection_GetInstrument */
|
2012-03-30 15:38:41 +02:00
|
|
|
HRESULT WINAPI IDirectMusicInstrumentImpl_Custom_Load (LPDIRECTMUSICINSTRUMENT iface, LPSTREAM stream)
|
|
|
|
{
|
|
|
|
ICOM_THIS_MULTI(IDirectMusicInstrumentImpl, InstrumentVtbl, iface);
|
|
|
|
LARGE_INTEGER move;
|
|
|
|
FOURCC fourcc;
|
|
|
|
DWORD bytes;
|
|
|
|
HRESULT hr;
|
2004-01-20 01:21:40 +01:00
|
|
|
|
2012-03-30 15:38:41 +02:00
|
|
|
TRACE("(%p, %p, offset = %s)\n", This, stream, wine_dbgstr_longlong(This->liInstrumentPosition.QuadPart));
|
2003-08-23 01:53:27 +02:00
|
|
|
|
2012-03-30 15:38:41 +02:00
|
|
|
hr = IStream_Seek(stream, This->liInstrumentPosition, STREAM_SEEK_SET, NULL);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
WARN("IStream_Seek failed: %08x\n", hr);
|
|
|
|
goto load_failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = read_from_stream(stream, &fourcc, sizeof(fourcc));
|
|
|
|
if(FAILED(hr))
|
|
|
|
goto load_failure;
|
|
|
|
|
|
|
|
if(fourcc != FOURCC_LIST){
|
|
|
|
WARN("Loading failed: Expected LIST chunk, got: %s\n", debugstr_fourcc(fourcc));
|
|
|
|
goto load_failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = read_from_stream(stream, &bytes, sizeof(bytes));
|
|
|
|
if(FAILED(hr))
|
|
|
|
goto load_failure;
|
|
|
|
|
|
|
|
TRACE("LIST chunk: %u bytes\n", bytes);
|
|
|
|
while(1){
|
|
|
|
hr = read_from_stream(stream, &fourcc, sizeof(fourcc));
|
|
|
|
if(FAILED(hr))
|
|
|
|
goto load_failure;
|
|
|
|
|
|
|
|
switch(fourcc){
|
|
|
|
case FOURCC_INS:
|
|
|
|
TRACE("INS chunk: (no byte count)\n");
|
|
|
|
hr = load_instrument(This, stream, bytes - sizeof(FOURCC));
|
|
|
|
if(FAILED(hr))
|
|
|
|
goto load_failure;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
hr = read_from_stream(stream, &bytes, sizeof(bytes));
|
|
|
|
if(FAILED(hr))
|
|
|
|
goto load_failure;
|
|
|
|
|
|
|
|
TRACE("Unknown chunk %s: %u bytes\n", debugstr_fourcc(fourcc), bytes);
|
|
|
|
|
|
|
|
move.QuadPart = bytes;
|
|
|
|
hr = IStream_Seek(stream, move, STREAM_SEEK_CUR, NULL);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
WARN("IStream_Seek failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
load_failure:
|
|
|
|
return DMUS_E_UNSUPPORTED_STREAM;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|