MIDI file issue with python mido module

40 views Asked by At

I'm having trouble with the mido python module. When I try to simply copy one MIDI file to another the resulting MIDI file is twice as long in length (all the notes are twice their durations). My intention is to strip out specific continuous controller data but I cannot figure this out. Here's a super simple code example

from mido import Message, MidiFile, MidiTrack

def copy_MIDI_File(midi_file):

    src_midi = MidiFile(midi_file)
    midi_file = MidiFile()
    for i, src_track in enumerate(src_midi.tracks):
        new_track = MidiTrack()
        print('Track {}: {}'.format(i, src_track.name))
    
        for msg in src_track:        
            new_track.append(msg)
                                           
        midi_file.tracks.append(new_track)
    
    midi_file.save('new_song.mid')

And here's a screen shot showing the 2 files. The upper MIDI file is the original, the lower is the resulting file. As you can see the note lengths are twice as long as the original.

screen shot of 2 MIDI files

I'm puzzled why this is happening. Thank you for any help you may have to offer with this!

--Debra Peri

0

There are 0 answers