LMMS
Loading...
Searching...
No Matches
juce_AudioParameterBool.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,
31 bool def,
32 const AudioParameterBoolAttributes& attributes)
33 : RangedAudioParameter (idToUse, nameToUse, attributes.getAudioProcessorParameterWithIDAttributes()),
34 value (def ? 1.0f : 0.0f),
35 valueDefault (def),
36 stringFromBoolFunction (attributes.getStringFromValueFunction() != nullptr
37 ? attributes.getStringFromValueFunction()
38 : [] (bool v, int) { return v ? TRANS("On") : TRANS("Off"); }),
39 boolFromStringFunction (attributes.getValueFromStringFunction() != nullptr
40 ? attributes.getValueFromStringFunction()
41 : [] (const String& text)
42 {
43 static const StringArray onStrings { TRANS ("on"), TRANS ("yes"), TRANS ("true") };
44 static const StringArray offStrings { TRANS ("off"), TRANS ("no"), TRANS ("false") };
45
46 String lowercaseText (text.toLowerCase());
47
48 for (auto& testText : onStrings)
49 if (lowercaseText == testText)
50 return true;
51
52 for (auto& testText : offStrings)
53 if (lowercaseText == testText)
54 return false;
55
56 return text.getIntValue() != 0;
57 })
58{
59}
60
62{
63 #if __cpp_lib_atomic_is_always_lock_free
64 static_assert (std::atomic<float>::is_always_lock_free,
65 "AudioParameterBool requires a lock-free std::atomic<float>");
66 #endif
67}
68
69float AudioParameterBool::getValue() const { return value; }
70void AudioParameterBool::setValue (float newValue) { value = newValue; valueChanged (get()); }
72int AudioParameterBool::getNumSteps() const { return 2; }
73bool AudioParameterBool::isDiscrete() const { return true; }
74bool AudioParameterBool::isBoolean() const { return true; }
76
78{
79 return boolFromStringFunction (text) ? 1.0f : 0.0f;
80}
81
82String AudioParameterBool::getText (float v, int maximumLength) const
83{
84 return stringFromBoolFunction (v >= 0.5f, maximumLength);
85}
86
87AudioParameterBool& AudioParameterBool::operator= (bool newValue)
88{
89 if (get() != newValue)
90 setValueNotifyingHost (newValue ? 1.0f : 0.0f);
91
92 return *this;
93}
94
95} // namespace juce
#define nullptr
Definition DistrhoDefines.h:75
Definition juce_AudioParameterBool.h:33
bool get() const noexcept
Definition juce_AudioParameterBool.h:101
String getText(float, int) const override
Definition juce_AudioParameterBool.cpp:82
std::atomic< float > value
Definition juce_AudioParameterBool.h:130
virtual void valueChanged(bool newValue)
Definition juce_AudioParameterBool.cpp:75
int getNumSteps() const override
Definition juce_AudioParameterBool.cpp:72
const float valueDefault
Definition juce_AudioParameterBool.h:131
float getValue() const override
Definition juce_AudioParameterBool.cpp:69
std::function< String(bool, int)> stringFromBoolFunction
Definition juce_AudioParameterBool.h:132
void setValue(float newValue) override
Definition juce_AudioParameterBool.cpp:70
std::function< bool(const String &)> boolFromStringFunction
Definition juce_AudioParameterBool.h:133
AudioParameterBool(const ParameterID &parameterID, const String &parameterName, bool defaultValue, const AudioParameterBoolAttributes &attributes={})
Definition juce_AudioParameterBool.cpp:29
~AudioParameterBool() override
Definition juce_AudioParameterBool.cpp:61
bool isBoolean() const override
Definition juce_AudioParameterBool.cpp:74
float getDefaultValue() const override
Definition juce_AudioParameterBool.cpp:71
float getValueForText(const String &) const override
Definition juce_AudioParameterBool.cpp:77
bool isDiscrete() const override
Definition juce_AudioParameterBool.cpp:73
void setValueNotifyingHost(float newValue)
Definition juce_AudioProcessor.cpp:1517
Definition juce_AudioProcessorParameterWithID.h:33
Definition juce_RangedAudioParameter.h:98
Definition juce_StringArray.h:35
Definition juce_String.h:53
unsigned v[N_MAX]
Definition inflate.c:1584
#define TRANS(stringLiteral)
Definition juce_LocalisedStrings.h:208
Definition carla_juce.cpp:31
const char * text
Definition swell-functions.h:167
for(n=0;n< RAND_HEAD_LEN;n++)
Definition crypt.c:467
typedef int(UZ_EXP MsgFn)()