edu.columbia.ee.csmit.MidiKaraoke.examples
Class MidiCommandSorterExample

java.lang.Object
  extended by edu.columbia.ee.csmit.MidiKaraoke.examples.MidiCommandSorterExample

public class MidiCommandSorterExample
extends java.lang.Object

Shows how to use the MidiCommandSorter class. This class takes a Sequence, parses its commands into MidiMessage objects and sorts the messages into time order. It then calculates the time in seconds for each command using the tick information and information from tempo changes.

    public static void main(String[] args) {
                if(args.length == 0){
            System.out.println("Usage: MidiCommandSorter [midi file name]");
            return;
        }


        try {

            File file = new File(args[0]);
            Sequence mySeq = MidiSystem.getSequence(file);

            ArrayList<Info> commands = MidiCommandSorter.sort(mySeq);
            Iterator<Info> it = commands.iterator();
            // Note that each line here contains the midi command, the track
            // number, the time of the command in seconds, and the time in
            // ticks.  Also note that the midi commands appear in time-order,
            // not file order.  The time in seconds has been calculated from
            // the tempo changes in the file.
            while(it.hasNext()){
               System.out.println(it.next());
            }


        } catch (Exception e) {
            System.out.println("Problem!");
            e.printStackTrace();
            System.out.println(e.toString());
        }


    }
 


Constructor Summary
MidiCommandSorterExample()
           
 
Method Summary
static void main(java.lang.String[] args)
          Shows how to use the MidiCommandSorter class to parse a Sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MidiCommandSorterExample

public MidiCommandSorterExample()
Method Detail

main

public static void main(java.lang.String[] args)
Shows how to use the MidiCommandSorter class to parse a Sequence. Prints out all of the midi commands it parses.

Parameters:
args - the command line arguments. The first (and only) parameter is the name of a midi file.