Math Help, Scaling

I need to scale a midi knob. For example:

  
my_max * value / 127  
  

Where value is 0 to 127.

This works if the scale is “0 to my_max”

I need something for “1 to my_max”

I tried:

  
math.max(1, my_max * value / 127)  
  

But it’s not what i want. It gives too much “weight” to the first value. Eg if my scale is 1 to 3, then 66% of the midi knob is “1” which is uneven. Does this make sense?

The trick is to normalise your input to a range of [0.0, 1.0] and then scale according to your output range:

local input_min = 0
local input_max = 127

local output_min = 1
local output_max = 3

local input = some value between [input_min, input_max]

local normalised_input = (input - input_min) / (input_max - input_min)

local output = output_min + (normalised_input * (output_max - output_min))

Works! Cheers.