MIDI I/O Interface
- muspy.read_midi(path, backend='mido', duplicate_note_mode='fifo')[source]
Read a MIDI file into a Music object.
- Parameters:
path (str or Path) – Path to the MIDI file to read.
backend ({'mido', 'pretty_midi'}, default: 'mido') – Backend to use.
duplicate_note_mode ({'fifo', 'lifo, 'all'}, default: 'fifo') –
Policy for dealing with duplicate notes. When a note off message is presetned while there are multiple correspoding note on messages that have not yet been closed, we need a policy to decide which note on messages to close. Only used when backend is ‘mido’.
’fifo’ (first in first out): close the earliest note on
’lifo’ (first in first out):close the latest note on
’all’: close all note on messages
- Returns:
Converted Music object.
- Return type:
- muspy.write_midi(path, music, realize_annotations=False, backend='mido', **kwargs)[source]
Write a Music object to a MIDI file.
- Parameters:
path (str or Path) – Path to write the MIDI file.
music (
muspy.Music) – Music object to write.realize_annotations (bool, default: False) – Should annotations be applied to loudness/timing of notes?
backend ({'mido', 'pretty_midi'}, default: 'mido') – Backend to use. Note that if realize_annotations is True, then the ‘mido’ backend is used, since the realize_annotations is better optimized for the ‘mido’ backend. However, the ‘pretty_midi’ backend has limited support for annotation realization.
See also
write_midi_midoWrite a Music object to a MIDI file using mido as backend.
write_midi_pretty_midiWrite a Music object to a MIDI file using pretty_midi as backend.