music.interval

music.interval(name)[source]

The number of semitones in an interval, from its traditional name.

Parameters:
namestr

"P5", "m3", "aug4", "TT", or a compound such as "M9" or "m16". Quality is P, M, m, aug (or A) and dim (or d).

Returns:
integer

Semitones above the lower note.

Raises:
ValueError

If the name is not an interval, or asks for a quality the degree cannot take – there is no major fifth.

Parameters:

name (str)

Return type:

int

See also

interval_names

the same, backwards.

consonance

how the article classifies it.

midi_to_hz_interval

turns these semitones into a frequency ratio.

Examples

>>> interval("M3"), interval("P5"), interval("m7")
(4, 7, 10)
>>> interval("M9"), interval("P11"), interval("m16")
(14, 17, 25)
>>> interval("aug4") == interval("dim5") == interval("TT")
True
>>> interval("aug3")  # a major third raised by a semitone
5