pymusicxml.score_components.Tuplet

class pymusicxml.score_components.Tuplet(contents: Sequence[MusicXMLComponent], ratio: tuple)[source]

Bases: BeamedGroup

Represents a tuplet; same as a BeamedGroup, but with a particular time ratio associated with it.

Parameters:
  • contents – a list of notes, chords and rests contained in this group.

  • ratio – a tuple representing the tuplet ratio (as described in Duration)

Methods

min_denominator()

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

render()

Renders this component to a tuple of ElementTree.Element.

Inherited Methods

append(value)

S.append(value) -- append value to the end of the sequence

clear()

count(value)

export_to_file(file_path[, pretty_print])

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

extend(values)

S.extend(iterable) -- extend sequence by appending elements from the iterable

index(value, [start, [stop]])

Raises ValueError if the value is not present.

insert(i, o)

Insert the given object before the given index.

pop([index])

Raise IndexError if list is empty or index is out of range.

remove(value)

S.remove(value) -- remove first occurrence of value.

render_contents_beaming()

Works out all the beaming for the contents of this group.

reverse()

S.reverse() -- reverse IN PLACE

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.

wrap_as_score()

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

Attributes

divisions

Subdivision used when representing this duration.

length_in_divisions

Length in terms of subdivisions.

true_length

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

written_length

Written length in terms of the number of quarter notes.

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.)

append(value)

S.append(value) – append value to the end of the sequence

clear() None -- remove all items from S
count(value) integer -- return number of occurrences of value
property divisions: int

Subdivision used when representing this duration.

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

extend(values)

S.extend(iterable) – extend sequence by appending elements from the iterable

index(value[, start[, stop]]) integer -- return first index of value.

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

insert(i, o) None

Insert the given object before the given index.

Parameters:
  • i – Index at which to insert

  • o – Object to insert

property length_in_divisions: int

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

pop([index]) item -- remove and return item at index (default last).

Raise IndexError if list is empty or index is out of range.

remove(value)

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

render_contents_beaming() None

Works out all the beaming for the contents of this group. (Sets the “beams” attribute for every element.)

reverse()

S.reverse() – reverse IN PLACE

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

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.

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.

wrap_as_score() Score

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

property written_length: float

Written length in terms of the number of quarter notes.