Page 1 of 1

Circular Knob that Snaps to Positions

Posted: Sat Apr 23, 2016 2:48 pm
by theotherbassist
Here I've got a basic circular knob that changes angle based on vertical mouse drag. I found the basis for this in the forums. In the stack, the upper field reports an integer value which is basically the angle as a fraction of a defined range. The lower field reports the angle value (just easier to visualize for me that way).

How can I make the knob so that it doesn't "freely" rotate (i.e. with a resolution of 360 possible positions per complete rotation) and have it snap instead only to the closest of a limited number of angles? I want the number of angles to be defined by the range of possible decimals defined in the script by the constant "cmaxdecimal."

In the example, cmaxdecimal is "5", so there should only be 6 possible positions of the knob (0-5, equally spaced). For my purposes, it doesn't matter if the snap happens while mouse tracking is still happening or once after mouseUp.

I know it should just basically be a reversal of the math that goes from angle to decimal, but my brain isn't working well enough today to reach something workable. Any ideas?

It would also be really nice to be able to define the lower limit of the decimal range, mostly because I want it to begin with 1, but that's sort of a separate thing.

Re: Circular Knob that Snaps to Positions

Posted: Sat Apr 23, 2016 6:50 pm
by dunbarx
I could not open your stack. I was told it was corrupted. Usually, if made in 7 or 8, I am only told about a "later version". I am still in v.6.

Anyway, do you use the "mouseMove" message to set rotation? If so, you can track the x and y components, and only trigger a change in the knob with a modulo value, whatever suits you. If you are using some other method, you can do the same thing.

Craig Newman

Re: Circular Knob that Snaps to Positions

Posted: Sat Apr 23, 2016 9:32 pm
by theotherbassist
Would you want mod or div? If you used div, you'd get the "whole" increments (some arbitrary px difference) for the change in x/y. Isn't that what you'd want? Am I thinking of it wrong?

...and yeah I'm using 7. I should just take 6 off altogether because of the way it corrupts the stacks permanently if you try to open 7+ in 6 or lower.

Re: Circular Knob that Snaps to Positions

Posted: Sun Apr 24, 2016 6:53 am
by RogGuay
Forgive me if I'm jumping the gun here or if I misunderstand your needs, But have you looked at my RadialDialOmatic stack available here: ... ecode?dl=0

I think you will find at least some useful ideas here for your requirements.



Re: Circular Knob that Snaps to Positions

Posted: Mon Apr 25, 2016 4:10 pm
by theotherbassist
Really cool stack, Roger. Thanks for the suggestions guys. I decided to give up on deciphering "stolen" code line by line and just developed my own solution.

In this version, the background is an image and the pointer is a graphic. The two are grouped and the knob's behavior is defined by a few custom properties of the group. I think I made it adaptable enough that others might find it useful. Feel free to DL and use.