dswave.c 31.7 KB
Newer Older
1 2 3 4
/* IDirectMusicWave Implementation
 *
 * Copyright (C) 2003-2004 Rok Mandeljc
 *
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 21 22 23
 */

#include "dswave_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(dswave);
WINE_DECLARE_DEBUG_CHANNEL(dmfile);
24 25 26
										 
/* an interface that is, according to my tests, obtained by loader after loading object; is it acting
   as some sort of bridge between object and loader? */
27
static const GUID IID_IDirectMusicWavePRIVATE = {0x69e934e4,0x97f1,0x4f1d,{0x88,0xe8,0xf2,0xac,0x88,0x67,0x13,0x27}};
28

29 30 31 32 33
static ULONG WINAPI IDirectMusicWaveImpl_IUnknown_AddRef (LPUNKNOWN iface);
static ULONG WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_AddRef (LPDIRECTMUSICSEGMENT8 iface);
static ULONG WINAPI IDirectMusicWaveImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface);
static ULONG WINAPI IDirectMusicWaveImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface);

34 35 36 37
/*****************************************************************************
 * IDirectMusicWaveImpl implementation
 */
/* IDirectMusicWaveImpl IUnknown part: */
38
static HRESULT WINAPI IDirectMusicWaveImpl_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) {
39 40
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, UnknownVtbl, iface);
	
41 42
	TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);

43
	if (IsEqualIID (riid, &IID_IUnknown)) {
44
		*ppobj = &This->UnknownVtbl;
45
		IDirectMusicWaveImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
46 47 48 49
		return S_OK;
	} else if (IsEqualIID (riid, &IID_IDirectMusicSegment)
	|| IsEqualIID (riid, &IID_IDirectMusicSegment2)
	|| IsEqualIID (riid, &IID_IDirectMusicSegment8)) {
50
		*ppobj = &This->SegmentVtbl;
51 52
		IDirectMusicWaveImpl_IDirectMusicSegment8_AddRef ((LPDIRECTMUSICSEGMENT8)&This->SegmentVtbl);
		return S_OK;
53
	} else if (IsEqualIID (riid, &IID_IDirectMusicObject)) {
54
		*ppobj = &This->ObjectVtbl;
55 56 57
		IDirectMusicWaveImpl_IDirectMusicObject_AddRef ((LPDIRECTMUSICOBJECT)&This->ObjectVtbl);		
		return S_OK;
	} else if (IsEqualIID (riid, &IID_IPersistStream)) {
58
		*ppobj = &This->PersistStreamVtbl;
59 60
		IDirectMusicWaveImpl_IPersistStream_AddRef ((LPPERSISTSTREAM)&This->PersistStreamVtbl);		
		return S_OK;
61 62 63
	} else if (IsEqualIID (riid, &IID_IDirectMusicWavePRIVATE)) {
		WARN(": requested private interface, expect crash\n");
		return E_NOINTERFACE;
64 65
	}
	
66
	WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
67 68 69
	return E_NOINTERFACE;
}

70
static ULONG WINAPI IDirectMusicWaveImpl_IUnknown_AddRef (LPUNKNOWN iface) {
71
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, UnknownVtbl, iface);
72 73
	ULONG refCount = InterlockedIncrement(&This->ref);

74
	TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
75

76 77
	DSWAVE_LockModule();

78
	return refCount;
79 80
}

81
static ULONG WINAPI IDirectMusicWaveImpl_IUnknown_Release (LPUNKNOWN iface) {
82
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, UnknownVtbl, iface);
83 84
	ULONG refCount = InterlockedDecrement(&This->ref);

85
	TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
86 87

	if (!refCount) {
88 89
		HeapFree(GetProcessHeap(), 0, This);
	}
90 91 92

	DSWAVE_UnlockModule();
	
93
	return refCount;
94 95
}

96
static const IUnknownVtbl DirectMusicWave_Unknown_Vtbl = {
97 98 99 100 101
	IDirectMusicWaveImpl_IUnknown_QueryInterface,
	IDirectMusicWaveImpl_IUnknown_AddRef,
	IDirectMusicWaveImpl_IUnknown_Release
};

102
/* IDirectMusicSegment8Impl IDirectMusicSegment part: */
103
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_QueryInterface (LPDIRECTMUSICSEGMENT8 iface, REFIID riid, LPVOID *ppobj) {
104 105 106 107
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	return IDirectMusicWaveImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
}

108
static ULONG WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_AddRef (LPDIRECTMUSICSEGMENT8 iface) {
109 110 111 112
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	return IDirectMusicWaveImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
}

113
static ULONG WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_Release (LPDIRECTMUSICSEGMENT8 iface) {
114 115 116 117
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	return IDirectMusicWaveImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
}

118
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_GetLength (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtLength) {
119 120 121 122 123
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	FIXME("(%p, %p): stub\n", This, pmtLength);
	return S_OK;
}

124
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_SetLength (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtLength) {
125
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
126
	FIXME("(%p, %d): stub\n", This, mtLength);
127 128 129
	return S_OK;
}

130
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_GetRepeats (LPDIRECTMUSICSEGMENT8 iface, DWORD* pdwRepeats) { 
131 132 133 134 135
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	FIXME("(%p, %p): stub\n", This, pdwRepeats);
	return S_OK;
}

136
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_SetRepeats (LPDIRECTMUSICSEGMENT8 iface, DWORD dwRepeats) {
137
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
138
	FIXME("(%p, %d): stub\n", This, dwRepeats);
139 140 141
	return S_OK;
}

142
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_GetDefaultResolution (LPDIRECTMUSICSEGMENT8 iface, DWORD* pdwResolution) {
143 144 145 146 147
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	FIXME("(%p, %p): stub\n", This, pdwResolution);
	return S_OK;
}

148
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_SetDefaultResolution (LPDIRECTMUSICSEGMENT8 iface, DWORD dwResolution) {
149
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
150
	FIXME("(%p, %d): stub\n", This, dwResolution);
151 152 153
	return S_OK;
}

