Mapping Functions

These functions convert a value from one range to another, maintaining the relative position within the range.  They are used to expand, contract, or offset data values.

These functions are included in the music library, so, in order to use them, you need the following in your program:

from music import *
Function Description
mapValue(value, minValue, maxValue, minResult, maxResult) Takes a number within one range and returns its equivalent within another range. The arguments are:

  • value – the number to be mapped
  • minValue – the lowest possible number to be mapped (inclusive)
  • maxValue – the highest possible number to be mapped (inclusive)
  • minResult – the lowest value of the destination range (inclusive)
  • maxResult – the highest value of the destination range (inclusive)
mapScale(value, minValue, maxValue, minResult, maxResult, scale) Takes a number (i.e., MIDI pitch) within one range and returns a its equivalent within another range, quantised to the pitch class value in scale. The arguments are:

  • value – the number to be mapped
  • minValue – the lowest possible number to be mapped (inclusive)
  • maxValue – the highest possible number to be mapped (inclusive)
  • minResult – the lowest value of the destination range (inclusive)
  • maxResult – the highest value of the destination range (inclusive)
  • scale – (optional) the musical scale (a list of pitch classes between 0 and 11) to be used in the destination range (see Appendix A for common scale constants)