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_AudioParameterFloat.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
30 const String& nameToUse,
32 float def,
33 const AudioParameterFloatAttributes& attributes)
34 : RangedAudioParameter (idToUse, nameToUse, attributes.getAudioProcessorParameterWithIDAttributes()),
35 range (r),
36 value (def),
37 valueDefault (def),
38 stringFromValueFunction (attributes.getStringFromValueFunction()),
39 valueFromStringFunction (attributes.getValueFromStringFunction())
40{
41 if (stringFromValueFunction == nullptr)
42 {
43 auto numDecimalPlacesToDisplay = [this]
44 {
45 int numDecimalPlaces = 7;
46
47 if (! approximatelyEqual (range.interval, 0.0f))
48 {
49 if (approximatelyEqual (std::abs (range.interval - std::floor (range.interval)), 0.0f))
50 return 0;
51
52 auto v = std::abs (roundToInt (range.interval * pow (10, numDecimalPlaces)));
53
54 while ((v % 10) == 0 && numDecimalPlaces > 0)
55 {
56 --numDecimalPlaces;
57 v /= 10;
58 }
59 }
60
61 return numDecimalPlaces;
62 }();
63
64 stringFromValueFunction = [numDecimalPlacesToDisplay] (float v, int length)
65 {
67 return length > 0 ? asText.substring (0, length) : asText;
68 };
69 }
70
71 if (valueFromStringFunction == nullptr)
72 valueFromStringFunction = [] (const String& text) { return text.getFloatValue(); };
73}
74
75AudioParameterFloat::AudioParameterFloat (const ParameterID& pid, const String& nm, float minValue, float maxValue, float def)
76 : AudioParameterFloat (pid, nm, { minValue, maxValue, 0.01f }, def)
77{
78}
79
81{
82 #if __cpp_lib_atomic_is_always_lock_free
84 "AudioParameterFloat requires a lock-free std::atomic<float>");
85 #endif
86}
87
88float AudioParameterFloat::getValue() const { return convertTo0to1 (value); }
89void AudioParameterFloat::setValue (float newValue) { value = convertFrom0to1 (newValue); valueChanged (get()); }
90float AudioParameterFloat::getDefaultValue() const { return convertTo0to1 (valueDefault); }
91int AudioParameterFloat::getNumSteps() const { return AudioProcessorParameterWithID::getNumSteps(); }
92String AudioParameterFloat::getText (float v, int length) const { return stringFromValueFunction (convertFrom0to1 (v), length); }
93float AudioParameterFloat::getValueForText (const String& text) const { return convertTo0to1 (valueFromStringFunction (text)); }
95
97{
98 if (! approximatelyEqual ((float) value, newValue))
100
101 return *this;
102}
103
104} // namespace juce
Properties of an AudioParameterFloat.
A subclass of AudioProcessorParameter that provides an easy way to create a parameter which maps onto...
float get() const noexcept
Returns the parameter's current value.
AudioParameterFloat(const ParameterID &parameterID, const String &parameterName, NormalisableRange< float > normalisableRange, float defaultValue, const AudioParameterFloatAttributes &attributes={})
Creates a AudioParameterFloat with the specified parameters.
virtual void valueChanged(float newValue)
Override this method if you are interested in receiving callbacks when the parameter value changes.
AudioParameterFloat & operator=(float newValue)
Changes the parameter's current value.
~AudioParameterFloat() override
Destructor.
NormalisableRange< float > range
Provides access to the parameter's range.
virtual int getNumSteps() const
Returns the number of steps that this parameter's range should be quantised into.
void setValueNotifyingHost(float newValue)
A processor should call this when it needs to change one of its parameters.
Represents a mapping between an arbitrary range of values and a normalised 0->1 range.
ValueType interval
The snapping interval that should be used (for a non-normalised value).
Combines a parameter ID and a version hint.
This abstract base class is used by some AudioProcessorParameter helper classes.
float convertTo0to1(float v) const noexcept
Normalises and snaps a value based on the normalisable range.
float convertFrom0to1(float v) const noexcept
Denormalises and snaps a value based on the normalisable range.
The JUCE String class!
Definition juce_String.h:53
T floor(T... args)
JUCE Namespace.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
@ valueChanged
Indicates that the UI element's value has changed.
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
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.
pow