# Rules formula for translating range

Cannot seem to figure out the correct formula here:
Incoming midi CC range of 0-127 needs to be translated into a range of 1-80.
I've tried this example:

Incoming:
B0 00 pp

Rules:
xx=pp*128
yy=xx/80

Outgoing:
B0 00 yy

But this creates a value string like "1-2-3-3-5-6-7-8-8-10-11...".
How does MT handle decimal/floating point? Rounding up/down? Truncate?

How would I solve this?

This looks like normal behavior since there are no decimal points in MIDI. If you crank your knob all of the way to the right and get value of 80 (Decimal 50) and all of the way to the left and you get a value of 0. Then it is working correctly. Your knob still has 128 steps 0-128 but several steps it will send the same value so you get the rang you are looking for.

It looks like you might need to add 1 for value of 0 if you want 1-80 instead of 0-80 though.

Again, since MIDI doesn't understand decimal you just see integers.

Steve Caldwell
Bome Customer Care

Also available for paid consulting services: bome@sniz.biz

Thanks Steve, that would explain it. The question is still open how MT handles decimal values in calculations (how it converts to integers). Does it just chop them off (truncate) or does it round?
Regardless, my current solution was to extend the range of the receiving device (Max for Live plugin) from 1-80 to 1-128 which lets me avoid messy math.
– Max

Bome Just rounds to the nearest integer. It would make no sense to do otherwise since MIDI is just integers.

If you want to avoid rounding errors you could multiply all of your values by 100, do the math as integer math and when you are done, divide by 100. That way you might get better precision but in the end, it will always end up an integer for sending MIDI values.

Steve