Protection of beginChangeGesture() : with a gentle use of SpinLock?

HI all,
I have a processor that changes a slider, and I use beginChangeGesture() / endChangeGesture()
When the user however touches the slider, I use onDragStart/onDragEnd to set a bool, notifying the processor to not set the gesture.
This way the user’s gestures and the gestures from the processor are combined.
Now this works fine with sliders, but I also have a textButton that sets a hidden slider. That means i can not use the slider drag callback’s… textButton does not have mouseup / mousedown callbacks either.
Is there a simple existing soltuion for this?
Thanks in advance!

my textButton is together with a hidden slider in a component.
the textButton toggles and sets the slider value.
It seems that I have to derive a textButton with the component methods mouseUp() and mouseDown() implemented to have it set/unset my protecting bool…
I’d however rather have a callback from a normal button.

Instead of deriving a new button, you can instead derive a new MouseListener that does what you want, and attach it to any standard JUCE buttons.
That allows you to keep using the regular JUCE buttons (or whatever other component you desire) and switch them around easily during development without the need to derive new classes for them all

1 Like

I never used custom listeners so far, ok, so that is something to learn

You are doing it correctly, calling beginChangeGesture(), setValueNotifyingHost() and endChangeGesture() in the mouseClick.
However, since that is something momentary unlike the slider dragging gesture, the changeGesture of the button and the setValue from your host most likely won’t happen at the same time.
You need a different strategy to define a precedence between the user and the processor.

ok, I have found the best way to do it. Note that this only the best way because I choose to loose gestures in the realtime thread.
A simple SpinLock works fine: the audiothread is never spinning.

In Processor:

//ccV contains incoming midi CC value
if(sliderSpinLock.tryEnter() )
       // we have the lock
        auto myp = state.getParameter("mySliderParam");
      // NO LOCK this time
      // processor could not ge a grip on the parameter
      // this means that the user has hold of the slider
      // so we let the users finger overrule the incoming midi CC.

In Editor:
NOTE: the editor lock will wait for the lock to be free, but that is ok, since this not the realtime thread and the locks are very short in my case.

mySlider.onDragStart=[this] {getProcessor().sliderSpinLock.enter();};
 mySlider.onDragEnd=[this] {getProcessor().sliderSpinLock.exit();};

IMHO it would suffice to have the ability to query a parameter, if a gesture is in progress.
I asked about that 9 months ago, but realised it wasn’t a FR.
You can vote now here:

Then you could simply do:

auto* myp = state.getParameter("mySliderParam");
if (!myp->isPerformingGesture())
    // ...
1 Like

yes, that is exactly what I want: just builtin registration of usage in the parameter itself.
Now i had to sidestep to SpinLock, which only fits very specific situations.
A builtin bool is much better and cleaner.