154
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_GetTrack (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, IDirectMusicTrack** ppTrack) {
155
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
156
	FIXME("(%p, %s, %d, %d, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, ppTrack);
157 158 159
	return S_OK;
}

160
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_GetTrackGroup (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack, DWORD* pdwGroupBits) {
161 162 163 164 165
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	FIXME("(%p, %p, %p): stub\n", This, pTrack, pdwGroupBits);
	return S_OK;
}

166
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_InsertTrack (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack, DWORD dwGroupBits) {
167
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
168
	FIXME("(%p, %p, %d): stub\n", This, pTrack, dwGroupBits);
169 170 171
	return S_OK;
}

172
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_RemoveTrack (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicTrack* pTrack) {
173 174 175 176 177
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	FIXME("(%p, %p): stub\n", This, pTrack);
	return S_OK;
}

178
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_InitPlay (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicSegmentState** ppSegState, IDirectMusicPerformance* pPerformance, DWORD dwFlags) {
179
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
180
	FIXME("(%p, %p, %p, %d): stub\n", This, ppSegState, pPerformance, dwFlags);
181 182 183
	return S_OK;
}

184
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_GetGraph (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicGraph** ppGraph) {
185 186 187 188 189
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	FIXME("(%p, %p): stub\n", This, ppGraph);
	return S_OK;
}

190
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_SetGraph (LPDIRECTMUSICSEGMENT8 iface, IDirectMusicGraph* pGraph) {
191 192 193 194 195
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	FIXME("(%p, %p): stub\n", This, pGraph);
	return S_OK;
}

196
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_AddNotificationType (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidNotificationType) {
197 198 199 200 201
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
	return S_OK;
}

202
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_RemoveNotificationType (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidNotificationType) {
203 204 205 206 207
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
	return S_OK;
}

208
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_GetParam (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
209
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
210
	FIXME("(%p, %s, %d, %d, %d, %p, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pmtNext, pParam);
211 212 213
	return S_OK;
}

214
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_SetParam (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, void* pParam) {
215
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
216
	FIXME("(%p, %s, %d, %d, %d, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pParam);
217 218 219
	return S_OK;
}

220
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_Clone (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd, IDirectMusicSegment** ppSegment) {
221
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
222
	FIXME("(%p, %d, %d, %p): stub\n", This, mtStart, mtEnd, ppSegment);
223 224 225
	return S_OK;
}

226
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_SetStartPoint (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart) {
227
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
228
	FIXME("(%p, %d): stub\n", This, mtStart);
229 230 231
	return S_OK;
}

232
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_GetStartPoint (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtStart) {
233 234 235 236 237
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	FIXME("(%p, %p): stub\n", This, pmtStart);
	return S_OK;
}

238
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_SetLoopPoints (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtStart, MUSIC_TIME mtEnd) {
239
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
240
	FIXME("(%p, %d, %d): stub\n", This, mtStart, mtEnd);
241 242 243
	return S_OK;
}

244
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_GetLoopPoints (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME* pmtStart, MUSIC_TIME* pmtEnd) {
245 246 247 248 249
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	FIXME("(%p, %p, %p): stub\n", This, pmtStart, pmtEnd);
	return S_OK;
}

250
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_SetPChannelsUsed (LPDIRECTMUSICSEGMENT8 iface, DWORD dwNumPChannels, DWORD* paPChannels) {
251
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
252
	FIXME("(%p, %d, %p): stub\n", This, dwNumPChannels, paPChannels);
253 254 255
	return S_OK;
}

256
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_SetTrackConfig (LPDIRECTMUSICSEGMENT8 iface, REFGUID rguidTrackClassID, DWORD dwGroupBits, DWORD dwIndex, DWORD dwFlagsOn, DWORD dwFlagsOff) {
257
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
258
	FIXME("(%p, %s, %d, %d, %d, %d): stub\n", This, debugstr_dmguid(rguidTrackClassID), dwGroupBits, dwIndex, dwFlagsOn, dwFlagsOff);
259 260 261
	return S_OK;
}

262
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_GetAudioPathConfig (LPDIRECTMUSICSEGMENT8 iface, IUnknown** ppAudioPathConfig){
263 264 265 266 267
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	FIXME("(%p, %p): stub\n", This, ppAudioPathConfig);
	return S_OK;
}

268
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_Compose (LPDIRECTMUSICSEGMENT8 iface, MUSIC_TIME mtTime, IDirectMusicSegment* pFromSegment, IDirectMusicSegment* pToSegment, IDirectMusicSegment** ppComposedSegment) {
269
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
270
	FIXME("(%p, %d, %p, %p, %p): stub\n", This, mtTime, pFromSegment, pToSegment, ppComposedSegment);
271 272 273
	return S_OK;
}

274
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_Download (LPDIRECTMUSICSEGMENT8 iface, IUnknown *pAudioPath) {
275 276 277 278 279
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	FIXME("(%p, %p): stub\n", This, pAudioPath);
	return S_OK;
}

280
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicSegment8_Unload (LPDIRECTMUSICSEGMENT8 iface, IUnknown *pAudioPath) {
281 282 283 284 285
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, SegmentVtbl, iface);
	FIXME("(%p, %p): stub\n", This, pAudioPath);
	return S_OK;
}

286
static const IDirectMusicSegment8Vtbl DirectMusicSegment8_Segment_Vtbl = {
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
	IDirectMusicWaveImpl_IDirectMusicSegment8_QueryInterface,
	IDirectMusicWaveImpl_IDirectMusicSegment8_AddRef,
	IDirectMusicWaveImpl_IDirectMusicSegment8_Release,
	IDirectMusicWaveImpl_IDirectMusicSegment8_GetLength,
	IDirectMusicWaveImpl_IDirectMusicSegment8_SetLength,
	IDirectMusicWaveImpl_IDirectMusicSegment8_GetRepeats,
	IDirectMusicWaveImpl_IDirectMusicSegment8_SetRepeats,
	IDirectMusicWaveImpl_IDirectMusicSegment8_GetDefaultResolution,
	IDirectMusicWaveImpl_IDirectMusicSegment8_SetDefaultResolution,
	IDirectMusicWaveImpl_IDirectMusicSegment8_GetTrack,
	IDirectMusicWaveImpl_IDirectMusicSegment8_GetTrackGroup,
	IDirectMusicWaveImpl_IDirectMusicSegment8_InsertTrack,
	IDirectMusicWaveImpl_IDirectMusicSegment8_RemoveTrack,
	IDirectMusicWaveImpl_IDirectMusicSegment8_InitPlay,
	IDirectMusicWaveImpl_IDirectMusicSegment8_GetGraph,
	IDirectMusicWaveImpl_IDirectMusicSegment8_SetGraph,
	IDirectMusicWaveImpl_IDirectMusicSegment8_AddNotificationType,
	IDirectMusicWaveImpl_IDirectMusicSegment8_RemoveNotificationType,
	IDirectMusicWaveImpl_IDirectMusicSegment8_GetParam,
	IDirectMusicWaveImpl_IDirectMusicSegment8_SetParam,
	IDirectMusicWaveImpl_IDirectMusicSegment8_Clone,
	IDirectMusicWaveImpl_IDirectMusicSegment8_SetStartPoint,
	IDirectMusicWaveImpl_IDirectMusicSegment8_GetStartPoint,
	IDirectMusicWaveImpl_IDirectMusicSegment8_SetLoopPoints,
	IDirectMusicWaveImpl_IDirectMusicSegment8_GetLoopPoints,
	IDirectMusicWaveImpl_IDirectMusicSegment8_SetPChannelsUsed,
	IDirectMusicWaveImpl_IDirectMusicSegment8_SetTrackConfig,
	IDirectMusicWaveImpl_IDirectMusicSegment8_GetAudioPathConfig,
	IDirectMusicWaveImpl_IDirectMusicSegment8_Compose,
	IDirectMusicWaveImpl_IDirectMusicSegment8_Download,
	IDirectMusicWaveImpl_IDirectMusicSegment8_Unload
};

320
/* IDirectMusicWaveImpl IDirectMusicObject part: */
321
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) {
322 323 324 325
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, ObjectVtbl, iface);
	return IDirectMusicWaveImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
}

