Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1800 lines
48 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dmperformanceobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // dmPerformanceObj.cpp
  11. #include "dmusici.h"
  12. #include "dmusicc.h"
  13. #include "dmusicf.h"
  14. #include "stdafx.h"
  15. #include "Direct.h"
  16. #include "dms.h"
  17. #include "dmPerformanceObj.h"
  18. #include "dmSegmentStateObj.h"
  19. #include "dmSegmentObj.h"
  20. #include "dmStyleObj.h"
  21. #include "dmChordMapObj.h"
  22. #include "dMusAudioPathObj.h"
  23. #include "dsoundobj.h"
  24. extern void *g_dxj_DirectMusicPerformance;
  25. extern void *g_dxj_DirectMusicSegmentState;
  26. extern void *g_dxj_DirectMusicSegment;
  27. extern void *g_dxj_DirectMusicStyle;
  28. extern void *g_dxj_DirectMusicAudioPath;
  29. extern void *g_dxj_DirectMusicChordMap;
  30. extern HRESULT BSTRtoGUID(LPGUID,BSTR);
  31. extern CRITICAL_SECTION g_cbCriticalSection;
  32. extern BOOL IsEmptyString(BSTR szString);
  33. extern BSTR GUIDtoBSTR(LPGUID);
  34. CONSTRUCTOR(_dxj_DirectMusicPerformance, {InternalInit();});
  35. DESTRUCTOR(_dxj_DirectMusicPerformance, {InternalCleanup();});
  36. GETSET_OBJECT(_dxj_DirectMusicPerformance);
  37. typedef IDirectMusicSegment* LPDIRECTMUSICSEGMENT;
  38. typedef IDirectMusicSegmentState* LPDIRECTMUSICSEGMENTSTATE ;
  39. HRESULT C_dxj_DirectMusicPerformanceObject::InternalInit(){
  40. return S_OK;
  41. }
  42. HRESULT C_dxj_DirectMusicPerformanceObject::InternalCleanup(){
  43. __try {
  44. m__dxj_DirectMusicPerformance->CloseDown();
  45. }
  46. __except(EXCEPTION_EXECUTE_HANDLER)
  47. {
  48. return S_OK;
  49. }
  50. return S_OK;
  51. }
  52. HRESULT C_dxj_DirectMusicPerformanceObject::closeDown( )
  53. {
  54. HRESULT hr;
  55. __try {
  56. hr=m__dxj_DirectMusicPerformance->CloseDown();
  57. }
  58. __except(EXCEPTION_EXECUTE_HANDLER)
  59. {
  60. return E_FAIL;
  61. }
  62. return hr;
  63. }
  64. #define VBREF_TO_REALREFTIME(startTime) ((__int64)startTime*10000)
  65. #define REALREF_TO_VBREFTIME(startTime) ((long)(startTime/10000))
  66. HRESULT C_dxj_DirectMusicPerformanceObject::getSegmentState(
  67. /* [in] */ long mtTime,
  68. /* [retval][out] */ I_dxj_DirectMusicSegmentState __RPC_FAR *__RPC_FAR *segmentState)
  69. {
  70. HRESULT hr;
  71. __try {
  72. IDirectMusicSegmentState *pState=NULL;
  73. hr=m__dxj_DirectMusicPerformance->GetSegmentState(&pState,(MUSIC_TIME)mtTime);
  74. if FAILED(hr) return hr;
  75. if (!pState) return E_FAIL;
  76. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicSegmentState,pState,segmentState);
  77. if (*segmentState==NULL) return E_OUTOFMEMORY;
  78. }
  79. __except(EXCEPTION_EXECUTE_HANDLER)
  80. {
  81. return E_FAIL;
  82. }
  83. return hr;
  84. }
  85. HRESULT C_dxj_DirectMusicPerformanceObject::invalidate(
  86. /* [in] */ long mtTime,
  87. /* [in] */ long flags)
  88. {
  89. HRESULT hr;
  90. __try {
  91. hr=m__dxj_DirectMusicPerformance->Invalidate((MUSIC_TIME)mtTime,(DWORD)flags);
  92. }
  93. __except(EXCEPTION_EXECUTE_HANDLER)
  94. {
  95. return E_FAIL;
  96. }
  97. return hr;
  98. }
  99. HRESULT C_dxj_DirectMusicPerformanceObject::isPlaying(
  100. /* [in] */ I_dxj_DirectMusicSegment __RPC_FAR *segment,
  101. /* [in] */ I_dxj_DirectMusicSegmentState __RPC_FAR *segmentState,
  102. /* [retval][out] */ VARIANT_BOOL __RPC_FAR *b)
  103. {
  104. HRESULT hr;
  105. __try {
  106. DO_GETOBJECT_NOTNULL(LPDIRECTMUSICSEGMENT,pSeg,segment);
  107. DO_GETOBJECT_NOTNULL(LPDIRECTMUSICSEGMENTSTATE,pSegState,segmentState);
  108. hr=m__dxj_DirectMusicPerformance->IsPlaying(pSeg,pSegState);
  109. if (hr==S_FALSE){
  110. *b=VARIANT_FALSE;
  111. }
  112. else if (hr==S_OK){
  113. *b=VARIANT_TRUE;
  114. }
  115. else{
  116. return hr;
  117. }
  118. }
  119. __except(EXCEPTION_EXECUTE_HANDLER)
  120. {
  121. return E_FAIL;
  122. }
  123. return S_OK;
  124. }
  125. HRESULT C_dxj_DirectMusicPerformanceObject::addNotificationType(CONST_DMUS_NOTIFICATION_TYPE t)
  126. {
  127. HRESULT hr;
  128. GUID g;
  129. __try {
  130. switch (t){
  131. case DMUS_NOTIFY_ON_CHORD:
  132. g=GUID_NOTIFICATION_CHORD;
  133. break;
  134. case DMUS_NOTIFY_ON_COMMAND:
  135. g=GUID_NOTIFICATION_COMMAND;
  136. break;
  137. case DMUS_NOTIFY_ON_MEASUREANDBEAT:
  138. g=GUID_NOTIFICATION_MEASUREANDBEAT;
  139. break;
  140. case DMUS_NOTIFY_ON_PERFORMANCE:
  141. g=GUID_NOTIFICATION_PERFORMANCE;
  142. break;
  143. case DMUS_NOTIFY_ON_SEGMENT:
  144. g=GUID_NOTIFICATION_SEGMENT;
  145. break;
  146. case DMUS_NOTIFY_ON_RECOMPOSE:
  147. g=GUID_NOTIFICATION_RECOMPOSE;
  148. default:
  149. return E_INVALIDARG;
  150. }
  151. hr=m__dxj_DirectMusicPerformance->AddNotificationType(g);
  152. }
  153. __except(EXCEPTION_EXECUTE_HANDLER)
  154. {
  155. return E_FAIL;
  156. }
  157. return hr;
  158. }
  159. HRESULT C_dxj_DirectMusicPerformanceObject::removeNotificationType( /* [in] */CONST_DMUS_NOTIFICATION_TYPE t)
  160. {
  161. HRESULT hr;
  162. GUID g;
  163. __try {
  164. switch (t){
  165. case DMUS_NOTIFY_ON_CHORD:
  166. g=GUID_NOTIFICATION_CHORD;
  167. break;
  168. case DMUS_NOTIFY_ON_COMMAND:
  169. g=GUID_NOTIFICATION_COMMAND;
  170. break;
  171. case DMUS_NOTIFY_ON_MEASUREANDBEAT:
  172. g=GUID_NOTIFICATION_MEASUREANDBEAT;
  173. break;
  174. case DMUS_NOTIFY_ON_PERFORMANCE:
  175. g=GUID_NOTIFICATION_PERFORMANCE;
  176. break;
  177. case DMUS_NOTIFY_ON_SEGMENT:
  178. g=GUID_NOTIFICATION_SEGMENT;
  179. break;
  180. case DMUS_NOTIFY_ON_RECOMPOSE:
  181. g=GUID_NOTIFICATION_RECOMPOSE;
  182. default:
  183. return E_INVALIDARG;
  184. }
  185. hr=m__dxj_DirectMusicPerformance->RemoveNotificationType(g);
  186. }
  187. __except(EXCEPTION_EXECUTE_HANDLER)
  188. {
  189. return E_FAIL;
  190. }
  191. return hr;
  192. }
  193. #ifdef _WIN64
  194. HRESULT C_dxj_DirectMusicPerformanceObject::setNotificationHandle( /* [in] */ HWND hnd)
  195. #else
  196. HRESULT C_dxj_DirectMusicPerformanceObject::setNotificationHandle( /* [in] */ long hnd)
  197. #endif
  198. {
  199. HRESULT hr;
  200. __try {
  201. hr=m__dxj_DirectMusicPerformance->SetNotificationHandle((HWND)hnd,0);
  202. }
  203. __except(EXCEPTION_EXECUTE_HANDLER)
  204. {
  205. return E_FAIL;
  206. }
  207. return hr;
  208. }
  209. HRESULT C_dxj_DirectMusicPerformanceObject::getNotificationPMSG( DMUS_NOTIFICATION_PMSG_CDESC *pMsgOut, VARIANT_BOOL *bOut)
  210. {
  211. HRESULT hr;
  212. DMUS_NOTIFICATION_PMSG *pMsg=NULL;
  213. IDirectMusicSegmentState *lpState = NULL;
  214. __try {
  215. if (!pMsgOut) return E_INVALIDARG;
  216. if (!bOut) return E_INVALIDARG;
  217. hr=m__dxj_DirectMusicPerformance->GetNotificationPMsg(&pMsg);
  218. if FAILED(hr) return hr;
  219. *bOut=VARIANT_FALSE;
  220. if (!pMsg) return S_OK;
  221. if (hr!=S_FALSE) *bOut=VARIANT_TRUE;
  222. pMsgOut->mtTime=(long)pMsg->mtTime;
  223. pMsgOut->ctTime=(long)REALREF_TO_VBREFTIME(pMsg->rtTime);
  224. pMsgOut->lFlags=(long)pMsg->dwFlags;
  225. pMsgOut->lNotificationOption =pMsg->dwNotificationOption;
  226. pMsgOut->lField1=pMsg->dwField1;
  227. pMsgOut->lField2=pMsg->dwField2;
  228. if (pMsg->punkUser)
  229. {
  230. if (SUCCEEDED( hr = pMsg->punkUser->QueryInterface(IID_IDirectMusicSegmentState, (void**)&lpState) ) )
  231. {
  232. // Create an instance of the segment state and return it to VB
  233. INTERNAL_CREATE(_dxj_DirectMusicSegmentState,lpState,&pMsgOut->User);
  234. }
  235. }
  236. if (0==memcmp(&GUID_NOTIFICATION_CHORD,&pMsg->guidNotificationType,sizeof(GUID))){
  237. pMsgOut->lNotificationType=DMUS_NOTIFY_ON_CHORD;
  238. }
  239. else if (0==memcmp(&GUID_NOTIFICATION_COMMAND,&pMsg->guidNotificationType,sizeof(GUID))){
  240. pMsgOut->lNotificationType=DMUS_NOTIFY_ON_COMMAND;
  241. }
  242. else if (0==memcmp(&GUID_NOTIFICATION_MEASUREANDBEAT,&pMsg->guidNotificationType,sizeof(GUID))){
  243. pMsgOut->lNotificationType=DMUS_NOTIFY_ON_MEASUREANDBEAT;
  244. }
  245. else if (0==memcmp(&GUID_NOTIFICATION_PERFORMANCE,&pMsg->guidNotificationType,sizeof(GUID))){
  246. pMsgOut->lNotificationType=DMUS_NOTIFY_ON_PERFORMANCE;
  247. }
  248. else if (0==memcmp(&GUID_NOTIFICATION_SEGMENT,&pMsg->guidNotificationType,sizeof(GUID))){
  249. pMsgOut->lNotificationType=DMUS_NOTIFY_ON_SEGMENT;
  250. }
  251. else if (0==memcmp(&GUID_NOTIFICATION_RECOMPOSE,&pMsg->guidNotificationType,sizeof(GUID))){
  252. pMsgOut->lNotificationType=DMUS_NOTIFY_ON_RECOMPOSE;
  253. }
  254. else {
  255. pMsgOut->lNotificationType=0;
  256. }
  257. m__dxj_DirectMusicPerformance->FreePMsg((DMUS_PMSG *)pMsg);
  258. }
  259. __except(EXCEPTION_EXECUTE_HANDLER)
  260. {
  261. return E_FAIL;
  262. }
  263. return hr;
  264. }
  265. HRESULT C_dxj_DirectMusicPerformanceObject::musicToClockTime( /* [in] */ long mtTime,
  266. /* [retval][out] */ long __RPC_FAR *rtTime)
  267. {
  268. HRESULT hr;
  269. __int64 outTime;
  270. __try {
  271. hr=m__dxj_DirectMusicPerformance->MusicToReferenceTime((MUSIC_TIME)mtTime,&outTime);
  272. if FAILED(hr) return hr;
  273. *rtTime=REALREF_TO_VBREFTIME(outTime);
  274. }
  275. __except(EXCEPTION_EXECUTE_HANDLER)
  276. {
  277. return E_FAIL;
  278. }
  279. return hr;
  280. }
  281. HRESULT C_dxj_DirectMusicPerformanceObject::clockToMusicTime( /* [in] */ long rtTime,
  282. /* [retval][out] */ long __RPC_FAR *mtTime)
  283. {
  284. HRESULT hr;
  285. __try {
  286. __int64 outTime=VBREF_TO_REALREFTIME(rtTime);;
  287. hr=m__dxj_DirectMusicPerformance->ReferenceToMusicTime(outTime,(MUSIC_TIME*)mtTime);
  288. }
  289. __except(EXCEPTION_EXECUTE_HANDLER)
  290. {
  291. return E_FAIL;
  292. }
  293. return hr;
  294. }
  295. HRESULT C_dxj_DirectMusicPerformanceObject::getMusicTime( /* [retval][out] */ long __RPC_FAR *mtTime)
  296. {
  297. HRESULT hr;
  298. __try {
  299. hr=m__dxj_DirectMusicPerformance->GetTime(NULL,(MUSIC_TIME*)mtTime);
  300. }
  301. __except(EXCEPTION_EXECUTE_HANDLER)
  302. {
  303. return E_FAIL;
  304. }
  305. return hr;
  306. }
  307. HRESULT C_dxj_DirectMusicPerformanceObject::getClockTime( /* [retval][out] */ long __RPC_FAR *rtTime)
  308. {
  309. HRESULT hr;
  310. __try {
  311. __int64 outTime=0;
  312. hr=m__dxj_DirectMusicPerformance->GetTime(&outTime,NULL);
  313. *rtTime=REALREF_TO_VBREFTIME(outTime);
  314. }
  315. __except(EXCEPTION_EXECUTE_HANDLER)
  316. {
  317. return E_FAIL;
  318. }
  319. return hr;
  320. }
  321. HRESULT C_dxj_DirectMusicPerformanceObject::getPrepareTime( /* [retval][out] */ long __RPC_FAR *pTime)
  322. {
  323. HRESULT hr;
  324. __try {
  325. hr=m__dxj_DirectMusicPerformance->GetPrepareTime((DWORD*)pTime);
  326. }
  327. __except(EXCEPTION_EXECUTE_HANDLER)
  328. {
  329. return E_FAIL;
  330. }
  331. return hr;
  332. }
  333. HRESULT C_dxj_DirectMusicPerformanceObject::getBumperLength(/* [retval][out] */ long __RPC_FAR *pTime)
  334. {
  335. HRESULT hr;
  336. __try {
  337. hr=m__dxj_DirectMusicPerformance->GetBumperLength((DWORD*)pTime);
  338. }
  339. __except(EXCEPTION_EXECUTE_HANDLER)
  340. {
  341. return E_FAIL;
  342. }
  343. return hr;
  344. }
  345. HRESULT C_dxj_DirectMusicPerformanceObject::getLatencyTime( /* [retval][out] */ long __RPC_FAR *pTime)
  346. {
  347. HRESULT hr;
  348. __int64 t;
  349. __try {
  350. if (!pTime) return E_INVALIDARG;
  351. hr=m__dxj_DirectMusicPerformance->GetLatencyTime(&t);
  352. *pTime=REALREF_TO_VBREFTIME(t);
  353. }
  354. __except(EXCEPTION_EXECUTE_HANDLER)
  355. {
  356. return E_FAIL;
  357. }
  358. return hr;
  359. }
  360. HRESULT C_dxj_DirectMusicPerformanceObject::getQueueTime( /* [retval][out] */ long __RPC_FAR *pTime)
  361. {
  362. HRESULT hr;
  363. __int64 t;
  364. __try {
  365. if (!pTime) return E_INVALIDARG;
  366. hr=m__dxj_DirectMusicPerformance->GetQueueTime(&t);
  367. *pTime=REALREF_TO_VBREFTIME(t);
  368. }
  369. __except(EXCEPTION_EXECUTE_HANDLER)
  370. {
  371. return E_FAIL;
  372. }
  373. return hr;
  374. }
  375. HRESULT C_dxj_DirectMusicPerformanceObject::getResolvedTime( /* [in] */ long rtTime, /* [in] */ long flags, /* [retval][out] */ long __RPC_FAR *ret)
  376. {
  377. HRESULT hr;
  378. __try {
  379. __int64 outtime1= VBREF_TO_REALREFTIME(rtTime);
  380. __int64 outtime2=0;
  381. hr=m__dxj_DirectMusicPerformance->GetResolvedTime(outtime1,&outtime2,(DWORD)flags);
  382. *ret=REALREF_TO_VBREFTIME(outtime2);
  383. }
  384. __except(EXCEPTION_EXECUTE_HANDLER)
  385. {
  386. return E_FAIL;
  387. }
  388. return hr;
  389. }
  390. HRESULT C_dxj_DirectMusicPerformanceObject::setPrepareTime( /* [retval][out] */ long t)
  391. {
  392. HRESULT hr;
  393. __try {
  394. hr=m__dxj_DirectMusicPerformance->SetPrepareTime((DWORD)t);
  395. }
  396. __except(EXCEPTION_EXECUTE_HANDLER)
  397. {
  398. return E_FAIL;
  399. }
  400. return hr;
  401. }
  402. HRESULT C_dxj_DirectMusicPerformanceObject::setBumperLength(/* [retval][out] */ long t)
  403. {
  404. HRESULT hr;
  405. __try {
  406. hr=m__dxj_DirectMusicPerformance->SetBumperLength((DWORD)t);
  407. }
  408. __except(EXCEPTION_EXECUTE_HANDLER)
  409. {
  410. return E_FAIL;
  411. }
  412. return hr;
  413. }
  414. HRESULT C_dxj_DirectMusicPerformanceObject::adjustTime(
  415. /* [retval][out] */ long t)
  416. {
  417. HRESULT hr;
  418. __try {
  419. REFERENCE_TIME rt =(REFERENCE_TIME)t;
  420. hr=m__dxj_DirectMusicPerformance->AdjustTime(rt);
  421. }
  422. __except(EXCEPTION_EXECUTE_HANDLER)
  423. {
  424. return E_FAIL;
  425. }
  426. return hr;
  427. }
  428. HRESULT C_dxj_DirectMusicPerformanceObject::setMasterAutoDownload( /* [in] */ VARIANT_BOOL bval)
  429. {
  430. HRESULT hr;
  431. __try {
  432. BOOL b=(BOOL)(bval==VARIANT_TRUE);
  433. hr=m__dxj_DirectMusicPerformance->SetGlobalParam(GUID_PerfAutoDownload,(void*)&b,sizeof(BOOL));
  434. }
  435. __except(EXCEPTION_EXECUTE_HANDLER)
  436. {
  437. return E_FAIL;
  438. }
  439. return hr;
  440. }
  441. HRESULT C_dxj_DirectMusicPerformanceObject::getMasterAutoDownload( /* [in] */ VARIANT_BOOL *bIn)
  442. {
  443. HRESULT hr;
  444. BOOL b;
  445. __try {
  446. hr=m__dxj_DirectMusicPerformance->GetGlobalParam(GUID_PerfAutoDownload,(void*) &b,sizeof(BOOL));
  447. if (b){
  448. *bIn=VARIANT_TRUE;
  449. }
  450. else{
  451. *bIn=VARIANT_FALSE;
  452. }
  453. }
  454. __except(EXCEPTION_EXECUTE_HANDLER)
  455. {
  456. return E_FAIL;
  457. }
  458. return hr;
  459. }
  460. HRESULT C_dxj_DirectMusicPerformanceObject::setMasterTempo( /* [in] */ float tempo)
  461. {
  462. HRESULT hr;
  463. __try {
  464. hr=m__dxj_DirectMusicPerformance->SetGlobalParam( GUID_PerfMasterTempo ,(void*) &tempo,sizeof(float));
  465. }
  466. __except(EXCEPTION_EXECUTE_HANDLER)
  467. {
  468. return E_FAIL;
  469. }
  470. return hr;
  471. }
  472. HRESULT C_dxj_DirectMusicPerformanceObject::getMasterTempo( /* [in] */ float *tempo)
  473. {
  474. HRESULT hr;
  475. __try {
  476. hr=m__dxj_DirectMusicPerformance->GetGlobalParam( GUID_PerfMasterTempo ,(void*) tempo,sizeof(float));
  477. }
  478. __except(EXCEPTION_EXECUTE_HANDLER)
  479. {
  480. return E_FAIL;
  481. }
  482. return hr;
  483. }
  484. HRESULT C_dxj_DirectMusicPerformanceObject::setMasterVolume( /* [in] */ long vol)
  485. {
  486. HRESULT hr;
  487. __try {
  488. hr=m__dxj_DirectMusicPerformance->SetGlobalParam(GUID_PerfMasterVolume ,(void*) &vol,sizeof(long));
  489. }
  490. __except(EXCEPTION_EXECUTE_HANDLER)
  491. {
  492. return E_FAIL;
  493. }
  494. return hr;
  495. }
  496. HRESULT C_dxj_DirectMusicPerformanceObject::getMasterVolume( /* [in] */ long *vol)
  497. {
  498. HRESULT hr;
  499. __try {
  500. hr=m__dxj_DirectMusicPerformance->GetGlobalParam(GUID_PerfMasterVolume ,(void*) vol,sizeof(long));
  501. }
  502. __except(EXCEPTION_EXECUTE_HANDLER)
  503. {
  504. return E_FAIL;
  505. }
  506. return hr;
  507. }
  508. HRESULT C_dxj_DirectMusicPerformanceObject::setMasterGrooveLevel( /* [in] */ short level)
  509. {
  510. HRESULT hr;
  511. __try {
  512. char l=(char)level;
  513. hr=m__dxj_DirectMusicPerformance->SetGlobalParam(GUID_PerfMasterGrooveLevel ,(void*) &l,sizeof(char));
  514. }
  515. __except(EXCEPTION_EXECUTE_HANDLER)
  516. {
  517. return E_FAIL;
  518. }
  519. return hr;
  520. }
  521. HRESULT C_dxj_DirectMusicPerformanceObject::getMasterGrooveLevel( /* [in] */ short *level)
  522. {
  523. HRESULT hr;
  524. __try {
  525. if (!level) return E_INVALIDARG;
  526. char l=0;
  527. hr=m__dxj_DirectMusicPerformance->GetGlobalParam(GUID_PerfMasterGrooveLevel ,(void*) &l,sizeof(char));
  528. *level=(short)l;
  529. }
  530. __except(EXCEPTION_EXECUTE_HANDLER)
  531. {
  532. return E_FAIL;
  533. }
  534. return hr;
  535. }
  536. HRESULT C_dxj_DirectMusicPerformanceObject::Reset(long resetFlags)
  537. {
  538. DMUS_SYSEX_PMSG *pGMReset;
  539. BYTE abGMReset[] = {0xF0,0x7E,0x7F,0x09,0x01,0xF7};
  540. DWORD dwLen;
  541. HRESULT hr=S_OK;
  542. __try {
  543. if (!resetFlags){
  544. dwLen = sizeof(abGMReset)/sizeof(abGMReset[0]);
  545. if(SUCCEEDED( m__dxj_DirectMusicPerformance->AllocPMsg( sizeof(DMUS_SYSEX_PMSG) + dwLen,
  546. (DMUS_PMSG**)&pGMReset )))
  547. {
  548. ZeroMemory(pGMReset, sizeof(pGMReset));
  549. pGMReset->dwSize = sizeof(DMUS_SYSEX_PMSG);
  550. pGMReset->dwPChannel = 0;
  551. pGMReset->dwVirtualTrackID = 0;
  552. pGMReset->dwType = DMUS_PMSGT_SYSEX ;
  553. pGMReset->dwVoiceID = 0;
  554. pGMReset->dwGroupID = 0xFFFFFFFF;
  555. pGMReset->dwLen = dwLen;
  556. memcpy(pGMReset->abData, abGMReset, dwLen);
  557. if (SUCCEEDED(m__dxj_DirectMusicPerformance->GetTime(NULL, &pGMReset->mtTime)))
  558. {
  559. pGMReset->dwFlags = DMUS_PMSGF_MUSICTIME | DMUS_PMSGF_TOOL_IMMEDIATE;
  560. }
  561. hr=m__dxj_DirectMusicPerformance->SendPMsg((DMUS_PMSG*)pGMReset);
  562. if (FAILED(hr))
  563. m__dxj_DirectMusicPerformance->FreePMsg((DMUS_PMSG*)pGMReset);
  564. }
  565. }
  566. else if(resetFlags==1){
  567. //1) Find out what port we're playing through
  568. //2) Close the port
  569. //3) Open the port back up.
  570. //hr=setPort(m_portid,m_number_of_groups);
  571. }
  572. else {
  573. hr=E_INVALIDARG;
  574. }
  575. }
  576. __except(EXCEPTION_EXECUTE_HANDLER)
  577. {
  578. return E_FAIL;
  579. }
  580. return hr;
  581. }
  582. HRESULT C_dxj_DirectMusicPerformanceObject::getStyle(
  583. /* [in] */ long mtTime,
  584. /* [in] */ long *mtUntil,
  585. /* [retval][out] */ I_dxj_DirectMusicStyle __RPC_FAR *__RPC_FAR *ret)
  586. {
  587. HRESULT hr;
  588. IDirectMusicStyle *pStyle=NULL;
  589. __try {
  590. if (!ret) return E_INVALIDARG;
  591. *ret=NULL;
  592. hr=m__dxj_DirectMusicPerformance->GetParam(GUID_IDirectMusicStyle,0xFFFFFFFF,(DWORD)0,(MUSIC_TIME)mtTime,(MUSIC_TIME*)mtUntil,&pStyle );
  593. if FAILED(hr) return hr;
  594. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicStyle,pStyle,ret);
  595. if (*ret==NULL) return E_OUTOFMEMORY;
  596. }
  597. __except(EXCEPTION_EXECUTE_HANDLER)
  598. {
  599. return E_FAIL;
  600. }
  601. return hr;
  602. }
  603. HRESULT C_dxj_DirectMusicPerformanceObject::getChordMap(
  604. /* [in] */ long mtTime,
  605. /* [in] */ long *mtUntil,
  606. /* [retval][out] */ I_dxj_DirectMusicChordMap __RPC_FAR *__RPC_FAR *ret)
  607. {
  608. HRESULT hr;
  609. IDirectMusicChordMap *pMap=NULL;
  610. __try {
  611. if (!ret) return E_INVALIDARG;
  612. *ret=NULL;
  613. hr=m__dxj_DirectMusicPerformance->GetParam(GUID_IDirectMusicChordMap,0xFFFFFFFF,(DWORD)0,(MUSIC_TIME)mtTime,(MUSIC_TIME*)mtUntil,&pMap );
  614. if FAILED(hr) return hr;
  615. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicChordMap,pMap,ret);
  616. if (*ret==NULL) return E_OUTOFMEMORY;
  617. }
  618. __except(EXCEPTION_EXECUTE_HANDLER)
  619. {
  620. return E_FAIL;
  621. }
  622. return hr;
  623. }
  624. HRESULT C_dxj_DirectMusicPerformanceObject::getCommand(
  625. /* [in] */ long mtTime,
  626. /* [in] */ long *mtUntil,
  627. /* [retval][out] */ Byte __RPC_FAR *command)
  628. {
  629. HRESULT hr;
  630. DMUS_COMMAND_PARAM cmd;
  631. __try {
  632. if (!command) return E_INVALIDARG;
  633. hr=m__dxj_DirectMusicPerformance->GetParam(GUID_CommandParam,0xFFFFFFFF,(DWORD)0,(MUSIC_TIME)mtTime,(MUSIC_TIME*)mtUntil,&cmd );
  634. if FAILED(hr) return hr;
  635. *command=cmd.bCommand;
  636. }
  637. __except(EXCEPTION_EXECUTE_HANDLER)
  638. {
  639. return E_FAIL;
  640. }
  641. return hr;
  642. }
  643. HRESULT C_dxj_DirectMusicPerformanceObject::getGrooveLevel(
  644. /* [in] */ long mtTime,
  645. /* [in] */ long *mtUntil,
  646. /* [retval][out] */ Byte __RPC_FAR *level)
  647. {
  648. HRESULT hr;
  649. DMUS_COMMAND_PARAM cmd;
  650. __try {
  651. if (!level) return E_INVALIDARG;
  652. hr=m__dxj_DirectMusicPerformance->GetParam(GUID_CommandParam,0xFFFFFFFF,(DWORD)0,(MUSIC_TIME)mtTime,(MUSIC_TIME*)mtUntil,&cmd );
  653. if FAILED(hr) return hr;
  654. *level=cmd.bGrooveLevel;
  655. }
  656. __except(EXCEPTION_EXECUTE_HANDLER)
  657. {
  658. return E_FAIL;
  659. }
  660. return hr;
  661. }
  662. HRESULT C_dxj_DirectMusicPerformanceObject::getTempo(
  663. /* [in] */ long mtTime,
  664. /* [in] */ long *mtUntil,
  665. /* [retval][out] */ double __RPC_FAR *tempo)
  666. {
  667. HRESULT hr;
  668. DMUS_TEMPO_PARAM tmp;
  669. __try {
  670. if (!tempo) return E_INVALIDARG;
  671. hr=m__dxj_DirectMusicPerformance->GetParam(GUID_TempoParam,0xFFFFFFFF,(DWORD)0,(MUSIC_TIME)mtTime,(MUSIC_TIME*)mtUntil,&tmp );
  672. if FAILED(hr) return hr;
  673. *tempo=tmp.dblTempo;
  674. }
  675. __except(EXCEPTION_EXECUTE_HANDLER)
  676. {
  677. return E_FAIL;
  678. }
  679. return hr;
  680. }
  681. HRESULT C_dxj_DirectMusicPerformanceObject::getTimeSig(
  682. /* [in] */ long mtTime,
  683. /* [in] */ long *mtUntil,
  684. /* [out][in] */ DMUS_TIMESIGNATURE_CDESC __RPC_FAR *timeSig)
  685. {
  686. HRESULT hr;
  687. __try {
  688. if (!timeSig) return E_INVALIDARG;
  689. hr=m__dxj_DirectMusicPerformance->GetParam(GUID_TimeSignature,0xFFFFFFFF,(DWORD)0,(MUSIC_TIME)mtTime,(MUSIC_TIME*)mtUntil,(DMUS_TIMESIGNATURE*)timeSig);
  690. }
  691. __except(EXCEPTION_EXECUTE_HANDLER)
  692. {
  693. return E_FAIL;
  694. }
  695. return hr;
  696. }
  697. HRESULT C_dxj_DirectMusicPerformanceObject::sendNotePMSG(
  698. /* [in] */ long mtTime,
  699. /* [in] */ long flags,
  700. /* [in] */ long channel,
  701. /* [in] */ DMUS_NOTE_PMSG_CDESC __RPC_FAR *msg)
  702. {
  703. HRESULT hr;
  704. DMUS_NOTE_PMSG *pPMSG=NULL;
  705. __try {
  706. if (!msg) return E_INVALIDARG;
  707. hr= m__dxj_DirectMusicPerformance->AllocPMsg( sizeof(DMUS_NOTE_PMSG),(DMUS_PMSG**)&pPMSG);
  708. if FAILED(hr) return hr;
  709. //memcpy(pPMSG,msg,sizeof(DMUS_NOTE_PMSG));
  710. //depends on alignment settings
  711. //and how dll is compiled to work right.
  712. //copy member by member instead..
  713. ZeroMemory(pPMSG,sizeof(DMUS_NOTE_PMSG));
  714. pPMSG->dwSize=sizeof(DMUS_NOTE_PMSG);
  715. pPMSG->mtTime=(MUSIC_TIME)mtTime;
  716. pPMSG->dwFlags=(DWORD)flags;
  717. pPMSG->dwType=DMUS_PMSGT_NOTE;
  718. pPMSG->dwPChannel =(DWORD)channel;
  719. pPMSG->dwVirtualTrackID =(DWORD)0;
  720. pPMSG->dwGroupID=(DWORD)-1;
  721. pPMSG->mtDuration=(MUSIC_TIME)msg->mtDuration;
  722. pPMSG->wMusicValue=(WORD)msg->musicValue;
  723. pPMSG->wMeasure=(WORD)msg->measure;
  724. pPMSG->nOffset=(short)msg->offset;
  725. pPMSG->bBeat=(BYTE)msg->beat;
  726. pPMSG->bGrid=(BYTE)msg->grid;
  727. pPMSG->bVelocity=(BYTE)msg->velocity;
  728. pPMSG->bFlags=(BYTE)msg->flags;
  729. pPMSG->bTimeRange=(BYTE)msg->timeRange;
  730. pPMSG->bDurRange=(BYTE)msg->durRange;
  731. pPMSG->bVelRange=(BYTE)msg->velRange;
  732. pPMSG->bPlayModeFlags=(BYTE)msg->playModeFlags;
  733. pPMSG->bSubChordLevel=(BYTE)msg->subChordLevel;
  734. pPMSG->bMidiValue=(BYTE)msg->midiValue;
  735. pPMSG->cTranspose=(char)msg->transpose;
  736. if (!flags) pPMSG->dwFlags= DMUS_PMSGF_MUSICTIME;
  737. hr=m__dxj_DirectMusicPerformance->SendPMsg((DMUS_PMSG*)pPMSG);
  738. if (FAILED(hr))
  739. m__dxj_DirectMusicPerformance->FreePMsg((DMUS_PMSG*)pPMSG);
  740. }
  741. __except(EXCEPTION_EXECUTE_HANDLER)
  742. {
  743. return E_FAIL;
  744. }
  745. return hr;
  746. }
  747. HRESULT C_dxj_DirectMusicPerformanceObject::sendCurvePMSG(
  748. /* [in] */ long mtTime,
  749. /* [in] */ long flags,
  750. /* [in] */ long channel,
  751. /* [in] */ DMUS_CURVE_PMSG_CDESC __RPC_FAR *msg)
  752. {
  753. HRESULT hr;
  754. DMUS_CURVE_PMSG *pPMSG=NULL;
  755. if (!msg) return E_INVALIDARG;
  756. __try {
  757. hr= m__dxj_DirectMusicPerformance->AllocPMsg( sizeof(DMUS_CURVE_PMSG),(DMUS_PMSG**)&pPMSG);
  758. pPMSG->dwSize=sizeof(DMUS_CURVE_PMSG);
  759. pPMSG->mtTime=(MUSIC_TIME)mtTime;
  760. pPMSG->dwFlags=(DWORD)flags;
  761. pPMSG->dwType=DMUS_PMSGT_CURVE;
  762. pPMSG->dwPChannel =(DWORD)channel;
  763. pPMSG->dwVirtualTrackID =(DWORD)0;
  764. pPMSG->dwGroupID=(DWORD)-1;
  765. if (!flags) pPMSG->dwFlags= DMUS_PMSGF_MUSICTIME;
  766. pPMSG->mtDuration=msg->mtDuration;
  767. pPMSG->mtOriginalStart=msg->mtOriginalStart;
  768. pPMSG->mtResetDuration=msg->mtResetDuration;
  769. pPMSG->nStartValue =(short)msg->startValue;
  770. pPMSG->nEndValue =(short)msg->endValue;
  771. pPMSG->nResetValue =(short)msg->resetValue;
  772. pPMSG->wMeasure =(short)msg->measure;
  773. pPMSG->nOffset =(short)msg->offset;
  774. pPMSG->bBeat =(Byte)msg->beat;
  775. pPMSG->bGrid =(Byte)msg->grid;
  776. pPMSG->bType =(Byte)msg->type;
  777. pPMSG->bCurveShape =(Byte)msg->curveShape;
  778. pPMSG->bCCData =(Byte)msg->ccData;
  779. pPMSG->bFlags =(Byte)msg->flags | DMUS_PMSGF_DX8;
  780. pPMSG->wParamType = (short) msg->ParamType;
  781. pPMSG->wMergeIndex = (short) msg->MergeIndex;
  782. hr=m__dxj_DirectMusicPerformance->SendPMsg((DMUS_PMSG*)pPMSG);
  783. if (FAILED(hr))
  784. m__dxj_DirectMusicPerformance->FreePMsg((DMUS_PMSG*)pPMSG);
  785. }
  786. __except(EXCEPTION_EXECUTE_HANDLER)
  787. {
  788. return E_FAIL;
  789. }
  790. return hr;
  791. }
  792. HRESULT C_dxj_DirectMusicPerformanceObject::sendMIDIPMSG(
  793. /* [in] */ long mtTime,
  794. /* [in] */ long flags,
  795. /* [in] */ long channel,
  796. /* [in] */ Byte status,
  797. /* [in] */ Byte byte1,
  798. /* [in] */ Byte byte2)
  799. {
  800. HRESULT hr;
  801. DMUS_MIDI_PMSG *pPMSG=NULL;
  802. __try {
  803. hr= m__dxj_DirectMusicPerformance->AllocPMsg( sizeof(DMUS_MIDI_PMSG),(DMUS_PMSG**)&pPMSG);
  804. ZeroMemory(pPMSG,sizeof(DMUS_MIDI_PMSG));
  805. pPMSG->dwSize=sizeof(DMUS_MIDI_PMSG);
  806. pPMSG->mtTime=(MUSIC_TIME)mtTime;
  807. pPMSG->dwFlags=(DWORD)flags;
  808. pPMSG->dwType=DMUS_PMSGT_MIDI;
  809. pPMSG->dwPChannel =(DWORD)channel;
  810. pPMSG->dwVirtualTrackID =(DWORD)0;
  811. pPMSG->dwGroupID=(DWORD)-1;
  812. pPMSG->bStatus=status;
  813. pPMSG->bByte1=byte1;
  814. pPMSG->bByte2=byte2;
  815. if (!flags) pPMSG->dwFlags= DMUS_PMSGF_MUSICTIME;
  816. hr=m__dxj_DirectMusicPerformance->SendPMsg((DMUS_PMSG*)pPMSG);
  817. if (FAILED(hr))
  818. m__dxj_DirectMusicPerformance->FreePMsg((DMUS_PMSG*)pPMSG);
  819. }
  820. __except(EXCEPTION_EXECUTE_HANDLER)
  821. {
  822. return E_FAIL;
  823. }
  824. return hr;
  825. }
  826. HRESULT C_dxj_DirectMusicPerformanceObject::sendPatchPMSG(
  827. /* [in] */ long mtTime,
  828. /* [in] */ long flags,
  829. /* [in] */ long channel,
  830. /* [in] */ Byte instrument,
  831. /* [in] */ Byte byte1,
  832. /* [in] */ Byte byte2)
  833. {
  834. HRESULT hr;
  835. DMUS_PATCH_PMSG *pPMSG=NULL;
  836. __try {
  837. hr= m__dxj_DirectMusicPerformance->AllocPMsg( sizeof(DMUS_PATCH_PMSG),(DMUS_PMSG**)&pPMSG);
  838. ZeroMemory(pPMSG,sizeof(DMUS_PATCH_PMSG));
  839. pPMSG->dwSize=sizeof(DMUS_PATCH_PMSG);
  840. pPMSG->mtTime=(MUSIC_TIME)mtTime;
  841. pPMSG->dwFlags=(DWORD)flags;
  842. pPMSG->dwType=DMUS_PMSGT_PATCH;
  843. pPMSG->dwPChannel =(DWORD)channel;
  844. pPMSG->dwVirtualTrackID =(DWORD)0;
  845. pPMSG->dwGroupID=(DWORD)-1;
  846. pPMSG->byInstrument=instrument;
  847. pPMSG->byMSB=byte1;
  848. pPMSG->byLSB=byte2;
  849. if (!flags) pPMSG->dwFlags= DMUS_PMSGF_MUSICTIME;
  850. hr=m__dxj_DirectMusicPerformance->SendPMsg((DMUS_PMSG*)pPMSG);
  851. if (FAILED(hr))
  852. m__dxj_DirectMusicPerformance->FreePMsg((DMUS_PMSG*)pPMSG);
  853. }
  854. __except(EXCEPTION_EXECUTE_HANDLER)
  855. {
  856. return E_FAIL;
  857. }
  858. return hr;
  859. }
  860. HRESULT C_dxj_DirectMusicPerformanceObject::sendTempoPMSG(
  861. /* [in] */ long mtTime,
  862. /* [in] */ long flags,
  863. ///* [in] */ long channel,
  864. /* [in] */ double tempo)
  865. {
  866. HRESULT hr;
  867. DMUS_TEMPO_PMSG *pPMSG=NULL;
  868. __try {
  869. hr= m__dxj_DirectMusicPerformance->AllocPMsg( sizeof(DMUS_TEMPO_PMSG),(DMUS_PMSG**)&pPMSG);
  870. ZeroMemory(pPMSG,sizeof(DMUS_TEMPO_PMSG));
  871. pPMSG->dwSize=sizeof(DMUS_TEMPO_PMSG);
  872. pPMSG->mtTime=(MUSIC_TIME)mtTime;
  873. pPMSG->dwFlags=(DWORD)flags;
  874. pPMSG->dwType=DMUS_PMSGT_TEMPO;
  875. pPMSG->dwPChannel =(DWORD)0;
  876. pPMSG->dwVirtualTrackID =(DWORD)0;
  877. pPMSG->dwGroupID=(DWORD)-1;
  878. pPMSG->dblTempo=tempo;
  879. if (!flags) pPMSG->dwFlags= DMUS_PMSGF_MUSICTIME;
  880. hr=m__dxj_DirectMusicPerformance->SendPMsg((DMUS_PMSG*)pPMSG);
  881. if (FAILED(hr))
  882. m__dxj_DirectMusicPerformance->FreePMsg((DMUS_PMSG*)pPMSG);
  883. }
  884. __except(EXCEPTION_EXECUTE_HANDLER)
  885. {
  886. return E_FAIL;
  887. }
  888. return hr;
  889. }
  890. HRESULT C_dxj_DirectMusicPerformanceObject::sendTransposePMSG(
  891. /* [in] */ long mtTime,
  892. /* [in] */ long flags,
  893. /* [in] */ long channel,
  894. /* [in] */ short transpose)
  895. {
  896. HRESULT hr;
  897. DMUS_TRANSPOSE_PMSG *pPMSG=NULL;
  898. __try {
  899. hr= m__dxj_DirectMusicPerformance->AllocPMsg( sizeof(DMUS_TRANSPOSE_PMSG),(DMUS_PMSG**)&pPMSG);
  900. ZeroMemory(pPMSG,sizeof(DMUS_TRANSPOSE_PMSG));
  901. pPMSG->dwSize=sizeof(DMUS_TRANSPOSE_PMSG);
  902. pPMSG->mtTime=(MUSIC_TIME)mtTime;
  903. pPMSG->dwFlags=(DWORD)flags;
  904. pPMSG->dwType=DMUS_PMSGT_TRANSPOSE;
  905. pPMSG->dwPChannel =(DWORD)channel;
  906. pPMSG->dwVirtualTrackID =(DWORD)0;
  907. pPMSG->dwGroupID=(DWORD)-1;
  908. pPMSG->nTranspose=transpose;
  909. if (!flags) pPMSG->dwFlags= DMUS_PMSGF_MUSICTIME;
  910. hr=m__dxj_DirectMusicPerformance->SendPMsg((DMUS_PMSG*)pPMSG);
  911. if (FAILED(hr))
  912. m__dxj_DirectMusicPerformance->FreePMsg((DMUS_PMSG*)pPMSG);
  913. }
  914. __except(EXCEPTION_EXECUTE_HANDLER)
  915. {
  916. return E_FAIL;
  917. }
  918. return hr;
  919. }
  920. HRESULT C_dxj_DirectMusicPerformanceObject::sendTimeSigPMSG(
  921. /* [in] */ long mtTime,
  922. /* [in] */ long flags,
  923. /* [in] */ DMUS_TIMESIGNATURE_CDESC __RPC_FAR *timesig)
  924. {
  925. HRESULT hr;
  926. DMUS_TIMESIG_PMSG *pPMSG=NULL;
  927. if (!timesig) return E_INVALIDARG;
  928. __try {
  929. hr= m__dxj_DirectMusicPerformance->AllocPMsg( sizeof(DMUS_TIMESIG_PMSG),(DMUS_PMSG**)&pPMSG);
  930. ZeroMemory(pPMSG,sizeof(DMUS_TIMESIG_PMSG));
  931. pPMSG->dwSize=sizeof(DMUS_TIMESIG_PMSG);
  932. pPMSG->mtTime=(MUSIC_TIME)mtTime;
  933. pPMSG->dwFlags=(DWORD)flags;
  934. pPMSG->dwType=DMUS_PMSGT_TIMESIG;
  935. pPMSG->dwPChannel =(DWORD)0;
  936. pPMSG->dwVirtualTrackID =(DWORD)0;
  937. pPMSG->dwGroupID=(DWORD)-1;
  938. if (!flags) pPMSG->dwFlags= DMUS_PMSGF_MUSICTIME;
  939. pPMSG->bBeatsPerMeasure =timesig->beatsPerMeasure;
  940. pPMSG->bBeat=timesig->beat;
  941. pPMSG->wGridsPerBeat=timesig->gridsPerBeat;
  942. hr=m__dxj_DirectMusicPerformance->SendPMsg((DMUS_PMSG*)pPMSG);
  943. if (FAILED(hr))
  944. m__dxj_DirectMusicPerformance->FreePMsg((DMUS_PMSG*)pPMSG);
  945. }
  946. __except(EXCEPTION_EXECUTE_HANDLER)
  947. {
  948. return E_FAIL;
  949. }
  950. return hr;
  951. }
  952. #ifdef _WIN64
  953. HRESULT C_dxj_DirectMusicPerformanceObject::InitAudio(HWND hWnd,
  954. long lFlags,
  955. DMUS_AUDIOPARAMS_CDESC *AudioParams,
  956. I_dxj_DirectSound **DirectSound,
  957. long lDefaultPathType,
  958. long lPChannelCount)
  959. #else
  960. HRESULT C_dxj_DirectMusicPerformanceObject::InitAudio(long hWnd,
  961. long lFlags,
  962. DMUS_AUDIOPARAMS_CDESC *AudioParams,
  963. I_dxj_DirectSound **DirectSound,
  964. long lDefaultPathType,
  965. long lPChannelCount)
  966. #endif
  967. {
  968. HRESULT hr;
  969. IDirectSound8 *pDS8 = NULL;
  970. LPDIRECTSOUND pSound = NULL;
  971. DMUS_AUDIOPARAMS *pAudioParams = NULL;
  972. __try {
  973. if (*DirectSound)
  974. {
  975. ((I_dxj_DirectSound*)*DirectSound)->InternalGetObject((IUnknown **)(&pSound));
  976. }
  977. // Do we have any Audio params to use?
  978. if (AudioParams->lValidData)
  979. {
  980. pAudioParams = new DMUS_AUDIOPARAMS;
  981. if (!pAudioParams)
  982. {
  983. return E_OUTOFMEMORY;
  984. }
  985. ZeroMemory(pAudioParams, sizeof(pAudioParams));
  986. pAudioParams->dwSize = sizeof(pAudioParams);
  987. pAudioParams->fInitNow = (AudioParams->fInitNow == VARIANT_TRUE);
  988. pAudioParams->dwValidData = AudioParams->lValidData;
  989. pAudioParams->dwFeatures = AudioParams->lFeatures;
  990. pAudioParams->dwVoices = AudioParams->lVoices;
  991. pAudioParams->dwSampleRate = AudioParams->lSampleRate;
  992. if (FAILED ( hr = BSTRtoGUID(&pAudioParams->clsidDefaultSynth,AudioParams->clsidDefaultSynth) ) )
  993. {
  994. return hr;
  995. }
  996. }
  997. hr = m__dxj_DirectMusicPerformance->InitAudio(NULL, &pSound,(HWND) hWnd,(DWORD) lDefaultPathType ,(DWORD) lPChannelCount,(DWORD)lFlags , pAudioParams);
  998. if FAILED(hr) {
  999. return hr;
  1000. }
  1001. //Now that we've finished, make sure our returned audio params struct is right
  1002. if (pAudioParams)
  1003. {
  1004. AudioParams->fInitNow = pAudioParams->fInitNow ? VARIANT_TRUE : VARIANT_FALSE;
  1005. AudioParams->lValidData = pAudioParams->dwValidData;
  1006. AudioParams->lFeatures = pAudioParams->dwFeatures;
  1007. AudioParams->lVoices = pAudioParams->dwVoices;
  1008. AudioParams->lSampleRate = pAudioParams->dwSampleRate;
  1009. AudioParams->clsidDefaultSynth = GUIDtoBSTR(&pAudioParams->clsidDefaultSynth);
  1010. }
  1011. if (FAILED( hr = pSound->QueryInterface(IID_IDirectSound8,(void**) &pDS8) ) )
  1012. return hr;
  1013. if (pDS8)
  1014. {
  1015. INTERNAL_CREATE(_dxj_DirectSound,pDS8,DirectSound);
  1016. }
  1017. if (pSound) pSound->Release();
  1018. }
  1019. __except(EXCEPTION_EXECUTE_HANDLER)
  1020. {
  1021. return E_FAIL;
  1022. }
  1023. return S_OK;
  1024. }
  1025. HRESULT C_dxj_DirectMusicPerformanceObject::PlaySegmentEx(IUnknown *Source,
  1026. long lFlags,
  1027. long StartTime,
  1028. IUnknown *From,
  1029. IUnknown *AudioPath,
  1030. #if 0
  1031. BSTR SegmentName,
  1032. IUnknown *Transition,
  1033. #endif
  1034. I_dxj_DirectMusicSegmentState **ppSegmentState)
  1035. {
  1036. HRESULT hr;
  1037. WCHAR wszSegName[MAX_PATH];
  1038. if (!Source) return E_INVALIDARG;
  1039. if (!ppSegmentState) return E_INVALIDARG;
  1040. __try {
  1041. IDirectMusicSegmentState *pState=NULL;
  1042. I_dxj_DirectMusicAudioPath *pAudio = NULL;
  1043. I_dxj_DirectMusicAudioPath *pFrom = NULL;
  1044. I_dxj_DirectMusicSegment *pSeg = NULL;
  1045. #if 0
  1046. I_dxj_DirectMusicSong *pSong = NULL;
  1047. I_dxj_DirectMusicSegment *pTrans = NULL;
  1048. if (Transition)
  1049. DO_GETOBJECT_NOTNULL(IDirectMusicSegment8*,Transition,pTrans);
  1050. if (!IsEmptyString(SegmentName)) wcscpy(wszSegName, SegmentName);
  1051. #endif
  1052. if (AudioPath)
  1053. {
  1054. if (FAILED ( hr = AudioPath->QueryInterface(IID_I_dxj_DirectMusicAudioPath, (void**)&pAudio) ) )
  1055. return hr;
  1056. }
  1057. DO_GETOBJECT_NOTNULL(IDirectMusicAudioPath8*,pPath,pAudio);
  1058. if (From)
  1059. {
  1060. if (FAILED ( hr = From->QueryInterface(IID_I_dxj_DirectMusicAudioPath, (void**)&pFrom) ) )
  1061. return hr;
  1062. }
  1063. DO_GETOBJECT_NOTNULL(IDirectMusicAudioPath8*,pFromPath,pFrom);
  1064. __int64 outTime=(__int64)StartTime;
  1065. if (lFlags & DMUS_SEGF_REFTIME) outTime=VBREF_TO_REALREFTIME(StartTime);
  1066. //We need to determine if the source is a segment or a song
  1067. // First check to see if it's a segment
  1068. if (SUCCEEDED ( hr = Source->QueryInterface(IID_I_dxj_DirectMusicSegment, (void**)&pSeg) ) )
  1069. {
  1070. if (!pSeg) return E_INVALIDARG;
  1071. DO_GETOBJECT_NOTNULL(IDirectMusicSegment8*,pPlaySeg,pSeg);
  1072. if (FAILED ( hr = m__dxj_DirectMusicPerformance->PlaySegmentEx(pPlaySeg,wszSegName, NULL, (DWORD)lFlags,outTime,&pState, pFromPath,pPath)) )
  1073. return hr;
  1074. }
  1075. #if 0
  1076. else
  1077. // Next check to see if it's a song
  1078. if (SUCCEEDED ( hr = Source->QueryInterface(IID_I_dxj_DirectMusicSong, (void**)&pSong) ) )
  1079. {
  1080. if (!pSong) return E_INVALIDARG;
  1081. DO_GETOBJECT_NOTNULL(IDirectMusicSong8*,pPlaySong,pSong);
  1082. if (!IsEmptyString(SegmentName))
  1083. {
  1084. if (FAILED ( hr = m__dxj_DirectMusicPerformance->PlaySegmentEx(pPlaySong,wszSegName, pTrans, (DWORD)lFlags,outTime,&pState, pFromPath,pPath)) )
  1085. return hr;
  1086. }
  1087. else
  1088. {
  1089. if (FAILED ( hr = m__dxj_DirectMusicPerformance->PlaySegmentEx(pPlaySong,NULL, pTrans, (DWORD)lFlags,outTime,&pState, pFromPath,pPath)) )
  1090. return hr;
  1091. }
  1092. }
  1093. #endif
  1094. else
  1095. return E_INVALIDARG;
  1096. if (!pState) return E_FAIL;
  1097. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicSegmentState,pState,ppSegmentState);
  1098. if (*ppSegmentState==NULL) return E_OUTOFMEMORY;
  1099. }
  1100. __except(EXCEPTION_EXECUTE_HANDLER)
  1101. {
  1102. return E_FAIL;
  1103. }
  1104. return hr;
  1105. }
  1106. HRESULT C_dxj_DirectMusicPerformanceObject::StopEx(IUnknown *ObjectToStop,
  1107. long lStopTime,
  1108. long lFlags)
  1109. {
  1110. HRESULT hr;
  1111. if (!ObjectToStop) return E_INVALIDARG;
  1112. I_dxj_DirectMusicSegment *pSeg = NULL;
  1113. #if 0
  1114. I_dxj_DirectMusicSong *pSong = NULL;
  1115. #endif
  1116. I_dxj_DirectMusicSegmentState *pSegState = NULL;
  1117. I_dxj_DirectMusicAudioPath *pPath = NULL;
  1118. __try {
  1119. //We need to determine if the source is a segment or a song
  1120. __int64 outTime=(__int64)lStopTime;
  1121. if (lFlags & DMUS_SEGF_REFTIME) outTime=VBREF_TO_REALREFTIME(lStopTime);
  1122. if (SUCCEEDED ( hr = ObjectToStop->QueryInterface(IID_I_dxj_DirectMusicSegment, (void**)&pSeg) ) )
  1123. {
  1124. if (!pSeg) return E_INVALIDARG;
  1125. DO_GETOBJECT_NOTNULL(IDirectMusicSegment8*,pPlaySeg,pSeg);
  1126. if (FAILED (hr = m__dxj_DirectMusicPerformance->StopEx(pPlaySeg, outTime, (DWORD) lFlags) ) )
  1127. return hr;
  1128. }
  1129. #if 0
  1130. else if (SUCCEEDED ( hr = ObjectToStop->QueryInterface(IID_I_dxj_DirectMusicSong, (void**)&pSong) ) )
  1131. {
  1132. if (!pSong) return E_INVALIDARG;
  1133. DO_GETOBJECT_NOTNULL(IDirectMusicSong8*,pPlaySong,pSong);
  1134. if (FAILED (hr = m__dxj_DirectMusicPerformance->StopEx(pPlaySong, outTime, (DWORD) lFlags) ) )
  1135. return hr;
  1136. }
  1137. #endif
  1138. else if (SUCCEEDED ( hr = ObjectToStop->QueryInterface(IID_I_dxj_DirectMusicSegmentState, (void**)&pSegState) ) )
  1139. {
  1140. if (!pSegState) return E_INVALIDARG;
  1141. DO_GETOBJECT_NOTNULL(IDirectMusicSegmentState8*,pPlayState,pSegState);
  1142. if (FAILED (hr = m__dxj_DirectMusicPerformance->StopEx(pPlayState, outTime, (DWORD) lFlags) ) )
  1143. return hr;
  1144. }
  1145. else if (SUCCEEDED ( hr = ObjectToStop->QueryInterface(IID_I_dxj_DirectMusicAudioPath, (void**)&pPath) ) )
  1146. {
  1147. if (!pPath) return E_INVALIDARG;
  1148. DO_GETOBJECT_NOTNULL(IDirectMusicAudioPath*,pPlayPath,pPath);
  1149. if (FAILED (hr = m__dxj_DirectMusicPerformance->StopEx(pPlayPath, outTime, (DWORD) lFlags) ) )
  1150. return hr;
  1151. }
  1152. else
  1153. return E_INVALIDARG;
  1154. }
  1155. __except(EXCEPTION_EXECUTE_HANDLER)
  1156. {
  1157. return E_FAIL;
  1158. }
  1159. return S_OK;
  1160. }
  1161. HRESULT C_dxj_DirectMusicPerformanceObject::CreateAudioPath(IUnknown *SourceConfig, VARIANT_BOOL fActive,
  1162. I_dxj_DirectMusicAudioPath **ppNewPath)
  1163. {
  1164. HRESULT hr;
  1165. IDirectMusicAudioPath *lpPath = NULL;
  1166. BOOL bActive = FALSE;
  1167. __try {
  1168. if (fActive == VARIANT_TRUE)
  1169. bActive = TRUE;
  1170. else
  1171. bActive = FALSE;
  1172. if (FAILED (hr = m__dxj_DirectMusicPerformance->CreateAudioPath(SourceConfig, bActive, &lpPath) ) )
  1173. return hr;
  1174. INTERNAL_CREATE(_dxj_DirectMusicAudioPath,lpPath,ppNewPath);
  1175. if (!ppNewPath) return E_OUTOFMEMORY;
  1176. }
  1177. __except(EXCEPTION_EXECUTE_HANDLER)
  1178. {
  1179. return E_FAIL;
  1180. }
  1181. return S_OK;
  1182. }
  1183. HRESULT C_dxj_DirectMusicPerformanceObject::CreateStandardAudioPath(long lType, long lPChannelCount, VARIANT_BOOL fActive,
  1184. I_dxj_DirectMusicAudioPath **ppNewPath)
  1185. {
  1186. HRESULT hr;
  1187. IDirectMusicAudioPath *lpPath = NULL;
  1188. __try {
  1189. //First let's create our standard path
  1190. if (FAILED ( hr = m__dxj_DirectMusicPerformance->CreateStandardAudioPath((DWORD) lType, (DWORD) lPChannelCount, (BOOL) fActive, &lpPath) ) )
  1191. return hr;
  1192. INTERNAL_CREATE(_dxj_DirectMusicAudioPath,lpPath,ppNewPath);
  1193. if (!ppNewPath) return E_OUTOFMEMORY;
  1194. }
  1195. __except(EXCEPTION_EXECUTE_HANDLER)
  1196. {
  1197. return E_FAIL;
  1198. }
  1199. return S_OK;
  1200. }
  1201. HRESULT C_dxj_DirectMusicPerformanceObject::SetDefaultAudioPath(I_dxj_DirectMusicAudioPath *AudioPath)
  1202. {
  1203. HRESULT hr;
  1204. __try {
  1205. DO_GETOBJECT_NOTNULL(IDirectMusicAudioPath8*,pPath,AudioPath);
  1206. if (FAILED(hr = m__dxj_DirectMusicPerformance->SetDefaultAudioPath(pPath) ) )
  1207. return hr;
  1208. }
  1209. __except(EXCEPTION_EXECUTE_HANDLER)
  1210. {
  1211. return E_FAIL;
  1212. }
  1213. return S_OK;
  1214. }
  1215. HRESULT C_dxj_DirectMusicPerformanceObject::GetDefaultAudioPath(I_dxj_DirectMusicAudioPath **ppAudioPath)
  1216. {
  1217. HRESULT hr;
  1218. IDirectMusicAudioPath *lpPath = NULL;
  1219. __try {
  1220. //First let's create our standard path
  1221. if (FAILED ( hr = m__dxj_DirectMusicPerformance->GetDefaultAudioPath(&lpPath) ) )
  1222. return hr;
  1223. INTERNAL_CREATE(_dxj_DirectMusicAudioPath,lpPath,ppAudioPath);
  1224. if (!ppAudioPath) return E_OUTOFMEMORY;
  1225. }
  1226. __except(EXCEPTION_EXECUTE_HANDLER)
  1227. {
  1228. return E_FAIL;
  1229. }
  1230. return S_OK;
  1231. }
  1232. //DEAD CODE left here for reference
  1233. #if 0
  1234. HRESULT C_dxj_DirectMusicPerformanceObject::addCommandParam(
  1235. /* [in] */ long trackIndex,
  1236. /* [in] */ long mtTime,
  1237. /* [in] */ Byte command,
  1238. /* [in] */ Byte grooveLevel)
  1239. {
  1240. HRESULT hr;
  1241. DMUS_COMMAND_PARAM cmd;
  1242. cmd.bCommand=(BYTE)command;
  1243. cmd.bGrooveLevel=(BYTE)grooveLevel;
  1244. cmd.bGrooveRange=0;
  1245. hr=m__dxj_DirectMusicPerformance->SetParam(GUID_CommandParam,0xFFFFFFFF,(DWORD)trackIndex,(MUSIC_TIME)mtTime,&cmd);
  1246. return hr;
  1247. }
  1248. HRESULT C_dxj_DirectMusicPerformanceObject::addBandChange( /* [in] */ long trackIndex, /* [in] */ long mtTime, /* [in] */ I_dxj_DirectMusicBand __RPC_FAR *band)
  1249. {
  1250. if (!band) return E_INVALIDARG;
  1251. DO_GETOBJECT_NOTNULL(IDirectMusicBand*,pBand,band);
  1252. HRESULT hr;
  1253. hr=m__dxj_DirectMusicPerformance->SetParam(GUID_IDirectMusicBand,0xFFFFFFFF,(DWORD)trackIndex,(MUSIC_TIME)mtTime,pBand);
  1254. return hr;
  1255. }
  1256. HRESULT C_dxj_DirectMusicPerformanceObject::addTempoChange(
  1257. /* [in] */ long trackIndex,
  1258. /* [in] */ long mtTime,
  1259. /* [in] */ double tempo)
  1260. {
  1261. HRESULT hr;
  1262. DMUS_TEMPO_PARAM tmp;
  1263. tmp.dblTempo=tempo;
  1264. tmp.mtTime=(MUSIC_TIME)mtTime;
  1265. hr=m__dxj_DirectMusicPerformance->SetParam(GUID_TempoParam,0xFFFFFFFF,(DWORD)trackIndex,(MUSIC_TIME)mtTime,&tmp);
  1266. return hr;
  1267. }
  1268. HRESULT C_dxj_DirectMusicPerformanceObject::addTimeSigChange( /* [in] */ long trackIndex,/* [in] */ DMUS_TIMESIGNATURE_CDESC __RPC_FAR *timeSignature)
  1269. {
  1270. HRESULT hr;
  1271. if (!timeSignature) return E_INVALIDARG;
  1272. MUSIC_TIME mtTime=((DMUS_TIMESIGNATURE*)timeSignature)->mtTime;
  1273. hr=m__dxj_DirectMusicPerformance->SetParam(GUID_TimeSignature,0xFFFFFFFF,(DWORD)trackIndex,(MUSIC_TIME)mtTime,(DMUS_TIMESIGNATURE*)timeSignature);
  1274. return hr;
  1275. }
  1276. HRESULT C_dxj_DirectMusicPerformanceObject::setAutoDownloadEnable( /* [in] */ long trackIndex, /* [retval][out] */ VARIANT_BOOL b)
  1277. {
  1278. HRESULT hr;
  1279. if (b==VARIANT_FALSE){
  1280. hr=m__dxj_DirectMusicPerformance->SetParam(GUID_Disable_Auto_Download,0xFFFFFFFF,(DWORD)trackIndex,(MUSIC_TIME)0,NULL);
  1281. }
  1282. else {
  1283. hr=m__dxj_DirectMusicPerformance->SetParam(GUID_Enable_Auto_Download,0xFFFFFFFF,(DWORD)trackIndex,(MUSIC_TIME)0,NULL);
  1284. }
  1285. return hr;
  1286. }
  1287. HRESULT C_dxj_DirectMusicPerformanceObject::setTempoEnable( /* [in] */ long trackIndex,/* [retval][out] */ VARIANT_BOOL b)
  1288. {
  1289. HRESULT hr;
  1290. if (b==VARIANT_FALSE){
  1291. hr=m__dxj_DirectMusicPerformance->SetParam(GUID_DisableTempo,0xFFFFFFFF,(DWORD)trackIndex,(MUSIC_TIME)0,NULL);
  1292. }
  1293. else {
  1294. hr=m__dxj_DirectMusicPerformance->SetParam(GUID_EnableTempo,0xFFFFFFFF,(DWORD)trackIndex,(MUSIC_TIME)0,NULL);
  1295. }
  1296. return hr;
  1297. }
  1298. HRESULT C_dxj_DirectMusicPerformanceObject::setTimeSigEnable( /* [in] */ long trackIndex,/* [retval][out] */ VARIANT_BOOL b)
  1299. {
  1300. HRESULT hr;
  1301. if (b==VARIANT_FALSE){
  1302. hr=m__dxj_DirectMusicPerformance->SetParam(GUID_DisableTimeSig,0xFFFFFFFF,(DWORD)trackIndex,(MUSIC_TIME)0,NULL);
  1303. }
  1304. else {
  1305. hr=m__dxj_DirectMusicPerformance->SetParam(GUID_EnableTimeSig,0xFFFFFFFF,(DWORD)trackIndex,(MUSIC_TIME)0,NULL);
  1306. }
  1307. return hr;
  1308. }
  1309. HRESULT C_dxj_DirectMusicPerformanceObject::clearAllBands ()
  1310. {
  1311. HRESULT hr;
  1312. hr=m__dxj_DirectMusicPerformance->SetParam(GUID_Clear_All_Bands,0xFFFFFFFF,0,0,NULL);
  1313. return hr;
  1314. }
  1315. HRESULT C_dxj_DirectMusicPerformanceObject::download( /* [in] */ long trackIndex, /* [in] */ I_dxj_DirectMusicPerformance __RPC_FAR *performance)
  1316. {
  1317. if (!performance) return E_INVALIDARG;
  1318. DO_GETOBJECT_NOTNULL(IDirectMusicPerformance*,pPerformance,performance);
  1319. HRESULT hr;
  1320. hr=m__dxj_DirectMusicPerformance->SetParam(GUID_Download,0xFFFFFFFF,(DWORD)trackIndex,(MUSIC_TIME)0,pPerformance);
  1321. return hr;
  1322. }
  1323. HRESULT C_dxj_DirectMusicPerformanceObject::unload( /* [in] */ long trackIndex, /* [in] */ I_dxj_DirectMusicPerformance __RPC_FAR *performance)
  1324. {
  1325. if (!performance) return E_INVALIDARG;
  1326. DO_GETOBJECT_NOTNULL(IDirectMusicPerformance*,pPerformance,performance);
  1327. HRESULT hr;
  1328. hr=m__dxj_DirectMusicPerformance->SetParam(GUID_Unload,0xFFFFFFFF,(DWORD)trackIndex,(MUSIC_TIME)0,pPerformance);
  1329. return hr;
  1330. }
  1331. HRESULT C_dxj_DirectMusicPerformanceObject::AddPort(I_dxj_DirectMusicPort *port)
  1332. {
  1333. HRESULT hr;
  1334. DO_GETOBJECT_NOTNULL(LPDIRECTMUSICPORT, lpPort, port);
  1335. if (FAILED (hr = m__dxj_DirectMusicPerformance->AddPort(lpPort) ) )
  1336. return hr;
  1337. return S_OK;
  1338. }
  1339. HRESULT C_dxj_DirectMusicPerformanceObject::RemovePort(I_dxj_DirectMusicPort *port)
  1340. {
  1341. HRESULT hr;
  1342. DO_GETOBJECT_NOTNULL(LPDIRECTMUSICPORT, lpPort, port);
  1343. if (FAILED (hr = m__dxj_DirectMusicPerformance->RemovePort(lpPort) ) )
  1344. return hr;
  1345. return S_OK;
  1346. }
  1347. HRESULT C_dxj_DirectMusicPerformanceObject::AssignPChannel(long lPChannel, I_dxj_DirectMusicPort *Port, long lGroup, long lMChannel)
  1348. {
  1349. HRESULT hr;
  1350. DO_GETOBJECT_NOTNULL(LPDIRECTMUSICPORT, lpPort, Port);
  1351. if (FAILED (hr = m__dxj_DirectMusicPerformance->AssignPChannel((DWORD)lPChannel, lpPort, (DWORD)lGroup, (DWORD) lMChannel) ) )
  1352. return hr;
  1353. return S_OK;
  1354. }
  1355. HRESULT C_dxj_DirectMusicPerformanceObject::AssignPChannelBlock(long lPChannel, I_dxj_DirectMusicPort *Port, long lGroup)
  1356. {
  1357. HRESULT hr;
  1358. DO_GETOBJECT_NOTNULL(LPDIRECTMUSICPORT, lpPort, Port);
  1359. if (FAILED (hr = m__dxj_DirectMusicPerformance->AssignPChannelBlock((DWORD)lPChannel, lpPort, (DWORD)lGroup) ) )
  1360. return hr;
  1361. return S_OK;
  1362. }
  1363. HRESULT C_dxj_DirectMusicPerformanceObject::PChannelInfo(long lPChannel, I_dxj_DirectMusicPort *Port, long *lGroup, long *lMChannel)
  1364. {
  1365. HRESULT hr;
  1366. DO_GETOBJECT_NOTNULL(LPDIRECTMUSICPORT, lpPort, Port);
  1367. if (FAILED (hr = m__dxj_DirectMusicPerformance->PChannelInfo((DWORD)lPChannel, &lpPort, (DWORD*)lGroup, (DWORD*) lMChannel) ) )
  1368. return hr;
  1369. return S_OK;
  1370. }
  1371. HRESULT C_dxj_DirectMusicPerformanceObject::init(
  1372. /* [in] */ I_dxj_DirectSound __RPC_FAR *DirectSound,
  1373. /* [in] */ long hWnd,
  1374. I_dxj_DirectMusic **ret)
  1375. {
  1376. HRESULT hr;
  1377. IDirectMusic *lpDMTemp = NULL;
  1378. DO_GETOBJECT_NOTNULL(LPDIRECTSOUND,pSound,DirectSound);
  1379. hr=m__dxj_DirectMusicPerformance->Init(&lpDMTemp,pSound,(HWND)hWnd);
  1380. if FAILED(hr) return hr;
  1381. if (FAILED( hr = lpDMTemp->QueryInterface(IID_IDirectMusic8,(void**) &m_pDM) ) )
  1382. return hr;
  1383. lpDMTemp->Release();
  1384. m_pDM->AddRef();
  1385. INTERNAL_CREATE(_dxj_DirectMusic,m_pDM,ret);
  1386. return hr;
  1387. }
  1388. HRESULT C_dxj_DirectMusicPerformanceObject::setPort(
  1389. /* [in] */ long portid,
  1390. /* [in] */ long number_of_groups)
  1391. {
  1392. if (!m_pDM) return DMUS_E_NOT_INIT;
  1393. HRESULT hr;
  1394. DMUS_PORTPARAMS dmos;
  1395. GUID guidSink;
  1396. IDirectMusicPort *port = NULL;
  1397. DWORD j=0;
  1398. // Initialize the performance. Have the performance create the
  1399. // DirectMusic object by setting pDM to NULL. It is needed to
  1400. // create the port.
  1401. // Set Port Params
  1402. ZeroMemory( &dmos, sizeof(DMUS_PORTPARAMS) );
  1403. dmos.dwSize = sizeof(DMUS_PORTPARAMS);
  1404. dmos.dwChannelGroups = number_of_groups;
  1405. dmos.dwEffectFlags = DMUS_EFFECT_REVERB;
  1406. dmos.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS | DMUS_PORTPARAMS_EFFECTS;
  1407. if (m_pPort){
  1408. // We've already got this port, lets get rid of it
  1409. hr = m_pPort->Release();
  1410. if ( FAILED(hr= m__dxj_DirectMusicPerformance->RemovePort(m_pPort) ))
  1411. return hr;
  1412. }
  1413. if (portid<=0) {
  1414. guidSink = GUID_NULL;
  1415. }
  1416. else {
  1417. DMUS_PORTCAPS caps;
  1418. ZeroMemory(&caps,sizeof(DMUS_PORTCAPS));
  1419. caps.dwSize=sizeof(DMUS_PORTCAPS);
  1420. hr=m_pDM->EnumPort( (DWORD) portid-1, &caps );
  1421. if FAILED(hr) return hr;
  1422. memcpy(&guidSink,&caps.guidPort,sizeof(GUID));
  1423. }
  1424. // Create the port
  1425. if (FAILED(hr = m_pDM->CreatePort( guidSink, &dmos, &port, NULL )))
  1426. return hr;
  1427. //Now get our DirectMusicPort8
  1428. hr = port->QueryInterface(IID_IDirectMusicPort8, (void **) &m_pPort );
  1429. port->Release();
  1430. if ( FAILED ( hr ) ) return hr;
  1431. // Activate all ports
  1432. if ( FAILED (hr = m_pDM->Activate( TRUE ) ) )
  1433. return hr;
  1434. // Add the port to the performance.
  1435. if (FAILED (hr = m__dxj_DirectMusicPerformance->AddPort( m_pPort ) ))
  1436. return hr;
  1437. // Assign PChannel blocks for the number of groups we want.
  1438. for( long i = 0; i < number_of_groups; i++ )
  1439. {
  1440. m__dxj_DirectMusicPerformance->AssignPChannelBlock( i, m_pPort, i+1 );
  1441. }
  1442. m_portid=portid;
  1443. m_number_of_groups=number_of_groups;
  1444. return S_OK;
  1445. }
  1446. HRESULT C_dxj_DirectMusicPerformanceObject::playSegment(
  1447. /* [in] */ I_dxj_DirectMusicSegment __RPC_FAR *segment,
  1448. /* [in] */ long lFlags,
  1449. /* [in] */ long startTime,
  1450. /* [retval][out] */ I_dxj_DirectMusicSegmentState __RPC_FAR *__RPC_FAR *segmentState)
  1451. {
  1452. HRESULT hr;
  1453. if (!segment) return E_INVALIDARG;
  1454. if (!segmentState) return E_INVALIDARG;
  1455. DO_GETOBJECT_NOTNULL(IDirectMusicSegment*,pSeg,segment);
  1456. IDirectMusicSegmentState *pState=NULL;
  1457. __int64 outTime=(__int64)startTime;
  1458. if (lFlags & DMUS_SEGF_REFTIME) outTime=VBREF_TO_REALREFTIME(startTime);
  1459. hr=m__dxj_DirectMusicPerformance->PlaySegment(pSeg,(DWORD)lFlags,outTime,&pState);
  1460. if FAILED(hr) return hr;
  1461. if (!pState) return E_FAIL;
  1462. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicSegmentState,pState,segmentState);
  1463. if (*segmentState==NULL) return E_OUTOFMEMORY;
  1464. return hr;
  1465. }
  1466. HRESULT C_dxj_DirectMusicPerformanceObject::stop(
  1467. /* [in] */ I_dxj_DirectMusicSegment __RPC_FAR *segment,
  1468. /* [in] */ I_dxj_DirectMusicSegmentState __RPC_FAR *segmentState,
  1469. /* [in] */ long endTime,
  1470. /* [in] */ long lFlags)
  1471. {
  1472. HRESULT hr;
  1473. DO_GETOBJECT_NOTNULL(LPDIRECTMUSICSEGMENT,pSeg,segment);
  1474. DO_GETOBJECT_NOTNULL(LPDIRECTMUSICSEGMENTSTATE,pSegState,segmentState);
  1475. __int64 outTime=(__int64)endTime;
  1476. if (lFlags & DMUS_SEGF_REFTIME) outTime=VBREF_TO_REALREFTIME(endTime);
  1477. hr=m__dxj_DirectMusicPerformance->Stop(pSeg,pSegState,(MUSIC_TIME)outTime,(DWORD)lFlags);
  1478. return hr;
  1479. }
  1480. HRESULT C_dxj_DirectMusicPerformanceObject::getPortName(
  1481. /* [in] */ long i,
  1482. /* [retval][out] */ BSTR __RPC_FAR *name)
  1483. {
  1484. HRESULT hr;
  1485. DMUS_PORTCAPS caps;
  1486. if (!m_pDM) return CO_E_NOTINITIALIZED;
  1487. if (i<=0) return E_INVALIDARG;
  1488. if (!name) return E_INVALIDARG;
  1489. ZeroMemory(&caps,sizeof(DMUS_PORTCAPS));
  1490. caps.dwSize=sizeof(DMUS_PORTCAPS);
  1491. hr=m_pDM->EnumPort( (DWORD) i-1, &caps );
  1492. if (hr!=S_OK) return E_INVALIDARG; //happens when we are out of bounds
  1493. //manbug23240
  1494. if FAILED(hr) return hr; //for other resason ?
  1495. *name=SysAllocString(caps.wszDescription);
  1496. return S_OK;
  1497. }
  1498. HRESULT C_dxj_DirectMusicPerformanceObject::getPortCount(
  1499. /* [retval][out] */ long __RPC_FAR *c)
  1500. {
  1501. HRESULT hr=S_OK;
  1502. DMUS_PORTCAPS caps;
  1503. DWORD i=0;
  1504. if (!m_pDM) return CO_E_NOTINITIALIZED;
  1505. if (!c) return E_INVALIDARG;
  1506. while (hr==S_OK){
  1507. caps.dwSize=sizeof(DMUS_PORTCAPS);
  1508. hr=m_pDM->EnumPort( i++, &caps );
  1509. if FAILED(hr) return hr;
  1510. }
  1511. *c=(long)i-1;
  1512. return S_OK;
  1513. }
  1514. HRESULT C_dxj_DirectMusicPerformanceObject::getPortCaps( long i,
  1515. /* [retval][out] */ DMUS_PORTCAPS_CDESC __RPC_FAR *c)
  1516. {
  1517. HRESULT hr;
  1518. if (!c) return E_INVALIDARG;
  1519. if (!m_pDM) return CO_E_NOTINITIALIZED;
  1520. if (i<=0) return E_INVALIDARG;
  1521. ZeroMemory(c,sizeof(DMUS_PORTCAPS));
  1522. ((DMUS_PORTCAPS*)c)->dwSize=sizeof(DMUS_PORTCAPS);
  1523. hr=m_pDM->EnumPort( (DWORD) i-1, (DMUS_PORTCAPS*)c );
  1524. if (hr==S_FALSE) return E_INVALIDARG;
  1525. return hr;
  1526. }
  1527. #endif