"normalizing" a value

bvdp bob at mellowood.ca
Thu Jul 2 02:12:36 CEST 2015

Not sure what this is called (and I'm sure it's not normalize). Perhaps "scaling"?

Anyway, I need to convert various values ranging from around -50 to 50 to an 0 to 12 range (this is part of a MIDI music program). I have a number of places where I do:

   while x < 0: x += 12
   while x >= 12: x -= 12

Okay, that works. Just wondering if there is an easier (or faster) way to accomplish this.

More information about the Python-list mailing list