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.
PerformedPart(notes, id=None, part_name=None, controls=None, sustain_pedal_threshold=64)¶
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).
- 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.
A list of dictionaries containing performed note information.
The identifier of the part
Name for the part
A list of dictionaries containing continuous control information
from_note_array(note_array, id=None, part_name=None)¶
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).
Structured array containing performance information. The fields are ‘id’, ‘pitch’, ‘p_onset’, ‘p_duration’ and ‘velocity’.
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.