LMMS
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
34{
35 operator= (other);
36}
37
38MarkerList& MarkerList::operator= (const MarkerList& other)
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
91{
92 return getMarkerByName (name);
93}
94
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
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
178bool MarkerList::Marker::operator== (const Marker& other) const noexcept
179{
180 return name == other.name && position == other.position;
181}
182
183bool MarkerList::Marker::operator!= (const Marker& other) const noexcept
184{
185 return ! operator== (other);
186}
187
188//==============================================================================
192
194 : state (state_)
195{
196}
197
199{
200 return state.getNumChildren();
201}
202
204{
205 return state.getChild (index);
206}
207
209{
210 return state.getChildWithProperty (nameProperty, name);
211}
212
214{
215 return marker.isAChildOf (state);
216}
217
224
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 {
236 marker.setProperty (nameProperty, m.name, nullptr);
237 marker.setProperty (posProperty, m.position.toString(), nullptr);
238 state.appendChild (marker, undoManager);
239 }
240}
241
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//==============================================================================
258{
259 const int numMarkers = getNumMarkers();
260
261 StringArray updatedMarkers;
262
263 for (int i = 0; i < numMarkers; ++i)
264 {
265 const ValueTree marker (state.getChild (i));
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
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
#define noexcept
Definition DistrhoDefines.h:72
static Audio_Scope * scope
Definition player.cpp:26
Definition juce_Component.h:36
Definition juce_Identifier.h:39
Definition juce_MarkerList.h:129
virtual void markerListBeingDeleted(MarkerList *markerList)
Definition juce_MarkerList.cpp:153
Definition juce_MarkerList.h:54
String name
Definition juce_MarkerList.h:62
Marker(const Marker &)
Definition juce_MarkerList.cpp:168
RelativeCoordinate position
Definition juce_MarkerList.h:75
void removeMarker(const ValueTree &state, UndoManager *undoManager)
Definition juce_MarkerList.cpp:242
static const Identifier nameProperty
Definition juce_MarkerList.h:179
MarkerList::Marker getMarker(const ValueTree &state) const
Definition juce_MarkerList.cpp:218
bool containsMarker(const ValueTree &state) const
Definition juce_MarkerList.cpp:213
int getNumMarkers() const
Definition juce_MarkerList.cpp:198
void setMarker(const MarkerList::Marker &marker, UndoManager *undoManager)
Definition juce_MarkerList.cpp:225
void applyTo(MarkerList &markerList)
Definition juce_MarkerList.cpp:257
ValueTree state
Definition juce_MarkerList.h:182
ValueTreeWrapper(const ValueTree &state)
Definition juce_MarkerList.cpp:193
void readFrom(const MarkerList &markerList, UndoManager *undoManager)
Definition juce_MarkerList.cpp:276
ValueTree getMarkerState(int index) const
Definition juce_MarkerList.cpp:203
static const Identifier posProperty
Definition juce_MarkerList.h:179
static const Identifier markerTag
Definition juce_MarkerList.h:179
void setMarker(const String &name, const RelativeCoordinate &position)
Definition juce_MarkerList.cpp:108
MarkerList()
Definition juce_MarkerList.cpp:29
Marker * getMarkerByName(const String &name) const noexcept
Definition juce_MarkerList.cpp:95
const Marker * getMarker(int index) const noexcept
Definition juce_MarkerList.cpp:85
void markersHaveChanged()
Definition juce_MarkerList.cpp:148
void removeListener(Listener *listener)
Definition juce_MarkerList.cpp:162
OwnedArray< Marker > markers
Definition juce_MarkerList.h:187
double getMarkerPosition(const Marker &marker, Component *parentComponent) const
Definition juce_MarkerList.cpp:247
void removeMarker(int index)
Definition juce_MarkerList.cpp:125
ListenerList< Listener > listeners
Definition juce_MarkerList.h:188
~MarkerList()
Definition juce_MarkerList.cpp:50
void addListener(Listener *listener)
Definition juce_MarkerList.cpp:157
int getNumMarkers() const noexcept
Definition juce_MarkerList.cpp:80
Definition juce_RelativeCoordinate.h:73
Definition juce_RelativeCoordinatePositioner.h:58
Definition juce_StringArray.h:35
bool contains(StringRef stringToLookFor, bool ignoreCase=false) const
Definition juce_StringArray.cpp:189
void add(String stringToAdd)
Definition juce_StringArray.cpp:136
Definition juce_String.h:53
Definition juce_UndoManager.h:52
Definition juce_ValueTree.h:72
int * l
Definition inflate.c:1579
unsigned * m
Definition inflate.c:1559
register unsigned i
Definition inflate.c:1575
static const char * name
Definition pugl.h:1582
int marker
Definition jpeglib.h:950
#define jassert(expression)
Definition carla_juce.cpp:31
juce::String toString(const Steinberg::char8 *string) noexcept
Definition juce_VST3Common.h:159
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Definition juce_MathsFunctions.h:279
#define const
Definition zconf.h:137