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_AudioProcessorParameterGroup.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
29AudioProcessorParameterGroup::AudioProcessorParameterNode::~AudioProcessorParameterNode() = default;
30
31AudioProcessorParameterGroup::AudioProcessorParameterNode::AudioProcessorParameterNode (AudioProcessorParameterNode&& other)
32 : group (std::move (other.group)), parameter (std::move (other.parameter))
33{
34 if (group != nullptr)
35 group->parent = parent;
36}
37
38AudioProcessorParameterGroup::AudioProcessorParameterNode::AudioProcessorParameterNode (std::unique_ptr<AudioProcessorParameter> param,
39 AudioProcessorParameterGroup* parentGroup)
40 : parameter (std::move (param)), parent (parentGroup)
41{}
42
43AudioProcessorParameterGroup::AudioProcessorParameterNode::AudioProcessorParameterNode (std::unique_ptr<AudioProcessorParameterGroup> grp,
44 AudioProcessorParameterGroup* parentGroup)
45 : group (std::move (grp)), parent (parentGroup)
46{
47 group->parent = parent;
48}
49
50AudioProcessorParameterGroup* AudioProcessorParameterGroup::AudioProcessorParameterNode::getParent() const { return parent; }
51AudioProcessorParameter* AudioProcessorParameterGroup::AudioProcessorParameterNode::getParameter() const { return parameter.get(); }
52AudioProcessorParameterGroup* AudioProcessorParameterGroup::AudioProcessorParameterNode::getGroup() const { return group.get(); }
53
54//==============================================================================
55AudioProcessorParameterGroup::AudioProcessorParameterGroup() = default;
56
57AudioProcessorParameterGroup::AudioProcessorParameterGroup (String groupID, String groupName, String subgroupSeparator)
58 : identifier (std::move (groupID)), name (std::move (groupName)), separator (std::move (subgroupSeparator))
59{
60}
61
63
65 : identifier (std::move (other.identifier)),
66 name (std::move (other.name)),
67 separator (std::move (other.separator)),
68 children (std::move (other.children))
69{
70 updateChildParentage();
71}
72
74{
75 identifier = std::move (other.identifier);
76 name = std::move (other.name);
77 separator = std::move (other.separator);
78 children = std::move (other.children);
79 updateChildParentage();
80 return *this;
81}
82
83void AudioProcessorParameterGroup::updateChildParentage()
84{
85 for (auto* child : children)
86 {
87 child->parent = this;
88
89 if (auto* group = child->getGroup())
90 group->parent = this;
91 }
92}
93
94String AudioProcessorParameterGroup::getID() const { return identifier; }
98
99void AudioProcessorParameterGroup::setName (String newName) { name = std::move (newName); }
100
101const AudioProcessorParameterGroup::AudioProcessorParameterNode* const* AudioProcessorParameterGroup::begin() const noexcept { return const_cast<const AudioProcessorParameterNode**> (children.begin()); }
102const AudioProcessorParameterGroup::AudioProcessorParameterNode* const* AudioProcessorParameterGroup::end() const noexcept { return const_cast<const AudioProcessorParameterNode**> (children.end()); }
103
104void AudioProcessorParameterGroup::append (std::unique_ptr<AudioProcessorParameter> newParameter)
105{
106 children.add (new AudioProcessorParameterNode (std::move (newParameter), this));
107}
108
109void AudioProcessorParameterGroup::append (std::unique_ptr<AudioProcessorParameterGroup> newSubGroup)
110{
111 children.add (new AudioProcessorParameterNode (std::move (newSubGroup), this));
112}
113
120
127
129{
131
132 if (auto* group = getGroupForParameter (parameter))
133 {
134 while (group != nullptr && group != this)
135 {
136 groups.insert (0, group);
137 group = group->getParent();
138 }
139 }
140
141 return groups;
142}
143
145{
146 for (auto* child : children)
147 {
148 if (auto* group = child->getGroup())
149 {
150 previousGroups.add (group);
151
152 if (recursive)
153 group->getSubgroups (previousGroups, true);
154 }
155 }
156}
157
159{
160 for (auto* child : children)
161 {
162 if (auto* parameter = child->getParameter())
163 previousParameters.add (parameter);
164 else if (recursive)
165 child->getGroup()->getParameters (previousParameters, true);
166 }
167}
168
169const AudioProcessorParameterGroup* AudioProcessorParameterGroup::getGroupForParameter (AudioProcessorParameter* parameter) const
170{
171 for (auto* child : children)
172 {
173 if (child->getParameter() == parameter)
174 return this;
175
176 if (auto* group = child->getGroup())
177 if (auto* foundGroup = group->getGroupForParameter (parameter))
178 return foundGroup;
179 }
180
181 return nullptr;
182}
183
184//==============================================================================
185#if JUCE_UNIT_TESTS
186
187class ParameterGroupTests final : public UnitTest
188{
189public:
191 : UnitTest ("ParameterGroups", UnitTestCategories::audioProcessorParameters)
192 {}
193
194 void runTest() override
195 {
196 beginTest ("ParameterGroups");
197
198 auto g1 = std::make_unique<AudioProcessorParameterGroup> ("g1", "g1", " - ");
199
200 auto* p1 = new AudioParameterFloat ("p1", "p1", { 0.0f, 2.0f }, 0.5f);
201 auto* p2 = new AudioParameterFloat ("p2", "p2", { 0.0f, 2.0f }, 0.5f);
202 auto* p3 = new AudioParameterFloat ("p3", "p3", { 0.0f, 2.0f }, 0.5f);
203
207
208 auto p4 = std::make_unique<AudioParameterFloat> ("p4", "p4", NormalisableRange<float> (0.0f, 2.0f), 0.5f);
209 auto p5 = std::make_unique<AudioParameterFloat> ("p5", "p5", NormalisableRange<float> (0.0f, 2.0f), 0.5f);
210 auto p6 = std::make_unique<AudioParameterFloat> ("p6", "p6", NormalisableRange<float> (0.0f, 2.0f), 0.5f);
211
212 g1->addChild (std::move (p4));
213 g1->addChild (std::move (p5),
214 std::move (p6));
215
216 {
217 auto topLevelParams = g1->getParameters (false);
218 auto params = g1->getParameters (true);
219 expect (topLevelParams == params);
220 expectEquals (params.size(), 6);
221
222 expect (params[0] == (AudioProcessorParameter*) p1);
223 expect (params[1] == (AudioProcessorParameter*) p2);
224 expect (params[2] == (AudioProcessorParameter*) p3);
225
226 expect (dynamic_cast<AudioParameterFloat*> (params[3])->name == "p4");
227 expect (dynamic_cast<AudioParameterFloat*> (params[4])->name == "p5");
228 expect (dynamic_cast<AudioParameterFloat*> (params[5])->name == "p6");
229 }
230
231 auto* p7 = new AudioParameterFloat ("p7", "p7", { 0.0f, 2.0f }, 0.5f);
232 auto* p8 = new AudioParameterFloat ("p8", "p8", { 0.0f, 2.0f }, 0.5f);
233 auto* p9 = new AudioParameterFloat ("p9", "p9", { 0.0f, 2.0f }, 0.5f);
234
235 auto p10 = std::make_unique<AudioParameterFloat> ("p10", "p10", NormalisableRange<float> (0.0f, 2.0f), 0.5f);
236 auto p11 = std::make_unique<AudioParameterFloat> ("p11", "p11", NormalisableRange<float> (0.0f, 2.0f), 0.5f);
237 auto p12 = std::make_unique<AudioParameterFloat> ("p12", "p12", NormalisableRange<float> (0.0f, 2.0f), 0.5f);
238
239 auto g2 = std::make_unique<AudioProcessorParameterGroup> ("g2", "g2", " | ", std::unique_ptr<AudioParameterFloat> (p7));
240 auto g3 = std::make_unique<AudioProcessorParameterGroup> ("g3", "g3", " | ", std::unique_ptr<AudioParameterFloat> (p8), std::unique_ptr<AudioParameterFloat> (p9));
241 auto g4 = std::make_unique<AudioProcessorParameterGroup> ("g4", "g4", " | ", std::move (p10));
242 auto g5 = std::make_unique<AudioProcessorParameterGroup> ("g5", "g5", " | ", std::move (p11), std::move (p12));
243
244 g1->addChild (std::move (g2));
245 g4->addChild (std::move (g5));
246 g1->addChild (std::move (g3), std::move (g4));
247
248 {
249 auto topLevelParams = g1->getParameters (false);
250 auto params = g1->getParameters (true);
251 expectEquals (topLevelParams.size(), 6);
252 expectEquals (params.size(), 12);
253
254 expect (params[0] == (AudioProcessorParameter*) p1);
255 expect (params[1] == (AudioProcessorParameter*) p2);
256 expect (params[2] == (AudioProcessorParameter*) p3);
257
258 expect (dynamic_cast<AudioParameterFloat*> (params[3])->name == "p4");
259 expect (dynamic_cast<AudioParameterFloat*> (params[4])->name == "p5");
260 expect (dynamic_cast<AudioParameterFloat*> (params[5])->name == "p6");
261
262 expect (params[6] == (AudioProcessorParameter*) p7);
263 expect (params[7] == (AudioProcessorParameter*) p8);
264 expect (params[8] == (AudioProcessorParameter*) p9);
265
266 expect (dynamic_cast<AudioParameterFloat*> (params[9]) ->name == "p10");
267 expect (dynamic_cast<AudioParameterFloat*> (params[10])->name == "p11");
268 expect (dynamic_cast<AudioParameterFloat*> (params[11])->name == "p12");
269 }
270
271 g1->addChild (std::make_unique<AudioProcessorParameterGroup> ("g6", "g6", " | ",
272 std::make_unique<AudioParameterFloat> ("p13", "p13", NormalisableRange<float> (0.0f, 2.0f), 0.5f),
273 std::make_unique<AudioProcessorParameterGroup> ("g7", "g7", " | ",
274 std::make_unique<AudioParameterFloat> ("p14", "p14", NormalisableRange<float> (0.0f, 2.0f), 0.5f)),
275 std::make_unique<AudioParameterFloat> ("p15", "p15", NormalisableRange<float> (0.0f, 2.0f), 0.5f)));
276
277 TestAudioProcessor processor;
278
279 processor.addParameter (new AudioParameterFloat ("pstart", "pstart", NormalisableRange<float> (0.0f, 2.0f), 0.5f));
280 auto groupParams = g1->getParameters (true);
281 processor.addParameterGroup (std::move (g1));
282 processor.addParameter (new AudioParameterFloat ("pend", "pend", NormalisableRange<float> (0.0f, 2.0f), 0.5f));
283
284 auto& processorParams = processor.getParameters();
285 expect (dynamic_cast<AudioParameterFloat*> (processorParams.getFirst())->name == "pstart");
286 expect (dynamic_cast<AudioParameterFloat*> (processorParams.getLast()) ->name == "pend");
287
288 auto numParams = processorParams.size();
289
290 for (int i = 1; i < numParams - 1; ++i)
291 expect (processorParams[i] == groupParams[i - 1]);
292
293 }
294private:
295 struct TestAudioProcessor final : public AudioProcessor
296 {
297 const String getName() const override { return "ap"; }
298 void prepareToPlay (double, int) override {}
299 void releaseResources() override {}
300 void processBlock (AudioBuffer<float>&, MidiBuffer&) override {}
301 using AudioProcessor::processBlock;
302 double getTailLengthSeconds() const override { return 0.0; }
303 bool acceptsMidi() const override { return false; }
304 bool producesMidi() const override { return false; }
305 AudioProcessorEditor* createEditor() override { return nullptr; }
306 bool hasEditor() const override { return false; }
307 int getNumPrograms() override { return 0; }
308 int getCurrentProgram() override { return 0; }
309 void setCurrentProgram (int) override {}
310 const String getProgramName (int) override { return {}; }
311 void changeProgramName (int, const String&) override {}
312 void getStateInformation (MemoryBlock&) override {}
313 void setStateInformation (const void*, int) override {}
314 };
315};
316
318
319#endif
320
321} // namespace juce
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
void insert(int indexToInsertAt, ParameterType newElement)
Inserts a new element into the array at a given position.
Definition juce_Array.h:462
A class encapsulating a group of AudioProcessorParameters and nested AudioProcessorParameterGroups.
String getSeparator() const
Returns the group's separator string.
void setName(String newName)
Changes the name of the group.
String getName() const
Returns the group's name.
Array< const AudioProcessorParameterGroup * > getGroupsForParameter(AudioProcessorParameter *) const
Searches this group recursively for a parameter and returns a depth ordered list of the groups it bel...
Array< AudioProcessorParameter * > getParameters(bool recursive) const
Returns all the parameters in this group.
const AudioProcessorParameterGroup * getParent() const noexcept
Returns the parent of the group, or nullptr if this is a top-level group.
Array< const AudioProcessorParameterGroup * > getSubgroups(bool recursive) const
Returns all subgroups of this group.
AudioProcessorParameterGroup & operator=(AudioProcessorParameterGroup &&)
Once a group has been added to an AudioProcessor don't try to mutate it by moving or swapping it - th...
String getID() const
Returns the group's ID.
AudioProcessorParameterGroup()
Creates an empty AudioProcessorParameterGroup with no name or ID.
An abstract base class for parameter objects that can be added to an AudioProcessor.
The JUCE String class!
Definition juce_String.h:53
T move(T... args)
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