Extract drum notes from midi using python midi

I am trying to read a midi file and create another midi with drum notes using python midi only. The code is as follows:

 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 only add drum notes and other MIDI events. However, using other notes causes some timing issues because the drum notes seem unequal to the grid when I load them onto the DAW. I tried with pattern.make_ticks_abs

but it didn't work.

How to delete unwanted notes without time problems?

+3


source to share





All Articles