pymusicxml.score_components.Pitch

class pymusicxml.score_components.Pitch(step: str, octave: int, alteration: float = 0)[source]

Bases: MusicXMLComponent

Class representing a notated musical pitch.

Parameters:
  • step – letter name of the pitch (“c”, “d”, “e”, “f”, “g”, “a” or “b”)

  • octave – which octave it is in (the octave starting with middle C is octave 4)

  • alteration – number of half steps sharp or flat. For instance, 1 would be sharp, -2 would be double-flat, and 0.5 would be quarter-tone sharp.

Variables:
  • step – letter name of the pitch (“c”, “d”, “e”, “f”, “g”, “a” or “b”)

  • octave – octave of the pitch

  • alteration – number of half steps sharp or flat

Methods

from_string(pitch_string)

Constructs Pitch from either a lilypond pitch string or from standard pitch/octave notation

render()

Renders this component to a tuple of ElementTree.Element.

wrap_as_score()

Wraps this component in a Score so that it can be exported and viewed

Inherited Methods

export_to_file(file_path[, pretty_print])

Exports this musical object (wrapped as a score) to the given file path.

to_xml([pretty_print])

Renders this component to MusicXML, adding a version tag, but not wrapping it up as a full score.

view_in_software(command)

Uses the given terminal command to create a score out of this musical object, and open it in music notation software.

classmethod from_string(pitch_string: str)[source]

Constructs Pitch from either a lilypond pitch string or from standard pitch/octave notation

Parameters:

pitch_string – can take the form “C#5” (specifying octave with number, and using ‘#’ for sharp) or “cs’” (specifying octave in the lilypond style and using ‘s’ for sharp)

Returns:

a Pitch

render() Sequence[Element][source]

Renders this component to a tuple of ElementTree.Element. (The reason for making it a tuple is that musical objects like chords are represented by several notes side by side, with all but the first containing a </chord> tag.)

wrap_as_score() Score[source]

Wraps this component in a Score so that it can be exported and viewed

export_to_file(file_path: str, pretty_print: bool = True) None

Exports this musical object (wrapped as a score) to the given file path.

Parameters:
  • file_path – The path of the file we want to write to.

  • pretty_print – If True, breaks the MusicXML onto multiple lines, with indentation

to_xml(pretty_print: bool = False) str

Renders this component to MusicXML, adding a version tag, but not wrapping it up as a full score.

Parameters:

pretty_print – If True, breaks the MusicXML onto multiple lines, with indentation

view_in_software(command: str) None

Uses the given terminal command to create a score out of this musical object, and open it in music notation software.

Parameters:

command – The terminal command corresponding to the software with which we want to open the score.