1
0

ParamEnvelope.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // ParamEnvelope.h: interface for the CParamEnvelope class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_PARAMENVELOPE_H__F04D0178_4674_45AF_9F7A_5C8206DE4CF6__INCLUDED_)
  5. #define AFX_PARAMENVELOPE_H__F04D0178_4674_45AF_9F7A_5C8206DE4CF6__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. ////////////////////////////////////////////////////////////////////////////////
  10. typedef std::vector<MP_ENVELOPE_SEGMENT> EnvelopeSegs;
  11. ////////////////////////////////////////////////////////////////////////////////
  12. struct ParamInfo
  13. {
  14. MP_PARAMINFO mppi; // external parameter info, as presented to the user
  15. float fInternalMin; // minimum value used by internal processing code
  16. float fInternalMax; // maximum value used by internal processing code
  17. const WCHAR* pwszEnumText; // text for enumerations
  18. float MapToInternal( float fValue ) const;
  19. float MapToExternal( float fValue ) const;
  20. };
  21. ////////////////////////////////////////////////////////////////////////////////
  22. class CParamEnvelope : public CCritSec
  23. {
  24. public:
  25. CParamEnvelope();
  26. virtual ~CParamEnvelope();
  27. // Attributes
  28. public:
  29. unsigned GetCount() const
  30. {
  31. return m_envSegs.size();
  32. }
  33. const MP_ENVELOPE_SEGMENT& GetAt( unsigned ix ) const
  34. {
  35. return m_envSegs[ ix ];
  36. }
  37. // Tell the envelope about the parameter being controlled
  38. void SetParamInfo( const ParamInfo& info );
  39. // These methods are called by CMediaParams to manipulate segments in an envelope
  40. HRESULT AddEnvelope( DWORD cSegments, MP_ENVELOPE_SEGMENT* pEnvelopeSegments, double dSamplesPerRefTime );
  41. HRESULT FlushEnvelope( REFERENCE_TIME refTimeStart, REFERENCE_TIME refTimeEnd, double dSamplesPerRefTime );
  42. HRESULT GetEnvelope( DWORD* cSegments, MP_ENVELOPE_SEGMENT* pEnvelopeSegments );
  43. HRESULT SetParam( float fValue );
  44. HRESULT GetParam( float* pfValue );
  45. // Manage UI capture and release
  46. void BeginCapture() { m_bCaptured = TRUE; }
  47. void EndCapture() { m_bCaptured = FALSE; }
  48. // Set the current position, updating current envelope value and deltas
  49. HRESULT UpdateValuesForRefTime( REFERENCE_TIME rt, long lSampleRate );
  50. // Check if automation envelopes have been overriden with a specific value
  51. BOOL IsOverrideActive() const { return m_bOverride || m_bCaptured; }
  52. // Get the current automation data point
  53. float GetCurrentValue() const
  54. {
  55. if (IsOverrideActive())
  56. return m_fOverrideValue;
  57. else
  58. return m_fEnvelopeValue;
  59. }
  60. // Get the current automation deltas (for per-sample rendering)
  61. HRESULT GetCurrentDeltas( double* pdDelta1, double* pdDelta2 ) const
  62. {
  63. if (!m_bValidDeltas)
  64. return E_FAIL;
  65. *pdDelta1 = m_dEnvelopeDelta1;
  66. *pdDelta2 = m_dEnvelopeDelta2;
  67. return S_OK;
  68. }
  69. int IndexForRefTime( REFERENCE_TIME rt ) const;
  70. private:
  71. // Stop overriding data
  72. void stopOverride()
  73. {
  74. if (IsOverrideActive() && GetCount() > 0)
  75. m_bOverride = FALSE;
  76. }
  77. // Make sure the automation track is in a state suitable for playback
  78. void cleanup();
  79. private:
  80. ParamInfo m_info; // information about this parameter
  81. EnvelopeSegs m_envSegs; // the list of envelope segments
  82. float m_fEnvelopeValue; // our evolving dynamic value
  83. double m_dEnvelopeDelta1; // 1st delta of current envelope (w.r.t. seconds)
  84. double m_dEnvelopeDelta2; // 2nd delta of current envelope (w.r.t. seconds)
  85. BOOL m_bValidDeltas; // TRUE when deltas can be used (e.g. except for sin)
  86. BOOL m_bOverride; // TRUE while automation point value is overridden
  87. BOOL m_bCaptured; // TRUE while the captured by the UI
  88. float m_fOverrideValue; // our override value
  89. REFERENCE_TIME m_rtRendered; // latest time rendered so far
  90. private:
  91. CParamEnvelope( const CParamEnvelope& );
  92. CParamEnvelope& operator=( const CParamEnvelope& );
  93. };
  94. ////////////////////////////////////////////////////////////////////////////////
  95. #endif // !defined(AFX_PARAMENVELOPE_H__F04D0178_4674_45AF_9F7A_5C8206DE4CF6__INCLUDED_)