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.

215 lines
4.6 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Base classes that implement aspects of a standard DirectMusic track.
  4. // Implementations for CBasicTrack.
  5. //
  6. #include "trackhelp.h"
  7. #include "validate.h"
  8. //////////////////////////////////////////////////////////////////////
  9. // Creation
  10. CBasicTrack::CBasicTrack(long *plModuleLockCounter, const CLSID &rclsid)
  11. : m_cRef(0),
  12. m_plModuleLockCounter(plModuleLockCounter),
  13. m_rclsid(rclsid)
  14. {
  15. InitializeCriticalSection(&m_CriticalSection);
  16. InterlockedIncrement(plModuleLockCounter);
  17. }
  18. //////////////////////////////////////////////////////////////////////
  19. // IUnknown
  20. STDMETHODIMP
  21. CBasicTrack::QueryInterface(const IID &iid, void **ppv)
  22. {
  23. V_INAME(CBasicTrack::QueryInterface);
  24. V_PTRPTR_WRITE(ppv);
  25. V_REFGUID(iid);
  26. if (iid == IID_IUnknown || iid == IID_IDirectMusicTrack || iid == IID_IDirectMusicTrack8)
  27. *ppv = static_cast<IDirectMusicTrack8*>(this);
  28. else if (iid == IID_IPersistStream)
  29. *ppv = static_cast<IPersistStream*>(this);
  30. else if (iid == IID_IPersist)
  31. *ppv = static_cast<IPersist*>(this);
  32. else
  33. {
  34. *ppv = NULL;
  35. return E_NOINTERFACE;
  36. }
  37. reinterpret_cast<IUnknown*>(this)->AddRef();
  38. return S_OK;
  39. }
  40. STDMETHODIMP_(ULONG)
  41. CBasicTrack::AddRef()
  42. {
  43. return InterlockedIncrement(&m_cRef);
  44. }
  45. STDMETHODIMP_(ULONG)
  46. CBasicTrack::Release()
  47. {
  48. if (!InterlockedDecrement(&m_cRef))
  49. {
  50. DeleteCriticalSection(&m_CriticalSection);
  51. delete this;
  52. return 0;
  53. }
  54. return m_cRef;
  55. }
  56. //////////////////////////////////////////////////////////////////////
  57. // IUnknown
  58. STDMETHODIMP
  59. CBasicTrack::GetClassID(CLSID* pClassID)
  60. {
  61. V_INAME(CBasicTrack::GetClassID);
  62. V_PTR_WRITE(pClassID, sizeof(pClassID));
  63. *pClassID = m_rclsid;
  64. return S_OK;
  65. }
  66. //////////////////////////////////////////////////////////////////////
  67. // IDirectMusicTrack
  68. STDMETHODIMP
  69. CBasicTrack::Init(IDirectMusicSegment *pSegment)
  70. {
  71. V_INAME(CBasicTrack::Init);
  72. V_INTERFACE(pSegment);
  73. return S_OK;
  74. }
  75. STDMETHODIMP
  76. CBasicTrack::Play(
  77. void *pStateData,
  78. MUSIC_TIME mtStart,
  79. MUSIC_TIME mtEnd,
  80. MUSIC_TIME mtOffset,
  81. DWORD dwFlags,
  82. IDirectMusicPerformance* pPerf,
  83. IDirectMusicSegmentState* pSegSt,
  84. DWORD dwVirtualID)
  85. {
  86. return this->PlayMusicOrClock(
  87. pStateData,
  88. mtStart,
  89. mtEnd,
  90. mtOffset,
  91. 0,
  92. dwFlags,
  93. pPerf,
  94. pSegSt,
  95. dwVirtualID,
  96. false);
  97. }
  98. //////////////////////////////////////////////////////////////////////
  99. // IDirectMusicTrack8
  100. STDMETHODIMP CBasicTrack::PlayEx(
  101. void* pStateData,
  102. REFERENCE_TIME rtStart,
  103. REFERENCE_TIME rtEnd,
  104. REFERENCE_TIME rtOffset,
  105. DWORD dwFlags,
  106. IDirectMusicPerformance* pPerf,
  107. IDirectMusicSegmentState* pSegSt,
  108. DWORD dwVirtualID)
  109. {
  110. if (dwFlags & DMUS_TRACKF_CLOCK)
  111. {
  112. // Convert all reference times to millisecond times and then just use them as if this were MUSIC_TIME.
  113. return this->PlayMusicOrClock(
  114. pStateData,
  115. static_cast<MUSIC_TIME>(rtStart / gc_RefPerMil),
  116. static_cast<MUSIC_TIME>(rtEnd / gc_RefPerMil),
  117. static_cast<MUSIC_TIME>(rtOffset / gc_RefPerMil),
  118. rtOffset,
  119. dwFlags,
  120. pPerf,
  121. pSegSt,
  122. dwVirtualID,
  123. true);
  124. }
  125. else
  126. {
  127. return this->PlayMusicOrClock(
  128. pStateData,
  129. static_cast<MUSIC_TIME>(rtStart),
  130. static_cast<MUSIC_TIME>(rtEnd),
  131. static_cast<MUSIC_TIME>(rtOffset),
  132. 0,
  133. dwFlags,
  134. pPerf,
  135. pSegSt,
  136. dwVirtualID,
  137. false);
  138. }
  139. }
  140. STDMETHODIMP CBasicTrack::GetParamEx(
  141. REFGUID rguidType,
  142. REFERENCE_TIME rtTime,
  143. REFERENCE_TIME* prtNext,
  144. void* pParam,
  145. void * pStateData,
  146. DWORD dwFlags)
  147. {
  148. HRESULT hr;
  149. MUSIC_TIME mtNext;
  150. if (dwFlags & DMUS_TRACK_PARAMF_CLOCK)
  151. {
  152. hr = GetParam(rguidType, static_cast<MUSIC_TIME>(rtTime / gc_RefPerMil), &mtNext, pParam);
  153. if (prtNext)
  154. {
  155. *prtNext = mtNext * gc_RefPerMil;
  156. }
  157. }
  158. else
  159. {
  160. hr = GetParam(rguidType, static_cast<MUSIC_TIME>(rtTime), &mtNext, pParam);
  161. if (prtNext)
  162. {
  163. *prtNext = mtNext;
  164. }
  165. }
  166. return hr;
  167. }
  168. STDMETHODIMP CBasicTrack::SetParamEx(
  169. REFGUID rguidType,
  170. REFERENCE_TIME rtTime,
  171. void* pParam, void * pStateData, DWORD dwFlags)
  172. {
  173. if (dwFlags & DMUS_TRACK_PARAMF_CLOCK)
  174. {
  175. rtTime /= gc_RefPerMil;
  176. }
  177. return SetParam(rguidType, static_cast<MUSIC_TIME>(rtTime ), pParam);
  178. }
  179. STDMETHODIMP CBasicTrack::Compose(
  180. IUnknown* pContext,
  181. DWORD dwTrackGroup,
  182. IDirectMusicTrack** ppResultTrack)
  183. {
  184. return E_NOTIMPL;
  185. }
  186. STDMETHODIMP CBasicTrack::Join(
  187. IDirectMusicTrack* pNewTrack,
  188. MUSIC_TIME mtJoin,
  189. IUnknown* pContext,
  190. DWORD dwTrackGroup,
  191. IDirectMusicTrack** ppResultTrack)
  192. {
  193. return E_NOTIMPL;
  194. }