title: Reading MIDI files in Java
body: <p>I'm trying to read in .MID files to a Java program, and would like to separate each note/chord so as to display them on a UI of some sort. I didn't have much luck using the Sequencer API in Java, and trying to use MidiFileReader directly didn't work for me either. I'll attach the code I used here, if anyone wants to see it:</p>
  
  <pre><code>package miditest;
  import java.io.File;
  import java.io.IOException;
  import javax.sound.midi.InvalidMidiDataException;
  import javax.sound.midi.MidiSystem;
  import javax.sound.midi.MidiUnavailableException;
  import javax.sound.midi.Sequence;
  import javax.sound.midi.Sequencer;
  
  public class Main {
      public static void main(String[] args) throws InvalidMidiDataException, IOException, MidiUnavailableException{
      Sequence sequence = MidiSystem.getSequence(new File("test.mid"));
  
      // Create a sequencer for the sequence
      Sequencer sequencer = MidiSystem.getSequencer();
      sequencer.open();
      sequencer.setSequence(sequence);
  
      // Start playing
      sequencer.start();
      }
  }
  </code></pre>