I've had a decent look at the midi file format and I thought I understood, so I wrote a python script that removed midis with multiple tracks from my data set in order to have only melodies in single tracks left. I did this by checking the track number bits in the header and if the track number was higher than one.. bingo! I am dealing with a large number of files so I checked a reasonable number of the latter removed files and they were indeed polyphonic with a melody and a chord sequence played simultaneously. I thought that that was mission accomplished but it was not, further data cleansing meant I heard midis as part of the testing and some of my remaining midis were still polyphonic. I can't see how to strip them from the dataset because I cannot figure out what uniquely identifies them as polyphonic midis.

I hope this is clear. Please advise.


3 Answers 3


Tracks in MIDI files are useful when you want to edit the file later, but have no meaning whatsoever on the MIDI level. It is possible to have events for multiple channels in one track (as you've seen), and to have events for the same channel in multiple tracks.

To filter out files that send note events to multiple channels, you have to parse all events in the file and to check their channel numbers.


As per Uncle Bob's comment, the tracks in a MIDI file are not necessarily monophonic lines - they typically represent data to be played back using a single instrument voice, but each of those parts could well still be polyphonic. A solo piano piece might well be recorded as one MIDI track (as only one instrumental voice is needed to play it back), but it would typically contain many notes sounding simultaneously.

If you need to identify monophonic tracks in your MIDI files, a good starting point would be to find tracks where the notes don't actually overlap. Even this wouldn't be 100% accurate as the actual synthesizer voice is what determines what you hear, but if you are dealing with General MIDI data, you could look at the voice being used to play the track and make your judgement based on that too.

Of course you might find that some MIDI files have more than one monophonic track, and you might find that some have a monophonic track that nevertheless doesn't seem to be a 'melody'. Your job then might be to more tightly define what you mean by 'melody'.


I'm not sure if I get your question right, but in general there are two types of MIDI files.

  • MIDI 0
  • MIDI 1

MIDI 0 = all the tracks are merged into a single track

MIDI 1 = contains separate information for each track

So if you would write a score for multiple instruments in Sibelius for example and export them as a MIDI 0 file, you will get just one (track-)file. If you would import this file into any DAW, you would get only one file with all instruments merged into this file. On the other hand, if you would export it as a MIDI 1 file and import it into your DAW, you would get a separate MIDI-track for each instrument.

This however doesn't really say anything about a monophonic or polyphonic file. If you would export a piano as MIDI 1 for example, you would still get a merged file with melody + chords, because in the end a piano (even tho it's polyphonic) is only one instrument.

So if you would want each file separate, you would have to do two piano tracks - One with melody only, one with chord only and then export it as MIDI 1. Then you would get each file separate, because it exports each track like it's a single piano.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.