Karaoke Midi Java Tools for Matlab

The Midi Toolbox is a great tool for analyzing midi files, but it can't handle files with tempo changes properly.   My code can substitute for the 'read_midi.m' function of the Midi Toolbox, and it should give you correct timing in the 6th and 7th columns of the note matrix.

Please note that this code is definitely in beta.  If you find any bugs, please send me a detailed email.

Using midi java tools for matlab:

  1. Make sure you version of Matlab has a recent enough java run-time environment.  At the matlab prompt, type version -java.  Matlab should say at least Java 1.5.0.  I think that Matlab R14 and later should work.
  2. Download midiToolboxNM.m and KaraokeMidiJava.jar.  midiToolboxNM is a wrapper for the java code and can be called just like read_midi.m.
  3. Tell Matlab where the jar is by editing classpath.txt.
    1. At the matlab prompt, type edit classpath.txt
    2. Add a line at the end telling Matlab the location of the jar: /<path-to-jar>/KarokeMidiJava.jar, where <path-to-jar> is the path to wherever you have saved KaraokeMidiJava.jar.  Obviously, if you are running Windows, use a Windows-style path.
    3. Save classpath.txt and restart Matlab.  (Matlab only reads classpath.txt at startup.)
  4. At the Matlab prompt, type nm = midiToolboxNM('<name_of_file.mid>');, where <name_of_file.mid> is the name of the midi file you want to read.  The nm variable will now have a notematrix just like the one defined in MidiToolbox.

Possible issues:

Problem: You don't own the right to change a global classpath.txt

Solution: Make a copy of classpath.txt to a local directory.  Make the changes you need to your local copy of classpath.txt.  Now, whenever you start up Matlab, have it use your local classpath.txt by putting the local classpath.txt on the command line.  In other words, rather than starting Matlab by typing matlab&, type matlab /<path-to-local-copy>/classpath.txt.

Problem: Matlab keeps complaining that it can't find my java code.

Solution: Read Matlab's own detailed site on making java classes available to Matlab here.  (Yes, this is definitely a punt on my part!)


Christine Smit

Christine Smit's email address