scamp_extensions.pitch.utilities.map_keyboard_to_microtonal_pitches

scamp_extensions.pitch.utilities.map_keyboard_to_microtonal_pitches(microtonal_pitches: Sequence[float], squared_penalty: bool = True) Dict[int, float][source]

Given a list of microtonal (floating-point) MIDI pitches, finds an efficient map from keyboard-friendly (integer) pitches to the original microtonal pitches. This is really useful if you’re trying to audition a microtonal collection on the keyboard and don’t want to deal with making a mapping manually. Note: the code here is taken nearly verbatim from StackOverflow user sacha in response to this question: https://stackoverflow.com/questions/61825905/match-list-of-floats-to-nearest-integers-without-repeating

Parameters:
  • microtonal_pitches – a collection of floating-point (microtonal) pitches

  • squared_penalty – whether or not the choice is based on simple or squared error. (I.e. are we using taxicab or euclidean distance.)

Returns:

a dictionary mapping keyboard-friendly (integer) pitches to the microtonal collection given