The following program uses MIDO to read 'g1.mid' then save it to 'g1_new.mid'. My question is that: in reading the file, 'msg.time' is a float value, but in saving the file, 'time in Message' is an integer in tick. How do we convert 'msg.time' to 'tick in message' in this case?
from mido import MidiFile
from mido import Message, MidiTrack
mid = MidiFile()
track = MidiTrack()
mid.tracks.append(track)
for msg in MidiFile('g1.mid'):
if (not msg.is_meta):
if (msg.type == 'note_on'):
# how to convert msg.time to tick to fill in '?'
track.append(Message('note_on', note=msg.note, velocity=msg.velocity, time=?))
elif (msg.type == 'note_off'):
# how to convert msg.time to tick to fill in '?'
track.append(Message('note_off', note=msg.note, velocity=msg.velocity, time=?))
elif (msg.type == 'program_change'):
track.append(Message('program_change', program=msg.program, channel=msg.channel))
mid.save('g1_new.mid')
Note: This piece of code is in a project about music generation.