Use Interlocked* functions in AddRef and Release.
[wine.git] / dlls / dmime / performance.c
blob2a7bbc274cd7c8a5db1a00696714fe150e329ef4
1 /* IDirectMusicPerformance Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
4 * Copyright (C) 2003-2004 Raphael Junqueira
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Library General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "dmime_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
25 typedef struct DMUS_PMSGItem DMUS_PMSGItem;
26 struct DMUS_PMSGItem {
27 DMUS_PMSGItem* next;
28 DMUS_PMSGItem* prev;
30 REFERENCE_TIME rtItemTime;
31 BOOL bInUse;
32 DWORD cb;
33 DMUS_PMSG pMsg;
36 #define DMUS_PMSGToItem(pMSG) ((DMUS_PMSGItem*) (((unsigned char*) pPMSG) - offsetof(DMUS_PMSGItem, pMsg)))
37 #define DMUS_ItemToPMSG(pItem) (&(pItem->pMsg))
38 #define DMUS_ItemRemoveFromQueue(This,pItem) \
40 if (pItem->prev) pItem->prev->next = pItem->next;\
41 if (pItem->next) pItem->next->prev = pItem->prev;\
42 if (This->head == pItem) This->head = pItem->next;\
43 if (This->imm_head == pItem) This->imm_head = pItem->next;\
44 pItem->bInUse = FALSE;\
47 #define PROCESSMSG_START (WM_APP + 0)
48 #define PROCESSMSG_EXIT (WM_APP + 1)
49 #define PROCESSMSG_REMOVE (WM_APP + 2)
50 #define PROCESSMSG_ADD (WM_APP + 4)
53 static DMUS_PMSGItem* ProceedMsg(IDirectMusicPerformance8Impl* This, DMUS_PMSGItem* cur) {
54 if (cur->pMsg.dwType == DMUS_PMSGT_NOTIFICATION) {
55 SetEvent(This->hNotification);
57 DMUS_ItemRemoveFromQueue(This, cur);
58 switch (cur->pMsg.dwType) {
59 case DMUS_PMSGT_WAVE:
60 case DMUS_PMSGT_TEMPO:
61 case DMUS_PMSGT_STOP:
62 default:
63 FIXME("Unhandled PMsg Type: 0x%lx\n", cur->pMsg.dwType);
64 break;
66 return cur;
69 static DWORD WINAPI ProcessMsgThread(LPVOID lpParam) {
70 IDirectMusicPerformance8Impl* This = (IDirectMusicPerformance8Impl*) lpParam;
71 DWORD timeOut = INFINITE;
72 MSG msg;
73 HRESULT hr;
74 REFERENCE_TIME rtLastTime;
75 REFERENCE_TIME rtCurTime;
76 DMUS_PMSGItem* it = NULL;
77 DMUS_PMSGItem* cur = NULL;
78 DMUS_PMSGItem* it_next = NULL;
80 while (TRUE) {
81 DWORD dwDec = This->rtLatencyTime + This->dwBumperLength;
83 if (timeOut > 0) MsgWaitForMultipleObjects(0, NULL, FALSE, timeOut, QS_POSTMESSAGE|QS_SENDMESSAGE|QS_TIMER);
84 timeOut = INFINITE;
86 EnterCriticalSection(&This->safe);
87 rtLastTime = rtCurTime;
88 hr = IDirectMusicPerformance8Impl_GetTime((IDirectMusicPerformance8*) This, &rtCurTime, NULL);
89 if (FAILED(hr)) {
90 goto outrefresh;
93 for (it = This->imm_head; NULL != it; ) {
94 it_next = it->next;
95 cur = ProceedMsg(This, it);
96 if (NULL != cur) {
97 HeapFree(GetProcessHeap(), 0, cur);
99 it = it_next;
102 for (it = This->head; NULL != it && it->rtItemTime < rtCurTime + dwDec; ) {
103 it_next = it->next;
104 cur = ProceedMsg(This, it);
105 if (NULL != cur) {
106 HeapFree(GetProcessHeap(), 0, cur);
108 it = it_next;
110 if (NULL != it) {
111 timeOut = ( it->rtItemTime - rtCurTime ) + This->rtLatencyTime;
114 outrefresh:
115 LeaveCriticalSection(&This->safe);
117 while (TRUE == PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) {
118 /** if hwnd we suppose that is a windows event ... */
119 if (NULL != msg.hwnd) {
120 TranslateMessage(&msg);
121 DispatchMessageA(&msg);
122 } else {
123 switch (msg.message) {
124 case WM_QUIT:
125 case PROCESSMSG_EXIT:
126 goto outofthread;
127 break;
128 case PROCESSMSG_START:
129 break;
130 case PROCESSMSG_ADD:
131 break;
132 case PROCESSMSG_REMOVE:
133 break;
134 default:
135 ERR("Unhandled message %u. Critical Path\n", msg.message);
136 break;
141 /** here we should run a little of current AudioPath */
145 outofthread:
146 TRACE("(%p): Exiting\n", This);
148 return 0;
151 static BOOL PostMessageToProcessMsgThread(IDirectMusicPerformance8Impl* This, UINT iMsg) {
152 if (FALSE == This->procThreadTicStarted && PROCESSMSG_EXIT != iMsg) {
153 This->procThread = CreateThread(NULL, 0, ProcessMsgThread, This, 0, &This->procThreadId);
154 if (NULL == This->procThread) return FALSE;
155 SetThreadPriority(This->procThread, THREAD_PRIORITY_TIME_CRITICAL);
156 This->procThreadTicStarted = TRUE;
158 return PostThreadMessageA(This->procThreadId, iMsg, 0, 0);
161 /* IDirectMusicPerformance8 IUnknown part: */
162 HRESULT WINAPI IDirectMusicPerformance8Impl_QueryInterface (LPDIRECTMUSICPERFORMANCE8 iface, REFIID riid, LPVOID *ppobj) {
163 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
164 TRACE("(%p, %s,%p)\n", This, debugstr_dmguid(riid), ppobj);
166 if (IsEqualIID (riid, &IID_IUnknown) ||
167 IsEqualIID (riid, &IID_IDirectMusicPerformance) ||
168 IsEqualIID (riid, &IID_IDirectMusicPerformance8)) {
169 IDirectMusicPerformance8Impl_AddRef(iface);
170 *ppobj = This;
171 return S_OK;
174 WARN("(%p, %s,%p): not found\n", This, debugstr_dmguid(riid), ppobj);
175 return E_NOINTERFACE;
178 ULONG WINAPI IDirectMusicPerformance8Impl_AddRef (LPDIRECTMUSICPERFORMANCE8 iface) {
179 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
180 TRACE("(%p): AddRef from %ld\n", This, This->ref);
181 return ++(This->ref);
184 ULONG WINAPI IDirectMusicPerformance8Impl_Release (LPDIRECTMUSICPERFORMANCE8 iface) {
185 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
186 ULONG ref = --This->ref;
187 TRACE("(%p): ReleaseRef to %ld\n", This, This->ref);
188 if (ref == 0) {
189 DeleteCriticalSection(&This->safe);
190 HeapFree(GetProcessHeap(), 0, This);
192 return ref;
195 /* IDirectMusicPerformanceImpl IDirectMusicPerformance Interface part: */
196 HRESULT WINAPI IDirectMusicPerformance8Impl_Init (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusic** ppDirectMusic, LPDIRECTSOUND pDirectSound, HWND hWnd) {
197 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
199 FIXME("(iface = %p, dmusic = %p, dsound = %p, hwnd = %p)\n", This, ppDirectMusic, pDirectSound, hWnd);
200 if (This->pDirectMusic || This->pDirectSound)
201 return DMUS_E_ALREADY_INITED;
203 if (NULL == hWnd) {
204 hWnd = GetForegroundWindow();
207 if (NULL != pDirectSound) {
208 This->pDirectSound = (IDirectSound*) pDirectSound;
209 IDirectSound_AddRef((LPDIRECTSOUND) This->pDirectSound);
210 } else {
211 DirectSoundCreate8(NULL, (LPDIRECTSOUND8*) &This->pDirectSound, NULL);
212 /**
213 * as seen in msdn
215 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directX/htm/idirectmusicperformance8initaudio.asp
217 if (NULL != hWnd) {
218 IDirectSound8_SetCooperativeLevel(This->pDirectSound, hWnd, DSSCL_PRIORITY);
219 } else {
220 /* how to get the ForeGround window handle ? */
221 /*IDirectSound8_SetCooperativeLevel(This->pDirectSound, hWnd, DSSCL_PRIORITY);*/
223 if (!This->pDirectSound)
224 return DSERR_NODRIVER;
227 if (NULL != ppDirectMusic && NULL != *ppDirectMusic) {
228 /* app creates it's own dmusic object and gives it to performance */
229 This->pDirectMusic = (IDirectMusic8*) *ppDirectMusic;
230 IDirectMusic8_AddRef((LPDIRECTMUSIC8) This->pDirectMusic);
231 } else {
232 /* app allows the performance to initialise itfself and needs a pointer to object*/
233 CoCreateInstance (&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic8, (void**)&This->pDirectMusic);
234 if (ppDirectMusic) {
235 *ppDirectMusic = (LPDIRECTMUSIC) This->pDirectMusic;
236 IDirectMusic8_AddRef((LPDIRECTMUSIC8) *ppDirectMusic);
240 return S_OK;
243 HRESULT WINAPI IDirectMusicPerformance8Impl_PlaySegment (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicSegment* pSegment, DWORD dwFlags, __int64 i64StartTime, IDirectMusicSegmentState** ppSegmentState) {
244 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
245 FIXME("(%p, %p, %ld, %lli, %p): stub\n", This, pSegment, dwFlags, i64StartTime, ppSegmentState);
246 return S_OK;
249 HRESULT WINAPI IDirectMusicPerformance8Impl_Stop (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicSegment* pSegment, IDirectMusicSegmentState* pSegmentState, MUSIC_TIME mtTime, DWORD dwFlags) {
250 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
251 FIXME("(%p, %p, %p, %ld, %ld): stub\n", This, pSegment, pSegmentState, mtTime, dwFlags);
252 return S_OK;
255 HRESULT WINAPI IDirectMusicPerformance8Impl_GetSegmentState (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicSegmentState** ppSegmentState, MUSIC_TIME mtTime) {
256 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
257 FIXME("(%p,%p, %ld): stub\n", This, ppSegmentState, mtTime);
258 return S_OK;
261 HRESULT WINAPI IDirectMusicPerformance8Impl_SetPrepareTime (LPDIRECTMUSICPERFORMANCE8 iface, DWORD dwMilliSeconds) {
262 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
263 TRACE("(%p, %ld)\n", This, dwMilliSeconds);
264 This->dwPrepareTime = dwMilliSeconds;
265 return S_OK;
268 HRESULT WINAPI IDirectMusicPerformance8Impl_GetPrepareTime (LPDIRECTMUSICPERFORMANCE8 iface, DWORD* pdwMilliSeconds) {
269 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
270 TRACE("(%p, %p)\n", This, pdwMilliSeconds);
271 if (NULL == pdwMilliSeconds) {
272 return E_POINTER;
274 *pdwMilliSeconds = This->dwPrepareTime;
275 return S_OK;
278 HRESULT WINAPI IDirectMusicPerformance8Impl_SetBumperLength (LPDIRECTMUSICPERFORMANCE8 iface, DWORD dwMilliSeconds) {
279 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
280 TRACE("(%p, %ld)\n", This, dwMilliSeconds);
281 This->dwBumperLength = dwMilliSeconds;
282 return S_OK;
285 HRESULT WINAPI IDirectMusicPerformance8Impl_GetBumperLength (LPDIRECTMUSICPERFORMANCE8 iface, DWORD* pdwMilliSeconds) {
286 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
287 TRACE("(%p, %p)\n", This, pdwMilliSeconds);
288 if (NULL == pdwMilliSeconds) {
289 return E_POINTER;
291 *pdwMilliSeconds = This->dwBumperLength;
292 return S_OK;
295 HRESULT WINAPI IDirectMusicPerformance8Impl_SendPMsg (LPDIRECTMUSICPERFORMANCE8 iface, DMUS_PMSG* pPMSG) {
296 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
297 DMUS_PMSGItem* pItem = NULL;
298 DMUS_PMSGItem* it = NULL;
299 DMUS_PMSGItem* prev_it = NULL;
300 DMUS_PMSGItem** queue = NULL;
302 FIXME("(%p, %p): stub\n", This, pPMSG);
304 if (NULL == pPMSG) {
305 return E_POINTER;
307 pItem = DMUS_PMSGToItem(pPMSG);
308 if (NULL == pItem) {
309 return E_POINTER;
311 if (TRUE == pItem->bInUse) {
312 return DMUS_E_ALREADY_SENT;
315 /* TODO: Valid Flags */
316 /* TODO: DMUS_PMSGF_MUSICTIME */
317 pItem->rtItemTime = pPMSG->rtTime;
319 if (pPMSG->dwFlags & DMUS_PMSGF_TOOL_IMMEDIATE) {
320 queue = &This->imm_head;
321 } else {
322 queue = &This->head;
325 EnterCriticalSection(&This->safe);
326 for (it = *queue; NULL != it && it->rtItemTime < pItem->rtItemTime; it = it->next) {
327 prev_it = it;
329 if (NULL == prev_it) {
330 pItem->prev = NULL;
331 if (NULL != *queue) pItem->next = (*queue)->next;
332 /*assert( NULL == pItem->next->prev );*/
333 if (NULL != pItem->next) pItem->next->prev = pItem;
334 *queue = pItem;
335 } else {
336 pItem->prev = prev_it;
337 pItem->next = prev_it->next;
338 prev_it->next = pItem;
339 if (NULL != pItem->next) pItem->next->prev = pItem;
341 LeaveCriticalSection(&This->safe);
343 /** now in use, prevent from stupid Frees */
344 pItem->bInUse = TRUE;
345 return S_OK;
348 HRESULT WINAPI IDirectMusicPerformance8Impl_MusicToReferenceTime (LPDIRECTMUSICPERFORMANCE8 iface, MUSIC_TIME mtTime, REFERENCE_TIME* prtTime) {
349 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
350 FIXME("(%p, %ld, %p): stub\n", This, mtTime, prtTime);
351 return S_OK;
354 HRESULT WINAPI IDirectMusicPerformance8Impl_ReferenceToMusicTime (LPDIRECTMUSICPERFORMANCE8 iface, REFERENCE_TIME rtTime, MUSIC_TIME* pmtTime) {
355 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
356 FIXME("(%p, %lli, %p): stub\n", This, rtTime, pmtTime);
357 return S_OK;
360 HRESULT WINAPI IDirectMusicPerformance8Impl_IsPlaying (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicSegment* pSegment, IDirectMusicSegmentState* pSegState) {
361 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
362 FIXME("(%p, %p, %p): stub\n", This, pSegment, pSegState);
363 return S_FALSE;
366 HRESULT WINAPI IDirectMusicPerformance8Impl_GetTime (LPDIRECTMUSICPERFORMANCE8 iface, REFERENCE_TIME* prtNow, MUSIC_TIME* pmtNow) {
367 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
368 HRESULT hr = S_OK;
369 REFERENCE_TIME rtCur = 0;
371 /*TRACE("(%p, %p, %p)\n", This, prtNow, pmtNow); */
372 if (TRUE == This->procThreadTicStarted) {
373 rtCur = ((REFERENCE_TIME) GetTickCount() * 10000) - This->procThreadStartTime;
374 } else {
375 /*return DMUS_E_NO_MASTER_CLOCK;*/
377 if (NULL != prtNow) {
378 *prtNow = rtCur;
380 if (NULL != pmtNow) {
381 hr = IDirectMusicPerformance8_ReferenceToMusicTime(iface, rtCur, pmtNow);
383 return hr;
386 HRESULT WINAPI IDirectMusicPerformance8Impl_AllocPMsg (LPDIRECTMUSICPERFORMANCE8 iface, ULONG cb, DMUS_PMSG** ppPMSG) {
387 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
388 DMUS_PMSGItem* pItem = NULL;
390 FIXME("(%p, %ld, %p): stub\n", This, cb, ppPMSG);
392 if (sizeof(DMUS_PMSG) > cb) {
393 return E_INVALIDARG;
395 if (NULL == ppPMSG) {
396 return E_POINTER;
398 pItem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb - sizeof(DMUS_PMSG) + sizeof(DMUS_PMSGItem));
399 if (NULL == pItem) {
400 return E_OUTOFMEMORY;
402 pItem->pMsg.dwSize = cb;
403 *ppPMSG = DMUS_ItemToPMSG(pItem);
404 return S_OK;
407 HRESULT WINAPI IDirectMusicPerformance8Impl_FreePMsg (LPDIRECTMUSICPERFORMANCE8 iface, DMUS_PMSG* pPMSG) {
408 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
409 DMUS_PMSGItem* pItem = NULL;
411 FIXME("(%p, %p): stub\n", This, pPMSG);
413 if (NULL == pPMSG) {
414 return E_POINTER;
416 pItem = DMUS_PMSGToItem(pPMSG);
417 if (NULL == pItem) {
418 return E_POINTER;
420 if (TRUE == pItem->bInUse) {
421 /** prevent for freeing PMsg in queue (ie to be processed) */
422 return DMUS_E_CANNOT_FREE;
424 /** now we can remove it safely */
425 EnterCriticalSection(&This->safe);
426 DMUS_ItemRemoveFromQueue( This, pItem );
427 LeaveCriticalSection(&This->safe);
429 /** TODO: see if we should Release the pItem->pMsg->punkUser and others Interfaces */
430 HeapFree(GetProcessHeap(), 0, pItem);
431 return S_OK;
434 HRESULT WINAPI IDirectMusicPerformance8Impl_GetGraph (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicGraph** ppGraph) {
435 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
436 FIXME("(%p, %p): to check\n", This, ppGraph);
437 if (NULL != This->pToolGraph) {
438 *ppGraph = (LPDIRECTMUSICGRAPH) This->pToolGraph;
439 IDirectMusicGraph_AddRef((LPDIRECTMUSICGRAPH) *ppGraph);
440 } else {
441 return E_FAIL;
443 return S_OK;
446 HRESULT WINAPI IDirectMusicPerformance8Impl_SetGraph (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicGraph* pGraph) {
447 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
449 FIXME("(%p, %p): to check\n", This, pGraph);
451 if (NULL != This->pToolGraph) {
452 /* Todo clean buffers and tools before */
453 IDirectMusicGraph_Release((LPDIRECTMUSICGRAPH) This->pToolGraph);
455 This->pToolGraph = pGraph;
456 if (NULL != This->pToolGraph) {
457 IDirectMusicGraph_AddRef((LPDIRECTMUSICGRAPH) This->pToolGraph);
459 return S_OK;
462 HRESULT WINAPI IDirectMusicPerformance8Impl_SetNotificationHandle (LPDIRECTMUSICPERFORMANCE8 iface, HANDLE hNotification, REFERENCE_TIME rtMinimum) {
463 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
464 FIXME("(%p, %p, %lli): stub\n", This, hNotification, rtMinimum);
465 This->hNotification = hNotification;
466 if (rtMinimum) This->rtMinimum = rtMinimum;
467 return S_OK;
470 HRESULT WINAPI IDirectMusicPerformance8Impl_GetNotificationPMsg (LPDIRECTMUSICPERFORMANCE8 iface, DMUS_NOTIFICATION_PMSG** ppNotificationPMsg) {
471 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
474 FIXME("(%p, %p): stub\n", This, ppNotificationPMsg);
475 if (NULL == ppNotificationPMsg) {
476 return E_POINTER;
481 return S_FALSE;
482 /*return S_OK;*/
485 HRESULT WINAPI IDirectMusicPerformance8Impl_AddNotificationType (LPDIRECTMUSICPERFORMANCE8 iface, REFGUID rguidNotificationType) {
486 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
487 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
488 return S_OK;
491 HRESULT WINAPI IDirectMusicPerformance8Impl_RemoveNotificationType (LPDIRECTMUSICPERFORMANCE8 iface, REFGUID rguidNotificationType) {
492 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
493 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
494 return S_OK;
497 HRESULT WINAPI IDirectMusicPerformance8Impl_AddPort (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicPort* pPort) {
498 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
499 FIXME("(%p, %p): stub\n", This, pPort);
500 IDirectMusicPort_AddRef (pPort);
501 return S_OK;
504 HRESULT WINAPI IDirectMusicPerformance8Impl_RemovePort (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicPort* pPort) {
505 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
506 FIXME("(%p, %p): stub\n", This, pPort);
507 IDirectMusicPort_Release (pPort);
508 return S_OK;
511 HRESULT WINAPI IDirectMusicPerformance8Impl_AssignPChannelBlock (LPDIRECTMUSICPERFORMANCE8 iface, DWORD dwBlockNum, IDirectMusicPort* pPort, DWORD dwGroup) {
512 int i, j, range /* min value in range */;
513 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
515 FIXME("(%p, %ld, %p, %ld): semi-stub\n", This, dwBlockNum, pPort, dwGroup-1);
516 range = 16 * dwBlockNum;
517 j = 0;
519 for (i = range; i < range+16; i++) {
520 /*TRACE("Setting PChannel[%i] to port %p, group %ld, MIDI port %i\n", i, pPort, dwGroup-1, j); */
521 This->PChannel[i].port = pPort;
522 This->PChannel[i].group = dwGroup - 1; /* first index is always zero */
523 This->PChannel[i].channel = j; /* FIXME: should this be assigned? */
524 j++;
527 return S_OK;
530 HRESULT WINAPI IDirectMusicPerformance8Impl_AssignPChannel (LPDIRECTMUSICPERFORMANCE8 iface, DWORD dwPChannel, IDirectMusicPort* pPort, DWORD dwGroup, DWORD dwMChannel) {
531 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
533 TRACE("(%p, %ld, %p, %ld, %ld)\n", This, dwPChannel, pPort, dwGroup, dwMChannel);
534 This->PChannel[dwPChannel].port = pPort;
535 This->PChannel[dwPChannel].group = dwGroup;
536 This->PChannel[dwPChannel].channel = dwMChannel;
538 return S_OK;
541 HRESULT WINAPI IDirectMusicPerformance8Impl_PChannelInfo (LPDIRECTMUSICPERFORMANCE8 iface, DWORD dwPChannel, IDirectMusicPort** ppPort, DWORD* pdwGroup, DWORD* pdwMChannel) {
542 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
543 FIXME("(%p, %ld, %p, %p, %p): stub\n", This, dwPChannel, ppPort, pdwGroup, pdwMChannel);
544 return S_OK;
547 HRESULT WINAPI IDirectMusicPerformance8Impl_DownloadInstrument (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicInstrument* pInst, DWORD dwPChannel, IDirectMusicDownloadedInstrument** ppDownInst, DMUS_NOTERANGE* pNoteRanges, DWORD dwNumNoteRanges, IDirectMusicPort** ppPort, DWORD* pdwGroup, DWORD* pdwMChannel) {
548 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
549 FIXME("(%p, %p, %ld, %p, %p, %ld, %p, %p, %p): stub\n", This, pInst, dwPChannel, ppDownInst, pNoteRanges, dwNumNoteRanges, ppPort, pdwGroup, pdwMChannel);
550 return S_OK;
553 HRESULT WINAPI IDirectMusicPerformance8Impl_Invalidate (LPDIRECTMUSICPERFORMANCE8 iface, MUSIC_TIME mtTime, DWORD dwFlags) {
554 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
555 FIXME("(%p, %ld, %ld): stub\n", This, mtTime, dwFlags);
556 return S_OK;
559 HRESULT WINAPI IDirectMusicPerformance8Impl_GetParam (LPDIRECTMUSICPERFORMANCE8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
560 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
561 FIXME("(%p, %s, %ld, %ld, %ld, %p, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pmtNext, pParam);
562 return S_OK;
565 HRESULT WINAPI IDirectMusicPerformance8Impl_SetParam (LPDIRECTMUSICPERFORMANCE8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, void* pParam) {
566 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
567 FIXME("(%p, %s, %ld, %ld, %ld, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pParam);
568 return S_OK;
571 HRESULT WINAPI IDirectMusicPerformance8Impl_GetGlobalParam (LPDIRECTMUSICPERFORMANCE8 iface, REFGUID rguidType, void* pParam, DWORD dwSize) {
572 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
574 TRACE("(%p, %s, %p, %ld): stub\n", This, debugstr_dmguid(rguidType), pParam, dwSize);
576 if (IsEqualGUID (rguidType, &GUID_PerfAutoDownload))
577 memcpy(pParam, &This->fAutoDownload, sizeof(&This->fAutoDownload));
578 if (IsEqualGUID (rguidType, &GUID_PerfMasterGrooveLevel))
579 memcpy(pParam, &This->cMasterGrooveLevel, sizeof(&This->cMasterGrooveLevel));
580 if (IsEqualGUID (rguidType, &GUID_PerfMasterTempo))
581 memcpy(pParam, &This->fMasterTempo, sizeof(&This->fMasterTempo));
582 if (IsEqualGUID (rguidType, &GUID_PerfMasterVolume))
583 memcpy(pParam, &This->lMasterVolume, sizeof(&This->lMasterVolume));
585 return S_OK;
588 HRESULT WINAPI IDirectMusicPerformance8Impl_SetGlobalParam (LPDIRECTMUSICPERFORMANCE8 iface, REFGUID rguidType, void* pParam, DWORD dwSize) {
589 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
591 TRACE("(%p, %s, %p, %ld)\n", This, debugstr_dmguid(rguidType), pParam, dwSize);
593 if (IsEqualGUID (rguidType, &GUID_PerfAutoDownload)) {
594 memcpy(&This->fAutoDownload, pParam, dwSize);
595 TRACE("=> AutoDownload set to %d\n", This->fAutoDownload);
597 if (IsEqualGUID (rguidType, &GUID_PerfMasterGrooveLevel)) {
598 memcpy(&This->cMasterGrooveLevel, pParam, dwSize);
599 TRACE("=> MasterGrooveLevel set to %i\n", This->cMasterGrooveLevel);
601 if (IsEqualGUID (rguidType, &GUID_PerfMasterTempo)) {
602 memcpy(&This->fMasterTempo, pParam, dwSize);
603 TRACE("=> MasterTempo set to %f\n", This->fMasterTempo);
605 if (IsEqualGUID (rguidType, &GUID_PerfMasterVolume)) {
606 memcpy(&This->lMasterVolume, pParam, dwSize);
607 TRACE("=> MasterVolume set to %li\n", This->lMasterVolume);
610 return S_OK;
613 HRESULT WINAPI IDirectMusicPerformance8Impl_GetLatencyTime (LPDIRECTMUSICPERFORMANCE8 iface, REFERENCE_TIME* prtTime) {
614 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
615 TRACE("(%p, %p): stub\n", This, prtTime);
616 *prtTime = This->rtLatencyTime;
617 return S_OK;
620 HRESULT WINAPI IDirectMusicPerformance8Impl_GetQueueTime (LPDIRECTMUSICPERFORMANCE8 iface, REFERENCE_TIME* prtTime) {
621 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
622 FIXME("(%p, %p): stub\n", This, prtTime);
623 return S_OK;
626 HRESULT WINAPI IDirectMusicPerformance8Impl_AdjustTime (LPDIRECTMUSICPERFORMANCE8 iface, REFERENCE_TIME rtAmount) {
627 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
628 FIXME("(%p, %lli): stub\n", This, rtAmount);
629 return S_OK;
632 HRESULT WINAPI IDirectMusicPerformance8Impl_CloseDown (LPDIRECTMUSICPERFORMANCE8 iface) {
633 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
634 FIXME("(%p): stub\n", This);
635 if (PostMessageToProcessMsgThread(This, PROCESSMSG_EXIT)) {
636 WaitForSingleObject(This->procThread, INFINITE);
637 This->procThreadTicStarted = FALSE;
638 CloseHandle(This->procThread);
640 if (NULL != This->pDirectSound) {
641 IDirectSound_Release((LPDIRECTSOUND) This->pDirectSound);
642 This->pDirectSound = NULL;
644 if (NULL != This->pDirectMusic) {
645 IDirectMusic8_Release((LPDIRECTMUSIC8) This->pDirectMusic);
646 This->pDirectMusic = NULL;
648 return S_OK;
651 HRESULT WINAPI IDirectMusicPerformance8Impl_GetResolvedTime (LPDIRECTMUSICPERFORMANCE8 iface, REFERENCE_TIME rtTime, REFERENCE_TIME* prtResolved, DWORD dwTimeResolveFlags) {
652 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
653 FIXME("(%p, %lli, %p, %ld): stub\n", This, rtTime, prtResolved, dwTimeResolveFlags);
654 return S_OK;
657 HRESULT WINAPI IDirectMusicPerformance8Impl_MIDIToMusic (LPDIRECTMUSICPERFORMANCE8 iface, BYTE bMIDIValue, DMUS_CHORD_KEY* pChord, BYTE bPlayMode, BYTE bChordLevel, WORD* pwMusicValue) {
658 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
659 FIXME("(%p, %d, %p, %d, %d, %p): stub\n", This, bMIDIValue, pChord, bPlayMode, bChordLevel, pwMusicValue);
660 return S_OK;
663 HRESULT WINAPI IDirectMusicPerformance8Impl_MusicToMIDI (LPDIRECTMUSICPERFORMANCE8 iface, WORD wMusicValue, DMUS_CHORD_KEY* pChord, BYTE bPlayMode, BYTE bChordLevel, BYTE* pbMIDIValue) {
664 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
665 FIXME("(%p, %d, %p, %d, %d, %p): stub\n", This, wMusicValue, pChord, bPlayMode, bChordLevel, pbMIDIValue);
666 return S_OK;
669 HRESULT WINAPI IDirectMusicPerformance8Impl_TimeToRhythm (LPDIRECTMUSICPERFORMANCE8 iface, MUSIC_TIME mtTime, DMUS_TIMESIGNATURE* pTimeSig, WORD* pwMeasure, BYTE* pbBeat, BYTE* pbGrid, short* pnOffset) {
670 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
671 FIXME("(%p, %ld, %p, %p, %p, %p, %p): stub\n", This, mtTime, pTimeSig, pwMeasure, pbBeat, pbGrid, pnOffset);
672 return S_OK;
675 HRESULT WINAPI IDirectMusicPerformance8Impl_RhythmToTime (LPDIRECTMUSICPERFORMANCE8 iface, WORD wMeasure, BYTE bBeat, BYTE bGrid, short nOffset, DMUS_TIMESIGNATURE* pTimeSig, MUSIC_TIME* pmtTime) {
676 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
677 FIXME("(%p, %d, %d, %d, %i, %p, %p): stub\n", This, wMeasure, bBeat, bGrid, nOffset, pTimeSig, pmtTime);
678 return S_OK;
681 /* IDirectMusicPerformance8 Interface part follow: */
682 HRESULT WINAPI IDirectMusicPerformance8Impl_InitAudio (LPDIRECTMUSICPERFORMANCE8 iface,
683 IDirectMusic** ppDirectMusic,
684 IDirectSound** ppDirectSound,
685 HWND hWnd,
686 DWORD dwDefaultPathType,
687 DWORD dwPChannelCount,
688 DWORD dwFlags,
689 DMUS_AUDIOPARAMS* pParams) {
691 IDirectSound* dsound = NULL;
692 HRESULT hr = S_OK;
694 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
695 FIXME("(%p, %p, %p, %p, %lx, %lu, %lx, %p): to check\n", This, ppDirectMusic, ppDirectSound, hWnd, dwDefaultPathType, dwPChannelCount, dwFlags, pParams);
697 if (This->pDirectMusic || This->pDirectSound)
698 return DMUS_E_ALREADY_INITED;
700 if (NULL != ppDirectSound && NULL != *ppDirectSound) {
701 dsound = *ppDirectSound;
702 } else {
703 hr = DirectSoundCreate8 (NULL, (LPDIRECTSOUND8*) &dsound, NULL);
704 FIXME("return dsound(%p,%ld)\n", dsound, hr);
705 if (FAILED(hr) || !dsound)
706 return DSERR_NODRIVER;
707 if (ppDirectSound)
708 *ppDirectSound = dsound;
711 IDirectMusicPerformance8Impl_Init(iface, ppDirectMusic, dsound, hWnd);
713 /* Init increases the ref count of the dsound object. Decremente it if the app don't want a pointer to the object. */
714 if (NULL == ppDirectSound) {
715 IDirectSound_Release(This->pDirectSound);
718 /* as seen in msdn we need params init before audio path creation */
719 if (NULL != pParams) {
720 memcpy(&This->pParams, pParams, sizeof(DMUS_AUDIOPARAMS));
721 } else {
723 * TODO, how can i fill the struct
724 * as seen at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directX/htm/dmusaudioparams.asp
726 memset(&This->pParams, 0, sizeof(DMUS_AUDIOPARAMS));
727 This->pParams.dwSize = sizeof(DMUS_AUDIOPARAMS);
728 This->pParams.fInitNow = FALSE;
729 This->pParams.dwValidData = DMUS_AUDIOPARAMS_FEATURES | DMUS_AUDIOPARAMS_VOICES | DMUS_AUDIOPARAMS_SAMPLERATE | DMUS_AUDIOPARAMS_DEFAULTSYNTH;
730 This->pParams.dwVoices = 64;
731 This->pParams.dwSampleRate = (DWORD) 22.050;
732 This->pParams.dwFeatures = dwFlags;
733 This->pParams.clsidDefaultSynth = CLSID_DirectMusicSynthSink;
735 hr = IDirectMusicPerformance8Impl_CreateStandardAudioPath(iface, dwDefaultPathType, dwPChannelCount, FALSE, (IDirectMusicAudioPath**) &This->pDefaultPath);
737 PostMessageToProcessMsgThread(This, PROCESSMSG_START);
739 return hr;
742 HRESULT WINAPI IDirectMusicPerformance8Impl_PlaySegmentEx (LPDIRECTMUSICPERFORMANCE8 iface, IUnknown* pSource, WCHAR* pwzSegmentName, IUnknown* pTransition, DWORD dwFlags, __int64 i64StartTime, IDirectMusicSegmentState** ppSegmentState, IUnknown* pFrom, IUnknown* pAudioPath) {
743 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
744 FIXME("(%p, %p, %p, %p, %ld, %lli, %p, %p, %p): stub\n", This, pSource, pwzSegmentName, pTransition, dwFlags, i64StartTime, ppSegmentState, pFrom, pAudioPath);
745 return S_OK;
748 HRESULT WINAPI IDirectMusicPerformance8Impl_StopEx (LPDIRECTMUSICPERFORMANCE8 iface, IUnknown* pObjectToStop, __int64 i64StopTime, DWORD dwFlags) {
749 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
750 FIXME("(%p, %p, %lli, %ld): stub\n", This, pObjectToStop, i64StopTime, dwFlags);
751 return S_OK;
754 HRESULT WINAPI IDirectMusicPerformance8Impl_ClonePMsg (LPDIRECTMUSICPERFORMANCE8 iface, DMUS_PMSG* pSourcePMSG, DMUS_PMSG** ppCopyPMSG) {
755 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
756 FIXME("(%p, %p, %p): stub\n", This, pSourcePMSG, ppCopyPMSG);
757 return S_OK;
760 HRESULT WINAPI IDirectMusicPerformance8Impl_CreateAudioPath (LPDIRECTMUSICPERFORMANCE8 iface, IUnknown* pSourceConfig, BOOL fActivate, IDirectMusicAudioPath** ppNewPath) {
761 IDirectMusicAudioPathImpl *default_path;
762 IDirectMusicAudioPath *pPath;
764 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
765 FIXME("(%p, %p, %d, %p): stub\n", This, pSourceConfig, fActivate, ppNewPath);
767 if (NULL == ppNewPath) {
768 return E_POINTER;
771 DMUSIC_CreateDirectMusicAudioPathImpl (&IID_IDirectMusicAudioPath, (LPVOID*)&pPath, NULL);
772 default_path = (IDirectMusicAudioPathImpl*)((char*)(pPath) - offsetof(IDirectMusicAudioPathImpl,AudioPathVtbl));
773 default_path->pPerf = (IDirectMusicPerformance8*) This;
775 /** TODO */
777 *ppNewPath = (LPDIRECTMUSICAUDIOPATH) pPath;
779 return IDirectMusicAudioPathImpl_IDirectMusicAudioPath_Activate(*ppNewPath, fActivate);
783 * see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directX/htm/standardaudiopaths.asp
785 HRESULT WINAPI IDirectMusicPerformance8Impl_CreateStandardAudioPath (LPDIRECTMUSICPERFORMANCE8 iface, DWORD dwType, DWORD dwPChannelCount, BOOL fActivate, IDirectMusicAudioPath** ppNewPath) {
786 IDirectMusicAudioPathImpl *default_path;
787 IDirectMusicAudioPath *pPath;
788 DSBUFFERDESC desc;
789 WAVEFORMATEX format;
790 LPDIRECTSOUNDBUFFER buffer;
791 HRESULT hr = S_OK;
793 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
795 FIXME("(%p)->(%ld, %ld, %d, %p): semi-stub\n", This, dwType, dwPChannelCount, fActivate, ppNewPath);
797 if (NULL == ppNewPath) {
798 return E_POINTER;
801 DMUSIC_CreateDirectMusicAudioPathImpl (&IID_IDirectMusicAudioPath, (LPVOID*)&pPath, NULL);
802 default_path = (IDirectMusicAudioPathImpl*)((char*)(pPath) - offsetof(IDirectMusicAudioPathImpl,AudioPathVtbl));
803 default_path->pPerf = (IDirectMusicPerformance8*) This;
805 /* Secondary buffer description */
806 memset(&format, 0, sizeof(format));
807 format.wFormatTag = WAVE_FORMAT_PCM;
808 format.nChannels = 1;
809 format.nSamplesPerSec = 44000;
810 format.nAvgBytesPerSec = 44000*2;
811 format.nBlockAlign = 2;
812 format.wBitsPerSample = 16;
813 format.cbSize = 0;
815 memset(&desc, 0, sizeof(desc));
816 desc.dwSize = sizeof(desc);
817 desc.dwFlags = DSBCAPS_CTRLFX | DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_GLOBALFOCUS;
818 desc.dwBufferBytes = DSBSIZE_MIN;
819 desc.dwReserved = 0;
820 desc.lpwfxFormat = &format;
821 desc.guid3DAlgorithm = GUID_NULL;
823 switch(dwType) {
824 case DMUS_APATH_DYNAMIC_3D:
825 desc.dwFlags |= DSBCAPS_CTRL3D | DSBCAPS_CTRLFREQUENCY | DSBCAPS_MUTE3DATMAXDISTANCE;
826 break;
827 case DMUS_APATH_DYNAMIC_MONO:
828 desc.dwFlags |= DSBCAPS_CTRLFREQUENCY;
829 break;
830 case DMUS_APATH_SHARED_STEREOPLUSREVERB:
831 /* normally we havet to create 2 buffers (one for music other for reverb)
832 * in this case. See msdn
834 case DMUS_APATH_DYNAMIC_STEREO:
835 desc.dwFlags |= DSBCAPS_CTRLFREQUENCY;
836 format.nChannels = 2;
837 format.nBlockAlign *= 2;
838 format.nAvgBytesPerSec *=2;
839 break;
840 default:
841 HeapFree(GetProcessHeap(), 0, default_path);
842 *ppNewPath = NULL;
843 return E_INVALIDARG;
844 break;
847 /* FIXME: Should we create one secondary buffer for each PChannel? */
848 hr = IDirectSound8_CreateSoundBuffer ((LPDIRECTSOUND8) This->pDirectSound, &desc, &buffer, NULL);
849 if (FAILED(hr)) {
850 HeapFree(GetProcessHeap(), 0, default_path);
851 *ppNewPath = NULL;
852 return DSERR_BUFFERLOST;
854 default_path->pDSBuffer = buffer;
856 /* Update description for creating primary buffer */
857 desc.dwFlags |= DSBCAPS_PRIMARYBUFFER;
858 desc.dwBufferBytes = 0;
859 desc.lpwfxFormat = NULL;
861 hr = IDirectSound8_CreateSoundBuffer ((LPDIRECTSOUND8) This->pDirectSound, &desc, &buffer, NULL);
862 if (FAILED(hr)) {
863 IDirectSoundBuffer_Release(default_path->pDSBuffer);
864 HeapFree(GetProcessHeap(), 0, default_path);
865 *ppNewPath = NULL;
866 return DSERR_BUFFERLOST;
868 default_path->pPrimary = buffer;
870 *ppNewPath = (LPDIRECTMUSICAUDIOPATH) pPath;
872 TRACE(" returning IDirectMusicPerformance interface at %p.\n", *ppNewPath);
874 return IDirectMusicAudioPathImpl_IDirectMusicAudioPath_Activate(*ppNewPath, fActivate);
877 HRESULT WINAPI IDirectMusicPerformance8Impl_SetDefaultAudioPath (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicAudioPath* pAudioPath) {
878 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
880 FIXME("(%p, %p): semi-stub\n", This, pAudioPath);
881 if (NULL != This->pDefaultPath) {
882 IDirectMusicAudioPath_Release((LPDIRECTMUSICAUDIOPATH) This->pDefaultPath);
883 ((IDirectMusicAudioPathImpl*) This->pDefaultPath)->pPerf = NULL;
884 This->pDefaultPath = NULL;
886 This->pDefaultPath = pAudioPath;
887 if (NULL != This->pDefaultPath) {
888 IDirectMusicAudioPath_AddRef((LPDIRECTMUSICAUDIOPATH) This->pDefaultPath);
889 ((IDirectMusicAudioPathImpl*) This->pDefaultPath)->pPerf = (IDirectMusicPerformance8*) This;
892 return S_OK;
895 HRESULT WINAPI IDirectMusicPerformance8Impl_GetDefaultAudioPath (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicAudioPath** ppAudioPath) {
896 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
898 FIXME("(%p, %p): semi-stub (%p)\n", This, ppAudioPath, This->pDefaultPath);
900 if (NULL != This->pDefaultPath) {
901 *ppAudioPath = (LPDIRECTMUSICAUDIOPATH) This->pDefaultPath;
902 IDirectMusicAudioPath_AddRef(*ppAudioPath);
903 } else {
904 *ppAudioPath = NULL;
906 return S_OK;
909 HRESULT WINAPI IDirectMusicPerformance8Impl_GetParamEx (LPDIRECTMUSICPERFORMANCE8 iface, REFGUID rguidType, DWORD dwTrackID, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
910 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
912 FIXME("(%p, %s, %ld, %ld, %ld, %ld, %p, %p): stub\n", This, debugstr_dmguid(rguidType), dwTrackID, dwGroupBits, dwIndex, mtTime, pmtNext, pParam);
914 return S_OK;
917 IDirectMusicPerformance8Vtbl DirectMusicPerformance8_Vtbl = {
918 IDirectMusicPerformance8Impl_QueryInterface,
919 IDirectMusicPerformance8Impl_AddRef,
920 IDirectMusicPerformance8Impl_Release,
921 IDirectMusicPerformance8Impl_Init,
922 IDirectMusicPerformance8Impl_PlaySegment,
923 IDirectMusicPerformance8Impl_Stop,
924 IDirectMusicPerformance8Impl_GetSegmentState,
925 IDirectMusicPerformance8Impl_SetPrepareTime,
926 IDirectMusicPerformance8Impl_GetPrepareTime,
927 IDirectMusicPerformance8Impl_SetBumperLength,
928 IDirectMusicPerformance8Impl_GetBumperLength,
929 IDirectMusicPerformance8Impl_SendPMsg,
930 IDirectMusicPerformance8Impl_MusicToReferenceTime,
931 IDirectMusicPerformance8Impl_ReferenceToMusicTime,
932 IDirectMusicPerformance8Impl_IsPlaying,
933 IDirectMusicPerformance8Impl_GetTime,
934 IDirectMusicPerformance8Impl_AllocPMsg,
935 IDirectMusicPerformance8Impl_FreePMsg,
936 IDirectMusicPerformance8Impl_GetGraph,
937 IDirectMusicPerformance8Impl_SetGraph,
938 IDirectMusicPerformance8Impl_SetNotificationHandle,
939 IDirectMusicPerformance8Impl_GetNotificationPMsg,
940 IDirectMusicPerformance8Impl_AddNotificationType,
941 IDirectMusicPerformance8Impl_RemoveNotificationType,
942 IDirectMusicPerformance8Impl_AddPort,
943 IDirectMusicPerformance8Impl_RemovePort,
944 IDirectMusicPerformance8Impl_AssignPChannelBlock,
945 IDirectMusicPerformance8Impl_AssignPChannel,
946 IDirectMusicPerformance8Impl_PChannelInfo,
947 IDirectMusicPerformance8Impl_DownloadInstrument,
948 IDirectMusicPerformance8Impl_Invalidate,
949 IDirectMusicPerformance8Impl_GetParam,
950 IDirectMusicPerformance8Impl_SetParam,
951 IDirectMusicPerformance8Impl_GetGlobalParam,
952 IDirectMusicPerformance8Impl_SetGlobalParam,
953 IDirectMusicPerformance8Impl_GetLatencyTime,
954 IDirectMusicPerformance8Impl_GetQueueTime,
955 IDirectMusicPerformance8Impl_AdjustTime,
956 IDirectMusicPerformance8Impl_CloseDown,
957 IDirectMusicPerformance8Impl_GetResolvedTime,
958 IDirectMusicPerformance8Impl_MIDIToMusic,
959 IDirectMusicPerformance8Impl_MusicToMIDI,
960 IDirectMusicPerformance8Impl_TimeToRhythm,
961 IDirectMusicPerformance8Impl_RhythmToTime,
962 IDirectMusicPerformance8Impl_InitAudio,
963 IDirectMusicPerformance8Impl_PlaySegmentEx,
964 IDirectMusicPerformance8Impl_StopEx,
965 IDirectMusicPerformance8Impl_ClonePMsg,
966 IDirectMusicPerformance8Impl_CreateAudioPath,
967 IDirectMusicPerformance8Impl_CreateStandardAudioPath,
968 IDirectMusicPerformance8Impl_SetDefaultAudioPath,
969 IDirectMusicPerformance8Impl_GetDefaultAudioPath,
970 IDirectMusicPerformance8Impl_GetParamEx
973 /* for ClassFactory */
974 HRESULT WINAPI DMUSIC_CreateDirectMusicPerformanceImpl (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
975 IDirectMusicPerformance8Impl *obj;
977 TRACE("(%p,%p,%p)\n", lpcGUID, ppobj, pUnkOuter);
979 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicPerformance8Impl));
980 if (NULL == obj) {
981 *ppobj = (LPDIRECTMUSICPERFORMANCE8)NULL;
982 return E_OUTOFMEMORY;
984 obj->lpVtbl = &DirectMusicPerformance8_Vtbl;
985 obj->ref = 0; /* will be inited by QueryInterface */
986 obj->pDirectMusic = NULL;
987 obj->pDirectSound = NULL;
988 obj->pDefaultPath = NULL;
989 InitializeCriticalSection(&obj->safe);
992 * @see http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c/directx/htm/latencyandbumpertime.asp
994 obj->rtLatencyTime = 100; /* 100ms TO FIX */
995 obj->dwBumperLength = 50; /* 50ms default */
996 obj->dwPrepareTime = 1000; /* 1000ms default */
997 return IDirectMusicPerformance8Impl_QueryInterface ((LPDIRECTMUSICPERFORMANCE8)obj, lpcGUID, ppobj);