From 86aa02413849cab4642791af52d5b370fb507a80 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 1 Jul 2020 16:11:33 +0100 Subject: [PATCH] ComboBoxAttachment: Fix an issue where parameter ranges were converted incorrectly --- .../utilities/juce_ParameterAttachments.cpp | 11 +++++++++-- .../utilities/juce_ParameterAttachments.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/juce_audio_processors/utilities/juce_ParameterAttachments.cpp b/modules/juce_audio_processors/utilities/juce_ParameterAttachments.cpp index cb990afec0..c46a67d469 100644 --- a/modules/juce_audio_processors/utilities/juce_ParameterAttachments.cpp +++ b/modules/juce_audio_processors/utilities/juce_ParameterAttachments.cpp @@ -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)); } //============================================================================== diff --git a/modules/juce_audio_processors/utilities/juce_ParameterAttachments.h b/modules/juce_audio_processors/utilities/juce_ParameterAttachments.h index 8dd83cc36d..6079df66f6 100644 --- a/modules/juce_audio_processors/utilities/juce_ParameterAttachments.h +++ b/modules/juce_audio_processors/utilities/juce_ParameterAttachments.h @@ -203,6 +203,7 @@ private: void comboBoxChanged (ComboBox*) override; ComboBox& comboBox; + RangedAudioParameter& storedParameter; ParameterAttachment attachment; bool ignoreCallbacks = false; };