I need help in the following: I am designing a new music notation. I want to read a midi file and get a list that contains every note/start-stop-time/track. Desired result:
[[60, 0, 0.25, 1], [62, 0.25, 0.50, 1]]# the format is [note, start-time, stop-time, miditrack]
*update 1 - getting [note, note_on(time), note_off(time), channel]
The following code creates a dictionary in which the delta times are converted to linear time(but I am not sure if this is the right approach):
from mido import MidiFile
mid = MidiFile('testsunvox.mid')
midimsgs = []
# Put all note on/off in midinote as dictionary
for i in mid:
if i.type == 'note_on' or i.type == 'note_off':
midimsgs.append(i.dict())
# change time values from delta to relative time # don't know for sure if this is the right way...
mem1=0
for i in midimsgs:
time = i['time'] + mem1
i['time'] = time
mem1 = i['time']
# put note, starttime, stoptime, as nested list in a list. # format is [note, start, stop, channel]
for i in midimsgs:
print (i)
I cannot find the right question for this right now but the goal is to get:
[note, note_on(time), note_off(time), channel]
for each note. But the problem is that there are two messages(note-on/off) and I want to make it one. I will post my solution if I found it. (or maybe someone knows a very simple trick of the mido libriary to do this...)