commandtrack.c 13.5 KB
Newer Older
1 2
/* IDirectMusicCommandTrack Implementation
 *
3
 * Copyright (C) 2003-2004 Rok Mandeljc
4
 *
5 6 7 8
 * 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.
9 10 11
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
14
 *
15 16 17
 * 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
18 19 20
 */

#include "dmstyle_private.h"
21
#include "dmobject.h"
22 23 24 25 26 27 28

WINE_DEFAULT_DEBUG_CHANNEL(dmstyle);
WINE_DECLARE_DEBUG_CHANNEL(dmfile);

/*****************************************************************************
 * IDirectMusicCommandTrack implementation
 */
29
typedef struct IDirectMusicCommandTrack {
30
    IDirectMusicTrack8 IDirectMusicTrack8_iface;
31
    struct dmobject dmobj;  /* IPersistStream only */
32 33 34 35
    LONG ref;
    struct list Commands;
} IDirectMusicCommandTrack;

36
/* IDirectMusicCommandTrack IDirectMusicTrack8 part: */
37 38
static inline IDirectMusicCommandTrack *impl_from_IDirectMusicTrack8(IDirectMusicTrack8 *iface)
{
39
    return CONTAINING_RECORD(iface, IDirectMusicCommandTrack, IDirectMusicTrack8_iface);
40 41
}

42
static HRESULT WINAPI IDirectMusicTrack8Impl_QueryInterface(IDirectMusicTrack8 *iface, REFIID riid,
43
        void **ret_iface)
44 45
{
    IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
46 47 48 49 50 51 52 53 54

    TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ret_iface);

    *ret_iface = NULL;

    if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDirectMusicTrack) ||
            IsEqualIID(riid, &IID_IDirectMusicTrack8))
        *ret_iface = iface;
    else if (IsEqualIID(riid, &IID_IPersistStream))
55
        *ret_iface = &This->dmobj.IPersistStream_iface;
56 57 58 59 60 61 62
    else {
        WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ret_iface);
        return E_NOINTERFACE;
    }

    IUnknown_AddRef((IUnknown*)*ret_iface);
    return S_OK;
63
}
64

65 66 67
static ULONG WINAPI IDirectMusicTrack8Impl_AddRef(IDirectMusicTrack8 *iface)
{
    IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
68 69 70 71 72
    LONG ref = InterlockedIncrement(&This->ref);

    TRACE("(%p) ref=%d\n", This, ref);

    return ref;
73 74
}

75 76 77
static ULONG WINAPI IDirectMusicTrack8Impl_Release(IDirectMusicTrack8 *iface)
{
    IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
78 79 80 81 82 83 84 85 86 87
    LONG ref = InterlockedDecrement(&This->ref);

    TRACE("(%p) ref=%d\n", This, ref);

    if (!ref) {
        HeapFree(GetProcessHeap(), 0, This);
        DMSTYLE_UnlockModule();
    }

    return ref;
88 89
}

90 91
static HRESULT WINAPI IDirectMusicTrack8Impl_Init(IDirectMusicTrack8 *iface,
        IDirectMusicSegment *pSegment)
92
{
93
        IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
94 95 96
	FIXME("(%p, %p): stub\n", This, pSegment);
	return S_OK;
}
97

98 99 100
static HRESULT WINAPI IDirectMusicTrack8Impl_InitPlay(IDirectMusicTrack8 *iface,
        IDirectMusicSegmentState *pSegmentState, IDirectMusicPerformance *pPerformance,
        void **ppStateData, DWORD dwVirtualTrack8ID, DWORD dwFlags)
101
{
102
        IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
103
	FIXME("(%p, %p, %p, %p, %d, %d): stub\n", This, pSegmentState, pPerformance, ppStateData, dwVirtualTrack8ID, dwFlags);
104 105 106
	return S_OK;
}

107
static HRESULT WINAPI IDirectMusicTrack8Impl_EndPlay(IDirectMusicTrack8 *iface, void *pStateData)
108
{
109
        IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
110 111 112 113
	FIXME("(%p, %p): stub\n", This, pStateData);
	return S_OK;
}

114 115 116
static HRESULT WINAPI IDirectMusicTrack8Impl_Play(IDirectMusicTrack8 *iface, void *pStateData,
        MUSIC_TIME mtStart, MUSIC_TIME mtEnd, MUSIC_TIME mtOffset, DWORD dwFlags,
        IDirectMusicPerformance *pPerf, IDirectMusicSegmentState *pSegSt, DWORD dwVirtualID)
