Note¶
note ¶
High-level note operations.
The Note namespace is the main entry point for working with musical
notes. It wraps the parser in _pitch_note with a richer API for
transposition, enharmonic spelling, sorting, and conversions to and from
MIDI numbers and frequencies.
Notes are parsed from strings in scientific notation: "C4", "Bb3",
"F##5", "Cbb-1". Pitch classes (no octave) are also accepted: "C",
"Bb", "F#". Invalid input returns the NO_NOTE sentinel rather than
raising — check .empty to detect failures.
Example
from tonal_py import Note Note.midi("C4") 60 Note.transpose("C4", "M3") 'E4' Note.simplify("C##") 'D'
Source parity: @tonaljs/note
name ¶
Get the canonical name of a note.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note
|
Any
|
A note name string, |
required |
Returns:
| Type | Description |
|---|---|
str
|
The note's canonical name (e.g. |
Example
from tonal_py import Note Note.name("Bb4") 'Bb4' Note.name("garbage") ''
Source code in src/tonal_py/note.py
pitch_class ¶
Get the pitch class of a note (note name without octave).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note
|
Any
|
A note name string, |
required |
Returns:
| Type | Description |
|---|---|
str
|
The pitch class string (e.g. |
Example
from tonal_py import Note Note.pitch_class("Bb4") 'Bb' Note.pitch_class("C") 'C'
Source code in src/tonal_py/note.py
accidentals ¶
Get the accidentals string of a note.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note
|
Any
|
A note name string, |
required |
Returns:
| Type | Description |
|---|---|
str
|
The accidentals (e.g. |
Example
from tonal_py import Note Note.accidentals("Bb4") 'b' Note.accidentals("F##5") '##' Note.accidentals("C4") ''
Source code in src/tonal_py/note.py
octave ¶
Get the octave number of a note.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note
|
Any
|
A note name string, |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
The octave (e.g. |
int | None
|
(notes without an octave) and invalid input. |
Example
from tonal_py import Note Note.octave("C4") 4 Note.octave("C") is None True
Source code in src/tonal_py/note.py
midi ¶
Get the MIDI number (0-127) of a note.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note
|
Any
|
A note name string, |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
The MIDI number, or |
int | None
|
out-of-range octaves, or invalid input. |
Example
from tonal_py import Note Note.midi("C4") 60 Note.midi("A4") 69 Note.midi("C") is None True
Source code in src/tonal_py/note.py
freq ¶
Get the frequency in Hz of a note (A4 = 440 Hz).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note
|
Any
|
A note name string, |
required |
Returns:
| Type | Description |
|---|---|
float | None
|
The frequency in hertz, or |
float | None
|
invalid input. |
Example
from tonal_py import Note Note.freq("A4") 440.0 round(Note.freq("C4"), 2) 261.63
Source code in src/tonal_py/note.py
chroma ¶
Get the pitch class number 0-11 of a note (C=0, C#=1, ..., B=11).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note
|
Any
|
A note name string, |
required |
Returns:
| Type | Description |
|---|---|
float
|
The chroma 0-11. |
Example
from tonal_py import Note Note.chroma("C4") 0 Note.chroma("D5") 2 Note.chroma("Bb3") 10
Source code in src/tonal_py/note.py
names ¶
Return the natural note names, or filter a list to its valid notes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
list | None
|
When |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Either the natural names |
list[str]
|
canonical names of valid input. |
Example
from tonal_py import Note Note.names() ['C', 'D', 'E', 'F', 'G', 'A', 'B'] Note.names(["C4", "garbage", "Bb3"]) ['C4', 'Bb3']
Source code in src/tonal_py/note.py
from_midi ¶
Convert a MIDI number to a note name (using flats for accidentals).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
midi_val
|
float
|
MIDI note number, typically 0-127. Decimal values are rounded. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The note name in scientific notation (e.g. |
str
|
Returns |
Example
from tonal_py import Note Note.from_midi(60) 'C4' Note.from_midi(61) 'Db4' Note.from_midi(61.7) 'D4'
See Also
from_midi_sharps — same but with sharps
Source code in src/tonal_py/note.py
from_midi_sharps ¶
Convert a MIDI number to a note name (using sharps for accidentals).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
midi_val
|
float
|
MIDI note number, typically 0-127. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The note name with sharps (e.g. |
Example
from tonal_py import Note Note.from_midi_sharps(61) 'C#4'
Source code in src/tonal_py/note.py
from_freq ¶
Convert a frequency in Hz to a note name (using flats).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freq_val
|
float
|
Frequency in hertz. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The nearest note name (rounded to nearest semitone). |
Example
from tonal_py import Note Note.from_freq(440) 'A4' Note.from_freq(261.62) 'C4'
Source code in src/tonal_py/note.py
from_freq_sharps ¶
Convert a frequency in Hz to a note name (using sharps).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freq_val
|
float
|
Frequency in hertz. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The nearest note name with sharps for accidentals. |
Example
from tonal_py import Note Note.from_freq_sharps(277.18) 'C#4'
Source code in src/tonal_py/note.py
transpose_by ¶
Curry the interval to map across many notes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval
|
Any
|
The interval to apply (string, |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Any], str]
|
A function that takes a note and returns the transposed note name. |
Example
from tonal_py import Note up_a_fifth = Note.transpose_by("P5") [up_a_fifth(n) for n in ["C", "D", "E"]]['G', 'A', 'B']
Source code in src/tonal_py/note.py
transpose_from ¶
Curry the starting note to map across many intervals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note
|
Any
|
The note to transpose from (string, |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Any], str]
|
A function that takes an interval and returns the transposed note. |
Example
from tonal_py import Note from_c = Note.transpose_from("C") [from_c(i) for i in ["1P", "3M", "5P"]]['C', 'E', 'G']
Source code in src/tonal_py/note.py
transpose_fifths ¶
Transpose by N perfect fifths (positive up, negative down).
This skips the interval-string parser entirely — it adds directly to the circle-of-fifths coordinate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note_name
|
Any
|
The note to transpose. |
required |
fifths
|
int
|
Number of perfect fifths to add (negative subtracts). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The transposed note name. |
Example
from tonal_py import Note Note.transpose_fifths("C", 2) 'D' [Note.transpose_fifths("C", n) for n in range(5)]['C', 'G', 'D', 'A', 'E']
Source code in src/tonal_py/note.py
transpose_octaves ¶
Transpose by N octaves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note_name
|
Any
|
The note to transpose. |
required |
octaves
|
int
|
Number of octaves to add (negative subtracts). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The transposed note name. |
Example
from tonal_py import Note Note.transpose_octaves("C4", 2) 'C6' Note.transpose_octaves("A4", -1) 'A3'
Source code in src/tonal_py/note.py
ascending ¶
Comparator that orders notes by pitch height (low to high).
Returns negative if a < b, zero if equal, positive if a > b.
Example
from tonal_py import Note Note.sorted_names(["E4", "C4", "G4"], Note.ascending) ['C4', 'E4', 'G4']
Source code in src/tonal_py/note.py
descending ¶
Comparator that orders notes by pitch height (high to low).
Example
from tonal_py import Note Note.sorted_names(["E4", "C4", "G4"], Note.descending) ['G4', 'E4', 'C4']
Source code in src/tonal_py/note.py
sorted_names ¶
Sort note names by pitch height; filter out invalid input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notes
|
list
|
Notes to sort (any inputs accepted by [ |
required |
comparator
|
Callable[[Note, Note], int] | None
|
Optional ordering function. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
The sorted, filtered note names. |
Example
from tonal_py import Note Note.sorted_names(["E4", "C4", "garbage", "G4"]) ['C4', 'E4', 'G4']
Source code in src/tonal_py/note.py
sorted_uniq_names ¶
Sort note names ascending and remove duplicates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notes
|
list
|
Notes (any inputs accepted by [ |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted, deduplicated, valid-only note names. |
Example
from tonal_py import Note Note.sorted_uniq_names(["E4", "C4", "C4", "G4", "garbage"]) ['C4', 'E4', 'G4']
Source code in src/tonal_py/note.py
simplify ¶
Reduce double accidentals and out-of-range spellings.
Picks a "simpler" enharmonic equivalent — C## becomes D, B#4
becomes C5, etc. Uses the source's accidental direction when picking
sharps or flats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note_name
|
Any
|
A note name (string, |
required |
Returns:
| Type | Description |
|---|---|
str
|
The simplified name, or |
Example
from tonal_py import Note Note.simplify("C##") 'D' Note.simplify("C###") 'D#' Note.simplify("B#4") 'C5' Note.simplify("Cbb") 'Bb'
Source code in src/tonal_py/note.py
enharmonic ¶
Find the enharmonic equivalent of a note.
By default picks "the other" common spelling (sharps if the source
used flats, vice versa). When dest_name is provided, returns the
note re-spelled to use that pitch class — but only if dest_name's
chroma matches the source's chroma.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note_name
|
Any
|
The source note (string, |
required |
dest_name
|
Any
|
Optional explicit destination pitch class (e.g.
|
None
|
Returns:
| Type | Description |
|---|---|
str
|
The enharmonic note name, or |
str
|
the requested destination doesn't share the source's chroma. |
Example
from tonal_py import Note Note.enharmonic("Db") 'C#' Note.enharmonic("C") # already simplest 'C' Note.enharmonic("F2", "E#") # explicit destination 'E#2' Note.enharmonic("C##b") # invalid input ''