Importing MIDI files - davidpanderson/Numula GitHub Wiki
To read a MIDI file into a Numula Score
:
import numula.read_midifile
numula.read_midifile.read_midifile(
filename: str,
ticks_per_beat: int = 960, use_velocity: bool = True
) -> Score
This reads the MIDI file and converts pairs of note_on and note_off MIDI events into Note
objects.
The file may consist of multiple tracks; notes from track N are tagged with "trackN".
ticks_per_beat
specifies the number of MIDI ticks per (quarter note) beat.
It's possible that this could be inferred from header information,
but I can't find a sufficiently coherent MIDI spec.
If use_velocity
is False, notes are created with vol=.5;
otherwise the volume is velocity/128.
An example (reading a MIDI file, adding nuance, playing the result) is here.
NOTE: this requires the mido (MIDI Objects) python package:
pip3 install mido