117
{
118
        IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
119
	FIXME("(%p, %p, %d, %d, %d, %d, %p, %p, %d): stub\n", This, pStateData, mtStart, mtEnd, mtOffset, dwFlags, pPerf, pSegSt, dwVirtualID);
120 121 122
	return S_OK;
}

123 124 125 126
static HRESULT WINAPI IDirectMusicTrack8Impl_GetParam(IDirectMusicTrack8 *iface, REFGUID rguidType,
        MUSIC_TIME mtTime, MUSIC_TIME *pmtNext, void *pParam)
{
        IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
127
	FIXME("(%p, %s, %d, %p, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pmtNext, pParam);
128 129 130
	return S_OK;
}

131 132 133 134
static HRESULT WINAPI IDirectMusicTrack8Impl_SetParam(IDirectMusicTrack8 *iface, REFGUID rguidType,
        MUSIC_TIME mtTime, void *pParam)
{
        IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
135
	FIXME("(%p, %s, %d, %p): stub\n", This, debugstr_dmguid(rguidType), mtTime, pParam);
136 137 138
	return S_OK;
}

139 140 141 142
static HRESULT WINAPI IDirectMusicTrack8Impl_IsParamSupported(IDirectMusicTrack8 *iface,
        REFGUID rguidType)
{
        IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
143

144
	TRACE("(%p, %s)\n", This, debugstr_dmguid(rguidType));
145 146 147 148

        if (!rguidType)
                return E_POINTER;

149 150 151 152 153
	if (IsEqualGUID (rguidType, &GUID_CommandParam)
		|| IsEqualGUID (rguidType, &GUID_CommandParam2)
		|| IsEqualGUID (rguidType, &GUID_CommandParamNext)) {
		TRACE("param supported\n");
		return S_OK;
154 155
	}
	
156 157 158 159
	TRACE("param unsupported\n");
	return DMUS_E_TYPE_UNSUPPORTED;
}

160 161 162 163
static HRESULT WINAPI IDirectMusicTrack8Impl_AddNotificationType(IDirectMusicTrack8 *iface,
        REFGUID rguidNotificationType)
{
        IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
164
	FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
165 166 167
	return S_OK;
}

168 169 170 171
static HRESULT WINAPI IDirectMusicTrack8Impl_RemoveNotificationType(IDirectMusicTrack8 *iface,
        REFGUID rguidNotificationType)
{
        IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
172
	FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
173 174 175
	return S_OK;
}

176 177 178 179
static HRESULT WINAPI IDirectMusicTrack8Impl_Clone(IDirectMusicTrack8 *iface, MUSIC_TIME mtStart,
        MUSIC_TIME mtEnd, IDirectMusicTrack **ppTrack)
{
        IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
180
	FIXME("(%p, %d, %d, %p): stub\n", This, mtStart, mtEnd, ppTrack);
181 182 183
	return S_OK;
}

184 185 186 187 188
static HRESULT WINAPI IDirectMusicTrack8Impl_PlayEx(IDirectMusicTrack8 *iface, void *pStateData,
        REFERENCE_TIME rtStart, REFERENCE_TIME rtEnd, REFERENCE_TIME rtOffset, DWORD dwFlags,
        IDirectMusicPerformance *pPerf, IDirectMusicSegmentState *pSegSt, DWORD dwVirtualID)
{
        IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
189
	FIXME("(%p, %p, 0x%s, 0x%s, 0x%s, %d, %p, %p, %d): stub\n", This, pStateData, wine_dbgstr_longlong(rtStart),
190
	    wine_dbgstr_longlong(rtEnd), wine_dbgstr_longlong(rtOffset), dwFlags, pPerf, pSegSt, dwVirtualID);
191 192 193
	return S_OK;
}

194 195 196 197 198
static HRESULT WINAPI IDirectMusicTrack8Impl_GetParamEx(IDirectMusicTrack8 *iface,
        REFGUID rguidType, REFERENCE_TIME rtTime, REFERENCE_TIME *prtNext, void *pParam,
        void *pStateData, DWORD dwFlags)
{
        IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
199
	FIXME("(%p, %s, 0x%s, %p, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
200
	    wine_dbgstr_longlong(rtTime), prtNext, pParam, pStateData, dwFlags);
201 202 203
	return S_OK;
}

204 205 206 207
static HRESULT WINAPI IDirectMusicTrack8Impl_SetParamEx(IDirectMusicTrack8 *iface,
        REFGUID rguidType, REFERENCE_TIME rtTime, void *pParam, void *pStateData, DWORD dwFlags)
{
        IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
208
	FIXME("(%p, %s, 0x%s, %p, %p, %d): stub\n", This, debugstr_dmguid(rguidType),
209
	    wine_dbgstr_longlong(rtTime), pParam, pStateData, dwFlags);
210 211 212
	return S_OK;
}

213 214 215 216 217 218 219
static HRESULT WINAPI IDirectMusicTrack8Impl_Compose(IDirectMusicTrack8 *iface, IUnknown *context,
        DWORD trackgroup, IDirectMusicTrack **track)
{
    IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);

    TRACE("(%p, %p, %d, %p): method not implemented\n", This, context, trackgroup, track);
    return E_NOTIMPL;
220 221
}

