Rotation slider value wrap using stopAtEnd?

Useful for parameter adjustment knobs found in hardware synths/effects.
If people use

	setRotaryParameters(degreesToRadians(0.0f), degreesToRadians(359.0f), false);
// or ~360.0f?

kbob
Using the existing stopAtEnd parameter…

All in juce_Slider.cpp
~Line 779 in handleAbsoluteDrag

		if (rotaryParams.stopAtEnd)
			return owner.proportionOfLengthToValue(jlimit(0.0, 1.0, newPos)) - value;
		else
			return owner.proportionOfLengthToValue(newPos - floor(newPos)) - value;

And
~Line 820 in handleVelocityDrag

			auto newPos = currentPos + speed;
            //valueWhenLastDragged = owner.proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
			if (rotaryParams.stopAtEnd)
			{
				valueWhenLastDragged = owner.proportionOfLengthToValue(jlimit(0.0, 1.0, newPos));
			}
			else
			{
				valueWhenLastDragged = owner.proportionOfLengthToValue(newPos - floor(newPos));
			}

And
~Line 1070 in getMouseWheelDelta

		if (rotaryParams.stopAtEnd)
			return owner.proportionOfLengthToValue(jlimit(0.0, 1.0, newPos)) - value;
		else
			return owner.proportionOfLengthToValue(newPos - floor(newPos)) - value;

Thanks for the consideration.
Dave H.

How does this interact with the changes proposed here?

It does exactly that. You can’t override a function to do this though, these changes need to be in Juce itself.

Sorry, I wasn’t clear. The commit linked to in the issue

doesn’t contain the same set of changes at the ones in this topic on the forum. Which set of changes are you proposing that JUCE uses?

I just tried that commit using 5.4.3 and it only worked with the mouse wheel and it made it move really slowly. The additions I used work with the mouse and holding CTRL for slower increments.

Sorry, I got myself confused with the two sets of changes and thought that they were linked…

It looks like you are proposing a breaking change, as this would alter how the wrap-around behaviour currently works. Is that correct?

No, it makes it actually work for linearly controlling.
Currently it only works for dials that point towards the mouse pointer.
The ‘jlimit’ is the existing function call in each case in my code. The if statement includes the wrap around 0-1. It’s not a complex solution.
‘newPos - floor(newPos)’ is just a neat way to wrap around 0-1. The whole change could of course be ternary in each case.

2 Likes

Dude! Nice one T0m. :smiley: