Fix filter type dropdown emptying when selecting LP 48dB

The APVTS parameterChanged callback delivers the parameter's denormalised
value, which for an AudioParameterChoice is the choice index, not a
normalised 0..1 value. The handler was multiplying it by (numItems - 1),
so LP 48dB (index 8) produced itemId 65 and cleared the box. Map the
received index straight to itemId (index + 1).
This commit is contained in:
Armin 2026-08-13 16:37:56 +02:00
commit 9e84707f93

View file

@ -218,6 +218,10 @@ private:
// so the dropdown can be displayed in an order that differs from the // so the dropdown can be displayed in an order that differs from the
// parameter's index order (e.g. LP 48dB listed under LP 24dB). This keeps // parameter's index order (e.g. LP 48dB listed under LP 24dB). This keeps
// stored parameter indices meaningful while only reordering the menu. // stored parameter indices meaningful while only reordering the menu.
//
// Note the value-basis split: the constructor reads the NORMALISED value
// via getValue(), while parameterChanged() receives the DENORMALISED
// value (the choice index itself). Both end at itemId = index + 1.
class IndexedComboBoxAttachment : public juce::AudioProcessorValueTreeState::Listener, class IndexedComboBoxAttachment : public juce::AudioProcessorValueTreeState::Listener,
private juce::ComboBox::Listener { private juce::ComboBox::Listener {
public: public:
@ -238,8 +242,12 @@ private:
} }
void parameterChanged (const juce::String& parameterID, float newValue) override { void parameterChanged (const juce::String& parameterID, float newValue) override {
if (parameterID == paramId) if (parameterID != paramId)
combo.setSelectedId (1 + juce::roundToInt (newValue * (combo.getNumItems() - 1)), return;
// The APVTS delivers the parameter's DENORMALISED value here, which
// for an AudioParameterChoice is the choice index (not a normalised
// 0..1 value), so map it straight to the itemId (index + 1).
combo.setSelectedId (1 + juce::roundToInt (newValue),
juce::dontSendNotification); juce::dontSendNotification);
} }