mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-28 02:30:05 +00:00
Fixed a bug when selecting AudioParameterChoice values in native DAW parameter views
This commit is contained in:
parent
2a15a9beab
commit
b0866b6a5f
3 changed files with 11 additions and 9 deletions
|
|
@ -67,6 +67,7 @@ public:
|
|||
private:
|
||||
//==============================================================================
|
||||
float value, defaultValue;
|
||||
const int maxIndex;
|
||||
|
||||
float getValue() const override;
|
||||
void setValue (float newValue) override;
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public:
|
|||
|
||||
private:
|
||||
//==============================================================================
|
||||
int minValue, maxValue;
|
||||
const int minValue, maxValue, rangeOfValues;
|
||||
float value, defaultValue;
|
||||
|
||||
float getValue() const override;
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ AudioParameterInt::AudioParameterInt (const String& idToUse, const String& nameT
|
|||
int mn, int mx, int def,
|
||||
const String& labelToUse)
|
||||
: AudioProcessorParameterWithID (idToUse, nameToUse, labelToUse),
|
||||
minValue (mn), maxValue (mx),
|
||||
minValue (mn), maxValue (mx), rangeOfValues (maxValue - minValue),
|
||||
value ((float) def),
|
||||
defaultValue (convertTo0to1 (def))
|
||||
{
|
||||
|
|
@ -93,13 +93,13 @@ AudioParameterInt::AudioParameterInt (const String& idToUse, const String& nameT
|
|||
AudioParameterInt::~AudioParameterInt() {}
|
||||
|
||||
int AudioParameterInt::limitRange (int v) const noexcept { return jlimit (minValue, maxValue, v); }
|
||||
float AudioParameterInt::convertTo0to1 (int v) const noexcept { return (limitRange (v) - minValue) / (float) (maxValue - minValue); }
|
||||
int AudioParameterInt::convertFrom0to1 (float v) const noexcept { return limitRange (roundToInt ((v * (float) (maxValue - minValue)) + minValue)); }
|
||||
float AudioParameterInt::convertTo0to1 (int v) const noexcept { return (limitRange (v) - minValue) / (float) rangeOfValues; }
|
||||
int AudioParameterInt::convertFrom0to1 (float v) const noexcept { return limitRange (roundToInt ((v * (float) rangeOfValues) + minValue)); }
|
||||
|
||||
float AudioParameterInt::getValue() const { return convertTo0to1 (roundToInt (value)); }
|
||||
void AudioParameterInt::setValue (float newValue) { value = (float) convertFrom0to1 (newValue); }
|
||||
float AudioParameterInt::getDefaultValue() const { return defaultValue; }
|
||||
int AudioParameterInt::getNumSteps() const { return AudioProcessorParameterWithID::getNumSteps(); }
|
||||
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)); }
|
||||
|
||||
|
|
@ -145,16 +145,17 @@ AudioParameterChoice::AudioParameterChoice (const String& idToUse, const String&
|
|||
const StringArray& c, int def, const String& labelToUse)
|
||||
: AudioProcessorParameterWithID (idToUse, nameToUse, labelToUse), choices (c),
|
||||
value ((float) def),
|
||||
defaultValue (convertTo0to1 (def))
|
||||
defaultValue (convertTo0to1 (def)),
|
||||
maxIndex (choices.size() - 1)
|
||||
{
|
||||
jassert (choices.size() > 0); // you must supply an actual set of items to choose from!
|
||||
}
|
||||
|
||||
AudioParameterChoice::~AudioParameterChoice() {}
|
||||
|
||||
int AudioParameterChoice::limitRange (int v) const noexcept { return jlimit (0, choices.size() - 1, v); }
|
||||
float AudioParameterChoice::convertTo0to1 (int v) const noexcept { return jlimit (0.0f, 1.0f, (v + 0.5f) / (float) choices.size()); }
|
||||
int AudioParameterChoice::convertFrom0to1 (float v) const noexcept { return limitRange ((int) (v * (float) choices.size())); }
|
||||
int AudioParameterChoice::limitRange (int v) const noexcept { return jlimit (0, maxIndex, v); }
|
||||
float AudioParameterChoice::convertTo0to1 (int v) const noexcept { return jlimit (0.0f, 1.0f, v / (float) maxIndex); }
|
||||
int AudioParameterChoice::convertFrom0to1 (float v) const noexcept { return limitRange (roundToInt (v * (float) maxIndex)); }
|
||||
|
||||
float AudioParameterChoice::getValue() const { return convertTo0to1 (roundToInt (value)); }
|
||||
void AudioParameterChoice::setValue (float newValue) { value = (float) convertFrom0to1 (newValue); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue