musicautobot
musicautobot copied to clipboard
midifile.py classifies most tracks as undefined
When trying to preprocess my midi files (using the DataPreProcessing notebook), it keeps on returning None when
try:
# if duet_only and num_piano_tracks(input_path) not in [1, 2]: return None
input_file = compress_midi_file(input_path, min_variation=min_variation, cutoff=cutoff) # remove non note tracks and standardize instruments
in the transform_midi function.
This leads to no conversion to npy's of my midi files
Hope this is still relevant, there is a small bug in the utils/midifile.py. During preprocessing this script validates the midifiles and extracts only the relevant Miditracks. However during this track selection step the get_track_instrument function looks for PROGRAM_CHANGED messages by comparing the music21 MidiEvent type to the string 'PROGRAM_CHANGED', whereas the event type is a enum of type ChannelVoiceMessages.
In summary change following line in the utils/midifile.py line 98:
def get_track_instrument(t):
for idx,e in enumerate(t.events):
#if e.type == 'PROGRAM_CHANGE': return e.data <-- issue here
if e.type == ChannelVoiceMessages.PROGRAM_CHANGE:return e.data # <-- my fix
return None