Log scaling to 0-127 Midi

Hiya all,

I’ve been recently tweaking the Nanobox Tangerine preset and was wondering if there’s an easy way to have the level faders mirror the dB values for each part’s level control. I’ve successfully used the Max / Mix / Default fields to map similar for pan (-64 / 63 / 0) and filter (-100 / 100 / 0) and pitch (-24/24/0) which seem to work well. But for the level control that seems to be -96dB to + 6dB with the default being 0 and if I use the Max / Mix / Default fields it’s not mapping the same as it’s presumably a linear transformation. I presume for dB it should be log scale? Is there an off-the-shelf type of lua function that would do this? (I’ve successfully used the percentage function from the tutorial so I’m hoping something along these lines). Thanks!

You could try this formatting function and set the default midi value to 120. The -96 is the min value of the control, 102 is the range of the control, and 127 is the range of midi values. 120 will correspond to 0 on this scale.

function plus6Minus96(valueObject,value)
  local scale = math.floor(-96+value*102/127)
  return(scale .. " dB")
end

PS. I think the log/linear question is more about how the device you are controlling turns midi values in voltages rather than the midi values themselves.

2 Likes

Awesome - thanks - I’ll give this a try, cheers!

This works a treat - I got my numbers wrong it was -96db to +12db but a bit of tweaking and now it’s working great so thanks again :slight_smile:

2 Likes