29AudioProcessorParameterGroup::AudioProcessorParameterNode::~AudioProcessorParameterNode() =
default;
31AudioProcessorParameterGroup::AudioProcessorParameterNode::AudioProcessorParameterNode (AudioProcessorParameterNode&& other)
32 : group (
std::
move (other.group)), parameter (
std::
move (other.parameter))
35 group->parent = parent;
39 AudioProcessorParameterGroup* parentGroup)
40 : parameter (
std::
move (param)), parent (parentGroup)
44 AudioProcessorParameterGroup* parentGroup)
45 : group (
std::
move (grp)), parent (parentGroup)
47 group->parent = parent;
51AudioProcessorParameter* AudioProcessorParameterGroup::AudioProcessorParameterNode::getParameter()
const {
return parameter.get(); }
55AudioProcessorParameterGroup::AudioProcessorParameterGroup() =
default;
57AudioProcessorParameterGroup::AudioProcessorParameterGroup (
String groupID,
String groupName,
String subgroupSeparator)
58 : identifier (
std::move (groupID)), name (
std::move (groupName)), separator (
std::move (subgroupSeparator))
65 : identifier (
std::move (other.identifier)),
66 name (
std::move (other.name)),
67 separator (
std::move (other.separator)),
68 children (
std::move (other.children))
70 updateChildParentage();
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();
83void AudioProcessorParameterGroup::updateChildParentage()
85 for (
auto* child : children)
89 if (
auto* group = child->getGroup())
102const AudioProcessorParameterGroup::AudioProcessorParameterNode*
const* AudioProcessorParameterGroup::end() const noexcept {
return const_cast<const AudioProcessorParameterNode**
> (children.end()); }
106 children.add (
new AudioProcessorParameterNode (std::move (newParameter),
this));
111 children.add (
new AudioProcessorParameterNode (std::move (newSubGroup),
this));
132 if (
auto* group = getGroupForParameter (parameter))
134 while (group !=
nullptr && group !=
this)
137 group = group->getParent();
146 for (
auto* child : children)
148 if (
auto* group = child->getGroup())
150 previousGroups.
add (group);
153 group->getSubgroups (previousGroups,
true);
160 for (
auto* child : children)
162 if (
auto* parameter = child->getParameter())
163 previousParameters.add (parameter);
165 child->getGroup()->getParameters (previousParameters,
true);
169const AudioProcessorParameterGroup* AudioProcessorParameterGroup::getGroupForParameter (AudioProcessorParameter* parameter)
const
171 for (
auto* child : children)
173 if (child->getParameter() == parameter)
176 if (
auto* group = child->getGroup())
177 if (
auto* foundGroup = group->getGroupForParameter (parameter))
187class ParameterGroupTests final :
public UnitTest
190 ParameterGroupTests()
191 : UnitTest (
"ParameterGroups", UnitTestCategories::audioProcessorParameters)
194 void runTest()
override
196 beginTest (
"ParameterGroups");
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);
212 g1->addChild (std::move (p4));
213 g1->addChild (std::move (p5),
217 auto topLevelParams = g1->getParameters (
false);
218 auto params = g1->getParameters (
true);
219 expect (topLevelParams == params);
220 expectEquals (params.size(), 6);
222 expect (params[0] == (AudioProcessorParameter*) p1);
223 expect (params[1] == (AudioProcessorParameter*) p2);
224 expect (params[2] == (AudioProcessorParameter*) p3);
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");
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);
244 g1->addChild (std::move (g2));
245 g4->addChild (std::move (g5));
246 g1->addChild (std::move (g3), std::move (g4));
249 auto topLevelParams = g1->getParameters (
false);
250 auto params = g1->getParameters (
true);
251 expectEquals (topLevelParams.size(), 6);
252 expectEquals (params.size(), 12);
254 expect (params[0] == (AudioProcessorParameter*) p1);
255 expect (params[1] == (AudioProcessorParameter*) p2);
256 expect (params[2] == (AudioProcessorParameter*) p3);
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");
262 expect (params[6] == (AudioProcessorParameter*) p7);
263 expect (params[7] == (AudioProcessorParameter*) p8);
264 expect (params[8] == (AudioProcessorParameter*) p9);
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");
277 TestAudioProcessor processor;
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));
284 auto& processorParams = processor.getParameters();
285 expect (
dynamic_cast<AudioParameterFloat*
> (processorParams.getFirst())->name ==
"pstart");
286 expect (
dynamic_cast<AudioParameterFloat*
> (processorParams.getLast()) ->name ==
"pend");
288 auto numParams = processorParams.size();
290 for (
int i = 1; i < numParams - 1; ++i)
291 expect (processorParams[i] == groupParams[i - 1]);
295 struct TestAudioProcessor final :
public AudioProcessor
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 {}
317static ParameterGroupTests parameterGroupTests;
Holds a resizable array of primitive or copy-by-value objects.
void insert(int indexToInsertAt, ParameterType newElement)
Inserts a new element into the array at a given position.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
A child of an AudioProcessorParameterGroup.
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.
~AudioProcessorParameterGroup()
Destructor.
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.