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.

115 lines
3.1 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Implementation of CAutDirectMusicSegmentState.
  4. //
  5. #include "stdinc.h"
  6. #include "autsegmentstate.h"
  7. #include "activescript.h"
  8. #include "autconstants.h"
  9. #include <limits>
  10. const WCHAR CAutDirectMusicSegmentState::ms_wszClassName[] = L"SegmentState";
  11. //////////////////////////////////////////////////////////////////////
  12. // Method Names/DispIDs
  13. const DISPID DMPDISP_IsPlaying = 1;
  14. const DISPID DMPDISP_Stop = 2;
  15. const AutDispatchMethod CAutDirectMusicSegmentState::ms_Methods[] =
  16. {
  17. // dispid, name,
  18. // return: type, (opt), (iid),
  19. // parm 1: type, opt, iid,
  20. // parm 2: type, opt, iid,
  21. // ...
  22. // ADT_None
  23. { DMPDISP_IsPlaying, L"IsPlaying",
  24. ADT_Long, true, &IID_NULL, // returns true if playing
  25. ADT_None },
  26. { DMPDISP_Stop, L"Stop",
  27. ADPARAM_NORETURN,
  28. ADT_Long, true, &IID_NULL, // flags
  29. ADT_None },
  30. { DISPID_UNKNOWN }
  31. };
  32. const DispatchHandlerEntry<CAutDirectMusicSegmentState> CAutDirectMusicSegmentState::ms_Handlers[] =
  33. {
  34. { DMPDISP_IsPlaying, IsPlaying },
  35. { DMPDISP_Stop, Stop },
  36. { DISPID_UNKNOWN }
  37. };
  38. //////////////////////////////////////////////////////////////////////
  39. // Creation
  40. CAutDirectMusicSegmentState::CAutDirectMusicSegmentState(
  41. IUnknown* pUnknownOuter,
  42. const IID& iid,
  43. void** ppv,
  44. HRESULT *phr)
  45. : BaseImpSegSt(pUnknownOuter, iid, ppv, phr)
  46. {
  47. }
  48. HRESULT
  49. CAutDirectMusicSegmentState::CreateInstance(
  50. IUnknown* pUnknownOuter,
  51. const IID& iid,
  52. void** ppv)
  53. {
  54. HRESULT hr = S_OK;
  55. CAutDirectMusicSegmentState *pInst = new CAutDirectMusicSegmentState(pUnknownOuter, iid, ppv, &hr);
  56. if (FAILED(hr))
  57. {
  58. delete pInst;
  59. return hr;
  60. }
  61. if (pInst == NULL)
  62. return E_OUTOFMEMORY;
  63. return hr;
  64. }
  65. //////////////////////////////////////////////////////////////////////
  66. // Automation
  67. HRESULT
  68. CAutDirectMusicSegmentState::IsPlaying(AutDispatchDecodedParams *paddp)
  69. {
  70. LONG *plRet = reinterpret_cast<LONG*>(paddp->pvReturn);
  71. if (!plRet)
  72. return S_OK;
  73. IDirectMusicPerformance *pPerf = CActiveScriptManager::GetCurrentPerformanceWEAK();
  74. HRESULT hr = pPerf->IsPlaying(NULL, m_pITarget);
  75. *plRet = ::BoolForVB(hr == S_OK);
  76. return hr;
  77. }
  78. const FlagMapEntry gc_flagmapStop[] =
  79. {
  80. { ScriptConstants::AtGrid, DMUS_SEGF_GRID },
  81. { ScriptConstants::AtBeat, DMUS_SEGF_BEAT },
  82. { ScriptConstants::AtMeasure, DMUS_SEGF_MEASURE },
  83. { ScriptConstants::AtImmediate, DMUS_SEGF_DEFAULT }, // this flag gets flipped later
  84. { 0 }
  85. };
  86. HRESULT
  87. CAutDirectMusicSegmentState::Stop(AutDispatchDecodedParams *paddp)
  88. {
  89. LONG lFlags = paddp->params[0].lVal;
  90. DWORD dwFlags = MapFlags(lFlags, gc_flagmapStop);
  91. // Reverse the default flag because our flag means the opposite. Default is the default and immediate is the flag.
  92. dwFlags ^= DMUS_SEGF_DEFAULT;
  93. IDirectMusicPerformance8 *pPerformance = CActiveScriptManager::GetCurrentPerformanceWEAK();
  94. __int64 i64IntendedStartTime;
  95. DWORD dwIntendedStartTimeFlags;
  96. CActiveScriptManager::GetCurrentTimingContext(&i64IntendedStartTime, &dwIntendedStartTimeFlags);
  97. HRESULT hr = pPerformance->Stop(NULL, m_pITarget, i64IntendedStartTime, dwFlags | dwIntendedStartTimeFlags);
  98. return hr;
  99. }