- Plus adding a re-entrance flag,
- plus adding beginChangeGesture() and endGesture(),
- plus atomic safety measure, because the notification from the parameter occurs most of the time from the audio thread, vs. the slider notification come from the message thread…
There is quite a bit of work involved to do it right.
The above solution will:
- cock up when an automation is recorded, since it doesn’t know when you touch the slider
- might go into a feedback spiral
- has thread safety issues
I created a safe passage into the message thread with this helper class:
You can copy that class and create a ParameterAttachment. It is not specific to a TwoValueSlider, but you can use it like that (untested):
AudioProcessorValueTreeState& treeState;
ParameterAttachment<double> minValue { treeState };
ParameterAttachment<double> maxValue { treeState };
Slider slider {Slider::TwoValueVertical, Slider::NoTextBox};
int lastDraggedThumb = 0;
// in constructor:
slider.onDragStart = [&]
{
lastDraggedThumb = slider.getThumbBeingDragged();
if (lastDraggedThumb == 1) minValue.beginGesture();
else if (lastDraggedThumb == 2) maxValue.beginGesture();
};
slider.onDragEnd = [&]
{
if (lastDraggedThumb == 1) minValue.endGesture();
else if (lastDraggedThumb == 2) maxValue.endGesture();
lastDraggedThumb = 0;
};
slider.onValueChanged = [&]
{
if (lastDraggedThumb == 1) minValue.setValueNotifyingHost (slider.getMinValue());
else if (lastDraggedThumb == 2) maxValue.setValueNotifyingHost (slider.getMaxValue());
};
minValue.onParameterChangedAsync = [&] { slider.setValue (minValue.getValue()); };
maxValue.onParameterChangedAsync = [&] { slider.setValue (maxValue.getValue()); };
minValue.attachToParameter (minParamID);
maxValue.attachToParameter (maxParamID);
Granted, this is a lot to copy, makes sense to wrap that into a MinMaxSliderAttachment class (haven’t needed a MinMax Slider so far).
Hope that helps…
