|
|
|
@@ -45,14 +45,27 @@ AudioProcessorParameter::Category AudioProcessorParameterWithID::getCategory() c |
|
|
|
//==============================================================================
|
|
|
|
AudioParameterFloat::AudioParameterFloat (const String& idToUse, const String& nameToUse,
|
|
|
|
NormalisableRange<float> r, float def,
|
|
|
|
const String& labelToUse, Category categoryToUse)
|
|
|
|
const String& labelToUse, Category categoryToUse,
|
|
|
|
std::function<String (float, int)> stringFromValue,
|
|
|
|
std::function<float (const String&)> valueFromString)
|
|
|
|
: AudioProcessorParameterWithID (idToUse, nameToUse, labelToUse, categoryToUse),
|
|
|
|
range (r), value (def), defaultValue (def)
|
|
|
|
range (r), value (def), defaultValue (def),
|
|
|
|
stringFromValueFunction (stringFromValue),
|
|
|
|
valueFromStringFunction (valueFromString)
|
|
|
|
{
|
|
|
|
if (stringFromValueFunction == nullptr)
|
|
|
|
stringFromValueFunction = [] (float v, int length)
|
|
|
|
{
|
|
|
|
String asText (v, 2);
|
|
|
|
return length > 0 ? asText.substring (0, length) : asText;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (valueFromStringFunction == nullptr)
|
|
|
|
valueFromStringFunction = [] (const String& text) { return text.getFloatValue(); };
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioParameterFloat::AudioParameterFloat (String pid, String nm, float minValue, float maxValue, float def)
|
|
|
|
: AudioProcessorParameterWithID (pid, nm), range (minValue, maxValue), value (def), defaultValue (def)
|
|
|
|
: AudioParameterFloat (pid, nm, { minValue, maxValue }, def)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@@ -62,15 +75,10 @@ float AudioParameterFloat::getValue() const { retur |
|
|
|
void AudioParameterFloat::setValue (float newValue) { value = range.convertFrom0to1 (newValue); valueChanged (get()); }
|
|
|
|
float AudioParameterFloat::getDefaultValue() const { return range.convertTo0to1 (defaultValue); }
|
|
|
|
int AudioParameterFloat::getNumSteps() const { return AudioProcessorParameterWithID::getNumSteps(); }
|
|
|
|
float AudioParameterFloat::getValueForText (const String& text) const { return range.convertTo0to1 (text.getFloatValue()); }
|
|
|
|
String AudioParameterFloat::getText (float v, int length) const { return stringFromValueFunction (range.convertFrom0to1 (v), length); }
|
|
|
|
float AudioParameterFloat::getValueForText (const String& text) const { return range.convertTo0to1 (valueFromStringFunction (text)); }
|
|
|
|
void AudioParameterFloat::valueChanged (float) {}
|
|
|
|
|
|
|
|
String AudioParameterFloat::getText (float v, int length) const
|
|
|
|
{
|
|
|
|
String asText (range.convertFrom0to1 (v), 2);
|
|
|
|
return length > 0 ? asText.substring (0, length) : asText;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioParameterFloat& AudioParameterFloat::operator= (float newValue)
|
|
|
|
{
|
|
|
|
if (value != newValue)
|
|
|
|
@@ -82,13 +90,23 @@ AudioParameterFloat& AudioParameterFloat::operator= (float newValue) |
|
|
|
//==============================================================================
|
|
|
|
AudioParameterInt::AudioParameterInt (const String& idToUse, const String& nameToUse,
|
|
|
|
int mn, int mx, int def,
|
|
|
|
const String& labelToUse)
|
|
|
|
const String& labelToUse,
|
|
|
|
std::function<String (int, int)> stringFromInt,
|
|
|
|
std::function<int (const String&)> intFromString)
|
|
|
|
: AudioProcessorParameterWithID (idToUse, nameToUse, labelToUse),
|
|
|
|
minValue (mn), maxValue (mx), rangeOfValues (maxValue - minValue),
|
|
|
|
value ((float) def),
|
|
|
|
defaultValue (convertTo0to1 (def))
|
|
|
|
defaultValue (convertTo0to1 (def)),
|
|
|
|
stringFromIntFunction (stringFromInt),
|
|
|
|
intFromStringFunction (intFromString)
|
|
|
|
{
|
|
|
|
jassert (minValue < maxValue); // must have a non-zero range of values!
|
|
|
|
|
|
|
|
if (stringFromIntFunction == nullptr)
|
|
|
|
stringFromIntFunction = [] (int v, int) { return String (v); };
|
|
|
|
|
|
|
|
if (intFromStringFunction == nullptr)
|
|
|
|
intFromStringFunction = [] (const String& text) { return text.getIntValue(); };
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioParameterInt::~AudioParameterInt() {}
|
|
|
|
@@ -101,8 +119,8 @@ float AudioParameterInt::getValue() const { retur |
|
|
|
void AudioParameterInt::setValue (float newValue) { value = (float) convertFrom0to1 (newValue); valueChanged (get()); }
|
|
|
|
float AudioParameterInt::getDefaultValue() const { return defaultValue; }
|
|
|
|
int AudioParameterInt::getNumSteps() const { return rangeOfValues + 1; }
|
|
|
|
float AudioParameterInt::getValueForText (const String& text) const { return convertTo0to1 (text.getIntValue()); }
|
|
|
|
String AudioParameterInt::getText (float v, int /*length*/) const { return String (convertFrom0to1 (v)); }
|
|
|
|
float AudioParameterInt::getValueForText (const String& text) const { return convertTo0to1 (intFromStringFunction (text)); }
|
|
|
|
String AudioParameterInt::getText (float v, int length) const { return stringFromIntFunction (convertFrom0to1 (v), length); }
|
|
|
|
void AudioParameterInt::valueChanged (int) {}
|
|
|
|
|
|
|
|
AudioParameterInt& AudioParameterInt::operator= (int newValue)
|
|
|
|
@@ -116,18 +134,45 @@ AudioParameterInt& AudioParameterInt::operator= (int newValue) |
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
AudioParameterBool::AudioParameterBool (const String& idToUse, const String& nameToUse,
|
|
|
|
bool def, const String& labelToUse)
|
|
|
|
bool def, const String& labelToUse,
|
|
|
|
std::function<String (bool, int)> stringFromBool,
|
|
|
|
std::function<bool (const String&)> boolFromString)
|
|
|
|
: AudioProcessorParameterWithID (idToUse, nameToUse, labelToUse),
|
|
|
|
value (def ? 1.0f : 0.0f),
|
|
|
|
defaultValue (value)
|
|
|
|
defaultValue (value),
|
|
|
|
stringFromBoolFunction (stringFromBool),
|
|
|
|
boolFromStringFunction (boolFromString)
|
|
|
|
{
|
|
|
|
onStrings.add (TRANS("on"));
|
|
|
|
onStrings.add (TRANS("yes"));
|
|
|
|
onStrings.add (TRANS("true"));
|
|
|
|
|
|
|
|
offStrings.add (TRANS("off"));
|
|
|
|
offStrings.add (TRANS("no"));
|
|
|
|
offStrings.add (TRANS("false"));
|
|
|
|
if (stringFromBoolFunction == nullptr)
|
|
|
|
stringFromBoolFunction = [] (bool v, int) { return v ? TRANS("On") : TRANS("Off"); };
|
|
|
|
|
|
|
|
if (boolFromStringFunction == nullptr)
|
|
|
|
{
|
|
|
|
StringArray onStrings;
|
|
|
|
onStrings.add (TRANS("on"));
|
|
|
|
onStrings.add (TRANS("yes"));
|
|
|
|
onStrings.add (TRANS("true"));
|
|
|
|
|
|
|
|
StringArray offStrings;
|
|
|
|
offStrings.add (TRANS("off"));
|
|
|
|
offStrings.add (TRANS("no"));
|
|
|
|
offStrings.add (TRANS("false"));
|
|
|
|
|
|
|
|
boolFromStringFunction = [onStrings, offStrings] (const String& text)
|
|
|
|
{
|
|
|
|
String lowercaseText (text.toLowerCase());
|
|
|
|
|
|
|
|
for (auto& testText : onStrings)
|
|
|
|
if (lowercaseText == testText)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for (auto& testText : offStrings)
|
|
|
|
if (lowercaseText == testText)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return text.getIntValue() != 0;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioParameterBool::~AudioParameterBool() {}
|
|
|
|
@@ -142,22 +187,12 @@ void AudioParameterBool::valueChanged (bool) {} |
|
|
|
|
|
|
|
float AudioParameterBool::getValueForText (const String& text) const
|
|
|
|
{
|
|
|
|
String lowercaseText (text.toLowerCase());
|
|
|
|
|
|
|
|
for (auto& testText : onStrings)
|
|
|
|
if (lowercaseText == testText)
|
|
|
|
return 1.0f;
|
|
|
|
|
|
|
|
for (auto& testText : offStrings)
|
|
|
|
if (lowercaseText == testText)
|
|
|
|
return 0.0f;
|
|
|
|
|
|
|
|
return text.getIntValue() != 0 ? 1.0f : 0.0f;
|
|
|
|
return boolFromStringFunction (text) ? 1.0f : 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
String AudioParameterBool::getText (float v, int /*length*/) const
|
|
|
|
String AudioParameterBool::getText (float v, int maximumLength) const
|
|
|
|
{
|
|
|
|
return v < 0.5f ? TRANS("Off") : TRANS("On");
|
|
|
|
return stringFromBoolFunction (v >= 0.5f, maximumLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioParameterBool& AudioParameterBool::operator= (bool newValue)
|
|
|
|
@@ -171,13 +206,23 @@ AudioParameterBool& AudioParameterBool::operator= (bool newValue) |
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
AudioParameterChoice::AudioParameterChoice (const String& idToUse, const String& nameToUse,
|
|
|
|
const StringArray& c, int def, const String& labelToUse)
|
|
|
|
const StringArray& c, int def, const String& labelToUse,
|
|
|
|
std::function<String (int, int)> stringFromIndex,
|
|
|
|
std::function<int (const String&)> indexFromString)
|
|
|
|
: AudioProcessorParameterWithID (idToUse, nameToUse, labelToUse), choices (c),
|
|
|
|
value ((float) def),
|
|
|
|
maxIndex (choices.size() - 1),
|
|
|
|
defaultValue (convertTo0to1 (def))
|
|
|
|
defaultValue (convertTo0to1 (def)),
|
|
|
|
stringFromIndexFunction (stringFromIndex),
|
|
|
|
indexFromStringFunction (indexFromString)
|
|
|
|
{
|
|
|
|
jassert (choices.size() > 0); // you must supply an actual set of items to choose from!
|
|
|
|
|
|
|
|
if (stringFromIndexFunction == nullptr)
|
|
|
|
stringFromIndexFunction = [this] (int index, int) { return choices [index]; };
|
|
|
|
|
|
|
|
if (indexFromStringFunction == nullptr)
|
|
|
|
indexFromStringFunction = [this] (const String& text) { return choices.indexOf (text); };
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioParameterChoice::~AudioParameterChoice() {}
|
|
|
|
@@ -191,8 +236,8 @@ void AudioParameterChoice::setValue (float newValue) { value |
|
|
|
float AudioParameterChoice::getDefaultValue() const { return defaultValue; }
|
|
|
|
int AudioParameterChoice::getNumSteps() const { return choices.size(); }
|
|
|
|
bool AudioParameterChoice::isDiscrete() const { return true; }
|
|
|
|
float AudioParameterChoice::getValueForText (const String& text) const { return convertTo0to1 (choices.indexOf (text)); }
|
|
|
|
String AudioParameterChoice::getText (float v, int /*length*/) const { return choices [convertFrom0to1 (v)]; }
|
|
|
|
float AudioParameterChoice::getValueForText (const String& text) const { return convertTo0to1 (indexFromStringFunction (text)); }
|
|
|
|
String AudioParameterChoice::getText (float v, int length) const { return stringFromIndexFunction (convertFrom0to1 (v), length); }
|
|
|
|
void AudioParameterChoice::valueChanged (int) {}
|
|
|
|
|
|
|
|
AudioParameterChoice& AudioParameterChoice::operator= (int newValue)
|
|
|
|
|