I am trying to read a midi file and generate another midi with the drum notes only using python midi. The code is the following:
pattern = midi.read_midifile(IN_PATH+file)
out_p = midi.Pattern()
out_t = midi.Track()
out_p.append(out_t)
for track in pattern:
for e in track:
if not(isinstance(e, midi.NoteEvent) and e.channel!=9):
out_t.append(e)
eot = midi.EndOfTrackEvent(tick=1)
out_t.append(eot)
midi.write_midifile(OUT_PATH+file, out_p)
Basically, I am appending just the drum notes and other MIDI events. However, rmoving other notes causes some timing issues because the drum notes appear to be unaligned with the grid when I load them on a DAW. I tried with pattern.make_ticks_abs
but it did not work.
How can I remove undesired notes without timing issues?