I am writing the script simply play the midi file
import pretty_midi
import mido
port = mido.open_output(mido.get_output_names()[0]) # open port of software synthesizer.
midi_file = '2021-01-02_101128_03.mid'
midi_data = pretty_midi.PrettyMIDI(midi_file)
notes = midi_data.instruments[0].notes # get notes from trackone.
for note in notes:
print(note)
msg = Message('note_on', note=note.pitch)
port.send(msg) # send message to synthesizer
It plays every notes at the same (for loop is too fast for us!)
I need to control the timing of sending message.
How can I make it ? how can I control the timing of sending message?
in Midi file there are message like this.
Note(start=0.000000, end=0.125000, pitch=60, velocity=100)
Note(start=0.375000, end=0.500000, pitch=60, velocity=100)
Note(start=0.500000, end=0.625000, pitch=64, velocity=100)
Note(start=0.750000, end=0.875000, pitch=67, velocity=100)
Note(start=1.000000, end=1.125000, pitch=68, velocity=100)
Note(start=1.375000, end=1.500000, pitch=67, velocity=100)
Note(start=1.500000, end=1.625000, pitch=65, velocity=100)
Note(start=1.750000, end=1.875000, pitch=62, velocity=100)
Note(start=1.875000, end=2.000000, pitch=62, velocity=100)