Source code of Windows XP (NT5)
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.

184 lines
4.9 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Implementation of CAutDirectMusicSong.
  4. //
  5. #include "stdinc.h"
  6. #include "autsong.h"
  7. #include "activescript.h"
  8. const WCHAR CAutDirectMusicSong::ms_wszClassName[] = L"Song";
  9. //////////////////////////////////////////////////////////////////////
  10. // Method Names/DispIDs
  11. const DISPID DMPDISP_Load = 1;
  12. const DISPID DMPDISP_Recompose = 2;
  13. const DISPID DMPDISP_Play = 3;
  14. const DISPID DMPDISP_GetSegment = 4;
  15. const DISPID DMPDISP_Stop = 5;
  16. const DISPID DMPDISP_DownloadSoundData = 6;
  17. const DISPID DMPDISP_UnloadSoundData = 7;
  18. const AutDispatchMethod CAutDirectMusicSong::ms_Methods[] =
  19. {
  20. // dispid, name,
  21. // return: type, (opt), (iid),
  22. // parm 1: type, opt, iid,
  23. // parm 2: type, opt, iid,
  24. // ...
  25. // ADT_None
  26. { DMPDISP_Load, L"Load",
  27. ADPARAM_NORETURN,
  28. ADT_None },
  29. { DMPDISP_Recompose, L"Recompose",
  30. ADPARAM_NORETURN,
  31. ADT_None },
  32. { DMPDISP_Play, L"Play",
  33. ADT_Interface, true, &IID_IUnknown, // returned segment state
  34. ADT_Bstr, true, &IID_NULL, // name of segment to play
  35. ADT_None },
  36. { DMPDISP_GetSegment, L"GetSegment",
  37. ADT_Interface, true, &IID_IUnknown, // returned segment
  38. ADT_Bstr, true, &IID_NULL, // name of segment to retrieve
  39. ADT_None },
  40. { DMPDISP_Stop, L"Stop",
  41. ADPARAM_NORETURN,
  42. ADT_None },
  43. { DMPDISP_DownloadSoundData, L"DownloadSoundData",
  44. ADPARAM_NORETURN,
  45. ADT_None },
  46. { DMPDISP_UnloadSoundData, L"UnloadSoundData",
  47. ADPARAM_NORETURN,
  48. ADT_None },
  49. { DISPID_UNKNOWN }
  50. };
  51. const DispatchHandlerEntry<CAutDirectMusicSong> CAutDirectMusicSong::ms_Handlers[] =
  52. {
  53. { DMPDISP_Load, Load },
  54. { DMPDISP_Recompose, Recompose },
  55. { DMPDISP_Play, Play },
  56. { DMPDISP_GetSegment, GetSegment },
  57. { DMPDISP_Stop, Stop },
  58. { DMPDISP_DownloadSoundData, DownloadSoundData },
  59. { DMPDISP_UnloadSoundData, UnloadSoundData },
  60. { DISPID_UNKNOWN }
  61. };
  62. //////////////////////////////////////////////////////////////////////
  63. // Creation
  64. CAutDirectMusicSong::CAutDirectMusicSong(
  65. IUnknown* pUnknownOuter,
  66. const IID& iid,
  67. void** ppv,
  68. HRESULT *phr)
  69. : BaseImpSong(pUnknownOuter, iid, ppv, phr)
  70. {
  71. }
  72. HRESULT
  73. CAutDirectMusicSong::CreateInstance(
  74. IUnknown* pUnknownOuter,
  75. const IID& iid,
  76. void** ppv)
  77. {
  78. HRESULT hr = S_OK;
  79. CAutDirectMusicSong *pInst = new CAutDirectMusicSong(pUnknownOuter, iid, ppv, &hr);
  80. if (FAILED(hr))
  81. {
  82. delete pInst;
  83. return hr;
  84. }
  85. if (pInst == NULL)
  86. return E_OUTOFMEMORY;
  87. return hr;
  88. }
  89. //////////////////////////////////////////////////////////////////////
  90. // Automation methods
  91. HRESULT
  92. CAutDirectMusicSong::Load(AutDispatchDecodedParams *paddp)
  93. {
  94. // Loading is actually implemented generically by container items.
  95. // If we're here, we're already loaded and don't need to do anything.
  96. return S_OK;
  97. }
  98. HRESULT
  99. CAutDirectMusicSong::Recompose(AutDispatchDecodedParams *paddp)
  100. {
  101. return m_pITarget->Compose();
  102. }
  103. HRESULT
  104. CAutDirectMusicSong::Play(AutDispatchDecodedParams *paddp)
  105. {
  106. IDirectMusicSegmentState **ppSegSt = reinterpret_cast<IDirectMusicSegmentState **>(paddp->pvReturn);
  107. BSTR bstrSegName = paddp->params[0].bstrVal;
  108. HRESULT hr = S_OK;
  109. IDirectMusicPerformance8 *pPerformance = CActiveScriptManager::GetCurrentPerformanceWEAK();
  110. __int64 i64IntendedStartTime;
  111. DWORD dwIntendedStartTimeFlags;
  112. CActiveScriptManager::GetCurrentTimingContext(&i64IntendedStartTime, &dwIntendedStartTimeFlags);
  113. hr = pPerformance->PlaySegmentEx(
  114. m_pITarget,
  115. bstrSegName,
  116. NULL,
  117. DMUS_SEGF_DEFAULT | DMUS_SEGF_AUTOTRANSITION | dwIntendedStartTimeFlags,
  118. i64IntendedStartTime,
  119. ppSegSt,
  120. NULL,
  121. NULL);
  122. if (FAILED(hr))
  123. return hr;
  124. return S_OK;
  125. }
  126. HRESULT
  127. CAutDirectMusicSong::GetSegment(AutDispatchDecodedParams *paddp)
  128. {
  129. IDirectMusicSegment **ppSeg = reinterpret_cast<IDirectMusicSegment **>(paddp->pvReturn);
  130. BSTR bstrSegName = paddp->params[0].bstrVal;
  131. HRESULT hr = S_OK;
  132. hr = m_pITarget->GetSegment(bstrSegName, ppSeg);
  133. if (FAILED(hr))
  134. return hr;
  135. return S_OK;
  136. }
  137. HRESULT
  138. CAutDirectMusicSong::Stop(AutDispatchDecodedParams *paddp)
  139. {
  140. HRESULT hr = S_OK;
  141. IDirectMusicPerformance8 *pPerformance = CActiveScriptManager::GetCurrentPerformanceWEAK();
  142. __int64 i64IntendedStartTime;
  143. DWORD dwIntendedStartTimeFlags;
  144. CActiveScriptManager::GetCurrentTimingContext(&i64IntendedStartTime, &dwIntendedStartTimeFlags);
  145. hr = pPerformance->StopEx(m_pITarget, i64IntendedStartTime, DMUS_SEGF_DEFAULT | dwIntendedStartTimeFlags);
  146. return hr;
  147. }
  148. HRESULT
  149. CAutDirectMusicSong::DownloadSoundData(AutDispatchDecodedParams *paddp)
  150. {
  151. IDirectMusicPerformance8 *pPerformance = CActiveScriptManager::GetCurrentPerformanceWEAK();
  152. return m_pITarget->Download(pPerformance);
  153. }
  154. HRESULT
  155. CAutDirectMusicSong::UnloadSoundData(AutDispatchDecodedParams *paddp)
  156. {
  157. IDirectMusicPerformance8 *pPerformance = CActiveScriptManager::GetCurrentPerformanceWEAK();
  158. return m_pITarget->Unload(pPerformance);
  159. }