scaled pitch bend does not go to 0

Florent Ghys's icon

hello, I'm sure this is a super easy fix but I can't figure it out
The pitch bend wheel on my midi controller is sending values from 0 to 127, and the value 64 when it is released.
When I convert (scale) these values to -1. 1., number of semitones for a groove~ to be detuned by, the release value 64 is converted into 0.01. This is problematic as I am using these values for pitch (sig~ > groove~).

Max Patch
Copy patch and select New From Clipboard in Max.

Is there a way to convert 0-127 values into -n., n. while making sure that the value 64 will always be exactly 0.00?
any idea would be greatly appreciated!
Florent

double_UG's icon

Max Patch
Copy patch and select New From Clipboard in Max.

Martin Beck's icon

The question seems to be what is the best interpolation method to map the integer number range 0-127 (128 different quantised values, 128 is an even number) to the float number range -n. , n. (which is something like (2*n + 1)*f quantised numbers).

I tried to sketch the math of scale in a gen codebox.

As you might be aware the problem is more or less the mapping of even to odd number ranges. You could change the offset b or the slope a of the linear mapping or try some nonlinear mapping (what DOUBLE_UG proposed while I was writing this reply :-).

Max Patch
Copy patch and select New From Clipboard in Max.

bkshepard's icon

If I remember correctly, MIDI devices that need a center point (pan and pitch-bend) get around the even to odd issue by simply treating the first two values (0 and 1) as the same. Here, I've mapped the 0 from the slider to a 1 and then scaled it to -1. to 1. See if something like that does the job for you.

Max Patch
Copy patch and select New From Clipboard in Max.

Roman Thilenius's icon

in a custom devices (like a max patch) it doesnt matter how it is implemented and the suggestion from bkshepard is the most straight forward way.

aka
clip 1 127
scale 1 127 -1. 1.

another question is what hardware controllers actually send out and how some hardware synths treat it internally. i believe many hardware synths just scale the lower half differently, so that it only has a higher resolution.

aka
split 0 64 split 64 127
scale 0 64 -1. 0. scale 64 127 0. 1.

Florent Ghys's icon

thanks so much guys! I didn't realize that it was an even to odd issue
all your solutions work great!

bkshepard's icon

Yeah, since most MIDI controllers use a 0-127 range, there are actually 128 integer values and because that's an even number, there isn't a "middle" integer. The actual middle would be 63.5, but since you're using integers, you don't have fractions. In most cases the amount of sonic difference between two adjacent MIDI values is imperceptible, so sacrificing the difference between 0 and 1 usually doesn't make any difference.

Florent Ghys's icon

thanks for the explanation! that totally makes sense now
cheers