librosa.key_to_degrees
- librosa.key_to_degrees(key)[source]
Construct the diatonic scale degrees for a given key.
- Parameters:
- keystr
Must be in the form TONIC:key. Tonic must be upper case (
CDEFGAB
), key must be lower-case (maj
,min
,ionian
,dorian
,phrygian
,lydian
,mixolydian
,aeolian
,locrian
).The following abbreviations are supported for the modes: either the first three letters of the mode name (e.g. “mix”) or the mode name without “ian” (e.g. “mixolyd”).
Both
major
andmaj
are supported as abbreviations.Single and multiple accidentals (
b!♭
for flat, or#♯
for sharp) are supported.Examples:
C:maj, C:major, Dbb:min, A♭:min, D:aeo, E𝄪:phryg
.
- Returns:
- degreesnp.ndarray
An array containing the semitone numbers (0=C, 1=C#, … 11=B) for each of the seven scale degrees in the given key, starting from the tonic.
See also
Examples
>>> librosa.key_to_degrees('C:maj') array([ 0, 2, 4, 5, 7, 9, 11])
>>> librosa.key_to_degrees('C#:maj') array([ 1, 3, 5, 6, 8, 10, 0])
>>> librosa.key_to_degrees('A:min') array([ 9, 11, 0, 2, 4, 5, 7])
>>> librosa.key_to_degrees('A:min') array([ 9, 11, 0, 2, 4, 5, 7])