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_AudioPluginInstance.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
35
36void* AudioPluginInstance::getPlatformSpecificData() { return nullptr; }
37
39
40String AudioPluginInstance::getParameterID (int parameterIndex)
41{
42 assertOnceOnDeprecatedMethodUse();
43
44 // Currently there is no corresponding method available in the
45 // AudioProcessorParameter class, and the previous behaviour of JUCE's
46 // plug-in hosting code simply returns a string version of the index; to
47 // maintain backwards compatibility you should perform the operation below
48 // this comment. However the caveat is that for plug-ins which change their
49 // number of parameters dynamically at runtime you cannot rely upon the
50 // returned parameter ID mapping to the correct parameter. A comprehensive
51 // solution to this problem requires some additional work in JUCE's hosting
52 // code.
53 return String (parameterIndex);
54}
55
56float AudioPluginInstance::getParameter (int parameterIndex)
57{
58 assertOnceOnDeprecatedMethodUse();
59
60 if (auto* param = getParameters()[parameterIndex])
61 return param->getValue();
62
63 return 0.0f;
64}
65
66void AudioPluginInstance::setParameter (int parameterIndex, float newValue)
67{
68 assertOnceOnDeprecatedMethodUse();
69
70 if (auto* param = getParameters()[parameterIndex])
71 param->setValue (newValue);
72}
73
74const String AudioPluginInstance::getParameterName (int parameterIndex)
75{
76 assertOnceOnDeprecatedMethodUse();
77
78 if (auto* param = getParameters()[parameterIndex])
79 return param->getName (1024);
80
81 return {};
82}
83
84String AudioPluginInstance::getParameterName (int parameterIndex, int maximumStringLength)
85{
86 assertOnceOnDeprecatedMethodUse();
87
88 if (auto* param = getParameters()[parameterIndex])
89 return param->getName (maximumStringLength);
90
91 return {};
92}
93
94const String AudioPluginInstance::getParameterText (int parameterIndex)
95{
96 assertOnceOnDeprecatedMethodUse();
97
98 if (auto* param = getParameters()[parameterIndex])
99 return param->getCurrentValueAsText();
100
101 return {};
102}
103
104String AudioPluginInstance::getParameterText (int parameterIndex, int maximumStringLength)
105{
106 assertOnceOnDeprecatedMethodUse();
107
108 if (auto* param = getParameters()[parameterIndex])
109 return param->getCurrentValueAsText().substring (0, maximumStringLength);
110
111 return {};
112}
113
114float AudioPluginInstance::getParameterDefaultValue (int parameterIndex)
115{
116 assertOnceOnDeprecatedMethodUse();
117
118 if (auto* param = getParameters()[parameterIndex])
119 return param->getDefaultValue();
120
121 return 0.0f;
122}
123
124int AudioPluginInstance::getParameterNumSteps (int parameterIndex)
125{
126 assertOnceOnDeprecatedMethodUse();
127
128 if (auto* param = getParameters()[parameterIndex])
129 return param->getNumSteps();
130
132}
133
134bool AudioPluginInstance::isParameterDiscrete (int parameterIndex) const
135{
136 assertOnceOnDeprecatedMethodUse();
137
138 if (auto* param = getParameters()[parameterIndex])
139 return param->isDiscrete();
140
141 return false;
142}
143
144bool AudioPluginInstance::isParameterAutomatable (int parameterIndex) const
145{
146 assertOnceOnDeprecatedMethodUse();
147
148 if (auto* param = getParameters()[parameterIndex])
149 return param->isAutomatable();
150
151 return true;
152}
153
154String AudioPluginInstance::getParameterLabel (int parameterIndex) const
155{
156 assertOnceOnDeprecatedMethodUse();
157
158 if (auto* param = getParameters()[parameterIndex])
159 return param->getLabel();
160
161 return {};
162}
163
164bool AudioPluginInstance::isParameterOrientationInverted (int parameterIndex) const
165{
166 assertOnceOnDeprecatedMethodUse();
167
168 if (auto* param = getParameters()[parameterIndex])
169 return param->isOrientationInverted();
170
171 return false;
172}
173
174bool AudioPluginInstance::isMetaParameter (int parameterIndex) const
175{
176 assertOnceOnDeprecatedMethodUse();
177
178 if (auto* param = getParameters()[parameterIndex])
179 return param->isMetaParameter();
180
181 return false;
182}
183
184AudioProcessorParameter::Category AudioPluginInstance::getParameterCategory (int parameterIndex) const
185{
186 assertOnceOnDeprecatedMethodUse();
187
188 if (auto* param = getParameters()[parameterIndex])
189 return param->getCategory();
190
192}
193
194void AudioPluginInstance::assertOnceOnDeprecatedMethodUse() const noexcept
195{
196 if (! deprecationAssertiontriggered)
197 {
198 // If you hit this assertion then you are using at least one of the
199 // methods marked as deprecated in this class. For now you can simply
200 // continue past this point and subsequent uses of deprecated methods
201 // will not trigger additional assertions. However, we will shortly be
202 // removing these methods so you are strongly advised to look at the
203 // implementation of the corresponding method in this class and use
204 // that approach instead.
206 }
207
208 deprecationAssertiontriggered = true;
209}
210
211bool AudioPluginInstance::deprecationAssertiontriggered = false;
212
213AudioPluginInstance::Parameter::Parameter()
214 : onStrings { TRANS ("on"), TRANS ("yes"), TRANS ("true") },
215 offStrings { TRANS ("off"), TRANS ("no"), TRANS ("false") }
216{
217}
218
220{
221 if (isBoolean())
222 return value < 0.5f ? TRANS ("Off") : TRANS ("On");
223
224 return String (value).substring (0, maximumStringLength);
225}
226
228{
229 auto floatValue = text.retainCharacters ("-0123456789.").getFloatValue();
230
231 if (isBoolean())
232 {
233 if (onStrings.contains (text, true))
234 return 1.0f;
235
236 if (offStrings.contains (text, true))
237 return 0.0f;
238
239 return floatValue < 0.5f ? 0.0f : 1.0f;
240 }
241
242 return floatValue;
243}
244
249
251{
252 #if JUCE_DEBUG
253 // All parameters *must* be HostedParameters, otherwise getHostedParameter will return
254 // garbage and your host will crash and burn
255 for (auto* param : group->getParameters (true))
256 {
257 jassert (dynamic_cast<HostedParameter*> (param) != nullptr);
258 }
259 #endif
260
261 addParameterGroup (std::move (group));
262}
263
265{
266 #if JUCE_DEBUG
267 // All parameters *must* be HostedParameters, otherwise getHostedParameter will return
268 // garbage and your host will crash and burn
269 for (auto* param : group.getParameters (true))
270 {
271 jassert (dynamic_cast<HostedParameter*> (param) != nullptr);
272 }
273 #endif
274
275 setParameterTree (std::move (group));
276}
277
279{
280 // It's important that all AudioPluginInstance implementations
281 // only ever own HostedParameters!
282 return static_cast<HostedParameter*> (getParameters()[index]);
283}
284
285} // namespace juce
PluginDescription getPluginDescription() const
Returns a PluginDescription for this plugin.
virtual void getExtensions(ExtensionsVisitor &) const
Allows retrieval of information related to the inner workings of a particular plugin format,...
virtual void fillInPluginDescription(PluginDescription &) const =0
Fills-in the appropriate parts of this plugin description object.
void addHostedParameterGroup(std::unique_ptr< AudioProcessorParameterGroup >)
Adds multiple parameters to this instance.
void addHostedParameter(std::unique_ptr< HostedParameter >)
Adds a parameter to this instance.
void setHostedParameterTree(AudioProcessorParameterGroup)
Adds multiple parameters to this instance.
HostedParameter * getHostedParameter(int index) const
Gets the parameter at a particular index.
A class encapsulating a group of AudioProcessorParameters and nested AudioProcessorParameterGroups.
@ genericParameter
If your parameter is not a meter then you should use this category.
virtual bool isBoolean() const
Returns whether the parameter represents a boolean switch, typically with "On" and "Off" states.
const Array< AudioProcessorParameter * > & getParameters() const
Returns a flat list of the parameters in the current tree.
static int getDefaultNumParameterSteps() noexcept
Returns the default number of steps for a parameter.
A small class to represent some facts about a particular type of plug-in.
The JUCE String class!
Definition juce_String.h:53
float getFloatValue() const noexcept
Parses this string as a floating point number.
String retainCharacters(StringRef charactersToRetain) const
Returns a version of this string that only retains a fixed set of characters.
String substring(int startIndex, int endIndex) const
Returns a subsection of the string.
#define TRANS(stringLiteral)
Uses the LocalisedStrings class to translate the given string literal.
#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
T release(T... args)
float getValueForText(const String &text) const override
Should parse a string and return the appropriate value for it.
String getText(float value, int maximumStringLength) const override
Returns a textual version of the supplied normalised parameter value.
Create a derived implementation of this class and pass it to AudioPluginInstance::getExtensions() to ...
virtual void visitUnknown(const Unknown &)
Will be called if there is no platform specific information available.
A parameter with functions that are useful for plugin hosts.