326
static ULONG WINAPI IDirectMusicWaveImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) {
327 328 329 330
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, ObjectVtbl, iface);
	return IDirectMusicWaveImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
}

331
static ULONG WINAPI IDirectMusicWaveImpl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) {
332 333 334 335
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, ObjectVtbl, iface);
	return IDirectMusicWaveImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
}

336
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
337 338 339 340 341 342 343
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, 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;
}

344
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicObject_SetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
345
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, ObjectVtbl, iface);
346
	TRACE("(%p, %p, %s): setting descriptor:\n", This, pDesc, debugstr_DMUS_OBJECTDESC(pDesc));
347

348 349
	/* According to MSDN, we should copy only given values, not whole struct */	
	if (pDesc->dwValidData & DMUS_OBJ_OBJECT)
350
		This->pDesc->guidObject = pDesc->guidObject;
351
	if (pDesc->dwValidData & DMUS_OBJ_CLASS)
352
		This->pDesc->guidClass = pDesc->guidClass;
353
	if (pDesc->dwValidData & DMUS_OBJ_NAME)
354
		lstrcpynW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
355
	if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
356
		lstrcpynW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
357
	if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
358
		lstrcpynW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
359
	if (pDesc->dwValidData & DMUS_OBJ_VERSION)
360
		This->pDesc->vVersion = pDesc->vVersion;
361
	if (pDesc->dwValidData & DMUS_OBJ_DATE)
362
		This->pDesc->ftDate = pDesc->ftDate;
363
	if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
364 365
		This->pDesc->llMemLength = pDesc->llMemLength;
		memcpy (This->pDesc->pbMemData, pDesc->pbMemData, pDesc->llMemLength);
366 367 368 369 370 371 372 373 374 375 376 377
	}
	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;
}

