Chromium Code Reviews| Index: third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.h |
| diff --git a/third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.h b/third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.h |
| index af85e1c7398713b97ab506be16a886ecbb2c432f..75aa304d1c58c531cdc9475c89e21c49b77654ca 100644 |
| --- a/third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.h |
| +++ b/third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.h |
| @@ -64,6 +64,7 @@ class AudioParamTimeline { |
| double duration, |
| ExceptionState&); |
| void cancelScheduledValues(double startTime, ExceptionState&); |
| + void cancelValuesAndHoldAtTime(double cancelTime, ExceptionState&); |
| // hasValue is set to true if a valid timeline value is returned. |
| // otherwise defaultValue is returned. |
| @@ -105,24 +106,44 @@ class AudioParamTimeline { |
| ExponentialRampToValue, |
| SetTarget, |
| SetValueCurve, |
| + // This type is not exposed to Javascript. It's meant to handle the |
| + // cancelValuesAndHoldAtTime() API. |
|
hongchan
2016/12/22 18:41:37
Just a thought: how about renaming this variable t
Raymond Toy
2016/12/22 19:06:23
Actually, the comment is kind of wrong. None of th
|
| + CancelValues, |
| LastType |
| }; |
| - static ParamEvent createLinearRampEvent(float value, |
| - double time, |
| - float initialValue, |
| - double callTime); |
| - static ParamEvent createExponentialRampEvent(float value, |
| - double time, |
| - float initialValue, |
| - double callTime); |
| - static ParamEvent createSetValueEvent(float value, double time); |
| - static ParamEvent createSetTargetEvent(float value, |
| - double time, |
| - double timeConstant); |
| - static ParamEvent createSetValueCurveEvent(const DOMFloat32Array* curve, |
| - double time, |
| - double duration); |
| + static std::unique_ptr<ParamEvent> createLinearRampEvent(float value, |
| + double time, |
| + float initialValue, |
| + double callTime); |
| + static std::unique_ptr<ParamEvent> createExponentialRampEvent( |
| + float value, |
| + double time, |
| + float initialValue, |
| + double callTime); |
| + static std::unique_ptr<ParamEvent> createSetValueEvent(float value, |
| + double time); |
| + static std::unique_ptr<ParamEvent> |
| + createSetTargetEvent(float value, double time, double timeConstant); |
| + static std::unique_ptr<ParamEvent> createSetValueCurveEvent( |
| + const DOMFloat32Array* curve, |
| + double time, |
| + double duration); |
| + static std::unique_ptr<ParamEvent> createCancelValuesEvent( |
| + double time, |
| + std::unique_ptr<ParamEvent> savedEvent); |
| + static std::unique_ptr<ParamEvent> createGeneralEvent( |
|
hongchan
2016/12/22 18:41:37
Can we have a comment why this method is needed? P
Raymond Toy
2016/12/22 19:06:23
It's needed to create a saved event (which is basi
|
| + Type, |
| + float value, |
| + double time, |
| + float initialValue, |
| + double callTime, |
| + double timeConstant, |
| + double duration, |
| + Vector<float>& curve, |
| + double curvePointsPerSecond, |
| + float curveEndValue, |
| + std::unique_ptr<ParamEvent> savedEvent); |
| Type getType() const { return m_type; } |
| float value() const { return m_value; } |
| @@ -136,34 +157,105 @@ class AudioParamTimeline { |
| bool needsTimeClampCheck() const { return m_needsTimeClampCheck; } |
| void clearTimeClampCheck() { m_needsTimeClampCheck = false; } |
| + double curvePointsPerSecond() const { return m_curvePointsPerSecond; } |
| + float curveEndValue() const { return m_curveEndValue; } |
| + |
| + // For CancelValues events. Not valid for any other event |
|
hongchan
2016/12/22 18:41:37
nit: a missing period. Also there is a couple of m
Raymond Toy
2016/12/22 19:21:34
Done.
|
| + ParamEvent* savedEvent() const; |
| + bool hasDefaultCancelledValue() const; |
| + void setCancelledValue(float); |
| + |
| private: |
| + // General event |
| ParamEvent(Type type, |
| float value, |
| double time, |
| + float initialValue, |
| + double callTime, |
| double timeConstant, |
| double duration, |
| + Vector<float>& curve, |
| + double curvePointsPerSecond, |
| + float curveEndValue, |
| + std::unique_ptr<ParamEvent> savedEvent); |
| + |
| + // Create simplest event needing just a value and time, like setValueAtTime |
|
hongchan
2016/12/22 18:41:37
nit: a missing period.
Raymond Toy
2016/12/22 19:21:34
Done.
|
| + ParamEvent(Type, float value, double time); |
| + |
| + // Create a linear or exponential ramp that requires an initial value and |
| + // time in case |
|
hongchan
2016/12/22 18:41:37
nit: the line breaks at the wrong position?
Raymond Toy
2016/12/22 19:21:34
Done.
|
| + // there is no actual event that preceeds this event. |
| + ParamEvent(Type, |
| + float value, |
| + double time, |
| + float initialValue, |
| + double callTime); |
| + |
| + // Create an event needing a time constant (setTargetAtTime) |
| + ParamEvent(Type, float value, double time, double timeConstant); |
| + |
| + // Create a setValueCurve event |
| + ParamEvent(Type, |
| + double time, |
| + double duration, |
| const DOMFloat32Array* curve, |
| - float initialValue = 0, |
| - double callTime = 0); |
| + double curvePointsPerSecond, |
| + float curveEndValue); |
| + |
| + // Create CancelValues event |
| + ParamEvent(Type, double time, std::unique_ptr<ParamEvent> savedEvent); |
| Type m_type; |
| + |
| + // The value for the event. The interpretation of this depends on |
| + // the event type. Not used for SetValueCurve. For CancelValues, |
| + // it is the end value to use when cancelling a LinearRampToValue |
| + // or ExponentialRampToValue event. |
| float m_value; |
| + |
| + // The time for the event. The interpretation of this depends on |
| + // the event type. |
| double m_time; |
| - // Only used for SetTarget events |
| - double m_timeConstant; |
| - // Only used for SetValueCurve events. |
| - double m_duration; |
| - Vector<float> m_curve; |
| + |
| // Initial value and time to use for linear and exponential ramps that don't |
| // have a preceding event. |
| float m_initialValue; |
| double m_callTime; |
| + |
| + // Only used for SetTarget events |
| + double m_timeConstant; |
| + |
| + // The following items are only used for SetValueCurve events |
|
hongchan
2016/12/22 18:41:37
nit: perhaps a colon at the end?
|
| + // |
| + // m_duration is the duration of the curve. |
| + // m_curve is the array of curve poitns. |
| + // m_curvePointsPerSecond is the number of curve points per second. it |
| + // is used to compute the curve index step when running the |
| + // automation. |
| + // m_curveEndValue is the default value to use at the end of the |
| + // curve. Normally it's the last entry in m_curve, but cancelling a |
| + // SetValueCurve will set this to a new value. // Only used for |
| + // SetValueCurve events. |
|
hongchan
2016/12/22 18:41:37
These comments should be located just above each v
Raymond Toy
2016/12/22 19:21:34
Done.
|
| + double m_duration; |
| + Vector<float> m_curve; |
| + double m_curvePointsPerSecond; |
| + float m_curveEndValue; |
| + |
| + // For CancelValues. If CancelValues is in the middle of an event, this |
| + // holds the event that is being cancelled, so that processing can |
| + // continue as if the event still existed up until we reach the actual |
| + // scheduled cancel time. |
| + std::unique_ptr<ParamEvent> m_savedEvent; |
| + |
| // True if the start time needs to be checked against current time |
| // to implement clamping. |
| bool m_needsTimeClampCheck; |
| + |
| + // True if a default value has been assigned to the CancelValues event. |
| + bool m_hasDefaultCancelledValue; |
| }; |
| - void insertEvent(const ParamEvent&, ExceptionState&); |
| + void insertEvent(std::unique_ptr<ParamEvent>, ExceptionState&); |
| float valuesForFrameRangeImpl(size_t startFrame, |
| size_t endFrame, |
| float defaultValue, |
| @@ -174,7 +266,33 @@ class AudioParamTimeline { |
| // Produce a nice string describing the event in human-readable form. |
| String eventToString(const ParamEvent&); |
| - Vector<ParamEvent> m_events; |
| + |
| + // Automation functions that compute the vlaue of the specified |
| + // automation at the specified time. |
| + float linearRampAtTime(double t, |
| + float value1, |
| + double time1, |
| + float value2, |
| + double time2); |
| + float exponentialRampAtTime(double t, |
| + float value1, |
| + double time1, |
| + float value2, |
| + double time2); |
| + float targetValueAtTime(double t, |
| + float value1, |
| + double time1, |
| + float value2, |
| + float timeConstant); |
| + float valueCurveAtTime(double t, |
| + double time1, |
| + double duration, |
| + const float* curveData, |
| + unsigned curveLength); |
| + |
| + // Vector of all automation events for the AudioParam. Access must |
| + // be locked via m_eventsLock. |
| + Vector<std::unique_ptr<ParamEvent>> m_events; |
| mutable Mutex m_eventsLock; |