tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_AutomationCurve.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
15{
16public:
18 AutomationCurve (const juce::ValueTree& parent, const juce::ValueTree& state);
21
22 void setState (const juce::ValueTree&);
23 void setParentState (const juce::ValueTree&);
24 void setOwnerParameter (AutomatableParameter*);
25
26 AutomatableParameter* getOwnerParameter() const noexcept { return ownerParam; }
27
28 //==============================================================================
30 {
31 AutomationPoint() noexcept = default;
32
33 AutomationPoint (TimePosition t, float v, float c) noexcept
34 : time (t), value (v), curve (c)
35 {
36 jassert (c >= -1.0 && c <= 1.0);
37 jassert (t.inSeconds() >= 0);
38 }
39
40 juce::ValueTree toValueTree() const;
41
42 TimePosition time;
43 float value = 0, curve = 0;
44
45 bool operator< (const AutomationPoint& other) const { return time < other.time; }
46 };
47
48 //==============================================================================
49 int getNumPoints() const noexcept;
50 TimeDuration getLength() const;
51 juce::Range<float> getValueLimits() const;
52
53 AutomationPoint getPoint (int index) const noexcept;
54 TimePosition getPointTime (int index) const noexcept;
55 float getPointValue (int index) const noexcept;
56 float getPointCurve (int index) const noexcept;
57
58 CurvePoint getBezierHandle (int index) const noexcept;
59 CurvePoint getBezierPoint (int index) const noexcept;
60 void getBezierEnds (int index, double& x1, float& y1, double& x2, float& y2) const noexcept;
61
62 float getValueAt (TimePosition) const;
63
64 int indexBefore (TimePosition) const;
65 int nextIndexAfter (TimePosition) const;
66
67 // returns the index of the next index after this point, xToYRatio is 1 scren unit in value / 1 screen unit in time
68 int getNearestPoint (TimePosition&, float& v, double xToYRatio) const;
69
70 int countPointsInRegion (TimeRange) const;
71
72 //==============================================================================
73 void clear();
74
75 // returns index of new point
76 int addPoint (TimePosition, float value, float curve);
77 void removePoint (int index);
78 void removePointsInRegion (TimeRange);
79 void removeRegionAndCloseGap (TimeRange);
80 void removeRedundantPoints (TimeRange);
81
82 juce::Array<AutomationPoint> getPointsInRegion (TimeRange) const;
83
84 // returns the new index of the point, which may have changed
85 int movePoint (int index, TimePosition, float newValue, bool removeInterveningPoints);
86
87 void setPointTime (int index, TimePosition);
88 void setPointValue (int index, float newValue);
89 void setCurveValue (int index, float newCurve);
90
91 //==============================================================================
92 void mergeOtherCurve (const AutomationCurve& source,
93 TimeRange destRange,
94 TimePosition sourceStartTime,
95 TimeDuration fadeLength,
96 bool leaveOpenAtStart,
97 bool leaveOpenEnded);
98
99 void simplify (TimeRange, double minTimeDifference, float minValueDifference);
100 void rescaleAllTimes (double factor);
101 void addToAllTimes (TimeDuration delta);
102 void rescaleValues (float factor, TimeRange);
103 void addToValues (float valueDelta, TimeRange);
104
105 static double getBezierXfromT (double t, double x1, double xb, double x2);
106 static float getBezierYFromX (double t, double x1, float y1, double xb, float yb, double x2, float y2);
107
108 static void removeAllAutomationCurvesRecursively (const juce::ValueTree&);
109
110 juce::ValueTree parentState, state;
111
112private:
113 AutomatableParameter* ownerParam = nullptr;
114
115 juce::UndoManager* getUndoManager() const;
116 void addPointAtIndex (int index, TimePosition, float v, float c);
117 void checkParenthoodStatus();
118
119 JUCE_LEAK_DETECTOR (AutomationCurve)
120};
121
122//==============================================================================
124int simplify (AutomationCurve&, int strength, TimeRange);
125
126}} // namespace tracktion { inline namespace engine
#define jassert(expression)
Represents a duration in real-life time.
Represents a position in real-life time.
time