ComboBox skips a value when attached to ValueTree

Hi,

I’m having a problem with the ComboBox component. I connected it to an AudioProcessorValueTree as shown below. It does what I expect for the first couple of values in the enum until it skips Position 5. Adding or removing values from the enum does not make a difference. you can see DBG output in the code samples below.

Any ideas what the problem could be?

Setup

  • Windows 10 64bit
  • Visual Studio 2017
  • JUCE 5.4.3
enum FilterType
{
    NoFilter = 0,
    HighPass,
    HighPass1st,
    LowShelf,
    BandPass,
    AllPass,
    Notch,
    Peak,
    HighShelf,
    LowPass1st,
    LowPass,
    LastFilterID
};
// IN EDITOR
for (int j = 0; j < LastFilterID; ++j)
{
    String label(EQ::getFilterTypeName(static_cast<EQ::FilterType>(j));)
    DBG(label+ ": " + String(j));
    combobox.addItem(label, j+1);
}

boxAttachments.add(new ComboBoxAttachment(state, type_id, combobox));

// DBG Output
//
// No Filter: 0
// High Pass: 1
// 1st High Pass: 2
// Low Shelf: 3
// Band Pass: 4
// All Pass: 5
// Notch: 6
// Peak: 7
// High Shelf: 8
// 1st Low Pass: 9
// Low Pass: 10
// IN PROCESSOR
void EqualizerProcessor::parameterChanged(const String& parameter, float newValue)
{
    DBG("CASTING " + String(newValue));
    bands[i].type = static_cast<FilterType>(static_cast<int>(newValue));
}

// DBG Output selecting every combobox item in order
// CASTING 0
// CASTING 1
// CASTING 2
// CASTING 3
// CASTING 4
// CASTING 6

Looks like a rounding error -> your parameter’s range might not be set up correctly. Can you show us the code where you define the parameter corresponding to state?

NormalisableRange<float> filterTypeRange(0, tobanteAudio::EqualizerProcessor::LastFilterID, 1);
// ...
state.createAndAddParameter(std::make_unique<Parameter>(
    getTypeParamID(i), band.name + " Type", translate("Filter Type"), filterTypeRange,
    static_cast<float>(band.type),
    [](float value) {
        using EP = tobanteAudio::EqualizerProcessor;
        return EP::getFilterTypeName(static_cast<EP::FilterType>(static_cast<int>(value)));
     },
     [](String text) {
                using EP = tobanteAudio::EqualizerProcessor;

                for (int i = 0; i < EP::LastFilterID; ++i)
                {
                    if (text == EP::getFilterTypeName(static_cast<EP::FilterType>(i)))
                    {
                        return static_cast<EP::FilterType>(i);
                    }
                }
                return EP::NoFilter;
            },
            false, true, true));

try

NormalisableRange<float> filterTypeRange(0, tobanteAudio::EqualizerProcessor::LastFilterID - 1, 1);
1 Like

Awesome!! Thanks a lot, always amazing how fast you guys are. :slight_smile: