pymusicxml.score_components.Chord

class pymusicxml.score_components.Chord(pitches: Sequence[Pitch | str], duration: Duration | str | float, ties: Optional[Union[str, Sequence[str | None]]] = None, notations=(), articulations=(), noteheads=None, directions=(), stemless: bool = False, velocity: Optional[int] = None)[source]

Bases: DurationalObject

Class representing a chord. When rendered to MusicXML, a chord is represented by sequential <note> tags, with all but the first carrying a </chord> tag.

Parameters:
  • pitches – either a Pitch object or a string to parse as a pitch (see Pitch.from_string())

  • duration – either a Duration object, a string to parse as a duration (see Duration.from_string()), or a number of quarter notes.

  • ties – either one of “start”, “continue”, “stop”, or None (in which case each note of the chord follows that tie indication), or a list of such tie indications, one for each note.

  • notations – a notation or list of notations like that passed to a Note object. Since this is a chord, it is also possible to include a StartMultiGliss or StopMultiGliss object.

  • articulations – an articulation or list of articulations like that passed to a Note object.

  • noteheads – Either a single notehead (in the form of a Notehead or string representing XML notehead type) or a list of such noteheads, one for each pitch. The former results in all noteheads in the chord being the same; the latter results in different noteheads for each chord member. Note that the default of None represents ordinary noteheads.

  • directions – a direction or list of directions like that passed to a Note object.

  • stemless – boolean for whether to render the chord with no stem.

  • velocity – a note velocity (0-127) which gets passed along and used for playback by many applications

Methods

min_denominator()

Minimum divisor of a quarter note that would be needed to represent the duration of this note accurately.

num_beams()

Returns the number of beams needed to represent this duration.

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.

Attributes

articulations

Articulations attached to this chord.

beams

Dictionary describing the notation of all the beams for this Chord.

directions

Directions attached to this chord.

divisions

Subdivision used when representing this duration.

duration

The Duration of this chord.

length_in_divisions

Length in terms of subdivisions.

notations

Notations attached to this chord.

pitches

Tuple of the pitches of the notes in this chord.

ties

Either a string representing the tie state of all the notes, if all notes have the same tie state, or a tuple representing the tie state of each note individually.

true_length

True length in terms of the number of quarter notes, taking into tuplet time modification.

tuplet_bracket

Whether or not this chord starts or stops a tuplet bracket.

voice

Which voice this chord resides in.

written_length

Written length in terms of the number of quarter notes.

property pitches

Tuple of the pitches of the notes in this chord.

num_beams() int[source]

Returns the number of beams needed to represent this duration.

property duration

The Duration of this chord.

property true_length: float

True length in terms of the number of quarter notes, taking into tuplet time modification. Returns 0 in the case of grace notes.

property written_length: float

Written length in terms of the number of quarter notes.

property length_in_divisions: int

Length in terms of subdivisions. (See description of “divisions” attribute in Duration)

property notations: Sequence[Notation]

Notations attached to this chord.

property articulations

Articulations attached to this chord.

property directions

Directions attached to this chord.

property divisions: int

Subdivision used when representing this duration.

property voice

Which voice this chord resides in.

property beams

Dictionary describing the notation of all the beams for this Chord.

property ties

Either a string representing the tie state of all the notes, if all notes have the same tie state, or a tuple representing the tie state of each note individually.

property tuplet_bracket

Whether or not this chord starts or stops a tuplet bracket.

min_denominator() int[source]

Minimum divisor of a quarter note that would be needed to represent the duration of this note accurately. For instance, a triplet quarter note would have min_denominator 3, since it is 2/3 of a quarter.

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.