partitura.performance

This module contains a lightweight ontology to represent a performance in a MIDI-like format. A performance is defined at the highest level by a PerformedPart. This object contains performed notes as well as continuous control parameters, such as sustain pedal.

class partitura.performance.Performance(performedparts: PerformedPart | Iterable[PerformedPart], id: str | None = None, performer: str | None = None, title: str | None = None, subtitle: str | None = None, composer: str | None = None, lyricist: str | None = None, copyright: str | None = None, ensure_unique_tracks: bool = True)[source]

Bases: object

Main object for representing a performance.

The Performance object is basically an iterable that provides access to all PerformedPart objects in a musical score.

Parameters:
  • id (str) – The identifier of the performance.

  • performer (str, optional.) – The person or machine performing.

  • title (str, optional) – Title of the score.

  • subtitle (str, optional) – Subtitle of the score.

  • composer (str, optional) – Composer of the score.

  • lyricist (str, optional) – Lyricist of the score.

  • copyright (str, optional.) – Copyright notice of the score.

id

See parameters.

Type:

str

performer

See parameters.

Type:

str

title

See parameters.

Type:

str

subtitle

See parameters.

Type:

str

composer

See parameters.

Type:

str

lyricist

See parameters.

Type:

str

copyright

See parameters.

Type:

str.

copyright: str | None
id: str | None
lyricist: str | None
note_array(*args, **kwargs) ndarray[source]

Get a note array that concatenates the note arrays of all Part/PartGroup objects in the score.

property num_tracks: int

Number of tracks in the performance

performedparts: List[PerformedPart]
sanitize_track_numbers() None[source]

Ensure that the track number info in each PerformedPart in self.performedparts is unique (i.e., that a track number does not appear in multiple PerformedPart instances)

subtitle: str | None
title: str | None
class partitura.performance.PerformedPart(notes: List[dict], id: str | None = None, part_name: str | None = None, controls: List[dict] | None = None, programs: List[dict] | None = None, sustain_pedal_threshold: int = 64, ppq: int = 480, mpq: int = 500000, track: int = 0)[source]

Bases: object

Represents a performed part, e.g. all notes and related controller/modifiers of one single instrument.

Performed notes are stored as a list of dictionaries, where each dictionary represents a performed note, should have at least the keys “note_on”, “note_off”, the onset and offset times of the note in seconds, respectively.

Continuous controls are also stored as a list of dictionaries, where each dictionary represents a control change. Each dictionary should have a key “type” (the name of the control, e.g. “sustain_pedal”, “soft_pedal”), “time” (in seconds), and “value” (a number).

Parameters:
  • notes (list) – A list of dictionaries containing performed note information.

  • id (str) – The identifier of the part

  • controls (list) – A list of dictionaries containing continuous control information

  • part_name (str) – Name for the part

  • sustain_pedal_threshold (int) – The threshold above which sustain pedal values are considered to be equivalent to on. For values below the threshold the sustain pedal is treated as off. Defaults to 64.

  • ppq (int) – Parts per Quarter (ppq) of the MIDI encoding. Defaults to 480.

  • mpq (int) – Microseconds per Quarter (mpq) tempo of the MIDI encoding. Defaults to 500000.

notes

A list of dictionaries containing performed note information.

Type:

list

id

The identifier of the part

Type:

str

part_name

Name for the part

Type:

str

controls

A list of dictionaries containing continuous control information

Type:

list

programs

List of dictionaries containing program change information

Type:

list

classmethod from_note_array(note_array: ndarray, id: str | None = None, part_name: str | None = None)[source]

Create an instance of PerformedPart from a note_array. Note that this property does not include non-note information (i.e. controls such as sustain pedal).

note_array(*args, **kwargs) ndarray[source]

Structured array containing performance information. The fields are ‘id’, ‘pitch’, ‘onset_div’, ‘duration_div’, ‘onset_sec’, ‘duration_sec’ and ‘velocity’.

property num_tracks: int

Number of tracks

property sustain_pedal_threshold: int

The threshold value (number) above which sustain pedal values are considered to be equivalent to on. For values below the threshold the sustain pedal is treated as off. Defaults to 64.

Based on the control items of type “sustain_pedal”, in combination with the value of the “sustain_pedal_threshold” attribute, the note dictionaries will be extended with a key “sound_off”. This key represents the time the note will stop sounding. When the sustain pedal is off, sound_off will coincide with note_off. When the sustain pedal is on, sound_off will equal the earliest time the sustain pedal is off after note_off. The sound_off values of notes will be automatically recomputed each time the sustain_pedal_threshold is set.