os/macosx/openttdmidi.java
changeset 1694 bbddafc87744
parent 0 29654efe3188
equal deleted inserted replaced
1693:e3a6eedee876 1694:bbddafc87744
       
     1 //
       
     2 //  OpenTTDMidi.java
       
     3 //  OpenTTDMidi
       
     4 //
       
     5 //  Created by Joshua King on Sun Apr 25 2004.
       
     6 //  Copyright (c) 2004 __MyCompanyName__. All rights reserved.
       
     7 //
       
     8 import java.io.*;
       
     9 import java.util.*;
       
    10 import javax.sound.midi.*;
       
    11 
       
    12 public class OpenTTDMidi {
       
    13 
       
    14     public static void main (String args[]) {
       
    15         // Currently command line is the MIDI file
       
    16 		if (args.length == 1) {
       
    17 			Sequencer s2 = null;
       
    18 			
       
    19 			try {
       
    20 				s2 = MidiSystem.getSequencer();
       
    21 				s2.open();
       
    22 			} catch (MidiUnavailableException mue) {
       
    23 				System.exit(1);
       
    24 			}
       
    25 			
       
    26 			Sequence s = null;
       
    27 			
       
    28 			try {
       
    29 				s = MidiSystem.getSequence(new File(args[0]));
       
    30 			} catch (InvalidMidiDataException imde) {
       
    31 				System.exit(2);
       
    32 			} catch (IOException ioe) {
       
    33 				System.exit(3);
       
    34 			}
       
    35 			
       
    36 			try {
       
    37 				s2.setSequence(s);
       
    38 				s2.setMicrosecondPosition(0);
       
    39 				s2.start();
       
    40 				for (long l = 0; l < (s.getMicrosecondLength() / 1000000); l++) {
       
    41 					try {
       
    42 						//System.out.print(".");
       
    43 						Thread.currentThread().sleep(1000);
       
    44 					} catch (InterruptedException ie) {}
       
    45 				}
       
    46 				System.out.println();
       
    47 			} catch (InvalidMidiDataException imde) {
       
    48 			}
       
    49 			
       
    50 			s2.stop();
       
    51 			s2.close();
       
    52 			System.exit(0);
       
    53 		}	
       
    54     }
       
    55 }