neoscore.western.pitch
- class neoscore.western.pitch.Pitch[source]
Bases:
object
A written pitch with a letter, octave, and accidental.
This class does not define an actual concert pitch, MIDI code, pitch class, etc. associated with it. Users building notation systems on it can decide whether this represents a concert pitch or a written one. Neoscore’s
western
module treats it mostly as a written pitch, unconditionally writing provided accidentals regardless of context and key signatures.The class supports a helpful shorthand for standard western 12-EDO pitches inspired by Lilypond’s pitch notation; see
Pitch.from_str
.Extended accidentals are fully supported by passing arbitrary SMuFL glyph names to the
accidental
attribute.- letter: str
The a-g letter name of the pitch.
- accidental: Optional[AccidentalType | str]
An accidental associated with the pitch.
For conventional accidentals, this can be an
AccidentalType
. Alternatively, this can be an arbitrary SMuFL glyph name string.
- octave: int
The octave number, where 4 is the octave starting with middle-C.
- classmethod from_str(shorthand: str) Pitch [source]
Create a conventional Western
Pitch
from a string shorthand.The pitch shorthand is inspired by Lilypond’s. It consists of three parts: a pitch letter, an optional accidental, and an optional octave mark.
Pitch letters are the standard
c
throughb
letters.The accidental may be
f
orb
for flat,s
or#
for sharp,n
for natural,ss
orx
for double-sharp, andff
orbb
for double-flat.The octave indication is given by a series of apostrophes (
'
) or commas (,
), where each apostrophe increases the pitch by an octave, and each comma decreases it. All octave transformations are relative to the octave starting at middle-C. The absence of an octave indicator means a pitch is within the octave starting at middle-C. (Note that this differs from Lilypond’s notation, which starts at the octave below middle-C.)
Some examples:
Middle-C:
c
The B directly below that:
b,
The C one octave below middle-C:
c,
The E-flat above middle-C:
ef
oreb
The F-sharp above middle-C:
fs
orf#
The G-double-sharp above middle-C:
fx
orfss
The A-double-flat above the treble staff:
aff'
orabb'
- __init__(letter: str, accidental: Optional[AccidentalType | str], octave: int) None
- property diatonic_degree_in_c: int
The diatonic degree of the pitch as if it were in C.
>>> Pitch.from_str("c").diatonic_degree_in_c 1 >>> Pitch.from_str("c'").diatonic_degree_in_c 1 >>> Pitch.from_str("d'''").diatonic_degree_in_c 2 >>> Pitch.from_str("bf,").diatonic_degree_in_c 7
- property staff_pos_from_middle_c: float
The pitch’s staff position relative to middle C.
Values are in numeric pseudo-staff-units where positive values mean positions below middle C, and negative values mean positions above it.
>>> Pitch.from_str("c").staff_pos_from_middle_c 0 >>> Pitch.from_str("cs").staff_pos_from_middle_c 0 >>> Pitch.from_str("d").staff_pos_from_middle_c -0.5 >>> Pitch.from_str("d'").staff_pos_from_middle_c -4 >>> Pitch.from_str("cn,,").staff_pos_from_middle_c 7