222 223 224 225 226
static HRESULT WINAPI IDirectMusicTrack8Impl_Join(IDirectMusicTrack8 *iface,
        IDirectMusicTrack *pNewTrack, MUSIC_TIME mtJoin, IUnknown *pContext, DWORD dwTrackGroup,
        IDirectMusicTrack **ppResultTrack)
{
        IDirectMusicCommandTrack *This = impl_from_IDirectMusicTrack8(iface);
227
	FIXME("(%p, %p, %d, %p, %d, %p): stub\n", This, pNewTrack, mtJoin, pContext, dwTrackGroup, ppResultTrack);
228 229 230
	return S_OK;
}

231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
static const IDirectMusicTrack8Vtbl dmtrack8_vtbl = {
    IDirectMusicTrack8Impl_QueryInterface,
    IDirectMusicTrack8Impl_AddRef,
    IDirectMusicTrack8Impl_Release,
    IDirectMusicTrack8Impl_Init,
    IDirectMusicTrack8Impl_InitPlay,
    IDirectMusicTrack8Impl_EndPlay,
    IDirectMusicTrack8Impl_Play,
    IDirectMusicTrack8Impl_GetParam,
    IDirectMusicTrack8Impl_SetParam,
    IDirectMusicTrack8Impl_IsParamSupported,
    IDirectMusicTrack8Impl_AddNotificationType,
    IDirectMusicTrack8Impl_RemoveNotificationType,
    IDirectMusicTrack8Impl_Clone,
    IDirectMusicTrack8Impl_PlayEx,
    IDirectMusicTrack8Impl_GetParamEx,
    IDirectMusicTrack8Impl_SetParamEx,
    IDirectMusicTrack8Impl_Compose,
    IDirectMusicTrack8Impl_Join
250 251
};

252 253 254
static inline IDirectMusicCommandTrack *impl_from_IPersistStream(IPersistStream *iface)
{
    return CONTAINING_RECORD(iface, IDirectMusicCommandTrack, dmobj.IPersistStream_iface);
255 256
}

257 258 259
static HRESULT WINAPI IPersistStreamImpl_Load(IPersistStream *iface, IStream *pStm)
{
        IDirectMusicCommandTrack *This = impl_from_IPersistStream(iface);
260
	FOURCC chunkID;
261
	DWORD chunkSize, dwSizeOfStruct, nrCommands;
262 263 264 265
	LARGE_INTEGER liMove; /* used when skipping chunks */
	
	IStream_Read (pStm, &chunkID, sizeof(FOURCC), NULL);
	IStream_Read (pStm, &chunkSize, sizeof(DWORD), NULL);
266
	TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (chunkID), chunkSize);
