Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.h

Issue 1533103002: Implement cancelValuesAndHoldAtTime (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 eeb0909954e19cb45652a7acab693e322930b75f..78997457467743bf5e140e7364b21e023d766324 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,27 +106,50 @@ class AudioParamTimeline {
ExponentialRampToValue,
SetTarget,
SetValueCurve,
+ // For cancelValuesAndHold
+ 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 bool eventPreceeds(const ParamEvent& a, const ParamEvent& b) {
- return a.time() < b.time();
+ 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);
+ // Needed for creating a saved event where we want to supply all
+ // the possible parameters because we're mostly copying an
+ // existing event.
+ static std::unique_ptr<ParamEvent> createGeneralEvent(
+ 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);
+
+ static bool eventPreceeds(const std::unique_ptr<ParamEvent>& a,
+ const std::unique_ptr<ParamEvent>& b) {
+ return a->time() < b->time();
}
Type getType() const { return m_type; }
@@ -140,34 +164,104 @@ 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.
+ 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.
+ ParamEvent(Type, float value, double time);
+
+ // Create a linear or exponential ramp that requires an initial
+ // value and time in case 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.
+ //
+ // The duration of the curve.
+ double m_duration;
+ // The array of curve points.
+ Vector<float> m_curve;
+ // The number of curve points per second. it is used to compute
+ // the curve index step when running the automation.
+ double m_curvePointsPerSecond;
+ // 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.
+ 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,
@@ -178,7 +272,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;

Powered by Google App Engine
This is Rietveld 408576698