LMMS
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 (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 {
66 String asText (v, numDecimalPlacesToDisplay);
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
83 static_assert (std::atomic<float>::is_always_lock_free,
84 "AudioParameterFloat requires a lock-free std::atomic<float>");
85 #endif
86}
87
89void AudioParameterFloat::setValue (float newValue) { value = convertFrom0to1 (newValue); valueChanged (get()); }
95
96AudioParameterFloat& AudioParameterFloat::operator= (float newValue)
97{
98 if (value != newValue)
100
101 return *this;
102}
103
104} // namespace juce
Definition juce_AudioParameterFloat.h:33
float get() const noexcept
Definition juce_AudioParameterFloat.h:121
int getNumSteps() const override
Definition juce_AudioParameterFloat.cpp:91
AudioParameterFloat(const ParameterID &parameterID, const String &parameterName, NormalisableRange< float > normalisableRange, float defaultValue, const AudioParameterFloatAttributes &attributes={})
Definition juce_AudioParameterFloat.cpp:29
std::function< String(float, int)> stringFromValueFunction
Definition juce_AudioParameterFloat.h:152
virtual void valueChanged(float newValue)
Definition juce_AudioParameterFloat.cpp:94
float getDefaultValue() const override
Definition juce_AudioParameterFloat.cpp:90
const float valueDefault
Definition juce_AudioParameterFloat.h:151
std::function< float(const String &)> valueFromStringFunction
Definition juce_AudioParameterFloat.h:153
void setValue(float newValue) override
Definition juce_AudioParameterFloat.cpp:89
~AudioParameterFloat() override
Definition juce_AudioParameterFloat.cpp:80
float getValueForText(const String &) const override
Definition juce_AudioParameterFloat.cpp:93
NormalisableRange< float > range
Definition juce_AudioParameterFloat.h:133
float getValue() const override
Definition juce_AudioParameterFloat.cpp:88
String getText(float, int) const override
Definition juce_AudioParameterFloat.cpp:92
std::atomic< float > value
Definition juce_AudioParameterFloat.h:150
virtual int getNumSteps() const
Definition juce_AudioProcessor.cpp:1603
void setValueNotifyingHost(float newValue)
Definition juce_AudioProcessor.cpp:1517
Definition juce_NormalisableRange.h:40
Definition juce_AudioProcessorParameterWithID.h:33
Definition juce_RangedAudioParameter.h:98
float convertTo0to1(float v) const noexcept
Definition juce_RangedAudioParameter.cpp:39
float convertFrom0to1(float v) const noexcept
Definition juce_RangedAudioParameter.cpp:45
Definition juce_String.h:53
String substring(int startIndex, int endIndex) const
Definition juce_String.cpp:1498
unsigned v[N_MAX]
Definition inflate.c:1584
Definition carla_juce.cpp:31
bool approximatelyEqual(Type a, Type b) noexcept
Definition juce_MathsFunctions.h:324
int roundToInt(const FloatType value) noexcept
Definition juce_MathsFunctions.h:465
png_uint_32 length
Definition png.c:2247
const char * text
Definition swell-functions.h:167
int r
Definition crypt.c:458