Skip to content

Instantly share code, notes, and snippets.

@Xenakios
Created March 4, 2021 18:02
Show Gist options
  • Save Xenakios/f15813e53e910e5540ceaa49c9272e48 to your computer and use it in GitHub Desktop.
Save Xenakios/f15813e53e910e5540ceaa49c9272e48 to your computer and use it in GitHub Desktop.
class DualSliderWithAttachments : public juce::Slider
{
public:
DualSliderWithAttachments(juce::Slider::SliderStyle style_, juce::RangedAudioParameter* minpar, juce::RangedAudioParameter* maxpar) :
minAttach(*minpar, [this](float x) { setMinValue(x, juce::dontSendNotification); }),
maxAttach(*maxpar, [this](float x) { setMaxValue(x, juce::dontSendNotification); })
{
setSliderStyle(style_);
setRange(minpar->getNormalisableRange().start, maxpar->getNormalisableRange().end);
minAttach.sendInitialUpdate();
maxAttach.sendInitialUpdate();
onDragStart = [this]()
{
thumbThatWasDragged = getThumbBeingDragged();
if (thumbThatWasDragged == 1)
minAttach.beginGesture();
else if (thumbThatWasDragged == 2)
maxAttach.beginGesture();
};
onValueChange = [this]()
{
if (thumbThatWasDragged == 1)
minAttach.setValueAsPartOfGesture(getMinValue());
else if (thumbThatWasDragged == 2)
maxAttach.setValueAsPartOfGesture(getMaxValue());
};
onDragEnd = [this]()
{
if (thumbThatWasDragged == 1)
minAttach.endGesture();
else if (thumbThatWasDragged == 2)
maxAttach.endGesture();
};
}
private:
juce::ParameterAttachment minAttach;
juce::ParameterAttachment maxAttach;
int thumbThatWasDragged = 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment