tonal_nearest_instance

tonal_nearest_instance(x: tuple[int, ...], y: tuple[int, ...])

Returns the location of an octave adjusted y that is closest to x. That is, if x and y are more than a tritone apart, the octave qualifier of y is adjusted to be within a tritone of x.

If x is not octave designated, y is returned with no octave designation. If y is not octave designated (but x is), y is returned with an octave designation making it closest to x.

Examples

>>> tonal_nearest_instance((0,0,0), (1,2,-1))
(1, 2, 0)
>>> tonal_nearest_instance((0,1,1), (6,10, -3))
(6, 10, 0)
>>> tonal_nearest_instance((0,0,0), (6,11,3))
(6, 11, -1)
>>> tonal_nearest_instance((0,0), (6,11,-1))
(6, 11)
>>> tonal_nearest_instance((0, 0, 0), (0, 11, 0))
(0, 11, 0)

A tritone is equally near in either direction; the tie goes to the smaller diatonic distance (an augmented 4th over a diminished 5th), as in Lilypond’s relative octave mode.

>>> tonal_nearest_instance((0, 0, 0), (3, 6)) # F-sharp, a 4th above
(3, 6, 0)
>>> tonal_nearest_instance((0, 0, 0), (4, 6)) # G-flat, a 4th below
(4, 6, -1)