modulo_shortest_distance

emlib.mathlib.modulo_shortest_distance(x, origin, mod)[source]

Return the shortest distance to x from origin around a circle of modulo mod.

A positive value means move clockwise, negative value means anticlockwise. Use abs to calculate the absolute distance

Example

Calculate the interval between note D5 and B3, independently of octaves

>>> interval = modulo_shortest_distance(74, 59, 12)
3