Browse Source

ComboBoxAttachment: Fix an issue where parameter ranges were converted incorrectly

tags/2021-05-28
reuk 5 years ago
parent
commit
86aa024138
2 changed files with 10 additions and 2 deletions
  1. +9
    -2
      modules/juce_audio_processors/utilities/juce_ParameterAttachments.cpp
  2. +1
    -0
      modules/juce_audio_processors/utilities/juce_ParameterAttachments.h

+ 9
- 2
modules/juce_audio_processors/utilities/juce_ParameterAttachments.cpp 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));
}
//==============================================================================


+ 1
- 0
modules/juce_audio_processors/utilities/juce_ParameterAttachments.h View File

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


Loading…
Cancel
Save