include: Add event trace flags and guid to evntrace.h.
[wine.git] / dlls / dmime / performance.c
blob38f68db61aa9578e52e56334863ece72a3519722
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
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "dmime_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
25 typedef struct IDirectMusicPerformance8Impl {
26 IDirectMusicPerformance8 IDirectMusicPerformance8_iface;
27 LONG ref;
28 /* IDirectMusicPerformanceImpl fields */
29 IDirectMusic8 *pDirectMusic;
30 IDirectSound *pDirectSound;
31 IDirectMusicGraph *pToolGraph;
32 DMUS_AUDIOPARAMS pParams;
33 /* global parameters */
34 BOOL fAutoDownload;
35 char cMasterGrooveLevel;
36 float fMasterTempo;
37 long lMasterVolume;
38 /* performance channels */
39 DMUSIC_PRIVATE_PCHANNEL PChannel[32];
40 /* IDirectMusicPerformance8Impl fields */
41 IDirectMusicAudioPath *pDefaultPath;
42 HANDLE hNotification;
43 REFERENCE_TIME rtMinimum;
44 REFERENCE_TIME rtLatencyTime;
45 DWORD dwBumperLength;
46 DWORD dwPrepareTime;
47 /** Message Processing */
48 HANDLE procThread;
49 DWORD procThreadId;
50 REFERENCE_TIME procThreadStartTime;
51 BOOL procThreadTicStarted;
52 CRITICAL_SECTION safe;
53 struct DMUS_PMSGItem *head;
54 struct DMUS_PMSGItem *imm_head;
55 } IDirectMusicPerformance8Impl;
57 typedef struct DMUS_PMSGItem DMUS_PMSGItem;
58 struct DMUS_PMSGItem {
59 DMUS_PMSGItem* next;
60 DMUS_PMSGItem* prev;
62 REFERENCE_TIME rtItemTime;
63 BOOL bInUse;
64 DWORD cb;
65 DMUS_PMSG pMsg;
68 #define DMUS_PMSGToItem(pMSG) ((DMUS_PMSGItem*) (((unsigned char*) pPMSG) - offsetof(DMUS_PMSGItem, pMsg)))
69 #define DMUS_ItemToPMSG(pItem) (&(pItem->pMsg))
70 #define DMUS_ItemRemoveFromQueue(This,pItem) \
72 if (pItem->prev) pItem->prev->next = pItem->next;\
73 if (pItem->next) pItem->next->prev = pItem->prev;\
74 if (This->head == pItem) This->head = pItem->next;\
75 if (This->imm_head == pItem) This->imm_head = pItem->next;\
76 pItem->bInUse = FALSE;\
79 #define PROCESSMSG_START (WM_APP + 0)
80 #define PROCESSMSG_EXIT (WM_APP + 1)
81 #define PROCESSMSG_REMOVE (WM_APP + 2)
82 #define PROCESSMSG_ADD (WM_APP + 4)
85 static DMUS_PMSGItem* ProceedMsg(IDirectMusicPerformance8Impl* This, DMUS_PMSGItem* cur) {
86 if (cur->pMsg.dwType == DMUS_PMSGT_NOTIFICATION) {
87 SetEvent(This->hNotification);
89 DMUS_ItemRemoveFromQueue(This, cur);
90 switch (cur->pMsg.dwType) {
91 case DMUS_PMSGT_WAVE:
92 case DMUS_PMSGT_TEMPO:
93 case DMUS_PMSGT_STOP:
94 default:
95 FIXME("Unhandled PMsg Type: 0x%x\n", cur->pMsg.dwType);
96 break;
98 return cur;
101 static DWORD WINAPI ProcessMsgThread(LPVOID lpParam) {
102 IDirectMusicPerformance8Impl* This = lpParam;
103 DWORD timeOut = INFINITE;
104 MSG msg;
105 HRESULT hr;
106 REFERENCE_TIME rtCurTime;
107 DMUS_PMSGItem* it = NULL;
108 DMUS_PMSGItem* cur = NULL;
109 DMUS_PMSGItem* it_next = NULL;
111 while (TRUE) {
112 DWORD dwDec = This->rtLatencyTime + This->dwBumperLength;
114 if (timeOut > 0) MsgWaitForMultipleObjects(0, NULL, FALSE, timeOut, QS_POSTMESSAGE|QS_SENDMESSAGE|QS_TIMER);
115 timeOut = INFINITE;
117 EnterCriticalSection(&This->safe);
118 hr = IDirectMusicPerformance8_GetTime(&This->IDirectMusicPerformance8_iface, &rtCurTime, NULL);
119 if (FAILED(hr)) {
120 goto outrefresh;
123 for (it = This->imm_head; NULL != it; ) {
124 it_next = it->next;
125 cur = ProceedMsg(This, it);
126 HeapFree(GetProcessHeap(), 0, cur);
127 it = it_next;
130 for (it = This->head; NULL != it && it->rtItemTime < rtCurTime + dwDec; ) {
131 it_next = it->next;
132 cur = ProceedMsg(This, it);
133 HeapFree(GetProcessHeap(), 0, cur);
134 it = it_next;
136 if (NULL != it) {
137 timeOut = ( it->rtItemTime - rtCurTime ) + This->rtLatencyTime;
140 outrefresh:
141 LeaveCriticalSection(&This->safe);
143 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) {
144 /** if hwnd we suppose that is a windows event ... */
145 if (NULL != msg.hwnd) {
146 TranslateMessage(&msg);
147 DispatchMessageA(&msg);
148 } else {
149 switch (msg.message) {
150 case WM_QUIT:
151 case PROCESSMSG_EXIT:
152 goto outofthread;
153 case PROCESSMSG_START:
154 break;
155 case PROCESSMSG_ADD:
156 break;
157 case PROCESSMSG_REMOVE:
158 break;
159 default:
160 ERR("Unhandled message %u. Critical Path\n", msg.message);
161 break;
166 /** here we should run a little of current AudioPath */
170 outofthread:
171 TRACE("(%p): Exiting\n", This);
173 return 0;
176 static BOOL PostMessageToProcessMsgThread(IDirectMusicPerformance8Impl* This, UINT iMsg) {
177 if (FALSE == This->procThreadTicStarted && PROCESSMSG_EXIT != iMsg) {
178 BOOL res;
179 This->procThread = CreateThread(NULL, 0, ProcessMsgThread, This, 0, &This->procThreadId);
180 if (NULL == This->procThread) return FALSE;
181 SetThreadPriority(This->procThread, THREAD_PRIORITY_TIME_CRITICAL);
182 This->procThreadTicStarted = TRUE;
183 while(1) {
184 res = PostThreadMessageA(This->procThreadId, iMsg, 0, 0);
185 /* Let the thread creates its message queue (with MsgWaitForMultipleObjects call) by yielding and retrying */
186 if (!res && (GetLastError() == ERROR_INVALID_THREAD_ID))
187 Sleep(0);
188 else
189 break;
191 return res;
193 return PostThreadMessageA(This->procThreadId, iMsg, 0, 0);
196 static inline IDirectMusicPerformance8Impl *impl_from_IDirectMusicPerformance8(IDirectMusicPerformance8 *iface)
198 return CONTAINING_RECORD(iface, IDirectMusicPerformance8Impl, IDirectMusicPerformance8_iface);
201 /* IDirectMusicPerformance8 IUnknown part: */
202 static HRESULT WINAPI IDirectMusicPerformance8Impl_QueryInterface(IDirectMusicPerformance8 *iface,
203 REFIID riid, void **ppv)
205 TRACE("(%p, %s,%p)\n", iface, debugstr_dmguid(riid), ppv);
207 if (IsEqualIID (riid, &IID_IUnknown) ||
208 IsEqualIID (riid, &IID_IDirectMusicPerformance) ||
209 IsEqualIID (riid, &IID_IDirectMusicPerformance2) ||
210 IsEqualIID (riid, &IID_IDirectMusicPerformance8)) {
211 *ppv = iface;
212 IUnknown_AddRef(iface);
213 return S_OK;
216 WARN("(%p, %s,%p): not found\n", iface, debugstr_dmguid(riid), ppv);
217 return E_NOINTERFACE;
220 static ULONG WINAPI IDirectMusicPerformance8Impl_AddRef(IDirectMusicPerformance8 *iface)
222 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
223 ULONG ref = InterlockedIncrement(&This->ref);
225 TRACE("(%p): AddRef from %d\n", This, ref - 1);
227 DMIME_LockModule();
229 return ref;
232 static ULONG WINAPI IDirectMusicPerformance8Impl_Release(IDirectMusicPerformance8 *iface)
234 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
235 ULONG ref = InterlockedDecrement(&This->ref);
237 TRACE("(%p): ReleaseRef to %d\n", This, ref);
239 if (ref == 0) {
240 This->safe.DebugInfo->Spare[0] = 0;
241 DeleteCriticalSection(&This->safe);
242 HeapFree(GetProcessHeap(), 0, This);
245 DMIME_UnlockModule();
247 return ref;
250 /* IDirectMusicPerformanceImpl IDirectMusicPerformance Interface part: */
251 static HRESULT WINAPI IDirectMusicPerformance8Impl_Init(IDirectMusicPerformance8 *iface,
252 IDirectMusic **ppDirectMusic, IDirectSound *pDirectSound, HWND hWnd)
254 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
256 FIXME("(iface = %p, dmusic = %p, dsound = %p, hwnd = %p)\n", This, ppDirectMusic, pDirectSound, hWnd);
257 if (This->pDirectMusic || This->pDirectSound)
258 return DMUS_E_ALREADY_INITED;
260 if (NULL == hWnd) {
261 hWnd = GetForegroundWindow();
264 if (NULL != pDirectSound) {
265 This->pDirectSound = pDirectSound;
266 IDirectSound_AddRef(This->pDirectSound);
267 } else {
268 DirectSoundCreate8(NULL, (LPDIRECTSOUND8*) &This->pDirectSound, NULL);
269 if (!This->pDirectSound) return DSERR_NODRIVER;
271 if (NULL != hWnd) {
272 IDirectSound8_SetCooperativeLevel(This->pDirectSound, hWnd, DSSCL_PRIORITY);
273 } else {
274 /* how to get the ForeGround window handle ? */
275 /*IDirectSound8_SetCooperativeLevel(This->pDirectSound, hWnd, DSSCL_PRIORITY);*/
279 if (NULL != ppDirectMusic && NULL != *ppDirectMusic) {
280 /* app creates its own dmusic object and gives it to performance */
281 This->pDirectMusic = (IDirectMusic8*) *ppDirectMusic;
282 IDirectMusic8_AddRef(This->pDirectMusic);
283 } else {
284 HRESULT hr;
285 /* App enables the performance to initialize itself and needs a pointer to object */
286 hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic8, (void**)&This->pDirectMusic);
287 if (FAILED(hr))
288 return hr;
289 if (ppDirectMusic) {
290 *ppDirectMusic = (LPDIRECTMUSIC)This->pDirectMusic;
291 IDirectMusic8_AddRef((LPDIRECTMUSIC8)*ppDirectMusic);
295 return S_OK;
298 static HRESULT WINAPI IDirectMusicPerformance8Impl_PlaySegment(IDirectMusicPerformance8 *iface,
299 IDirectMusicSegment *pSegment, DWORD dwFlags, __int64 i64StartTime,
300 IDirectMusicSegmentState **ppSegmentState)
302 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
304 FIXME("(%p, %p, %d, 0x%s, %p): stub\n", This, pSegment, dwFlags,
305 wine_dbgstr_longlong(i64StartTime), ppSegmentState);
306 if (ppSegmentState)
307 return create_dmsegmentstate(&IID_IDirectMusicSegmentState,(void**)ppSegmentState);
308 return S_OK;
311 static HRESULT WINAPI IDirectMusicPerformance8Impl_Stop(IDirectMusicPerformance8 *iface,
312 IDirectMusicSegment *pSegment, IDirectMusicSegmentState *pSegmentState, MUSIC_TIME mtTime,
313 DWORD dwFlags)
315 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
317 FIXME("(%p, %p, %p, %d, %d): stub\n", This, pSegment, pSegmentState, mtTime, dwFlags);
318 return S_OK;
321 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetSegmentState(IDirectMusicPerformance8 *iface,
322 IDirectMusicSegmentState **ppSegmentState, MUSIC_TIME mtTime)
324 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
326 FIXME("(%p,%p, %d): stub\n", This, ppSegmentState, mtTime);
327 return S_OK;
330 static HRESULT WINAPI IDirectMusicPerformance8Impl_SetPrepareTime(IDirectMusicPerformance8 *iface,
331 DWORD dwMilliSeconds)
333 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
335 TRACE("(%p, %d)\n", This, dwMilliSeconds);
336 This->dwPrepareTime = dwMilliSeconds;
337 return S_OK;
340 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetPrepareTime(IDirectMusicPerformance8 *iface,
341 DWORD *pdwMilliSeconds)
343 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
345 TRACE("(%p, %p)\n", This, pdwMilliSeconds);
346 if (NULL == pdwMilliSeconds) {
347 return E_POINTER;
349 *pdwMilliSeconds = This->dwPrepareTime;
350 return S_OK;
353 static HRESULT WINAPI IDirectMusicPerformance8Impl_SetBumperLength(IDirectMusicPerformance8 *iface,
354 DWORD dwMilliSeconds)
356 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
358 TRACE("(%p, %d)\n", This, dwMilliSeconds);
359 This->dwBumperLength = dwMilliSeconds;
360 return S_OK;
363 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetBumperLength(IDirectMusicPerformance8 *iface,
364 DWORD *pdwMilliSeconds)
366 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
368 TRACE("(%p, %p)\n", This, pdwMilliSeconds);
369 if (NULL == pdwMilliSeconds) {
370 return E_POINTER;
372 *pdwMilliSeconds = This->dwBumperLength;
373 return S_OK;
376 static HRESULT WINAPI IDirectMusicPerformance8Impl_SendPMsg(IDirectMusicPerformance8 *iface,
377 DMUS_PMSG *pPMSG)
379 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
380 DMUS_PMSGItem* pItem = NULL;
381 DMUS_PMSGItem* it = NULL;
382 DMUS_PMSGItem* prev_it = NULL;
383 DMUS_PMSGItem** queue = NULL;
385 FIXME("(%p, %p): stub\n", This, pPMSG);
387 if (NULL == pPMSG) {
388 return E_POINTER;
390 pItem = DMUS_PMSGToItem(pPMSG);
391 if (pItem->bInUse) {
392 return DMUS_E_ALREADY_SENT;
395 /* TODO: Valid Flags */
396 /* TODO: DMUS_PMSGF_MUSICTIME */
397 pItem->rtItemTime = pPMSG->rtTime;
399 if (pPMSG->dwFlags & DMUS_PMSGF_TOOL_IMMEDIATE) {
400 queue = &This->imm_head;
401 } else {
402 queue = &This->head;
405 EnterCriticalSection(&This->safe);
406 for (it = *queue; NULL != it && it->rtItemTime < pItem->rtItemTime; it = it->next) {
407 prev_it = it;
409 if (NULL == prev_it) {
410 pItem->prev = NULL;
411 if (NULL != *queue) pItem->next = (*queue)->next;
412 /*assert( NULL == pItem->next->prev );*/
413 if (NULL != pItem->next) pItem->next->prev = pItem;
414 *queue = pItem;
415 } else {
416 pItem->prev = prev_it;
417 pItem->next = prev_it->next;
418 prev_it->next = pItem;
419 if (NULL != pItem->next) pItem->next->prev = pItem;
421 LeaveCriticalSection(&This->safe);
423 /** now in use, prevent from stupid Frees */
424 pItem->bInUse = TRUE;
425 return S_OK;
428 static HRESULT WINAPI IDirectMusicPerformance8Impl_MusicToReferenceTime(IDirectMusicPerformance8 *iface,
429 MUSIC_TIME mtTime, REFERENCE_TIME *prtTime)
431 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
433 FIXME("(%p, %d, %p): stub\n", This, mtTime, prtTime);
434 return S_OK;
437 static HRESULT WINAPI IDirectMusicPerformance8Impl_ReferenceToMusicTime(IDirectMusicPerformance8 *iface,
438 REFERENCE_TIME rtTime, MUSIC_TIME *pmtTime)
440 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
442 FIXME("(%p, 0x%s, %p): stub\n", This, wine_dbgstr_longlong(rtTime), pmtTime);
443 return S_OK;
446 static HRESULT WINAPI IDirectMusicPerformance8Impl_IsPlaying(IDirectMusicPerformance8 *iface,
447 IDirectMusicSegment *pSegment, IDirectMusicSegmentState *pSegState)
449 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
451 FIXME("(%p, %p, %p): stub\n", This, pSegment, pSegState);
452 return S_FALSE;
455 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetTime(IDirectMusicPerformance8 *iface,
456 REFERENCE_TIME *prtNow, MUSIC_TIME *pmtNow)
458 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
459 HRESULT hr = S_OK;
460 REFERENCE_TIME rtCur = 0;
462 /*TRACE("(%p, %p, %p)\n", This, prtNow, pmtNow); */
463 if (This->procThreadTicStarted) {
464 rtCur = ((REFERENCE_TIME) GetTickCount() * 10000) - This->procThreadStartTime;
465 } else {
466 /*return DMUS_E_NO_MASTER_CLOCK;*/
468 if (NULL != prtNow) {
469 *prtNow = rtCur;
471 if (NULL != pmtNow) {
472 hr = IDirectMusicPerformance8_ReferenceToMusicTime(iface, rtCur, pmtNow);
474 return hr;
477 static HRESULT WINAPI IDirectMusicPerformance8Impl_AllocPMsg(IDirectMusicPerformance8 *iface,
478 ULONG cb, DMUS_PMSG **ppPMSG)
480 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
481 DMUS_PMSGItem* pItem = NULL;
483 FIXME("(%p, %d, %p): stub\n", This, cb, ppPMSG);
485 if (sizeof(DMUS_PMSG) > cb) {
486 return E_INVALIDARG;
488 if (NULL == ppPMSG) {
489 return E_POINTER;
491 pItem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb - sizeof(DMUS_PMSG) + sizeof(DMUS_PMSGItem));
492 if (NULL == pItem) {
493 return E_OUTOFMEMORY;
495 pItem->pMsg.dwSize = cb;
496 *ppPMSG = DMUS_ItemToPMSG(pItem);
497 return S_OK;
500 static HRESULT WINAPI IDirectMusicPerformance8Impl_FreePMsg(IDirectMusicPerformance8 *iface,
501 DMUS_PMSG *pPMSG)
503 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
504 DMUS_PMSGItem* pItem = NULL;
506 FIXME("(%p, %p): stub\n", This, pPMSG);
508 if (NULL == pPMSG) {
509 return E_POINTER;
511 pItem = DMUS_PMSGToItem(pPMSG);
512 if (pItem->bInUse) {
513 /** prevent for freeing PMsg in queue (ie to be processed) */
514 return DMUS_E_CANNOT_FREE;
516 /** now we can remove it safely */
517 EnterCriticalSection(&This->safe);
518 DMUS_ItemRemoveFromQueue( This, pItem );
519 LeaveCriticalSection(&This->safe);
521 /** TODO: see if we should Release the pItem->pMsg->punkUser and others Interfaces */
522 HeapFree(GetProcessHeap(), 0, pItem);
523 return S_OK;
526 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetGraph(IDirectMusicPerformance8 *iface,
527 IDirectMusicGraph **ppGraph)
529 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
531 FIXME("(%p, %p): to check\n", This, ppGraph);
532 if (NULL != This->pToolGraph) {
533 *ppGraph = This->pToolGraph;
534 IDirectMusicGraph_AddRef(*ppGraph);
535 } else {
536 return E_FAIL;
538 return S_OK;
541 static HRESULT WINAPI IDirectMusicPerformance8Impl_SetGraph(IDirectMusicPerformance8 *iface,
542 IDirectMusicGraph *pGraph)
544 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
546 FIXME("(%p, %p): to check\n", This, pGraph);
548 if (NULL != This->pToolGraph) {
549 /* Todo clean buffers and tools before */
550 IDirectMusicGraph_Release(This->pToolGraph);
552 This->pToolGraph = pGraph;
553 if (NULL != This->pToolGraph) {
554 IDirectMusicGraph_AddRef(This->pToolGraph);
556 return S_OK;
559 static HRESULT WINAPI IDirectMusicPerformance8Impl_SetNotificationHandle(IDirectMusicPerformance8 *iface,
560 HANDLE hNotification, REFERENCE_TIME rtMinimum)
562 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
564 FIXME("(%p, %p, 0x%s): stub\n", This, hNotification, wine_dbgstr_longlong(rtMinimum));
565 This->hNotification = hNotification;
566 if (rtMinimum) This->rtMinimum = rtMinimum;
567 return S_OK;
570 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetNotificationPMsg(IDirectMusicPerformance8 *iface,
571 DMUS_NOTIFICATION_PMSG **ppNotificationPMsg)
573 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
575 FIXME("(%p, %p): stub\n", This, ppNotificationPMsg);
576 if (NULL == ppNotificationPMsg) {
577 return E_POINTER;
582 return S_FALSE;
583 /*return S_OK;*/
586 static HRESULT WINAPI IDirectMusicPerformance8Impl_AddNotificationType(IDirectMusicPerformance8 *iface,
587 REFGUID rguidNotificationType)
589 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
591 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
592 return S_OK;
595 static HRESULT WINAPI IDirectMusicPerformance8Impl_RemoveNotificationType(IDirectMusicPerformance8 *iface,
596 REFGUID rguidNotificationType)
598 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
600 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
601 return S_OK;
604 static HRESULT WINAPI IDirectMusicPerformance8Impl_AddPort(IDirectMusicPerformance8 *iface,
605 IDirectMusicPort *pPort)
607 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
608 HRESULT hr = E_FAIL;
610 FIXME("(%p, %p): stub\n", This, pPort);
611 if (!This->pDirectMusic || !This->pDirectSound) return DMUS_E_NOT_INIT;
612 if (NULL == pPort) {
613 GUID port_guid;
614 IDirectMusicPort* pDefaultPort = NULL;
615 DMUS_PORTPARAMS params;
616 int i, j;
617 hr = IDirectMusic8_GetDefaultPort(This->pDirectMusic, &port_guid);
618 if (FAILED(hr)) return hr;
619 ZeroMemory(&params, sizeof(params));
620 params.dwSize = sizeof(params);
621 params.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS | DMUS_PORTPARAMS_SHARE;
622 params.dwChannelGroups = 1;
623 params.fShare = TRUE;
624 hr = IDirectMusic8_CreatePort(This->pDirectMusic, &port_guid, &params, &pDefaultPort, NULL);
625 if (FAILED(hr)) return hr;
626 hr = IDirectMusicPort_Activate(pDefaultPort, TRUE);
627 if (FAILED(hr)) { IDirectMusicPort_Release(pDefaultPort); return hr; }
628 j = 0;
629 for (i = 0; i < 16; ++i) {
630 if (NULL == This->PChannel[i].port) {
631 This->PChannel[i].port = pPort;
632 This->PChannel[i].group = 0;
633 This->PChannel[i].channel = j; /* FIXME: should this be assigned? */
634 j++;
637 } else {
638 IDirectMusicPort_AddRef(pPort);
641 * We should remember added Ports (for example using a list)
642 * and control if Port is registered for each api who use ports
644 return S_OK;
647 static HRESULT WINAPI IDirectMusicPerformance8Impl_RemovePort(IDirectMusicPerformance8 *iface,
648 IDirectMusicPort *pPort)
650 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
652 FIXME("(%p, %p): stub\n", This, pPort);
653 IDirectMusicPort_Release (pPort);
654 return S_OK;
657 static HRESULT WINAPI IDirectMusicPerformance8Impl_AssignPChannelBlock(IDirectMusicPerformance8 *iface,
658 DWORD dwBlockNum, IDirectMusicPort *pPort, DWORD dwGroup)
660 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
661 int i, j, range /* min value in range */;
663 FIXME("(%p, %d, %p, %d): semi-stub\n", This, dwBlockNum, pPort, dwGroup-1);
664 if (NULL == pPort) return E_POINTER;
666 range = 16 * dwBlockNum;
667 j = 0;
668 for (i = range; i < range+16; i++) {
669 /*TRACE("Setting PChannel[%i] to port %p, group %ld, MIDI port %i\n", i, pPort, dwGroup-1, j); */
670 This->PChannel[i].port = pPort;
671 This->PChannel[i].group = dwGroup - 1; /* first index is always zero */
672 This->PChannel[i].channel = j; /* FIXME: should this be assigned? */
673 j++;
675 /*if (dwGroup > 2) return S_FALSE;*/
677 return S_OK;
680 static HRESULT WINAPI IDirectMusicPerformance8Impl_AssignPChannel(IDirectMusicPerformance8 *iface,
681 DWORD PChannel, IDirectMusicPort *port, DWORD group, DWORD MChannel)
683 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
685 TRACE("(%p)->(%d, %p, %d, %d)\n", This, PChannel, port, group, MChannel);
687 if (!port)
688 return E_POINTER;
690 This->PChannel[PChannel].port = port;
691 This->PChannel[PChannel].group = group;
692 This->PChannel[PChannel].channel = MChannel;
694 return S_OK;
697 static HRESULT WINAPI IDirectMusicPerformance8Impl_PChannelInfo(IDirectMusicPerformance8 *iface,
698 DWORD PChannel, IDirectMusicPort **port, DWORD *group, DWORD *MChannel)
700 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
701 DMUS_PORTPARAMS8 port_params;
702 GUID default_port;
704 FIXME("(%p)->(%d, %p, %p, %p): stub\n", This, PChannel, port, group, MChannel);
706 port_params.dwSize = sizeof(DMUS_PORTPARAMS8);
707 port_params.dwValidParams = 0;
708 IDirectMusic8_GetDefaultPort(This->pDirectMusic, &default_port);
709 IDirectMusic8_CreatePort(This->pDirectMusic, &default_port, &port_params, port, NULL);
711 return S_OK;
714 static HRESULT WINAPI IDirectMusicPerformance8Impl_DownloadInstrument(IDirectMusicPerformance8 *iface,
715 IDirectMusicInstrument *pInst, DWORD dwPChannel,
716 IDirectMusicDownloadedInstrument **ppDownInst, DMUS_NOTERANGE *pNoteRanges,
717 DWORD dwNumNoteRanges, IDirectMusicPort **ppPort, DWORD *pdwGroup, DWORD *pdwMChannel)
719 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
721 FIXME("(%p, %p, %d, %p, %p, %d, %p, %p, %p): stub\n", This, pInst, dwPChannel, ppDownInst, pNoteRanges, dwNumNoteRanges, ppPort, pdwGroup, pdwMChannel);
722 return S_OK;
725 static HRESULT WINAPI IDirectMusicPerformance8Impl_Invalidate(IDirectMusicPerformance8 *iface,
726 MUSIC_TIME mtTime, DWORD dwFlags)
728 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
730 FIXME("(%p, %d, %d): stub\n", This, mtTime, dwFlags);
731 return S_OK;
734 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetParam(IDirectMusicPerformance8 *iface,
735 REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime,
736 MUSIC_TIME *pmtNext, void *pParam)
738 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
740 FIXME("(%p, %s, %d, %d, %d, %p, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pmtNext, pParam);
741 return S_OK;
744 static HRESULT WINAPI IDirectMusicPerformance8Impl_SetParam(IDirectMusicPerformance8 *iface,
745 REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, void *pParam)
747 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
749 FIXME("(%p, %s, %d, %d, %d, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pParam);
750 return S_OK;
753 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetGlobalParam(IDirectMusicPerformance8 *iface,
754 REFGUID rguidType, void *pParam, DWORD dwSize)
756 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
758 TRACE("(%p, %s, %p, %d): stub\n", This, debugstr_dmguid(rguidType), pParam, dwSize);
760 if (IsEqualGUID (rguidType, &GUID_PerfAutoDownload))
761 memcpy(pParam, &This->fAutoDownload, sizeof(This->fAutoDownload));
762 if (IsEqualGUID (rguidType, &GUID_PerfMasterGrooveLevel))
763 memcpy(pParam, &This->cMasterGrooveLevel, sizeof(This->cMasterGrooveLevel));
764 if (IsEqualGUID (rguidType, &GUID_PerfMasterTempo))
765 memcpy(pParam, &This->fMasterTempo, sizeof(This->fMasterTempo));
766 if (IsEqualGUID (rguidType, &GUID_PerfMasterVolume))
767 memcpy(pParam, &This->lMasterVolume, sizeof(This->lMasterVolume));
769 return S_OK;
772 static HRESULT WINAPI IDirectMusicPerformance8Impl_SetGlobalParam(IDirectMusicPerformance8 *iface,
773 REFGUID rguidType, void *pParam, DWORD dwSize)
775 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
777 TRACE("(%p, %s, %p, %d)\n", This, debugstr_dmguid(rguidType), pParam, dwSize);
779 if (IsEqualGUID (rguidType, &GUID_PerfAutoDownload)) {
780 memcpy(&This->fAutoDownload, pParam, dwSize);
781 TRACE("=> AutoDownload set to %d\n", This->fAutoDownload);
783 if (IsEqualGUID (rguidType, &GUID_PerfMasterGrooveLevel)) {
784 memcpy(&This->cMasterGrooveLevel, pParam, dwSize);
785 TRACE("=> MasterGrooveLevel set to %i\n", This->cMasterGrooveLevel);
787 if (IsEqualGUID (rguidType, &GUID_PerfMasterTempo)) {
788 memcpy(&This->fMasterTempo, pParam, dwSize);
789 TRACE("=> MasterTempo set to %f\n", This->fMasterTempo);
791 if (IsEqualGUID (rguidType, &GUID_PerfMasterVolume)) {
792 memcpy(&This->lMasterVolume, pParam, dwSize);
793 TRACE("=> MasterVolume set to %li\n", This->lMasterVolume);
796 return S_OK;
799 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetLatencyTime(IDirectMusicPerformance8 *iface,
800 REFERENCE_TIME *prtTime)
802 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
804 TRACE("(%p, %p): stub\n", This, prtTime);
805 *prtTime = This->rtLatencyTime;
806 return S_OK;
809 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetQueueTime(IDirectMusicPerformance8 *iface,
810 REFERENCE_TIME *prtTime)
813 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
815 FIXME("(%p, %p): stub\n", This, prtTime);
816 return S_OK;
819 static HRESULT WINAPI IDirectMusicPerformance8Impl_AdjustTime(IDirectMusicPerformance8 *iface,
820 REFERENCE_TIME rtAmount)
822 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
824 FIXME("(%p, 0x%s): stub\n", This, wine_dbgstr_longlong(rtAmount));
825 return S_OK;
828 static HRESULT WINAPI IDirectMusicPerformance8Impl_CloseDown(IDirectMusicPerformance8 *iface)
830 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
832 FIXME("(%p): stub\n", This);
833 if (PostMessageToProcessMsgThread(This, PROCESSMSG_EXIT)) {
834 WaitForSingleObject(This->procThread, INFINITE);
835 This->procThreadTicStarted = FALSE;
836 CloseHandle(This->procThread);
838 if (NULL != This->pDirectSound) {
839 IDirectSound_Release(This->pDirectSound);
840 This->pDirectSound = NULL;
842 if (NULL != This->pDirectMusic) {
843 IDirectMusic8_Release(This->pDirectMusic);
844 This->pDirectMusic = NULL;
846 return S_OK;
849 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetResolvedTime(IDirectMusicPerformance8 *iface,
850 REFERENCE_TIME rtTime, REFERENCE_TIME *prtResolved, DWORD dwTimeResolveFlags)
852 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
854 FIXME("(%p, 0x%s, %p, %d): stub\n", This, wine_dbgstr_longlong(rtTime),
855 prtResolved, dwTimeResolveFlags);
856 return S_OK;
859 static HRESULT WINAPI IDirectMusicPerformance8Impl_MIDIToMusic(IDirectMusicPerformance8 *iface,
860 BYTE bMIDIValue, DMUS_CHORD_KEY *pChord, BYTE bPlayMode, BYTE bChordLevel,
861 WORD *pwMusicValue)
863 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
865 FIXME("(%p, %d, %p, %d, %d, %p): stub\n", This, bMIDIValue, pChord, bPlayMode, bChordLevel, pwMusicValue);
866 return S_OK;
869 static HRESULT WINAPI IDirectMusicPerformance8Impl_MusicToMIDI(IDirectMusicPerformance8 *iface,
870 WORD wMusicValue, DMUS_CHORD_KEY *pChord, BYTE bPlayMode, BYTE bChordLevel,
871 BYTE *pbMIDIValue)
873 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
875 FIXME("(%p, %d, %p, %d, %d, %p): stub\n", This, wMusicValue, pChord, bPlayMode, bChordLevel, pbMIDIValue);
876 return S_OK;
879 static HRESULT WINAPI IDirectMusicPerformance8Impl_TimeToRhythm(IDirectMusicPerformance8 *iface,
880 MUSIC_TIME mtTime, DMUS_TIMESIGNATURE *pTimeSig, WORD *pwMeasure, BYTE *pbBeat,
881 BYTE *pbGrid, short *pnOffset)
883 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
885 FIXME("(%p, %d, %p, %p, %p, %p, %p): stub\n", This, mtTime, pTimeSig, pwMeasure, pbBeat, pbGrid, pnOffset);
886 return S_OK;
889 static HRESULT WINAPI IDirectMusicPerformance8Impl_RhythmToTime(IDirectMusicPerformance8 *iface,
890 WORD wMeasure, BYTE bBeat, BYTE bGrid, short nOffset, DMUS_TIMESIGNATURE *pTimeSig,
891 MUSIC_TIME *pmtTime)
893 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
895 FIXME("(%p, %d, %d, %d, %i, %p, %p): stub\n", This, wMeasure, bBeat, bGrid, nOffset, pTimeSig, pmtTime);
896 return S_OK;
899 /* IDirectMusicPerformance8 Interface part follow: */
900 static HRESULT WINAPI IDirectMusicPerformance8Impl_InitAudio(IDirectMusicPerformance8 *iface,
901 IDirectMusic **ppDirectMusic, IDirectSound **ppDirectSound, HWND hWnd,
902 DWORD dwDefaultPathType, DWORD dwPChannelCount, DWORD dwFlags, DMUS_AUDIOPARAMS* pParams)
904 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
905 IDirectSound* dsound = NULL;
906 HRESULT hr = S_OK;
908 FIXME("(%p, %p, %p, %p, %x, %u, %x, %p): to check\n", This, ppDirectMusic, ppDirectSound, hWnd, dwDefaultPathType, dwPChannelCount, dwFlags, pParams);
910 if (This->pDirectMusic || This->pDirectSound)
911 return DMUS_E_ALREADY_INITED;
913 if (NULL != ppDirectSound && NULL != *ppDirectSound) {
914 dsound = *ppDirectSound;
915 } else {
916 hr = DirectSoundCreate8 (NULL, (LPDIRECTSOUND8*) &dsound, NULL);
917 FIXME("return dsound(%p,%d)\n", dsound, hr);
918 if (FAILED(hr) || !dsound)
919 return DSERR_NODRIVER;
920 if (ppDirectSound)
921 *ppDirectSound = dsound;
924 IDirectMusicPerformance8Impl_Init(iface, ppDirectMusic, dsound, hWnd);
926 /* Init increases the ref count of the dsound object. Decrement it if the app doesn't want a pointer to the object. */
927 if (NULL == ppDirectSound) {
928 IDirectSound_Release(This->pDirectSound);
931 /* as seen in msdn we need params init before audio path creation */
932 if (NULL != pParams) {
933 This->pParams = *pParams;
934 } else {
935 /* TODO, how can i fill the struct as seen on msdn */
936 memset(&This->pParams, 0, sizeof(DMUS_AUDIOPARAMS));
937 This->pParams.dwSize = sizeof(DMUS_AUDIOPARAMS);
938 This->pParams.fInitNow = FALSE;
939 This->pParams.dwValidData = DMUS_AUDIOPARAMS_FEATURES | DMUS_AUDIOPARAMS_VOICES | DMUS_AUDIOPARAMS_SAMPLERATE | DMUS_AUDIOPARAMS_DEFAULTSYNTH;
940 This->pParams.dwVoices = 64;
941 This->pParams.dwSampleRate = (DWORD) 22.050;
942 This->pParams.dwFeatures = dwFlags;
943 This->pParams.clsidDefaultSynth = CLSID_DirectMusicSynthSink;
945 if(dwDefaultPathType != 0)
946 hr = IDirectMusicPerformance8_CreateStandardAudioPath(iface, dwDefaultPathType, dwPChannelCount, FALSE, &This->pDefaultPath);
948 PostMessageToProcessMsgThread(This, PROCESSMSG_START);
950 return hr;
953 static HRESULT WINAPI IDirectMusicPerformance8Impl_PlaySegmentEx(IDirectMusicPerformance8 *iface,
954 IUnknown *pSource, WCHAR *pwzSegmentName, IUnknown *pTransition, DWORD dwFlags,
955 __int64 i64StartTime, IDirectMusicSegmentState **ppSegmentState, IUnknown *pFrom,
956 IUnknown *pAudioPath)
958 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
960 FIXME("(%p, %p, %p, %p, %d, 0x%s, %p, %p, %p): stub\n", This, pSource, pwzSegmentName,
961 pTransition, dwFlags, wine_dbgstr_longlong(i64StartTime), ppSegmentState, pFrom, pAudioPath);
962 if (ppSegmentState)
963 return create_dmsegmentstate(&IID_IDirectMusicSegmentState,(void**)ppSegmentState);
964 return S_OK;
967 static HRESULT WINAPI IDirectMusicPerformance8Impl_StopEx(IDirectMusicPerformance8 *iface,
968 IUnknown *pObjectToStop, __int64 i64StopTime, DWORD dwFlags)
970 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
972 FIXME("(%p, %p, 0x%s, %d): stub\n", This, pObjectToStop,
973 wine_dbgstr_longlong(i64StopTime), dwFlags);
974 return S_OK;
977 static HRESULT WINAPI IDirectMusicPerformance8Impl_ClonePMsg(IDirectMusicPerformance8 *iface,
978 DMUS_PMSG *pSourcePMSG, DMUS_PMSG **ppCopyPMSG)
980 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
982 FIXME("(%p, %p, %p): stub\n", This, pSourcePMSG, ppCopyPMSG);
983 return S_OK;
986 static HRESULT WINAPI IDirectMusicPerformance8Impl_CreateAudioPath(IDirectMusicPerformance8 *iface,
987 IUnknown *pSourceConfig, BOOL fActivate, IDirectMusicAudioPath **ppNewPath)
989 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
990 IDirectMusicAudioPath *pPath;
992 FIXME("(%p, %p, %d, %p): stub\n", This, pSourceConfig, fActivate, ppNewPath);
994 if (NULL == ppNewPath) {
995 return E_POINTER;
998 create_dmaudiopath(&IID_IDirectMusicAudioPath, (void**)&pPath);
999 set_audiopath_perf_pointer(pPath, iface);
1001 /** TODO */
1003 *ppNewPath = pPath;
1005 return IDirectMusicAudioPath_Activate(*ppNewPath, fActivate);
1008 static HRESULT WINAPI IDirectMusicPerformance8Impl_CreateStandardAudioPath(IDirectMusicPerformance8 *iface,
1009 DWORD dwType, DWORD dwPChannelCount, BOOL fActivate, IDirectMusicAudioPath **ppNewPath)
1011 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
1012 IDirectMusicAudioPath *pPath;
1013 DSBUFFERDESC desc;
1014 WAVEFORMATEX format;
1015 IDirectSoundBuffer *buffer, *primary_buffer;
1016 HRESULT hr = S_OK;
1018 FIXME("(%p)->(%d, %d, %d, %p): semi-stub\n", This, dwType, dwPChannelCount, fActivate, ppNewPath);
1020 if (NULL == ppNewPath) {
1021 return E_POINTER;
1024 *ppNewPath = NULL;
1026 /* Secondary buffer description */
1027 memset(&format, 0, sizeof(format));
1028 format.wFormatTag = WAVE_FORMAT_PCM;
1029 format.nChannels = 1;
1030 format.nSamplesPerSec = 44000;
1031 format.nAvgBytesPerSec = 44000*2;
1032 format.nBlockAlign = 2;
1033 format.wBitsPerSample = 16;
1034 format.cbSize = 0;
1036 memset(&desc, 0, sizeof(desc));
1037 desc.dwSize = sizeof(desc);
1038 desc.dwFlags = DSBCAPS_CTRLFX | DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_GLOBALFOCUS;
1039 desc.dwBufferBytes = DSBSIZE_MIN;
1040 desc.dwReserved = 0;
1041 desc.lpwfxFormat = &format;
1042 desc.guid3DAlgorithm = GUID_NULL;
1044 switch(dwType) {
1045 case DMUS_APATH_DYNAMIC_3D:
1046 desc.dwFlags |= DSBCAPS_CTRL3D | DSBCAPS_CTRLFREQUENCY | DSBCAPS_MUTE3DATMAXDISTANCE;
1047 break;
1048 case DMUS_APATH_DYNAMIC_MONO:
1049 desc.dwFlags |= DSBCAPS_CTRLFREQUENCY;
1050 break;
1051 case DMUS_APATH_SHARED_STEREOPLUSREVERB:
1052 /* normally we have to create 2 buffers (one for music other for reverb)
1053 * in this case. See msdn
1055 case DMUS_APATH_DYNAMIC_STEREO:
1056 desc.dwFlags |= DSBCAPS_CTRLFREQUENCY;
1057 format.nChannels = 2;
1058 format.nBlockAlign *= 2;
1059 format.nAvgBytesPerSec *=2;
1060 break;
1061 default:
1062 return E_INVALIDARG;
1065 /* FIXME: Should we create one secondary buffer for each PChannel? */
1066 hr = IDirectSound8_CreateSoundBuffer ((LPDIRECTSOUND8) This->pDirectSound, &desc, &buffer, NULL);
1067 if (FAILED(hr))
1068 return DSERR_BUFFERLOST;
1070 /* Update description for creating primary buffer */
1071 desc.dwFlags |= DSBCAPS_PRIMARYBUFFER;
1072 desc.dwBufferBytes = 0;
1073 desc.lpwfxFormat = NULL;
1075 hr = IDirectSound8_CreateSoundBuffer ((LPDIRECTSOUND8) This->pDirectSound, &desc, &primary_buffer, NULL);
1076 if (FAILED(hr)) {
1077 IDirectSoundBuffer_Release(buffer);
1078 return DSERR_BUFFERLOST;
1081 create_dmaudiopath(&IID_IDirectMusicAudioPath, (void**)&pPath);
1082 set_audiopath_perf_pointer(pPath, iface);
1083 set_audiopath_dsound_buffer(pPath, buffer);
1084 set_audiopath_primary_dsound_buffer(pPath, primary_buffer);
1086 *ppNewPath = pPath;
1088 TRACE(" returning IDirectMusicAudioPath interface at %p.\n", *ppNewPath);
1090 return IDirectMusicAudioPath_Activate(*ppNewPath, fActivate);
1093 static HRESULT WINAPI IDirectMusicPerformance8Impl_SetDefaultAudioPath(IDirectMusicPerformance8 *iface,
1094 IDirectMusicAudioPath *pAudioPath)
1096 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
1098 FIXME("(%p, %p): semi-stub\n", This, pAudioPath);
1100 if (This->pDefaultPath) {
1101 IDirectMusicAudioPath_Release(This->pDefaultPath);
1102 This->pDefaultPath = NULL;
1104 This->pDefaultPath = pAudioPath;
1105 if (This->pDefaultPath) {
1106 IDirectMusicAudioPath_AddRef(This->pDefaultPath);
1107 set_audiopath_perf_pointer(This->pDefaultPath, iface);
1110 return S_OK;
1113 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetDefaultAudioPath(IDirectMusicPerformance8 *iface,
1114 IDirectMusicAudioPath **ppAudioPath)
1116 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
1118 FIXME("(%p, %p): semi-stub (%p)\n", This, ppAudioPath, This->pDefaultPath);
1120 if (NULL != This->pDefaultPath) {
1121 *ppAudioPath = This->pDefaultPath;
1122 IDirectMusicAudioPath_AddRef(*ppAudioPath);
1123 } else {
1124 *ppAudioPath = NULL;
1126 return S_OK;
1129 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetParamEx(IDirectMusicPerformance8 *iface,
1130 REFGUID rguidType, DWORD dwTrackID, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime,
1131 MUSIC_TIME *pmtNext, void *pParam)
1133 IDirectMusicPerformance8Impl *This = impl_from_IDirectMusicPerformance8(iface);
1135 FIXME("(%p, %s, %d, %d, %d, %d, %p, %p): stub\n", This, debugstr_dmguid(rguidType), dwTrackID, dwGroupBits, dwIndex, mtTime, pmtNext, pParam);
1137 return S_OK;
1140 static const IDirectMusicPerformance8Vtbl DirectMusicPerformance8_Vtbl = {
1141 IDirectMusicPerformance8Impl_QueryInterface,
1142 IDirectMusicPerformance8Impl_AddRef,
1143 IDirectMusicPerformance8Impl_Release,
1144 IDirectMusicPerformance8Impl_Init,
1145 IDirectMusicPerformance8Impl_PlaySegment,
1146 IDirectMusicPerformance8Impl_Stop,
1147 IDirectMusicPerformance8Impl_GetSegmentState,
1148 IDirectMusicPerformance8Impl_SetPrepareTime,
1149 IDirectMusicPerformance8Impl_GetPrepareTime,
1150 IDirectMusicPerformance8Impl_SetBumperLength,
1151 IDirectMusicPerformance8Impl_GetBumperLength,
1152 IDirectMusicPerformance8Impl_SendPMsg,
1153 IDirectMusicPerformance8Impl_MusicToReferenceTime,
1154 IDirectMusicPerformance8Impl_ReferenceToMusicTime,
1155 IDirectMusicPerformance8Impl_IsPlaying,
1156 IDirectMusicPerformance8Impl_GetTime,
1157 IDirectMusicPerformance8Impl_AllocPMsg,
1158 IDirectMusicPerformance8Impl_FreePMsg,
1159 IDirectMusicPerformance8Impl_GetGraph,
1160 IDirectMusicPerformance8Impl_SetGraph,
1161 IDirectMusicPerformance8Impl_SetNotificationHandle,
1162 IDirectMusicPerformance8Impl_GetNotificationPMsg,
1163 IDirectMusicPerformance8Impl_AddNotificationType,
1164 IDirectMusicPerformance8Impl_RemoveNotificationType,
1165 IDirectMusicPerformance8Impl_AddPort,
1166 IDirectMusicPerformance8Impl_RemovePort,
1167 IDirectMusicPerformance8Impl_AssignPChannelBlock,
1168 IDirectMusicPerformance8Impl_AssignPChannel,
1169 IDirectMusicPerformance8Impl_PChannelInfo,
1170 IDirectMusicPerformance8Impl_DownloadInstrument,
1171 IDirectMusicPerformance8Impl_Invalidate,
1172 IDirectMusicPerformance8Impl_GetParam,
1173 IDirectMusicPerformance8Impl_SetParam,
1174 IDirectMusicPerformance8Impl_GetGlobalParam,
1175 IDirectMusicPerformance8Impl_SetGlobalParam,
1176 IDirectMusicPerformance8Impl_GetLatencyTime,
1177 IDirectMusicPerformance8Impl_GetQueueTime,
1178 IDirectMusicPerformance8Impl_AdjustTime,
1179 IDirectMusicPerformance8Impl_CloseDown,
1180 IDirectMusicPerformance8Impl_GetResolvedTime,
1181 IDirectMusicPerformance8Impl_MIDIToMusic,
1182 IDirectMusicPerformance8Impl_MusicToMIDI,
1183 IDirectMusicPerformance8Impl_TimeToRhythm,
1184 IDirectMusicPerformance8Impl_RhythmToTime,
1185 IDirectMusicPerformance8Impl_InitAudio,
1186 IDirectMusicPerformance8Impl_PlaySegmentEx,
1187 IDirectMusicPerformance8Impl_StopEx,
1188 IDirectMusicPerformance8Impl_ClonePMsg,
1189 IDirectMusicPerformance8Impl_CreateAudioPath,
1190 IDirectMusicPerformance8Impl_CreateStandardAudioPath,
1191 IDirectMusicPerformance8Impl_SetDefaultAudioPath,
1192 IDirectMusicPerformance8Impl_GetDefaultAudioPath,
1193 IDirectMusicPerformance8Impl_GetParamEx
1196 /* for ClassFactory */
1197 HRESULT WINAPI create_dmperformance(REFIID lpcGUID, void **ppobj)
1199 IDirectMusicPerformance8Impl *obj;
1201 TRACE("(%p,%p)\n", lpcGUID, ppobj);
1203 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicPerformance8Impl));
1204 if (NULL == obj) {
1205 *ppobj = NULL;
1206 return E_OUTOFMEMORY;
1208 obj->IDirectMusicPerformance8_iface.lpVtbl = &DirectMusicPerformance8_Vtbl;
1209 obj->ref = 0; /* will be inited by QueryInterface */
1210 obj->pDirectMusic = NULL;
1211 obj->pDirectSound = NULL;
1212 obj->pDefaultPath = NULL;
1213 InitializeCriticalSection(&obj->safe);
1214 obj->safe.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IDirectMusicPerformance8Impl*->safe");
1216 obj->rtLatencyTime = 100; /* 100 ms TO FIX */
1217 obj->dwBumperLength = 50; /* 50 ms default */
1218 obj->dwPrepareTime = 1000; /* 1000 ms default */
1219 return IDirectMusicPerformance8Impl_QueryInterface(&obj->IDirectMusicPerformance8_iface,
1220 lpcGUID, ppobj);