Cabbage Logo
Back to Cabbage Site

Move xy-controlled parameter in increments

Hello Rory,

I was wondering if you have any tips on how to achieve this particular thing. I’m trying to move the “gain”-channel in increments that are defined in the cabbage portion of the code. Obviously works great with just a knob, but when I use the xy-pad to control it, the increment-value changes because you can’t change xy-pad range at runtime.

So what I’m trying to do is perhaps rounding the value up when the xy-pad hits the specified “gain”-increment value, which would then make the knob jump up to the next increment then.
XYIncrements.csd (810 Bytes)

Seems like this is fine

if (kx > 0 && kx < 0.25) then
    kvalue = 0
    
elseif (kx > 0.25 && kx < 0.5) then
    kvalue = 0.25

elseif (kx > 0.5 && kx < 0.75) then
    kvalue = 0.5

elseif (kx > 0.75 && kx < 1) then
    kvalue = 0.75
    
elseif kx = 1  then
    kvalue = 1
endif

chnset kvalue, "gain"

But, I’m doing the same thing for a pitch-knob going from -12 to 12. Any way to avoid having over 20 if-statements in a row? :sob:

I was just about to crack open your code when I saw you have a solution. Nice one :laughing: Taht saves me some time. Regarding how to best avoid all those if statements? I would put all the kvalues I want into an array and then use the kx values to choose what I want:

kValues[] fillarray 0, .25, .5, .75, 1 
chnset kValues[int(kx*4)], "gain"

Code untested, but you should get the picture. 40 lines become 2 :wink: