What is the best way to read a MIDI file (chronologically) with multiple tracks? (Java)
Note: I don\'t want to play the MIDI file, just read the messages.
Co
In Java, you can read a midi file with :
try {
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.setSequence(MidiSystem.getSequence(yourMidiFile));
sequencer.open();
sequencer.start();
while(true) {
if(sequencer.isRunning()) {
try {
Thread.sleep(1000); // Check every second
} catch(InterruptedException ignore) {
break;
}
} else {
break;
}
}
} catch(Exception e) {
System.out.println(e.toString());
} finally {
// Close resources
sequencer.stop();
sequencer.close();
}
This code should read your midi files (even if there are multiple tracks)
JFugue can read a MIDI file and sort the messages in chronological order.
The results can be read as JFugue MusicStrings (for example, C-sharp, 5th octave, whole note = "C#5w"), or you can write your own ParserListener and attach it to the MidiParser so you can output your own text.