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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_CurveEditor.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
14class CurveEditor;
15
16// Vertical components will ignore mouse events if they occur over a comp which
17// inherits from this class..
19
20
22{
23 CurvePoint() = default;
24 CurvePoint (EditTime t, float val) : time (t), value (val) {}
25
26 EditTime time;
27 float value = 0;
28};
29
30//==============================================================================
32{
33public:
34 CurveEditorPoint() noexcept {}
35 CurveEditorPoint (int i, CurveEditor* ed) : index (i), editor (ed) {}
36 ~CurveEditorPoint() override;
37
38 void selectionStatusChanged (bool isNowSelected) override;
39
40 static bool arePointsConsecutive (const SelectableList&);
41 static bool arePointsOnSameCurve (const SelectableList&);
42
43 static TimeRange getPointTimeRange (const SelectableList&);
44
45 int index = 0;
47};
48
49
50//==============================================================================
52 public SelectableListener,
55 public MouseHoverDetector,
57{
58public:
60 ~CurveEditor() override;
61
62 void paint (juce::Graphics&) override;
63 bool hitTest (int x, int y) override;
64 void visibilityChanged() override;
65
66 void mouseDown (const juce::MouseEvent&) override;
67 void mouseUp (const juce::MouseEvent&) override;
68 void mouseDrag (const juce::MouseEvent&) override;
69 void mouseMove (const juce::MouseEvent&) override;
70 void mouseEnter (const juce::MouseEvent&) override;
71 void mouseExit (const juce::MouseEvent&) override;
72 void mouseDoubleClick (const juce::MouseEvent&) override;
73 void mouseHovered (int mouseX, int mouseY) override;
74 void mouseMovedAfterHover() override;
75
76 juce::MouseCursor getMouseCursor() override;
77
78 void setTimes (TimePosition leftTime, TimePosition rightTime);
79
80 float timeToX (TimePosition) const;
81 TimePosition xToTime (double x) const;
82 float valueToY (float val) const;
83 float yToValue (double y) const;
86
87 void selectableObjectChanged (Selectable*) override;
88 void selectableObjectAboutToBeDeleted (Selectable*) override;
89
90 void changeListenerCallback (juce::ChangeBroadcaster*) override;
91 void updateLineThickness();
92
93 Edit& getEdit() const;
94 virtual Track* getTrack() { return {}; }
95
97
98 virtual float getValueAt (TimePosition) = 0;
99 virtual TimePosition getPointTime (int idx) = 0;
100 virtual float getPointValue (int idx) = 0;
101 virtual float getPointCurve (int idx) = 0;
102 virtual void removePoint (int index) = 0;
103 virtual int addPoint (TimePosition time, float value, float curve) = 0;
104 virtual int getNumPoints() = 0;
105 virtual CurvePoint getBezierHandle (int idx) = 0;
106 virtual CurvePoint getBezierPoint (int idx) = 0;
107 virtual int nextIndexAfter (TimePosition) = 0;
108 virtual void getBezierEnds (int index, double& x1out, float& y1out, double& x2out, float& y2out) = 0;
109 virtual int movePoint (int index, TimePosition newTime, float newValue, bool removeInterveningPoints) = 0;
110 virtual void setValueWhenNoPoints (float value) = 0;
111 virtual CurveEditorPoint* createPoint (int idx) = 0;
112 virtual int curvePoint (int index, float newCurve) = 0;
113 virtual juce::String getCurveName() = 0;
114 virtual int getCurveNameOffset() = 0;
115 virtual Selectable* getItem() = 0;
116 virtual bool isShowingCurve() const = 0;
117 virtual void updateFromTrack() = 0;
118
119 virtual juce::Colour getCurrentLineColour() = 0;
120 virtual juce::Colour getCurrentFillColour();
121 virtual juce::Colour getDefaultLineColour() const = 0;
122 virtual juce::Colour getSelectedLineColour() const = 0;
123 virtual juce::Colour getBackgroundColour() const = 0;
124 virtual juce::Colour getCurveNameTextBackgroundColour() const = 0;
125 virtual juce::Colour getPointOutlineColour() const = 0;
126
127 void selectPoint (int pointIdx, bool addToSelection);
128
129protected:
130 void updatePointUnderMouse (juce::Point<float>);
131 virtual void showBubbleForPointUnderMouse() = 0;
132 virtual void hideBubble() = 0;
133
134 virtual void nonRealTimeDragStart() {}
135 virtual void nonRealTimeDragEnd() {}
136
137 bool isPointSelected (int idx);
138 bool areAnyPointsSelected();
139 CurveEditorPoint* getSelectedPoint (int);
140
141 static constexpr const float pointRadius = 5.0f;
142
143 Edit& edit;
144 juce::UndoManager& undoManager;
145 SelectionManager& selectionManager;
146 float parameterMinValue = 0, parameterRange = 1.0f;
147 TimePosition leftTime, rightTime;
148 int firstIndexOnScreen = 0;
149 int pointUnderMouse = -1, pointBeingMoved = -1;
150 int curveUnderMouse = -1, lineUnderMouse = -1;
151 bool dragged = false, movingAllPoints = false;
152 TimePosition mouseDownTime;
153 float mouseDownValue = 0;
154 bool isCurveSelected = false;
155 float mouseDownCurve = 0;
156 float point1 = 0, point2 = 0;
157 bool realTimeDrag = true;
158 float defaultCurve = 0;
159 float lineThickness = 1.0f;
160
162};
163
164}} // namespace tracktion { inline namespace engine
Point< int > getPosition() const noexcept
void selectionStatusChanged(bool isNowSelected) override
Can be overridden to tell this object that it has just been selected or deselected.
The Tracktion Edit class!
Base class for things that can be selected, and whose properties can appear in the properties panel.
Manages a list of items that are currently selected.
Base class for tracks which contain clips and plugins and can be added to Edit[s].
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Represents a position in real-life time.
Represents a time point in an Edit stored as either time or beats.
A list of Selectables, similar to a juce::Array but contains a cached list of the SelectableClasses f...
time