Spelling fixes.
[wine/multimedia.git] / dlls / dmime / performance.c
blob973010422dbeadabfed5a04a5befa0687541ae28
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 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%x\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 rtCurTime;
75 DMUS_PMSGItem* it = NULL;
76 DMUS_PMSGItem* cur = NULL;
77 DMUS_PMSGItem* it_next = NULL;
79 while (TRUE) {
80 DWORD dwDec = This->rtLatencyTime + This->dwBumperLength;
82 if (timeOut > 0) MsgWaitForMultipleObjects(0, NULL, FALSE, timeOut, QS_POSTMESSAGE|QS_SENDMESSAGE|QS_TIMER);
83 timeOut = INFINITE;
85 EnterCriticalSection(&This->safe);
86 hr = IDirectMusicPerformance8_GetTime((IDirectMusicPerformance8*) This, &rtCurTime, NULL);
87 if (FAILED(hr)) {
88 goto outrefresh;
91 for (it = This->imm_head; NULL != it; ) {
92 it_next = it->next;
93 cur = ProceedMsg(This, it);
94 HeapFree(GetProcessHeap(), 0, cur);
95 it = it_next;
98 for (it = This->head; NULL != it && it->rtItemTime < rtCurTime + dwDec; ) {
99 it_next = it->next;
100 cur = ProceedMsg(This, it);
101 HeapFree(GetProcessHeap(), 0, cur);
102 it = it_next;
104 if (NULL != it) {
105 timeOut = ( it->rtItemTime - rtCurTime ) + This->rtLatencyTime;
108 outrefresh:
109 LeaveCriticalSection(&This->safe);
111 while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) {
112 /** if hwnd we suppose that is a windows event ... */
113 if (NULL != msg.hwnd) {
114 TranslateMessage(&msg);
115 DispatchMessageA(&msg);
116 } else {
117 switch (msg.message) {
118 case WM_QUIT:
119 case PROCESSMSG_EXIT:
120 goto outofthread;
121 case PROCESSMSG_START:
122 break;
123 case PROCESSMSG_ADD:
124 break;
125 case PROCESSMSG_REMOVE:
126 break;
127 default:
128 ERR("Unhandled message %u. Critical Path\n", msg.message);
129 break;
134 /** here we should run a little of current AudioPath */
138 outofthread:
139 TRACE("(%p): Exiting\n", This);
141 return 0;
144 static BOOL PostMessageToProcessMsgThread(IDirectMusicPerformance8Impl* This, UINT iMsg) {
145 if (FALSE == This->procThreadTicStarted && PROCESSMSG_EXIT != iMsg) {
146 BOOL res;
147 This->procThread = CreateThread(NULL, 0, ProcessMsgThread, This, 0, &This->procThreadId);
148 if (NULL == This->procThread) return FALSE;
149 SetThreadPriority(This->procThread, THREAD_PRIORITY_TIME_CRITICAL);
150 This->procThreadTicStarted = TRUE;
151 while(1) {
152 res = PostThreadMessageA(This->procThreadId, iMsg, 0, 0);
153 /* Let the thread creates its message queue (with MsgWaitForMultipleObjects call) by yielding and retrying */
154 if (!res && (GetLastError() == ERROR_INVALID_THREAD_ID))
155 Sleep(0);
156 else
157 break;
159 return res;
161 return PostThreadMessageA(This->procThreadId, iMsg, 0, 0);
164 /* IDirectMusicPerformance8 IUnknown part: */
165 static HRESULT WINAPI IDirectMusicPerformance8Impl_QueryInterface (LPDIRECTMUSICPERFORMANCE8 iface, REFIID riid, LPVOID *ppobj) {
166 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
167 TRACE("(%p, %s,%p)\n", This, debugstr_dmguid(riid), ppobj);
169 if (IsEqualIID (riid, &IID_IUnknown) ||
170 IsEqualIID (riid, &IID_IDirectMusicPerformance) ||
171 IsEqualIID (riid, &IID_IDirectMusicPerformance2) ||
172 IsEqualIID (riid, &IID_IDirectMusicPerformance8)) {
173 IUnknown_AddRef(iface);
174 *ppobj = This;
175 return S_OK;
178 WARN("(%p, %s,%p): not found\n", This, debugstr_dmguid(riid), ppobj);
179 return E_NOINTERFACE;
182 static ULONG WINAPI IDirectMusicPerformance8Impl_AddRef (LPDIRECTMUSICPERFORMANCE8 iface) {
183 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
184 ULONG ref = InterlockedIncrement(&This->ref);
186 TRACE("(%p): AddRef from %d\n", This, ref - 1);
188 DMIME_LockModule();
190 return ref;
193 static ULONG WINAPI IDirectMusicPerformance8Impl_Release (LPDIRECTMUSICPERFORMANCE8 iface) {
194 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
195 ULONG ref = InterlockedDecrement(&This->ref);
196 TRACE("(%p): ReleaseRef to %d\n", This, ref);
198 if (ref == 0) {
199 This->safe.DebugInfo->Spare[0] = 0;
200 DeleteCriticalSection(&This->safe);
201 HeapFree(GetProcessHeap(), 0, This);
204 DMIME_UnlockModule();
206 return ref;
209 /* IDirectMusicPerformanceImpl IDirectMusicPerformance Interface part: */
210 static HRESULT WINAPI IDirectMusicPerformance8Impl_Init (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusic** ppDirectMusic, LPDIRECTSOUND pDirectSound, HWND hWnd) {
211 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
213 FIXME("(iface = %p, dmusic = %p, dsound = %p, hwnd = %p)\n", This, ppDirectMusic, pDirectSound, hWnd);
214 if (This->pDirectMusic || This->pDirectSound)
215 return DMUS_E_ALREADY_INITED;
217 if (NULL == hWnd) {
218 hWnd = GetForegroundWindow();
221 if (NULL != pDirectSound) {
222 This->pDirectSound = pDirectSound;
223 IDirectSound_AddRef(This->pDirectSound);
224 } else {
225 HRESULT hr;
226 hr = DirectSoundCreate8(NULL, (LPDIRECTSOUND8*) &This->pDirectSound, NULL);
227 if (!This->pDirectSound) return DSERR_NODRIVER;
229 if (NULL != hWnd) {
230 IDirectSound8_SetCooperativeLevel(This->pDirectSound, hWnd, DSSCL_PRIORITY);
231 } else {
232 /* how to get the ForeGround window handle ? */
233 /*IDirectSound8_SetCooperativeLevel(This->pDirectSound, hWnd, DSSCL_PRIORITY);*/
237 if (NULL != ppDirectMusic && NULL != *ppDirectMusic) {
238 /* app creates it's own dmusic object and gives it to performance */
239 This->pDirectMusic = (IDirectMusic8*) *ppDirectMusic;
240 IDirectMusic8_AddRef(This->pDirectMusic);
241 } else {
242 /* app allows the performance to initialise itself and needs a pointer to object*/
243 CoCreateInstance (&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic8, (void**)&This->pDirectMusic);
244 if (ppDirectMusic) {
245 *ppDirectMusic = (LPDIRECTMUSIC) This->pDirectMusic;
246 IDirectMusic8_AddRef((LPDIRECTMUSIC8) *ppDirectMusic);
250 return S_OK;
253 static HRESULT WINAPI IDirectMusicPerformance8Impl_PlaySegment (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicSegment* pSegment, DWORD dwFlags, __int64 i64StartTime, IDirectMusicSegmentState** ppSegmentState) {
254 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
255 FIXME("(%p, %p, %d, 0x%s, %p): stub\n", This, pSegment, dwFlags,
256 wine_dbgstr_longlong(i64StartTime), ppSegmentState);
257 return S_OK;
260 static HRESULT WINAPI IDirectMusicPerformance8Impl_Stop (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicSegment* pSegment, IDirectMusicSegmentState* pSegmentState, MUSIC_TIME mtTime, DWORD dwFlags) {
261 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
262 FIXME("(%p, %p, %p, %ld, %d): stub\n", This, pSegment, pSegmentState, mtTime, dwFlags);
263 return S_OK;
266 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetSegmentState (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicSegmentState** ppSegmentState, MUSIC_TIME mtTime) {
267 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
268 FIXME("(%p,%p, %ld): stub\n", This, ppSegmentState, mtTime);
269 return S_OK;
272 static HRESULT WINAPI IDirectMusicPerformance8Impl_SetPrepareTime (LPDIRECTMUSICPERFORMANCE8 iface, DWORD dwMilliSeconds) {
273 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
274 TRACE("(%p, %d)\n", This, dwMilliSeconds);
275 This->dwPrepareTime = dwMilliSeconds;
276 return S_OK;
279 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetPrepareTime (LPDIRECTMUSICPERFORMANCE8 iface, DWORD* pdwMilliSeconds) {
280 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
281 TRACE("(%p, %p)\n", This, pdwMilliSeconds);
282 if (NULL == pdwMilliSeconds) {
283 return E_POINTER;
285 *pdwMilliSeconds = This->dwPrepareTime;
286 return S_OK;
289 static HRESULT WINAPI IDirectMusicPerformance8Impl_SetBumperLength (LPDIRECTMUSICPERFORMANCE8 iface, DWORD dwMilliSeconds) {
290 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
291 TRACE("(%p, %d)\n", This, dwMilliSeconds);
292 This->dwBumperLength = dwMilliSeconds;
293 return S_OK;
296 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetBumperLength (LPDIRECTMUSICPERFORMANCE8 iface, DWORD* pdwMilliSeconds) {
297 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
298 TRACE("(%p, %p)\n", This, pdwMilliSeconds);
299 if (NULL == pdwMilliSeconds) {
300 return E_POINTER;
302 *pdwMilliSeconds = This->dwBumperLength;
303 return S_OK;
306 static HRESULT WINAPI IDirectMusicPerformance8Impl_SendPMsg (LPDIRECTMUSICPERFORMANCE8 iface, DMUS_PMSG* pPMSG) {
307 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
308 DMUS_PMSGItem* pItem = NULL;
309 DMUS_PMSGItem* it = NULL;
310 DMUS_PMSGItem* prev_it = NULL;
311 DMUS_PMSGItem** queue = NULL;
313 FIXME("(%p, %p): stub\n", This, pPMSG);
315 if (NULL == pPMSG) {
316 return E_POINTER;
318 pItem = DMUS_PMSGToItem(pPMSG);
319 if (NULL == pItem) {
320 return E_POINTER;
322 if (pItem->bInUse) {
323 return DMUS_E_ALREADY_SENT;
326 /* TODO: Valid Flags */
327 /* TODO: DMUS_PMSGF_MUSICTIME */
328 pItem->rtItemTime = pPMSG->rtTime;
330 if (pPMSG->dwFlags & DMUS_PMSGF_TOOL_IMMEDIATE) {
331 queue = &This->imm_head;
332 } else {
333 queue = &This->head;
336 EnterCriticalSection(&This->safe);
337 for (it = *queue; NULL != it && it->rtItemTime < pItem->rtItemTime; it = it->next) {
338 prev_it = it;
340 if (NULL == prev_it) {
341 pItem->prev = NULL;
342 if (NULL != *queue) pItem->next = (*queue)->next;
343 /*assert( NULL == pItem->next->prev );*/
344 if (NULL != pItem->next) pItem->next->prev = pItem;
345 *queue = pItem;
346 } else {
347 pItem->prev = prev_it;
348 pItem->next = prev_it->next;
349 prev_it->next = pItem;
350 if (NULL != pItem->next) pItem->next->prev = pItem;
352 LeaveCriticalSection(&This->safe);
354 /** now in use, prevent from stupid Frees */
355 pItem->bInUse = TRUE;
356 return S_OK;
359 static HRESULT WINAPI IDirectMusicPerformance8Impl_MusicToReferenceTime (LPDIRECTMUSICPERFORMANCE8 iface, MUSIC_TIME mtTime, REFERENCE_TIME* prtTime) {
360 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
361 FIXME("(%p, %ld, %p): stub\n", This, mtTime, prtTime);
362 return S_OK;
365 static HRESULT WINAPI IDirectMusicPerformance8Impl_ReferenceToMusicTime (LPDIRECTMUSICPERFORMANCE8 iface, REFERENCE_TIME rtTime, MUSIC_TIME* pmtTime) {
366 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
367 FIXME("(%p, 0x%s, %p): stub\n", This, wine_dbgstr_longlong(rtTime), pmtTime);
368 return S_OK;
371 static HRESULT WINAPI IDirectMusicPerformance8Impl_IsPlaying (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicSegment* pSegment, IDirectMusicSegmentState* pSegState) {
372 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
373 FIXME("(%p, %p, %p): stub\n", This, pSegment, pSegState);
374 return S_FALSE;
377 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetTime (LPDIRECTMUSICPERFORMANCE8 iface, REFERENCE_TIME* prtNow, MUSIC_TIME* pmtNow) {
378 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
379 HRESULT hr = S_OK;
380 REFERENCE_TIME rtCur = 0;
382 /*TRACE("(%p, %p, %p)\n", This, prtNow, pmtNow); */
383 if (This->procThreadTicStarted) {
384 rtCur = ((REFERENCE_TIME) GetTickCount() * 10000) - This->procThreadStartTime;
385 } else {
386 /*return DMUS_E_NO_MASTER_CLOCK;*/
388 if (NULL != prtNow) {
389 *prtNow = rtCur;
391 if (NULL != pmtNow) {
392 hr = IDirectMusicPerformance8_ReferenceToMusicTime(iface, rtCur, pmtNow);
394 return hr;
397 static HRESULT WINAPI IDirectMusicPerformance8Impl_AllocPMsg (LPDIRECTMUSICPERFORMANCE8 iface, ULONG cb, DMUS_PMSG** ppPMSG) {
398 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
399 DMUS_PMSGItem* pItem = NULL;
401 FIXME("(%p, %d, %p): stub\n", This, cb, ppPMSG);
403 if (sizeof(DMUS_PMSG) > cb) {
404 return E_INVALIDARG;
406 if (NULL == ppPMSG) {
407 return E_POINTER;
409 pItem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb - sizeof(DMUS_PMSG) + sizeof(DMUS_PMSGItem));
410 if (NULL == pItem) {
411 return E_OUTOFMEMORY;
413 pItem->pMsg.dwSize = cb;
414 *ppPMSG = DMUS_ItemToPMSG(pItem);
415 return S_OK;
418 static HRESULT WINAPI IDirectMusicPerformance8Impl_FreePMsg (LPDIRECTMUSICPERFORMANCE8 iface, DMUS_PMSG* pPMSG) {
419 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
420 DMUS_PMSGItem* pItem = NULL;
422 FIXME("(%p, %p): stub\n", This, pPMSG);
424 if (NULL == pPMSG) {
425 return E_POINTER;
427 pItem = DMUS_PMSGToItem(pPMSG);
428 if (NULL == pItem) {
429 return E_POINTER;
431 if (pItem->bInUse) {
432 /** prevent for freeing PMsg in queue (ie to be processed) */
433 return DMUS_E_CANNOT_FREE;
435 /** now we can remove it safely */
436 EnterCriticalSection(&This->safe);
437 DMUS_ItemRemoveFromQueue( This, pItem );
438 LeaveCriticalSection(&This->safe);
440 /** TODO: see if we should Release the pItem->pMsg->punkUser and others Interfaces */
441 HeapFree(GetProcessHeap(), 0, pItem);
442 return S_OK;
445 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetGraph (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicGraph** ppGraph) {
446 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
447 FIXME("(%p, %p): to check\n", This, ppGraph);
448 if (NULL != This->pToolGraph) {
449 *ppGraph = This->pToolGraph;
450 IDirectMusicGraph_AddRef(*ppGraph);
451 } else {
452 return E_FAIL;
454 return S_OK;
457 static HRESULT WINAPI IDirectMusicPerformance8Impl_SetGraph (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicGraph* pGraph) {
458 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
460 FIXME("(%p, %p): to check\n", This, pGraph);
462 if (NULL != This->pToolGraph) {
463 /* Todo clean buffers and tools before */
464 IDirectMusicGraph_Release(This->pToolGraph);
466 This->pToolGraph = pGraph;
467 if (NULL != This->pToolGraph) {
468 IDirectMusicGraph_AddRef(This->pToolGraph);
470 return S_OK;
473 static HRESULT WINAPI IDirectMusicPerformance8Impl_SetNotificationHandle (LPDIRECTMUSICPERFORMANCE8 iface, HANDLE hNotification, REFERENCE_TIME rtMinimum) {
474 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
475 FIXME("(%p, %p, 0x%s): stub\n", This, hNotification, wine_dbgstr_longlong(rtMinimum));
476 This->hNotification = hNotification;
477 if (rtMinimum) This->rtMinimum = rtMinimum;
478 return S_OK;
481 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetNotificationPMsg (LPDIRECTMUSICPERFORMANCE8 iface, DMUS_NOTIFICATION_PMSG** ppNotificationPMsg) {
482 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
485 FIXME("(%p, %p): stub\n", This, ppNotificationPMsg);
486 if (NULL == ppNotificationPMsg) {
487 return E_POINTER;
492 return S_FALSE;
493 /*return S_OK;*/
496 static HRESULT WINAPI IDirectMusicPerformance8Impl_AddNotificationType (LPDIRECTMUSICPERFORMANCE8 iface, REFGUID rguidNotificationType) {
497 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
498 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
499 return S_OK;
502 static HRESULT WINAPI IDirectMusicPerformance8Impl_RemoveNotificationType (LPDIRECTMUSICPERFORMANCE8 iface, REFGUID rguidNotificationType) {
503 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
504 FIXME("(%p, %s): stub\n", This, debugstr_dmguid(rguidNotificationType));
505 return S_OK;
508 static HRESULT WINAPI IDirectMusicPerformance8Impl_AddPort (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicPort* pPort) {
509 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
510 HRESULT hr = E_FAIL;
511 FIXME("(%p, %p): stub\n", This, pPort);
512 if (!This->pDirectMusic || !This->pDirectSound) return DMUS_E_NOT_INIT;
513 if (NULL == pPort) {
514 GUID port_guid;
515 IDirectMusicPort* pDefaultPort = NULL;
516 DMUS_PORTPARAMS params;
517 int i, j;
518 hr = IDirectMusic8_GetDefaultPort(This->pDirectMusic, &port_guid);
519 if (FAILED(hr)) return hr;
520 ZeroMemory(&params, sizeof(params));
521 params.dwSize = sizeof(params);
522 params.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS | DMUS_PORTPARAMS_SHARE;
523 params.dwChannelGroups = 1;
524 params.fShare = TRUE;
525 hr = IDirectMusic8_CreatePort(This->pDirectMusic, &port_guid, &params, &pDefaultPort, NULL);
526 if (FAILED(hr)) return hr;
527 hr = IDirectMusicPort_Activate(pDefaultPort, TRUE);
528 if (FAILED(hr)) { IDirectMusicPort_Release(pDefaultPort); return hr; }
529 j = 0;
530 for (i = 0; i < 16; ++i) {
531 if (NULL == This->PChannel[i].port) {
532 This->PChannel[i].port = pPort;
533 This->PChannel[i].group = 0;
534 This->PChannel[i].channel = j; /* FIXME: should this be assigned? */
535 j++;
538 } else {
539 IDirectMusicPort_AddRef(pPort);
542 * We should remember added Ports (for example using a list)
543 * and control if Port is registered for each api who use ports
545 return S_OK;
548 static HRESULT WINAPI IDirectMusicPerformance8Impl_RemovePort (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicPort* pPort) {
549 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
550 FIXME("(%p, %p): stub\n", This, pPort);
551 IDirectMusicPort_Release (pPort);
552 return S_OK;
555 static HRESULT WINAPI IDirectMusicPerformance8Impl_AssignPChannelBlock (LPDIRECTMUSICPERFORMANCE8 iface, DWORD dwBlockNum, IDirectMusicPort* pPort, DWORD dwGroup) {
556 int i, j, range /* min value in range */;
557 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
559 FIXME("(%p, %d, %p, %d): semi-stub\n", This, dwBlockNum, pPort, dwGroup-1);
560 if (NULL == pPort) return E_POINTER;
562 range = 16 * dwBlockNum;
563 j = 0;
564 for (i = range; i < range+16; i++) {
565 /*TRACE("Setting PChannel[%i] to port %p, group %ld, MIDI port %i\n", i, pPort, dwGroup-1, j); */
566 This->PChannel[i].port = pPort;
567 This->PChannel[i].group = dwGroup - 1; /* first index is always zero */
568 This->PChannel[i].channel = j; /* FIXME: should this be assigned? */
569 j++;
571 /*if (dwGroup > 2) return S_FALSE;*/
573 return S_OK;
576 static HRESULT WINAPI IDirectMusicPerformance8Impl_AssignPChannel (LPDIRECTMUSICPERFORMANCE8 iface, DWORD dwPChannel, IDirectMusicPort* pPort, DWORD dwGroup, DWORD dwMChannel) {
577 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
579 TRACE("(%p, %d, %p, %d, %d)\n", This, dwPChannel, pPort, dwGroup, dwMChannel);
580 if (NULL == pPort) return E_POINTER;
581 This->PChannel[dwPChannel].port = pPort;
582 This->PChannel[dwPChannel].group = dwGroup;
583 This->PChannel[dwPChannel].channel = dwMChannel;
585 return S_OK;
588 static HRESULT WINAPI IDirectMusicPerformance8Impl_PChannelInfo (LPDIRECTMUSICPERFORMANCE8 iface, DWORD dwPChannel, IDirectMusicPort** ppPort, DWORD* pdwGroup, DWORD* pdwMChannel) {
589 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
590 FIXME("(%p, %d, %p, %p, %p): stub\n", This, dwPChannel, ppPort, pdwGroup, pdwMChannel);
591 return S_OK;
594 static HRESULT WINAPI IDirectMusicPerformance8Impl_DownloadInstrument (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicInstrument* pInst, DWORD dwPChannel, IDirectMusicDownloadedInstrument** ppDownInst, DMUS_NOTERANGE* pNoteRanges, DWORD dwNumNoteRanges, IDirectMusicPort** ppPort, DWORD* pdwGroup, DWORD* pdwMChannel) {
595 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
596 FIXME("(%p, %p, %d, %p, %p, %d, %p, %p, %p): stub\n", This, pInst, dwPChannel, ppDownInst, pNoteRanges, dwNumNoteRanges, ppPort, pdwGroup, pdwMChannel);
597 return S_OK;
600 static HRESULT WINAPI IDirectMusicPerformance8Impl_Invalidate (LPDIRECTMUSICPERFORMANCE8 iface, MUSIC_TIME mtTime, DWORD dwFlags) {
601 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
602 FIXME("(%p, %ld, %d): stub\n", This, mtTime, dwFlags);
603 return S_OK;
606 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetParam (LPDIRECTMUSICPERFORMANCE8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
607 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
608 FIXME("(%p, %s, %d, %d, %ld, %p, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pmtNext, pParam);
609 return S_OK;
612 static HRESULT WINAPI IDirectMusicPerformance8Impl_SetParam (LPDIRECTMUSICPERFORMANCE8 iface, REFGUID rguidType, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, void* pParam) {
613 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
614 FIXME("(%p, %s, %d, %d, %ld, %p): stub\n", This, debugstr_dmguid(rguidType), dwGroupBits, dwIndex, mtTime, pParam);
615 return S_OK;
618 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetGlobalParam (LPDIRECTMUSICPERFORMANCE8 iface, REFGUID rguidType, void* pParam, DWORD dwSize) {
619 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
621 TRACE("(%p, %s, %p, %d): stub\n", This, debugstr_dmguid(rguidType), pParam, dwSize);
623 if (IsEqualGUID (rguidType, &GUID_PerfAutoDownload))
624 memcpy(pParam, &This->fAutoDownload, sizeof(&This->fAutoDownload));
625 if (IsEqualGUID (rguidType, &GUID_PerfMasterGrooveLevel))
626 memcpy(pParam, &This->cMasterGrooveLevel, sizeof(&This->cMasterGrooveLevel));
627 if (IsEqualGUID (rguidType, &GUID_PerfMasterTempo))
628 memcpy(pParam, &This->fMasterTempo, sizeof(&This->fMasterTempo));
629 if (IsEqualGUID (rguidType, &GUID_PerfMasterVolume))
630 memcpy(pParam, &This->lMasterVolume, sizeof(&This->lMasterVolume));
632 return S_OK;
635 static HRESULT WINAPI IDirectMusicPerformance8Impl_SetGlobalParam (LPDIRECTMUSICPERFORMANCE8 iface, REFGUID rguidType, void* pParam, DWORD dwSize) {
636 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
638 TRACE("(%p, %s, %p, %d)\n", This, debugstr_dmguid(rguidType), pParam, dwSize);
640 if (IsEqualGUID (rguidType, &GUID_PerfAutoDownload)) {
641 memcpy(&This->fAutoDownload, pParam, dwSize);
642 TRACE("=> AutoDownload set to %d\n", This->fAutoDownload);
644 if (IsEqualGUID (rguidType, &GUID_PerfMasterGrooveLevel)) {
645 memcpy(&This->cMasterGrooveLevel, pParam, dwSize);
646 TRACE("=> MasterGrooveLevel set to %i\n", This->cMasterGrooveLevel);
648 if (IsEqualGUID (rguidType, &GUID_PerfMasterTempo)) {
649 memcpy(&This->fMasterTempo, pParam, dwSize);
650 TRACE("=> MasterTempo set to %f\n", This->fMasterTempo);
652 if (IsEqualGUID (rguidType, &GUID_PerfMasterVolume)) {
653 memcpy(&This->lMasterVolume, pParam, dwSize);
654 TRACE("=> MasterVolume set to %li\n", This->lMasterVolume);
657 return S_OK;
660 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetLatencyTime (LPDIRECTMUSICPERFORMANCE8 iface, REFERENCE_TIME* prtTime) {
661 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
662 TRACE("(%p, %p): stub\n", This, prtTime);
663 *prtTime = This->rtLatencyTime;
664 return S_OK;
667 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetQueueTime (LPDIRECTMUSICPERFORMANCE8 iface, REFERENCE_TIME* prtTime) {
668 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
669 FIXME("(%p, %p): stub\n", This, prtTime);
670 return S_OK;
673 static HRESULT WINAPI IDirectMusicPerformance8Impl_AdjustTime (LPDIRECTMUSICPERFORMANCE8 iface, REFERENCE_TIME rtAmount) {
674 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
675 FIXME("(%p, 0x%s): stub\n", This, wine_dbgstr_longlong(rtAmount));
676 return S_OK;
679 static HRESULT WINAPI IDirectMusicPerformance8Impl_CloseDown (LPDIRECTMUSICPERFORMANCE8 iface) {
680 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
681 FIXME("(%p): stub\n", This);
682 if (PostMessageToProcessMsgThread(This, PROCESSMSG_EXIT)) {
683 WaitForSingleObject(This->procThread, INFINITE);
684 This->procThreadTicStarted = FALSE;
685 CloseHandle(This->procThread);
687 if (NULL != This->pDirectSound) {
688 IDirectSound_Release(This->pDirectSound);
689 This->pDirectSound = NULL;
691 if (NULL != This->pDirectMusic) {
692 IDirectMusic8_Release(This->pDirectMusic);
693 This->pDirectMusic = NULL;
695 return S_OK;
698 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetResolvedTime (LPDIRECTMUSICPERFORMANCE8 iface, REFERENCE_TIME rtTime, REFERENCE_TIME* prtResolved, DWORD dwTimeResolveFlags) {
699 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
700 FIXME("(%p, 0x%s, %p, %d): stub\n", This, wine_dbgstr_longlong(rtTime),
701 prtResolved, dwTimeResolveFlags);
702 return S_OK;
705 static HRESULT WINAPI IDirectMusicPerformance8Impl_MIDIToMusic (LPDIRECTMUSICPERFORMANCE8 iface, BYTE bMIDIValue, DMUS_CHORD_KEY* pChord, BYTE bPlayMode, BYTE bChordLevel, WORD* pwMusicValue) {
706 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
707 FIXME("(%p, %d, %p, %d, %d, %p): stub\n", This, bMIDIValue, pChord, bPlayMode, bChordLevel, pwMusicValue);
708 return S_OK;
711 static HRESULT WINAPI IDirectMusicPerformance8Impl_MusicToMIDI (LPDIRECTMUSICPERFORMANCE8 iface, WORD wMusicValue, DMUS_CHORD_KEY* pChord, BYTE bPlayMode, BYTE bChordLevel, BYTE* pbMIDIValue) {
712 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
713 FIXME("(%p, %d, %p, %d, %d, %p): stub\n", This, wMusicValue, pChord, bPlayMode, bChordLevel, pbMIDIValue);
714 return S_OK;
717 static HRESULT WINAPI IDirectMusicPerformance8Impl_TimeToRhythm (LPDIRECTMUSICPERFORMANCE8 iface, MUSIC_TIME mtTime, DMUS_TIMESIGNATURE* pTimeSig, WORD* pwMeasure, BYTE* pbBeat, BYTE* pbGrid, short* pnOffset) {
718 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
719 FIXME("(%p, %ld, %p, %p, %p, %p, %p): stub\n", This, mtTime, pTimeSig, pwMeasure, pbBeat, pbGrid, pnOffset);
720 return S_OK;
723 static HRESULT WINAPI IDirectMusicPerformance8Impl_RhythmToTime (LPDIRECTMUSICPERFORMANCE8 iface, WORD wMeasure, BYTE bBeat, BYTE bGrid, short nOffset, DMUS_TIMESIGNATURE* pTimeSig, MUSIC_TIME* pmtTime) {
724 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
725 FIXME("(%p, %d, %d, %d, %i, %p, %p): stub\n", This, wMeasure, bBeat, bGrid, nOffset, pTimeSig, pmtTime);
726 return S_OK;
729 /* IDirectMusicPerformance8 Interface part follow: */
730 static HRESULT WINAPI IDirectMusicPerformance8Impl_InitAudio (LPDIRECTMUSICPERFORMANCE8 iface,
731 IDirectMusic** ppDirectMusic,
732 IDirectSound** ppDirectSound,
733 HWND hWnd,
734 DWORD dwDefaultPathType,
735 DWORD dwPChannelCount,
736 DWORD dwFlags,
737 DMUS_AUDIOPARAMS* pParams) {
739 IDirectSound* dsound = NULL;
740 HRESULT hr = S_OK;
742 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
743 FIXME("(%p, %p, %p, %p, %x, %u, %x, %p): to check\n", This, ppDirectMusic, ppDirectSound, hWnd, dwDefaultPathType, dwPChannelCount, dwFlags, pParams);
745 if (This->pDirectMusic || This->pDirectSound)
746 return DMUS_E_ALREADY_INITED;
748 if (NULL != ppDirectSound && NULL != *ppDirectSound) {
749 dsound = *ppDirectSound;
750 } else {
751 hr = DirectSoundCreate8 (NULL, (LPDIRECTSOUND8*) &dsound, NULL);
752 FIXME("return dsound(%p,%d)\n", dsound, hr);
753 if (FAILED(hr) || !dsound)
754 return DSERR_NODRIVER;
755 if (ppDirectSound)
756 *ppDirectSound = dsound;
759 IDirectMusicPerformance8Impl_Init(iface, ppDirectMusic, dsound, hWnd);
761 /* Init increases the ref count of the dsound object. Decrement it if the app doesn't want a pointer to the object. */
762 if (NULL == ppDirectSound) {
763 IDirectSound_Release(This->pDirectSound);
766 /* as seen in msdn we need params init before audio path creation */
767 if (NULL != pParams) {
768 This->pParams = *pParams;
769 } else {
770 /* TODO, how can i fill the struct as seen on msdn */
771 memset(&This->pParams, 0, sizeof(DMUS_AUDIOPARAMS));
772 This->pParams.dwSize = sizeof(DMUS_AUDIOPARAMS);
773 This->pParams.fInitNow = FALSE;
774 This->pParams.dwValidData = DMUS_AUDIOPARAMS_FEATURES | DMUS_AUDIOPARAMS_VOICES | DMUS_AUDIOPARAMS_SAMPLERATE | DMUS_AUDIOPARAMS_DEFAULTSYNTH;
775 This->pParams.dwVoices = 64;
776 This->pParams.dwSampleRate = (DWORD) 22.050;
777 This->pParams.dwFeatures = dwFlags;
778 This->pParams.clsidDefaultSynth = CLSID_DirectMusicSynthSink;
780 hr = IDirectMusicPerformance8_CreateStandardAudioPath(iface, dwDefaultPathType, dwPChannelCount, FALSE, &This->pDefaultPath);
782 PostMessageToProcessMsgThread(This, PROCESSMSG_START);
784 return hr;
787 static HRESULT WINAPI IDirectMusicPerformance8Impl_PlaySegmentEx (LPDIRECTMUSICPERFORMANCE8 iface, IUnknown* pSource, WCHAR* pwzSegmentName, IUnknown* pTransition, DWORD dwFlags, __int64 i64StartTime, IDirectMusicSegmentState** ppSegmentState, IUnknown* pFrom, IUnknown* pAudioPath) {
788 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
789 FIXME("(%p, %p, %p, %p, %d, 0x%s, %p, %p, %p): stub\n", This, pSource, pwzSegmentName,
790 pTransition, dwFlags, wine_dbgstr_longlong(i64StartTime), ppSegmentState, pFrom, pAudioPath);
791 return S_OK;
794 static HRESULT WINAPI IDirectMusicPerformance8Impl_StopEx (LPDIRECTMUSICPERFORMANCE8 iface, IUnknown* pObjectToStop, __int64 i64StopTime, DWORD dwFlags) {
795 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
796 FIXME("(%p, %p, 0x%s, %d): stub\n", This, pObjectToStop,
797 wine_dbgstr_longlong(i64StopTime), dwFlags);
798 return S_OK;
801 static HRESULT WINAPI IDirectMusicPerformance8Impl_ClonePMsg (LPDIRECTMUSICPERFORMANCE8 iface, DMUS_PMSG* pSourcePMSG, DMUS_PMSG** ppCopyPMSG) {
802 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
803 FIXME("(%p, %p, %p): stub\n", This, pSourcePMSG, ppCopyPMSG);
804 return S_OK;
807 static HRESULT WINAPI IDirectMusicPerformance8Impl_CreateAudioPath (LPDIRECTMUSICPERFORMANCE8 iface, IUnknown* pSourceConfig, BOOL fActivate, IDirectMusicAudioPath** ppNewPath) {
808 IDirectMusicAudioPathImpl *default_path;
809 IDirectMusicAudioPath *pPath;
811 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
812 FIXME("(%p, %p, %d, %p): stub\n", This, pSourceConfig, fActivate, ppNewPath);
814 if (NULL == ppNewPath) {
815 return E_POINTER;
818 DMUSIC_CreateDirectMusicAudioPathImpl (&IID_IDirectMusicAudioPath, (LPVOID*)&pPath, NULL);
819 default_path = (IDirectMusicAudioPathImpl*)((char*)(pPath) - offsetof(IDirectMusicAudioPathImpl,AudioPathVtbl));
820 default_path->pPerf = (IDirectMusicPerformance8*) This;
822 /** TODO */
824 *ppNewPath = pPath;
826 return IDirectMusicAudioPath_Activate(*ppNewPath, fActivate);
829 static HRESULT WINAPI IDirectMusicPerformance8Impl_CreateStandardAudioPath (LPDIRECTMUSICPERFORMANCE8 iface, DWORD dwType, DWORD dwPChannelCount, BOOL fActivate, IDirectMusicAudioPath** ppNewPath) {
830 IDirectMusicAudioPathImpl *default_path;
831 IDirectMusicAudioPath *pPath;
832 DSBUFFERDESC desc;
833 WAVEFORMATEX format;
834 LPDIRECTSOUNDBUFFER buffer;
835 HRESULT hr = S_OK;
837 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
839 FIXME("(%p)->(%d, %d, %d, %p): semi-stub\n", This, dwType, dwPChannelCount, fActivate, ppNewPath);
841 if (NULL == ppNewPath) {
842 return E_POINTER;
845 DMUSIC_CreateDirectMusicAudioPathImpl (&IID_IDirectMusicAudioPath, (LPVOID*)&pPath, NULL);
846 default_path = (IDirectMusicAudioPathImpl*)((char*)(pPath) - offsetof(IDirectMusicAudioPathImpl,AudioPathVtbl));
847 default_path->pPerf = (IDirectMusicPerformance8*) This;
849 /* Secondary buffer description */
850 memset(&format, 0, sizeof(format));
851 format.wFormatTag = WAVE_FORMAT_PCM;
852 format.nChannels = 1;
853 format.nSamplesPerSec = 44000;
854 format.nAvgBytesPerSec = 44000*2;
855 format.nBlockAlign = 2;
856 format.wBitsPerSample = 16;
857 format.cbSize = 0;
859 memset(&desc, 0, sizeof(desc));
860 desc.dwSize = sizeof(desc);
861 desc.dwFlags = DSBCAPS_CTRLFX | DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_GLOBALFOCUS;
862 desc.dwBufferBytes = DSBSIZE_MIN;
863 desc.dwReserved = 0;
864 desc.lpwfxFormat = &format;
865 desc.guid3DAlgorithm = GUID_NULL;
867 switch(dwType) {
868 case DMUS_APATH_DYNAMIC_3D:
869 desc.dwFlags |= DSBCAPS_CTRL3D | DSBCAPS_CTRLFREQUENCY | DSBCAPS_MUTE3DATMAXDISTANCE;
870 break;
871 case DMUS_APATH_DYNAMIC_MONO:
872 desc.dwFlags |= DSBCAPS_CTRLFREQUENCY;
873 break;
874 case DMUS_APATH_SHARED_STEREOPLUSREVERB:
875 /* normally we have to create 2 buffers (one for music other for reverb)
876 * in this case. See msdn
878 case DMUS_APATH_DYNAMIC_STEREO:
879 desc.dwFlags |= DSBCAPS_CTRLFREQUENCY;
880 format.nChannels = 2;
881 format.nBlockAlign *= 2;
882 format.nAvgBytesPerSec *=2;
883 break;
884 default:
885 HeapFree(GetProcessHeap(), 0, default_path);
886 *ppNewPath = NULL;
887 return E_INVALIDARG;
890 /* FIXME: Should we create one secondary buffer for each PChannel? */
891 hr = IDirectSound8_CreateSoundBuffer ((LPDIRECTSOUND8) This->pDirectSound, &desc, &buffer, NULL);
892 if (FAILED(hr)) {
893 HeapFree(GetProcessHeap(), 0, default_path);
894 *ppNewPath = NULL;
895 return DSERR_BUFFERLOST;
897 default_path->pDSBuffer = buffer;
899 /* Update description for creating primary buffer */
900 desc.dwFlags |= DSBCAPS_PRIMARYBUFFER;
901 desc.dwBufferBytes = 0;
902 desc.lpwfxFormat = NULL;
904 hr = IDirectSound8_CreateSoundBuffer ((LPDIRECTSOUND8) This->pDirectSound, &desc, &buffer, NULL);
905 if (FAILED(hr)) {
906 IDirectSoundBuffer_Release(default_path->pDSBuffer);
907 HeapFree(GetProcessHeap(), 0, default_path);
908 *ppNewPath = NULL;
909 return DSERR_BUFFERLOST;
911 default_path->pPrimary = buffer;
913 *ppNewPath = pPath;
915 TRACE(" returning IDirectMusicPerformance interface at %p.\n", *ppNewPath);
917 return IDirectMusicAudioPath_Activate(*ppNewPath, fActivate);
920 static HRESULT WINAPI IDirectMusicPerformance8Impl_SetDefaultAudioPath (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicAudioPath* pAudioPath) {
921 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
923 FIXME("(%p, %p): semi-stub\n", This, pAudioPath);
924 if (NULL != This->pDefaultPath) {
925 IDirectMusicAudioPath_Release(This->pDefaultPath);
926 ((IDirectMusicAudioPathImpl*) This->pDefaultPath)->pPerf = NULL;
927 This->pDefaultPath = NULL;
929 This->pDefaultPath = pAudioPath;
930 if (NULL != This->pDefaultPath) {
931 IDirectMusicAudioPath_AddRef(This->pDefaultPath);
932 ((IDirectMusicAudioPathImpl*) This->pDefaultPath)->pPerf = (IDirectMusicPerformance8*) This;
935 return S_OK;
938 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetDefaultAudioPath (LPDIRECTMUSICPERFORMANCE8 iface, IDirectMusicAudioPath** ppAudioPath) {
939 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
941 FIXME("(%p, %p): semi-stub (%p)\n", This, ppAudioPath, This->pDefaultPath);
943 if (NULL != This->pDefaultPath) {
944 *ppAudioPath = This->pDefaultPath;
945 IDirectMusicAudioPath_AddRef(*ppAudioPath);
946 } else {
947 *ppAudioPath = NULL;
949 return S_OK;
952 static HRESULT WINAPI IDirectMusicPerformance8Impl_GetParamEx (LPDIRECTMUSICPERFORMANCE8 iface, REFGUID rguidType, DWORD dwTrackID, DWORD dwGroupBits, DWORD dwIndex, MUSIC_TIME mtTime, MUSIC_TIME* pmtNext, void* pParam) {
953 IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
955 FIXME("(%p, %s, %d, %d, %d, %ld, %p, %p): stub\n", This, debugstr_dmguid(rguidType), dwTrackID, dwGroupBits, dwIndex, mtTime, pmtNext, pParam);
957 return S_OK;
960 static const IDirectMusicPerformance8Vtbl DirectMusicPerformance8_Vtbl = {
961 IDirectMusicPerformance8Impl_QueryInterface,
962 IDirectMusicPerformance8Impl_AddRef,
963 IDirectMusicPerformance8Impl_Release,
964 IDirectMusicPerformance8Impl_Init,
965 IDirectMusicPerformance8Impl_PlaySegment,
966 IDirectMusicPerformance8Impl_Stop,
967 IDirectMusicPerformance8Impl_GetSegmentState,
968 IDirectMusicPerformance8Impl_SetPrepareTime,
969 IDirectMusicPerformance8Impl_GetPrepareTime,
970 IDirectMusicPerformance8Impl_SetBumperLength,
971 IDirectMusicPerformance8Impl_GetBumperLength,
972 IDirectMusicPerformance8Impl_SendPMsg,
973 IDirectMusicPerformance8Impl_MusicToReferenceTime,
974 IDirectMusicPerformance8Impl_ReferenceToMusicTime,
975 IDirectMusicPerformance8Impl_IsPlaying,
976 IDirectMusicPerformance8Impl_GetTime,
977 IDirectMusicPerformance8Impl_AllocPMsg,
978 IDirectMusicPerformance8Impl_FreePMsg,
979 IDirectMusicPerformance8Impl_GetGraph,
980 IDirectMusicPerformance8Impl_SetGraph,
981 IDirectMusicPerformance8Impl_SetNotificationHandle,
982 IDirectMusicPerformance8Impl_GetNotificationPMsg,
983 IDirectMusicPerformance8Impl_AddNotificationType,
984 IDirectMusicPerformance8Impl_RemoveNotificationType,
985 IDirectMusicPerformance8Impl_AddPort,
986 IDirectMusicPerformance8Impl_RemovePort,
987 IDirectMusicPerformance8Impl_AssignPChannelBlock,
988 IDirectMusicPerformance8Impl_AssignPChannel,
989 IDirectMusicPerformance8Impl_PChannelInfo,
990 IDirectMusicPerformance8Impl_DownloadInstrument,
991 IDirectMusicPerformance8Impl_Invalidate,
992 IDirectMusicPerformance8Impl_GetParam,
993 IDirectMusicPerformance8Impl_SetParam,
994 IDirectMusicPerformance8Impl_GetGlobalParam,
995 IDirectMusicPerformance8Impl_SetGlobalParam,
996 IDirectMusicPerformance8Impl_GetLatencyTime,
997 IDirectMusicPerformance8Impl_GetQueueTime,
998 IDirectMusicPerformance8Impl_AdjustTime,
999 IDirectMusicPerformance8Impl_CloseDown,
1000 IDirectMusicPerformance8Impl_GetResolvedTime,
1001 IDirectMusicPerformance8Impl_MIDIToMusic,
1002 IDirectMusicPerformance8Impl_MusicToMIDI,
1003 IDirectMusicPerformance8Impl_TimeToRhythm,
1004 IDirectMusicPerformance8Impl_RhythmToTime,
1005 IDirectMusicPerformance8Impl_InitAudio,
1006 IDirectMusicPerformance8Impl_PlaySegmentEx,
1007 IDirectMusicPerformance8Impl_StopEx,
1008 IDirectMusicPerformance8Impl_ClonePMsg,
1009 IDirectMusicPerformance8Impl_CreateAudioPath,
1010 IDirectMusicPerformance8Impl_CreateStandardAudioPath,
1011 IDirectMusicPerformance8Impl_SetDefaultAudioPath,
1012 IDirectMusicPerformance8Impl_GetDefaultAudioPath,
1013 IDirectMusicPerformance8Impl_GetParamEx
1016 /* for ClassFactory */
1017 HRESULT WINAPI DMUSIC_CreateDirectMusicPerformanceImpl (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
1018 IDirectMusicPerformance8Impl *obj;
1020 TRACE("(%p,%p,%p)\n", lpcGUID, ppobj, pUnkOuter);
1022 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicPerformance8Impl));
1023 if (NULL == obj) {
1024 *ppobj = (LPDIRECTMUSICPERFORMANCE8)NULL;
1025 return E_OUTOFMEMORY;
1027 obj->lpVtbl = &DirectMusicPerformance8_Vtbl;
1028 obj->ref = 0; /* will be inited by QueryInterface */
1029 obj->pDirectMusic = NULL;
1030 obj->pDirectSound = NULL;
1031 obj->pDefaultPath = NULL;
1032 InitializeCriticalSection(&obj->safe);
1033 obj->safe.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IDirectMusicPerformance8Impl*->safe");
1035 obj->rtLatencyTime = 100; /* 100ms TO FIX */
1036 obj->dwBumperLength = 50; /* 50ms default */
1037 obj->dwPrepareTime = 1000; /* 1000ms default */
1038 return IDirectMusicPerformance8Impl_QueryInterface ((LPDIRECTMUSICPERFORMANCE8)obj, lpcGUID, ppobj);