378
static HRESULT WINAPI IDirectMusicWaveImpl_IDirectMusicObject_ParseDescriptor (LPDIRECTMUSICOBJECT iface, LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc) {
379 380 381 382 383
	DMUS_PRIVATE_CHUNK Chunk;
	DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
	LARGE_INTEGER liMove; /* used when skipping chunks */

	TRACE("(%p, %p)\n", pStream, pDesc);
384

385 386
	/* FIXME: should this be determined from stream? */
	pDesc->dwValidData |= DMUS_OBJ_CLASS;
387 388
	pDesc->guidClass = CLSID_DirectMusicSegment;

389
	IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
390
	TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
391 392 393 394 395 396 397 398 399 400 401
	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 == mmioFOURCC('W','A','V','E')) {
				TRACE_(dmfile)(": wave form\n");
				do {
					IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
					StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
402
					TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
					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;
434
										TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
										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: {
474
												TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
475 476 477 478 479
												liMove.QuadPart = Chunk.dwSize;
												IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
												break;						
											}
										}
480
										TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
481 482 483 484 485 486 487 488 489 490 491 492 493
									} 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: {
494
							TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
495 496 497 498 499
							liMove.QuadPart = Chunk.dwSize;
							IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
							break;						
						}
					}
500
					TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
				} while (StreamCount < StreamSize);
			} 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;
		}
	}	
	
520
	TRACE(": returning descriptor: %s\n", debugstr_DMUS_OBJECTDESC (pDesc));
521 522 523 524
	
	return S_OK;	
}

525
static const IDirectMusicObjectVtbl DirectMusicWave_Object_Vtbl = {
526 527 528 529 530 531 532 533 534
	IDirectMusicWaveImpl_IDirectMusicObject_QueryInterface,
	IDirectMusicWaveImpl_IDirectMusicObject_AddRef,
	IDirectMusicWaveImpl_IDirectMusicObject_Release,
	IDirectMusicWaveImpl_IDirectMusicObject_GetDescriptor,
	IDirectMusicWaveImpl_IDirectMusicObject_SetDescriptor,
	IDirectMusicWaveImpl_IDirectMusicObject_ParseDescriptor
};

/* IDirectMusicWaveImpl IPersistStream part: */
535
static HRESULT WINAPI IDirectMusicWaveImpl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
536 537 538 539
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, PersistStreamVtbl, iface);
	return IDirectMusicWaveImpl_IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
}

540
static ULONG WINAPI IDirectMusicWaveImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
541 542 543 544
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, PersistStreamVtbl, iface);
	return IDirectMusicWaveImpl_IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl);
}

545
static ULONG WINAPI IDirectMusicWaveImpl_IPersistStream_Release (LPPERSISTSTREAM iface) {
546 547 548 549
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, PersistStreamVtbl, iface);
	return IDirectMusicWaveImpl_IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl);
}

550
static HRESULT WINAPI IDirectMusicWaveImpl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
551 552 553
	return E_NOTIMPL;
}

554
static HRESULT WINAPI IDirectMusicWaveImpl_IPersistStream_IsDirty (LPPERSISTSTREAM iface) {
555 556 557
	return E_NOTIMPL;
}

