Sweden-Number/dlls/dmstyle/commandtrack.c

388 lines
13 KiB
C

/* IDirectMusicCommandTrack Implementation
*
* Copyright (C) 2003 Rok Mandeljc
*
* 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 "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "wingdi.h"
#include "wine/debug.h"
#include "dmstyle_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmstyle);
WINE_DECLARE_DEBUG_CHANNEL(dmfile);
/*****************************************************************************
* IDirectMusicCommandTrack implementation
*/
/* IDirectMusicCommandTrack IUnknown part: */
HRESULT WINAPI IDirectMusicCommandTrack_QueryInterface (LPDIRECTMUSICTRACK8 iface, REFIID riid, LPVOID *ppobj)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
if (IsEqualIID (riid, &IID_IUnknown) ||
IsEqualIID (riid, &IID_IDirectMusicTrack) ||
IsEqualIID (riid, &IID_IDirectMusicTrack8)) {
IDirectMusicCommandTrack_AddRef(iface);
*ppobj = This;
return S_OK;
} else if (IsEqualIID (riid, &IID_IPersistStream)) {
IDirectMusicCommandTrackStream_AddRef ((LPPERSISTSTREAM)This->pStream);
*ppobj = This->pStream;
return S_OK;
}
WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
return E_NOINTERFACE;
}
ULONG WINAPI IDirectMusicCommandTrack_AddRef (LPDIRECTMUSICTRACK8 iface)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
TRACE("(%p) : AddRef from %ld\n", This, This->ref);
return ++(This->ref);
}
ULONG WINAPI IDirectMusicCommandTrack_Release (LPDIRECTMUSICTRACK8 iface)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
ULONG ref = --This->ref;
TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
return ref;
}
/* IDirectMusicCommandTrack IDirectMusicTrack part: */
HRESULT WINAPI IDirectMusicCommandTrack_Init (LPDIRECTMUSICTRACK8 iface, IDirectMusicSegment* pSegment)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
FIXME("(%p, %p): stub\n", This, pSegment);
return S_OK;
}
HRESULT WINAPI IDirectMusicCommandTrack_InitPlay (LPDIRECTMUSICTRACK8 iface, IDirectMusicSegmentState* pSegmentState, IDirectMusicPerformance* pPerformance, void** ppStateData, DWORD dwVirtualTrack8ID, DWORD dwFlags)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
FIXME("(%p, %p, %p, %p, %ld, %ld): stub\n", This, pSegmentState, pPerformance, ppStateData, dwVirtualTrack8ID, dwFlags);
return S_OK;
}
HRESULT WINAPI IDirectMusicCommandTrack_EndPlay (LPDIRECTMUSICTRACK8 iface, void* pStateData)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
FIXME("(%p, %p): stub\n", This, pStateData);
return S_OK;
}
HRESULT WINAPI IDirectMusicCommandTrack_Play (LPDIRECTMUSICTRACK8 iface, void* pStateData, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, MUSIC_TIME mtOffset, DWORD dwFlags, IDirectMusicPerformance* pPerf, IDirectMusicSegmentState* pSegSt, DWORD dwVirtualID)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
FIXME("(%p, %p, %ld, %ld, %ld, %ld, %p, %p, %ld): stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
return S_OK;
}
HRESULT WINAPI IDirectMusicCommandTrack_GetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
FIXME("(%p, %s, %ld, %p, %p): stub\n", This, debugstr_guid(rguidType), mtTime, pmtNext, pParam);
return S_OK;
}
HRESULT WINAPI IDirectMusicCommandTrack_SetParam (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, MUSIC_TIME mtTime, void* pParam)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
FIXME("(%p, %s, %ld, %p): stub\n", This, debugstr_guid(rguidType), mtTime, pParam);
return S_OK;
}
HRESULT WINAPI IDirectMusicCommandTrack_IsParamSupported (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
TRACE("(%p, %s): ", This, debugstr_guid(rguidType));
if (IsEqualGUID (rguidType, &GUID_CommandParam)
|| IsEqualGUID (rguidType, &GUID_CommandParam2)
|| IsEqualGUID (rguidType, &GUID_CommandParamNext)) {
TRACE("param supported\n");
return S_OK;
}
TRACE("param unsupported\n");
return DMUS_E_TYPE_UNSUPPORTED;
}
HRESULT WINAPI IDirectMusicCommandTrack_AddNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
FIXME("(%p, %s): stub\n", This, debugstr_guid(rguidNotificationType));
return S_OK;
}
HRESULT WINAPI IDirectMusicCommandTrack_RemoveNotificationType (LPDIRECTMUSICTRACK8 iface, REFGUID rguidNotificationType)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
FIXME("(%p, %s): stub\n", This, debugstr_guid(rguidNotificationType));
return S_OK;
}
HRESULT WINAPI IDirectMusicCommandTrack_Clone (LPDIRECTMUSICTRACK8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicTrack** ppTrack)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
FIXME("(%p, %ld, %ld, %p): stub\n", This, mtStart, mtEnd, ppTrack);
return S_OK;
}
/* IDirectMusicCommandTrack IDirectMusicTrack8 part: */
HRESULT WINAPI IDirectMusicCommandTrack_PlayEx (LPDIRECTMUSICTRACK8 iface, void* pStateData, REFERENCE_TIME rtStart, REFERENCE_TIME rtEnd, REFERENCE_TIME rtOffset, DWORD dwFlags, IDirectMusicPerformance* pPerf, IDirectMusicSegmentState* pSegSt, DWORD dwVirtualID)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
FIXME("(%p, %p, %lli, %lli, %lli, %ld, %p, %p, %ld): stub\n", This, pStateData, rtStart, rtEnd, rtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
/* implement code for sending PMsgs */
return S_OK;
}
HRESULT WINAPI IDirectMusicCommandTrack_GetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, REFERENCE_TIME* prtNext, void* pParam, void* pStateData, DWORD dwFlags)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
FIXME("(%p, %s, %lli, %p, %p, %p, %ld): stub\n", This, debugstr_guid(rguidType), rtTime, prtNext, pParam, pStateData, dwFlags);
return S_OK;
}
HRESULT WINAPI IDirectMusicCommandTrack_SetParamEx (LPDIRECTMUSICTRACK8 iface, REFGUID rguidType, REFERENCE_TIME rtTime, void* pParam, void* pStateData, DWORD dwFlags)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
FIXME("(%p, %s, %lli, %p, %p, %ld): stub\n", This, debugstr_guid(rguidType), rtTime, pParam, pStateData, dwFlags);
return S_OK;
}
HRESULT WINAPI IDirectMusicCommandTrack_Compose (LPDIRECTMUSICTRACK8 iface, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
FIXME("(%p, %p, %ld, %p): stub\n", This, pContext, dwTrackGroup, ppResultTrack);
return S_OK;
}
HRESULT WINAPI IDirectMusicCommandTrack_Join (LPDIRECTMUSICTRACK8 iface, IDirectMusicTrack* pNewTrack, MUSIC_TIME mtJoin, IUnknown* pContext, DWORD dwTrackGroup, IDirectMusicTrack** ppResultTrack)
{
ICOM_THIS(IDirectMusicCommandTrack,iface);
FIXME("(%p, %p, %ld, %p, %ld, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
return S_OK;
}
ICOM_VTABLE(IDirectMusicTrack8) DirectMusicCommandTrack_Vtbl =
{
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
IDirectMusicCommandTrack_QueryInterface,
IDirectMusicCommandTrack_AddRef,
IDirectMusicCommandTrack_Release,
IDirectMusicCommandTrack_Init,
IDirectMusicCommandTrack_InitPlay,
IDirectMusicCommandTrack_EndPlay,
IDirectMusicCommandTrack_Play,
IDirectMusicCommandTrack_GetParam,
IDirectMusicCommandTrack_SetParam,
IDirectMusicCommandTrack_IsParamSupported,
IDirectMusicCommandTrack_AddNotificationType,
IDirectMusicCommandTrack_RemoveNotificationType,
IDirectMusicCommandTrack_Clone,
IDirectMusicCommandTrack_PlayEx,
IDirectMusicCommandTrack_GetParamEx,
IDirectMusicCommandTrack_SetParamEx,
IDirectMusicCommandTrack_Compose,
IDirectMusicCommandTrack_Join
};
/* for ClassFactory */
HRESULT WINAPI DMUSIC_CreateDirectMusicCommandTrack (LPCGUID lpcGUID, LPDIRECTMUSICTRACK8 *ppTrack, LPUNKNOWN pUnkOuter)
{
IDirectMusicCommandTrack* track;
if (IsEqualIID (lpcGUID, &IID_IDirectMusicTrack)
|| IsEqualIID (lpcGUID, &IID_IDirectMusicTrack8)) {
track = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicCommandTrack));
if (NULL == track) {
*ppTrack = (LPDIRECTMUSICTRACK8) NULL;
return E_OUTOFMEMORY;
}
track->lpVtbl = &DirectMusicCommandTrack_Vtbl;
track->ref = 1;
track->pStream = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(IDirectMusicCommandTrackStream));
track->pStream->lpVtbl = &DirectMusicCommandTrackStream_Vtbl;
track->pStream->ref = 1;
track->pStream->pParentTrack = track;
*ppTrack = (LPDIRECTMUSICTRACK8) track;
return S_OK;
}
WARN("No interface found\n");
return E_NOINTERFACE;
}
/*****************************************************************************
* IDirectMusicCommandTrackStream implementation
*/
/* IDirectMusicCommandTrackStream IUnknown part follow: */
HRESULT WINAPI IDirectMusicCommandTrackStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj)
{
ICOM_THIS(IDirectMusicCommandTrackStream,iface);
if (IsEqualIID (riid, &IID_IUnknown)
|| IsEqualIID (riid, &IID_IPersistStream)) {
IDirectMusicCommandTrackStream_AddRef(iface);
*ppobj = This;
return S_OK;
}
WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
return E_NOINTERFACE;
}
ULONG WINAPI IDirectMusicCommandTrackStream_AddRef (LPPERSISTSTREAM iface)
{
ICOM_THIS(IDirectMusicCommandTrackStream,iface);
TRACE("(%p) : AddRef from %ld\n", This, This->ref);
return ++(This->ref);
}
ULONG WINAPI IDirectMusicCommandTrackStream_Release (LPPERSISTSTREAM iface)
{
ICOM_THIS(IDirectMusicCommandTrackStream,iface);
ULONG ref = --This->ref;
TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
return ref;
}
/* IDirectMusicCommandTrackStream IPersist part: */
HRESULT WINAPI IDirectMusicCommandTrackStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID)
{
return E_NOTIMPL;
}
/* IDirectMusicCommandTrackStream IPersistStream part: */
HRESULT WINAPI IDirectMusicCommandTrackStream_IsDirty (LPPERSISTSTREAM iface)
{
return E_NOTIMPL;
}
HRESULT WINAPI IDirectMusicCommandTrackStream_Load (LPPERSISTSTREAM iface, IStream* pStm)
{
ICOM_THIS(IDirectMusicCommandTrackStream,iface);
FOURCC chunkID;
DWORD chunkSize, dwSizeOfStruct;
LARGE_INTEGER liMove; /* used when skipping chunks */
IDirectMusicCommandTrack* pTrack = This->pParentTrack; /* that's where we load data to */
IStream_Read (pStm, &chunkID, sizeof(FOURCC), NULL);
IStream_Read (pStm, &chunkSize, sizeof(DWORD), NULL);
TRACE_(dmfile)(": %s chunk (size = %ld)", debugstr_fourcc (chunkID), chunkSize);
switch (chunkID) {
case DMUS_FOURCC_COMMANDTRACK_CHUNK: {
TRACE_(dmfile)(": command track chunk\n");
IStream_Read (pStm, &dwSizeOfStruct, sizeof(DWORD), NULL);
if (dwSizeOfStruct != sizeof(DMUS_IO_COMMAND)) {
TRACE_(dmfile)(": declared size of struct (=%ld) != actual size (=%i); loading failed\n", dwSizeOfStruct, sizeof(DMUS_IO_COMMAND));
liMove.QuadPart = chunkSize - sizeof(DWORD);
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
return E_FAIL;
}
chunkSize -= sizeof(DWORD); /* now chunk size is one DWORD shorter */
pTrack->pCommands = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, chunkSize);
IStream_Read (pStm, pTrack->pCommands, chunkSize, NULL);
pTrack->dwCommands = chunkSize/dwSizeOfStruct;
/* in the end, let's see what we got */
TRACE_(dmfile)(": reading finished\n");
if (TRACE_ON(dmfile)) {
int i;
TRACE_(dmfile)(": (READ): number of commands in track = %ld\n", pTrack->dwCommands);
for (i = 0; i < pTrack->dwCommands; i++) {
TRACE_(dmfile)(": (READ): command[%i]: mtTime = %li; wMeasure = %d; bBeat = %i; bCommand = %i; bGrooveLevel = %i; bGrooveRange = %i; bRepeatMode = %i\n", \
i, pTrack->pCommands[i].mtTime, pTrack->pCommands[i].wMeasure, pTrack->pCommands[i].bBeat, pTrack->pCommands[i].bCommand, \
pTrack->pCommands[i].bGrooveLevel, pTrack->pCommands[i].bGrooveRange, pTrack->pCommands[i].bRepeatMode);
}
}
}
break;
default: {
TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
liMove.QuadPart = chunkSize;
IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
return E_FAIL;
}
}
return S_OK;
}
HRESULT WINAPI IDirectMusicCommandTrackStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty)
{
return E_NOTIMPL;
}
HRESULT WINAPI IDirectMusicCommandTrackStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize)
{
return E_NOTIMPL;
}
ICOM_VTABLE(IPersistStream) DirectMusicCommandTrackStream_Vtbl =
{
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
IDirectMusicCommandTrackStream_QueryInterface,
IDirectMusicCommandTrackStream_AddRef,
IDirectMusicCommandTrackStream_Release,
IDirectMusicCommandTrackStream_GetClassID,
IDirectMusicCommandTrackStream_IsDirty,
IDirectMusicCommandTrackStream_Load,
IDirectMusicCommandTrackStream_Save,
IDirectMusicCommandTrackStream_GetSizeMax
};