A pitch with a letter, octave, and accidental.

Pitches are represented as strings in a subset of lilypond pitch notation.

A pitch indicator has three parts: a pitch letter, an optional accidental letter, and an optional octave mark.

  • Pitch letters are the standard c through b letters.
  • The accidental letter may be f for flat, s for sharp, and n for natural. If omitted, the actual logical pitch depends on context the pitch appears in.
  • 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 below middle-C. By extension, the absence of an octave indicator means a pitch is within 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 F-sharp above middle-C: fs'

__init__ (pitch) permalink view source


pitch (str): A pitch indicator. (see above class documentation).


pitch: str A pitch indicator. permalink view source

letter: str The a-g letter name of the pitch. permalink view source


accidental_type: AccidentalType or None The accidental descriptor. permalink view source

If no accidental is needed for this pitch (e.g. C-natural in C Major), this should be left as None.


octave: int The octave number for the pitch in scientific notation. permalink view source

octave == 4 corresponds to middle-C. Descending pitches correspond to lower octave numbers.


pitch_class: int The 0-11 pitch class of this pitch. permalink view source


diatonic_degree_in_c: int The diatonic degree of the pitch as if it were in C. permalink view source

>>> Pitch("c").diatonic_degree_in_c
>>> Pitch("c'").diatonic_degree_in_c
>>> Pitch("d'''").diatonic_degree_in_c
>>> Pitch("bf,").diatonic_degree_in_c


staff_pos_from_middle_c: float The pitch's staff position relative to middle C. permalink view source

Values are in numeric pseudo-staff-units where positive values mean positions below middle C, and negative values mean positions above it.

>>> Pitch("c'").staff_pos_from_middle_c
>>> Pitch("cs'").staff_pos_from_middle_c
>>> Pitch("d'").staff_pos_from_middle_c
>>> Pitch("d''").staff_pos_from_middle_c
>>> Pitch("cn,").staff_pos_from_middle_c


string_desriptor: str The string that can be used to recreate this Pitch permalink view source



__repr__ () permalink view source

Represent the pitch as the code needed to instantiate it

__eq__ (other) permalink view source

Two Pitches are equal if all of their attributes are equal.

__hash__ () permalink view source

Hash based on the __repr__() of the Pitch.

Pitches with different attributes will have different hashes