558
static HRESULT WINAPI IDirectMusicWaveImpl_IPersistStream_Load (LPPERSISTSTREAM iface, IStream* pStm) {
559
	ICOM_THIS_MULTI(IDirectMusicWaveImpl, PersistStreamVtbl, iface);
560 561 562 563 564 565
	
	DMUS_PRIVATE_CHUNK Chunk;
	DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
	LARGE_INTEGER liMove; /* used when skipping chunks */

	FIXME("(%p, %p): loading not implemented yet (only descriptor is loaded)\n", This, pStm);
566

567 568
	/* FIXME: should this be determined from stream? */
	This->pDesc->dwValidData |= DMUS_OBJ_CLASS;
569 570
	This->pDesc->guidClass = CLSID_DirectMusicSegment;

571
	IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
572
	TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
573 574 575 576 577 578 579 580 581 582 583
	switch (Chunk.fccID) {	
		case FOURCC_RIFF: {
			IStream_Read (pStm, &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 == mmioFOURCC('W','A','V','E')) {
				TRACE_(dmfile)(": wave form\n");
				do {
					IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
					StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
584
					TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
					switch (Chunk.fccID) {
						case DMUS_FOURCC_GUID_CHUNK: {
							TRACE_(dmfile)(": GUID chunk\n");
							This->pDesc->dwValidData |= DMUS_OBJ_OBJECT;
							IStream_Read (pStm, &This->pDesc->guidObject, Chunk.dwSize, NULL);
							break;
						}
						case DMUS_FOURCC_VERSION_CHUNK: {
							TRACE_(dmfile)(": version chunk\n");
							This->pDesc->dwValidData |= DMUS_OBJ_VERSION;
							IStream_Read (pStm, &This->pDesc->vVersion, Chunk.dwSize, NULL);
							break;
						}
						case DMUS_FOURCC_CATEGORY_CHUNK: {
							TRACE_(dmfile)(": category chunk\n");
							This->pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
							IStream_Read (pStm, This->pDesc->wszCategory, Chunk.dwSize, NULL);
							break;
						}
						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) {
								/* evil M$ UNFO list, which can (!?) contain INFO elements */
								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;
616
										TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
										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");
												This->pDesc->dwValidData |= DMUS_OBJ_NAME;
												IStream_Read (pStm, This->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 (pStm, 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 (pStm, 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 (pStm, 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 (pStm, liMove, STREAM_SEEK_CUR, NULL);
												break;
											}
											default: {
656
												TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
657 658 659 660 661
												liMove.QuadPart = Chunk.dwSize;
												IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
												break;						
											}
										}
662
										TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
663 664 665 666 667 668 669 670 671 672 673 674 675
									} while (ListCount[0] < ListSize[0]);
									break;
								}
								default: {
									TRACE_(dmfile)(": unknown (skipping)\n");
									liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
									IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
									break;						
								}
							}
							break;
						}	
						default: {
676
							TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
677 678 679 680 681
							liMove.QuadPart = Chunk.dwSize;
							IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
							break;						
						}
					}
682
					TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
				} while (StreamCount < StreamSize);
			} else {
				TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
				liMove.QuadPart = StreamSize;
				IStream_Seek (pStm, 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 (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
			return DMUS_E_INVALIDFILE;
		}
	}
	
702 703 704
	return S_OK;
}

705
static HRESULT WINAPI IDirectMusicWaveImpl_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty) {
706 707 708
	return E_NOTIMPL;
}

709
static HRESULT WINAPI IDirectMusicWaveImpl_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize) {
710 711 712
	return E_NOTIMPL;
}

713
static const IPersistStreamVtbl DirectMusicWave_PersistStream_Vtbl = {
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
	IDirectMusicWaveImpl_IPersistStream_QueryInterface,
	IDirectMusicWaveImpl_IPersistStream_AddRef,
	IDirectMusicWaveImpl_IPersistStream_Release,
	IDirectMusicWaveImpl_IPersistStream_GetClassID,
	IDirectMusicWaveImpl_IPersistStream_IsDirty,
	IDirectMusicWaveImpl_IPersistStream_Load,
	IDirectMusicWaveImpl_IPersistStream_Save,
	IDirectMusicWaveImpl_IPersistStream_GetSizeMax
};


/* for ClassFactory */
HRESULT WINAPI DMUSIC_CreateDirectMusicWaveImpl (LPCGUID lpcGUID, LPVOID* ppobj, LPUNKNOWN pUnkOuter) {
	IDirectMusicWaveImpl* obj;
	
	obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicWaveImpl));
	if (NULL == obj) {
731
		*ppobj = NULL;
732 733 734
		return E_OUTOFMEMORY;
	}
	obj->UnknownVtbl = &DirectMusicWave_Unknown_Vtbl;
735
	obj->SegmentVtbl = &DirectMusicSegment8_Segment_Vtbl;
736 737 738 739 740
	obj->ObjectVtbl = &DirectMusicWave_Object_Vtbl;
	obj->PersistStreamVtbl = &DirectMusicWave_PersistStream_Vtbl;
	obj->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
	DM_STRUCT_INIT(obj->pDesc);
	obj->pDesc->dwValidData |= DMUS_OBJ_CLASS;
741
	obj->pDesc->guidClass = CLSID_DirectMusicSegment; /* shown by tests */
742
	obj->ref = 0; /* will be inited by QueryInterface */
743

744 745
	return IDirectMusicWaveImpl_IUnknown_QueryInterface ((LPUNKNOWN)&obj->UnknownVtbl, lpcGUID, ppobj);
}