JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_MarkerList.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
32
37
39{
40 if (other != *this)
41 {
42 markers.clear();
43 markers.addCopiesOf (other.markers);
45 }
46
47 return *this;
48}
49
51{
52 listeners.call ([this] (Listener& l) { l.markerListBeingDeleted (this); });
53}
54
55bool MarkerList::operator== (const MarkerList& other) const noexcept
56{
57 if (other.markers.size() != markers.size())
58 return false;
59
60 for (int i = markers.size(); --i >= 0;)
61 {
62 const Marker* const m1 = markers.getUnchecked (i);
63 jassert (m1 != nullptr);
64
65 const Marker* const m2 = other.getMarker (m1->name);
66
67 if (m2 == nullptr || *m1 != *m2)
68 return false;
69 }
70
71 return true;
72}
73
74bool MarkerList::operator!= (const MarkerList& other) const noexcept
75{
76 return ! operator== (other);
77}
78
79//==============================================================================
81{
82 return markers.size();
83}
84
85const MarkerList::Marker* MarkerList::getMarker (const int index) const noexcept
86{
87 return markers [index];
88}
89
90const MarkerList::Marker* MarkerList::getMarker (const String& name) const noexcept
91{
92 return getMarkerByName (name);
93}
94
95MarkerList::Marker* MarkerList::getMarkerByName (const String& name) const noexcept
96{
97 for (int i = 0; i < markers.size(); ++i)
98 {
99 Marker* const m = markers.getUnchecked (i);
100
101 if (m->name == name)
102 return m;
103 }
104
105 return nullptr;
106}
107
108void MarkerList::setMarker (const String& name, const RelativeCoordinate& position)
109{
110 if (Marker* const m = getMarkerByName (name))
111 {
112 if (m->position != position)
113 {
114 m->position = position;
116 }
117
118 return;
119 }
120
121 markers.add (new Marker (name, position));
123}
124
125void MarkerList::removeMarker (const int index)
126{
127 if (isPositiveAndBelow (index, markers.size()))
128 {
129 markers.remove (index);
131 }
132}
133
135{
136 for (int i = 0; i < markers.size(); ++i)
137 {
138 const Marker* const m = markers.getUnchecked (i);
139
140 if (m->name == name)
141 {
142 markers.remove (i);
144 }
145 }
146}
147
149{
150 listeners.call ([this] (Listener& l) { l.markersChanged (this); });
151}
152
156
158{
159 listeners.add (listener);
160}
161
163{
164 listeners.remove (listener);
165}
166
167//==============================================================================
169 : name (other.name), position (other.position)
170{
171}
172
174 : name (name_), position (position_)
175{
176}
177
179{
180 return name == other.name && position == other.position;
181}
182
184{
185 return ! operator== (other);
186}
187
188//==============================================================================
189const Identifier MarkerList::ValueTreeWrapper::markerTag ("Marker");
190const Identifier MarkerList::ValueTreeWrapper::nameProperty ("name");
191const Identifier MarkerList::ValueTreeWrapper::posProperty ("position");
192
193MarkerList::ValueTreeWrapper::ValueTreeWrapper (const ValueTree& state_)
194 : state (state_)
195{
196}
197
198int MarkerList::ValueTreeWrapper::getNumMarkers() const
199{
200 return state.getNumChildren();
201}
202
203ValueTree MarkerList::ValueTreeWrapper::getMarkerState (int index) const
204{
205 return state.getChild (index);
206}
207
208ValueTree MarkerList::ValueTreeWrapper::getMarkerState (const String& name) const
209{
210 return state.getChildWithProperty (nameProperty, name);
211}
212
213bool MarkerList::ValueTreeWrapper::containsMarker (const ValueTree& marker) const
214{
215 return marker.isAChildOf (state);
216}
217
218MarkerList::Marker MarkerList::ValueTreeWrapper::getMarker (const ValueTree& marker) const
219{
220 jassert (containsMarker (marker));
221
222 return MarkerList::Marker (marker [nameProperty], RelativeCoordinate (marker [posProperty].toString()));
223}
224
225void MarkerList::ValueTreeWrapper::setMarker (const MarkerList::Marker& m, UndoManager* undoManager)
226{
227 ValueTree marker (state.getChildWithProperty (nameProperty, m.name));
228
229 if (marker.isValid())
230 {
231 marker.setProperty (posProperty, m.position.toString(), undoManager);
232 }
233 else
234 {
235 marker = ValueTree (markerTag);
236 marker.setProperty (nameProperty, m.name, nullptr);
237 marker.setProperty (posProperty, m.position.toString(), nullptr);
238 state.appendChild (marker, undoManager);
239 }
240}
241
242void MarkerList::ValueTreeWrapper::removeMarker (const ValueTree& marker, UndoManager* undoManager)
243{
244 state.removeChild (marker, undoManager);
245}
246
247double MarkerList::getMarkerPosition (const Marker& marker, Component* parentComponent) const
248{
249 if (parentComponent == nullptr)
250 return marker.position.resolve (nullptr);
251
253 return marker.position.resolve (&scope);
254}
255
256//==============================================================================
257void MarkerList::ValueTreeWrapper::applyTo (MarkerList& markerList)
258{
259 const int numMarkers = getNumMarkers();
260
262
263 for (int i = 0; i < numMarkers; ++i)
264 {
265 const ValueTree marker (state.getChild (i));
266 const String name (marker [nameProperty].toString());
267 markerList.setMarker (name, RelativeCoordinate (marker [posProperty].toString()));
268 updatedMarkers.add (name);
269 }
270
271 for (int i = markerList.getNumMarkers(); --i >= 0;)
272 if (! updatedMarkers.contains (markerList.getMarker (i)->name))
273 markerList.removeMarker (i);
274}
275
276void MarkerList::ValueTreeWrapper::readFrom (const MarkerList& markerList, UndoManager* undoManager)
277{
278 state.removeAllChildren (undoManager);
279
280 for (int i = 0; i < markerList.getNumMarkers(); ++i)
281 setMarker (*markerList.getMarker (i), undoManager);
282}
283
284} // namespace juce
The base class for all JUCE user-interface objects.
Represents a string identifier, designed for accessing properties by name.
A class for receiving events when changes are made to a MarkerList.
virtual void markerListBeingDeleted(MarkerList *markerList)
Called when the given marker list is being deleted.
Represents a marker in a MarkerList.
bool operator==(const Marker &) const noexcept
Returns true if both the names and positions of these two markers match.
String name
The marker's name.
Marker(const Marker &)
Creates a copy of another Marker.
RelativeCoordinate position
The marker's position.
bool operator!=(const Marker &) const noexcept
Returns true if either the name or position of these two markers differ.
Holds a set of named marker points along a one-dimensional axis.
void setMarker(const String &name, const RelativeCoordinate &position)
Sets the position of a marker.
bool operator!=(const MarkerList &) const noexcept
Returns true if not all the markers in these two lists match exactly.
MarkerList()
Creates an empty marker list.
const Marker * getMarker(int index) const noexcept
Returns one of the markers in the list, by its index.
void markersHaveChanged()
Synchronously calls markersChanged() on all the registered listeners.
void removeListener(Listener *listener)
Deregisters a previously-registered listener.
bool operator==(const MarkerList &) const noexcept
Returns true if all the markers in these two lists match exactly.
double getMarkerPosition(const Marker &marker, Component *parentComponent) const
Evaluates the given marker and returns its absolute position.
void removeMarker(int index)
Deletes the marker at the given list index.
~MarkerList()
Destructor.
void addListener(Listener *listener)
Registers a listener that will be called when the markers are changed.
int getNumMarkers() const noexcept
Returns the number of markers in the list.
MarkerList & operator=(const MarkerList &)
Copies another marker list to this one.
Used for resolving a RelativeCoordinate expression in the context of a component.
Expresses a coordinate as a dynamically evaluated expression.
double resolve(const Expression::Scope *evaluationScope) const
Calculates the absolute position of this coordinate.
A special array for holding a list of strings.
The JUCE String class!
Definition juce_String.h:53
A powerful tree structure that can be used to hold free-form data, and which can handle its own undo ...
#define jassert(expression)
Platform-independent assertion macro.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.
std::u16string toString(NumberT value)
convert an number to an UTF-16 string