I'm trying to implement a ParameterChoiceComboBox class like the ParameterSlider in the juce demo plugin.
I overrided ComboBox::valueChanged() and Timer::timerCallback() as the ParameterSlider class does.
But sometimes, instead of the ParameterSlider, the ParameterChoiceComboBox component triggers the timerCallback just before valueChanged(), which reset the changes.
Fastest the timer is, more often the problem occured.
Is there any ComboBox callback that could be everytime triggered before the Timer one ?
Here is code :
class ParameterChoiceComboBox : public ComboBox, private Timer {
public:
ParameterChoiceComboBox(AudioParameterChoice &p) : param(p) {
for (int i = 0; i < param.choices.size(); ++i)
addItem(param.choices[i], i + 1);
startTimerHz(300); // Fast timer will bug everytime
update();
}
void valueChanged(Value &v) override {
ComboBox::valueChanged(v);
param.setValueNotifyingHost((float)(ComboBox::getSelectedId() - 1) /
(float)(param.choices.size() - 1));
}
void timerCallback() override { update(); }
void update() {
if (param != ComboBox::getSelectedId() - 1)
setSelectedId(param + 1, NotificationType::dontSendNotification);
}
AudioParameterChoice ¶m;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ParameterChoiceComboBox)
};
You can notice that for sliders the wheel still works, even if isMouseButtonDown() returns false, i think because internal slider set and Slider::valueChanged() cannot be interlaced with the timerCallback()
And unfortunatly, for combobox there are no function like isMouseButtonDown() available or startedDragging()/stoppedDragging(), and even if one existed perhaps that Combobox::valueChanged() would still be triggered too late.
I just tried it, but it doesn't work. ComboBox::valueChanged() is called too late, isPopupActive() already returns false, so the timerCallback
may have been called meanwhile with isPopupActive() = false.