Boundaris for control values


#1

Hi, I hope I write to right section. Is it posible to make boundaries for control range of knob or slider. Let say software control values can be from 0 to 127. But for me useful only values from 20 to 80. So with physical potentiometer I would like contor range from 20 to 80 using all potentiometer range. Is there way to do thia? Sorry If my exploration is not clear.


#2

Yeah this is no problem, look at @TheSlowGrowth's math objects, limit and map.

or you could implement it yourself, for example by stealing arduinos map() function:

long map(long x, long in_min, long in_max, long out_min, long out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
  }

edit - i think i realized TSGs mapping objects only work for scaling something down, not scaling up as you seem to want. if nobody else has an idea i might actually implement that arduino function with input and output ranges.

edit: couldn't go home thinking about this. feel free to try these objects, seem to work fine for me. i think TSG's limiting algorithm is more efficient but this should be just fine.

map.axp (4.0 KB)

if ((inlet_in >= param_inmin) && (inlet_in <= param_inmax)) {
outlet_out = abs((int64_t) (inlet_in - param_inmin) * (param_outmax - param_outmin) / (param_inmax - param_inmin) + param_outmin);
}
else if (inlet_in < param_inmin) outlet_out = param_outmin;
	else outlet_out = param_outmax;

oh, the abs in there is pointless, was from when i was trying to be elegant for a hot second.

also, have absolutely no clue how this would react if i feed it bipolar fracs. scared to try.

edit nr 500 cause i like this forum software so much:
i made a version that works fine with bipolar inputs and also doubles as a convenient flexible P/B or B/P converter.
map.axp (4.0 KB)
mapfrac.axo (1.1 KB)

i think this is actually a very convenient and often used tool in music apps, so if i didn't overlook something existing (very likely...), can someone take me by the hand and show me how to push this to the community library?


Newbe needing help patching a 3 position switch/option