1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-16 00:34:19 +00:00

ComboBoxAttachment: Fix an issue where parameter ranges were converted incorrectly

This commit is contained in:
reuk 2020-07-01 16:11:33 +01:00
parent 16ebe88346
commit 86aa024138
2 changed files with 10 additions and 2 deletions

View file

@ -191,6 +191,7 @@ ComboBoxParameterAttachment::ComboBoxParameterAttachment (RangedAudioParameter&
ComboBox& c,
UndoManager* um)
: comboBox (c),
storedParameter (param),
attachment (param, [this] (float f) { setValue (f); }, um)
{
sendInitialUpdate();
@ -209,7 +210,8 @@ void ComboBoxParameterAttachment::sendInitialUpdate()
void ComboBoxParameterAttachment::setValue (float newValue)
{
const auto index = roundToInt (newValue);
const auto normValue = storedParameter.convertTo0to1 (newValue);
const auto index = roundToInt (normValue * (float) (comboBox.getNumItems() - 1));
if (index == comboBox.getSelectedItemIndex())
return;
@ -223,7 +225,12 @@ void ComboBoxParameterAttachment::comboBoxChanged (ComboBox*)
if (ignoreCallbacks)
return;
attachment.setValueAsCompleteGesture ((float) comboBox.getSelectedItemIndex());
const auto numItems = comboBox.getNumItems();
const auto selected = (float) comboBox.getSelectedItemIndex();
const auto newValue = numItems > 1 ? selected / (float) (numItems - 1)
: 0.0f;
attachment.setValueAsCompleteGesture (storedParameter.convertFrom0to1 (newValue));
}
//==============================================================================

View file

@ -203,6 +203,7 @@ private:
void comboBoxChanged (ComboBox*) override;
ComboBox& comboBox;
RangedAudioParameter& storedParameter;
ParameterAttachment attachment;
bool ignoreCallbacks = false;
};