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_LegacyAudioParameter.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
29JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wdeprecated-declarations")
30JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4996)
31
33{
34public:
36 {
37 processor = &audioProcessorToUse;
38
39 parameterIndex = audioParameterIndex;
40 jassert (parameterIndex < processor->getNumParameters());
41 }
42
43 //==============================================================================
44 float getValue() const override { return processor->getParameter (parameterIndex); }
45 void setValue (float newValue) override { processor->setParameter (parameterIndex, newValue); }
46 float getDefaultValue() const override { return processor->getParameterDefaultValue (parameterIndex); }
47 String getName (int maxLen) const override { return processor->getParameterName (parameterIndex, maxLen); }
48 String getLabel() const override { return processor->getParameterLabel (parameterIndex); }
49 int getNumSteps() const override { return processor->getParameterNumSteps (parameterIndex); }
50 bool isDiscrete() const override { return processor->isParameterDiscrete (parameterIndex); }
51 bool isBoolean() const override { return false; }
52 bool isOrientationInverted() const override { return processor->isParameterOrientationInverted (parameterIndex); }
53 bool isAutomatable() const override { return processor->isParameterAutomatable (parameterIndex); }
54 bool isMetaParameter() const override { return processor->isMetaParameter (parameterIndex); }
55 Category getCategory() const override { return processor->getParameterCategory (parameterIndex); }
56 String getCurrentValueAsText() const override { return processor->getParameterText (parameterIndex); }
57 String getParameterID() const override { return processor->getParameterID (parameterIndex); }
58
59 //==============================================================================
60 float getValueForText (const String&) const override
61 {
62 // legacy parameters do not support this method
64 return 0.0f;
65 }
66
67 String getText (float, int) const override
68 {
69 // legacy parameters do not support this method
71 return {};
72 }
73
74 //==============================================================================
75 static bool isLegacy (AudioProcessorParameter* param) noexcept
76 {
77 return (dynamic_cast<LegacyAudioParameter*> (param) != nullptr);
78 }
79
80 static int getParamIndex (AudioProcessor& processor, AudioProcessorParameter* param) noexcept
81 {
82 if (auto* legacy = dynamic_cast<LegacyAudioParameter*> (param))
83 {
84 return legacy->parameterIndex;
85 }
86 else
87 {
88 auto n = processor.getNumParameters();
89 jassert (n == processor.getParameters().size());
90
91 for (int i = 0; i < n; ++i)
92 {
93 if (processor.getParameters()[i] == param)
94 return i;
95 }
96 }
97
98 return -1;
99 }
100
101 static String getParamID (const AudioProcessorParameter* param, bool forceLegacyParamIDs) noexcept
102 {
103 if (auto* legacy = dynamic_cast<const LegacyAudioParameter*> (param))
104 return forceLegacyParamIDs ? String (legacy->parameterIndex) : legacy->getParameterID();
105
106 if (auto* paramWithID = dynamic_cast<const HostedAudioProcessorParameter*> (param))
107 {
109 return paramWithID->getParameterID();
110 }
111
112 if (param != nullptr)
113 return String (param->getParameterIndex());
114
115 return {};
116 }
117};
118
119//==============================================================================
121{
122public:
124
126 {
128 }
129
131 {
132 clear();
133
134 legacyParamIDs = forceLegacyParamIDs;
135
136 auto numParameters = audioProcessor.getNumParameters();
137 usingManagedParameters = audioProcessor.getParameters().size() == numParameters;
138
139 for (int i = 0; i < numParameters; ++i)
140 {
141 auto* param = [&]() -> AudioProcessorParameter*
142 {
143 if (usingManagedParameters)
144 return audioProcessor.getParameters()[i];
145
146 auto newParam = std::make_unique<LegacyAudioParameter> (audioProcessor, i);
147 auto* result = newParam.get();
148 ownedGroup.addChild (std::move (newParam));
149
150 return result;
151 }();
152
153 params.add (param);
154 }
155
156 processorGroup = usingManagedParameters ? &audioProcessor.getParameterTree()
157 : nullptr;
158 }
159
160 void clear()
161 {
162 ownedGroup = AudioProcessorParameterGroup();
163 params.clear();
164 }
165
166 AudioProcessorParameter* getParamForIndex (int index) const
167 {
168 if (isPositiveAndBelow (index, params.size()))
169 return params[index];
170
171 return nullptr;
172 }
173
174 String getParamID (AudioProcessor& processor, int idx) const noexcept
175 {
176 if (usingManagedParameters && ! legacyParamIDs)
177 return processor.getParameterID (idx);
178
179 return String (idx);
180 }
181
182 const AudioProcessorParameterGroup& getGroup() const
183 {
184 return processorGroup != nullptr ? *processorGroup
185 : ownedGroup;
186 }
187
188 void addNonOwning (AudioProcessorParameter* param)
189 {
190 params.add (param);
191 }
192
193 size_t size() const noexcept { return (size_t) params.size(); }
194
195 bool isUsingManagedParameters() const noexcept { return usingManagedParameters; }
196 int getNumParameters() const noexcept { return params.size(); }
197
198 AudioProcessorParameter* const* begin() const { return params.begin(); }
199 AudioProcessorParameter* const* end() const { return params.end(); }
200
201 bool contains (AudioProcessorParameter* param) const
202 {
203 return params.contains (param);
204 }
205
206private:
207 const AudioProcessorParameterGroup* processorGroup = nullptr;
210 bool legacyParamIDs = false, usingManagedParameters = false;
211};
212
213JUCE_END_IGNORE_WARNINGS_GCC_LIKE
214JUCE_END_IGNORE_WARNINGS_MSVC
215
216} // namespace juce
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
A class encapsulating a group of AudioProcessorParameters and nested AudioProcessorParameterGroups.
void addChild(std::unique_ptr< ParameterOrGroup > child)
Adds a child to the group.
An abstract base class for parameter objects that can be added to an AudioProcessor.
Base class for audio processing classes or plugins.
bool isOrientationInverted() const override
This can be overridden to tell the host that this parameter operates in the reverse direction.
bool isMetaParameter() const override
Should return true if this parameter is a "meta" parameter.
bool isBoolean() const override
Returns whether the parameter represents a boolean switch, typically with "On" and "Off" states.
String getName(int maxLen) const override
Returns the name to display for this parameter, which should be made to fit within the given string l...
float getDefaultValue() const override
This should return the default value for this parameter.
bool isDiscrete() const override
Returns whether the parameter uses discrete values, based on the result of getNumSteps,...
void setValue(float newValue) override
The host will call this method to change the value of a parameter.
String getCurrentValueAsText() const override
Returns the current value of the parameter as a String.
float getValueForText(const String &) const override
Should parse a string and return the appropriate value for it.
Category getCategory() const override
Returns the parameter's category.
String getText(float, int) const override
Returns a textual version of the supplied normalised parameter value.
float getValue() const override
Called by the host to find out the value of this parameter.
bool isAutomatable() const override
Returns true if the host can automate this parameter.
int getNumSteps() const override
Returns the number of steps that this parameter's range should be quantised into.
String getLabel() const override
Some parameters may be able to return a label string for their units.
String getParameterID() const override
Returns an ID that is unique to this parameter.
The JUCE String class!
Definition juce_String.h:53
#define jassert(expression)
Platform-independent assertion macro.
#define jassertfalse
This will always cause an assertion failure.
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.
A parameter with functions that are useful for plugin hosts.