Caution
You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.9.1.
librosa.key_to_notes¶
- librosa.key_to_notes(key, unicode=True)[source]¶
Lists all 12 note names in the chromatic scale, as spelled according to a given key (major or minor).
This function exists to resolve enharmonic equivalences between different spellings for the same pitch (e.g. C♯ vs D♭), and is primarily useful when producing human-readable outputs (e.g. plotting) for pitch content.
Note names are decided by the following rules:
If the tonic of the key has an accidental (sharp or flat), that accidental will be used consistently for all notes.
If the tonic does not have an accidental, accidentals will be inferred to minimize the total number used for diatonic scale degrees.
If there is a tie (e.g., in the case of C:maj vs A:min), sharps will be preferred.
- Parameters
- keystring
Must be in the form TONIC:key. Tonic must be upper case (
CDEFGAB
), key must be lower-case (maj
ormin
).Single accidentals (
b!♭
for flat, or#♯
for sharp) are supported.Examples:
C:maj, Db:min, A♭:min
.- unicode: bool
If
True
(default), use Unicode symbols (♯𝄪♭𝄫)for accidentals.If
False
, Unicode symbols will be mapped to low-order ASCII representations:♯ -> #, 𝄪 -> ##, ♭ -> b, 𝄫 -> bb
- Returns
- noteslist
notes[k]
is the name for semitonek
(starting from C) under the given key. All chromatic notes (0 through 11) are included.
See also
Examples
C:maj will use all sharps
>>> librosa.key_to_notes('C:maj') ['C', 'C♯', 'D', 'D♯', 'E', 'F', 'F♯', 'G', 'G♯', 'A', 'A♯', 'B']
A:min has the same notes
>>> librosa.key_to_notes('A:min') ['C', 'C♯', 'D', 'D♯', 'E', 'F', 'F♯', 'G', 'G♯', 'A', 'A♯', 'B']
A♯:min will use sharps, but spell note 0 (C) as B♯
>>> librosa.key_to_notes('A#:min') ['B♯', 'C♯', 'D', 'D♯', 'E', 'E♯', 'F♯', 'G', 'G♯', 'A', 'A♯', 'B']
G♯:maj will use a double-sharp to spell note 7 (G) as F𝄪:
>>> librosa.key_to_notes('G#:maj') ['B♯', 'C♯', 'D', 'D♯', 'E', 'E♯', 'F♯', 'F𝄪', 'G♯', 'A', 'A♯', 'B']
F♭:min will use double-flats
>>> librosa.key_to_notes('Fb:min') ['D𝄫', 'D♭', 'E𝄫', 'E♭', 'F♭', 'F', 'G♭', 'A𝄫', 'A♭', 'B𝄫', 'B♭', 'C♭']