267 268
	switch (chunkID) {
		case DMUS_FOURCC_COMMANDTRACK_CHUNK: {
269
			DWORD count;
270 271 272
			TRACE_(dmfile)(": command track chunk\n");
			IStream_Read (pStm, &dwSizeOfStruct, sizeof(DWORD), NULL);
			if (dwSizeOfStruct != sizeof(DMUS_IO_COMMAND)) {
273
				TRACE_(dmfile)(": declared size of struct (=%d) != actual size; indicates older direct music version\n", dwSizeOfStruct);
274 275
			}
			chunkSize -= sizeof(DWORD); /* now chunk size is one DWORD shorter */
276
			nrCommands = chunkSize/dwSizeOfStruct; /* and this is the number of commands */
277
			/* load each command separately in new entry */
278
			for (count = 0; count < nrCommands; count++) {
279
				LPDMUS_PRIVATE_COMMAND pNewCommand = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(DMUS_PRIVATE_COMMAND));
280 281
				IStream_Read (pStm, &pNewCommand->pCommand, dwSizeOfStruct, NULL);
				list_add_tail (&This->Commands, &pNewCommand->entry);
282
			}
283
			TRACE_(dmfile)(": reading finished\n");
284
			This->dmobj.desc.dwValidData |= DMUS_OBJ_LOADED;
285 286
			break;
		}	
287 288 289 290 291 292 293
		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;
		}
	}
294 295 296 297 298 299

	/* DEBUG: dumps whole band track object tree: */
	if (TRACE_ON(dmstyle)) {
		int r = 0;
		DMUS_PRIVATE_COMMAND *tmpEntry;
		struct list *listEntry;
300
		TRACE("*** IDirectMusicCommandTrack (%p) ***\n", This);
301 302 303 304
		TRACE(" - Commands:\n");
		LIST_FOR_EACH (listEntry, &This->Commands) {
			tmpEntry = LIST_ENTRY (listEntry, DMUS_PRIVATE_COMMAND, entry);
			TRACE("    - Command[%i]:\n", r);
305
			TRACE("       - mtTime = %i\n", tmpEntry->pCommand.mtTime);
306 307 308 309 310 311 312 313 314 315
			TRACE("       - wMeasure = %d\n", tmpEntry->pCommand.wMeasure);
			TRACE("       - bBeat = %i\n", tmpEntry->pCommand.bBeat);
			TRACE("       - bCommand = %i\n", tmpEntry->pCommand.bCommand);
			TRACE("       - bGrooveLevel = %i\n", tmpEntry->pCommand.bGrooveLevel);
			TRACE("       - bGrooveRange = %i\n", tmpEntry->pCommand.bGrooveRange);
			TRACE("       - bRepeatMode = %i\n", tmpEntry->pCommand.bRepeatMode);			
			r++;
		}
	}

316 317 318
	return S_OK;
}

319 320 321
static HRESULT WINAPI IPersistStreamImpl_Save(IPersistStream *iface, IStream *stream,
        BOOL cleardirty)
{
322 323 324 325 326 327 328 329
    IDirectMusicCommandTrack *This = impl_from_IPersistStream(iface);

    FIXME("(%p, %p, %d): stub\n", This, stream, cleardirty);

    if (!stream)
        return E_POINTER;

    return E_NOTIMPL;
330 331
}

332 333 334 335 336 337 338 339 340
static const IPersistStreamVtbl persiststream_vtbl = {
    dmobj_IPersistStream_QueryInterface,
    dmobj_IPersistStream_AddRef,
    dmobj_IPersistStream_Release,
    dmobj_IPersistStream_GetClassID,
    unimpl_IPersistStream_IsDirty,
    IPersistStreamImpl_Load,
    IPersistStreamImpl_Save,
    unimpl_IPersistStream_GetSizeMax
341
};
342 343

/* for ClassFactory */
344 345
HRESULT WINAPI create_dmcommandtrack(REFIID lpcGUID, void **ppobj)
{
346 347 348 349 350 351 352 353
    IDirectMusicCommandTrack *track;
    HRESULT hr;

    track = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*track));
    if (!track) {
        *ppobj = NULL;
        return E_OUTOFMEMORY;
    }
354
    track->IDirectMusicTrack8_iface.lpVtbl = &dmtrack8_vtbl;
355
    track->ref = 1;
356 357 358
    dmobject_init(&track->dmobj, &CLSID_DirectMusicCommandTrack,
                  (IUnknown *)&track->IDirectMusicTrack8_iface);
    track->dmobj.IPersistStream_iface.lpVtbl = &persiststream_vtbl;
359 360 361 362 363 364
    list_init (&track->Commands);

    DMSTYLE_LockModule();
    hr = IDirectMusicTrack8_QueryInterface(&track->IDirectMusicTrack8_iface,
                                           lpcGUID, ppobj);
    IDirectMusicTrack8_Release(&track->IDirectMusicTrack8_iface);
365

366
    return hr;
367
}