package jmsltestsuite; import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.*; import com.softsynth.jmsl.*; public class MusicJobTest { /** Build a MusicJob that repeats 5 times, once each second, and simply prints out its start, repeat, and stop activity */ // Weird that the duration of the first one is about 1.5 seconds. // The rest follow at a steady 2 second interval public static void main(String args[]) { if (args.length != 1) { System.out.println( "Usage: MusicJob r|w|p \nr = read a MusicJob from a file\nw = create and write a MusicJob to file\np=just make one and play it"); System.exit(0); } try { Frame f = new Frame("MusicJobTest"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.setSize(500, 100); f.setVisible(true); String filename = "musicjob.tmp"; MusicJob mj; if (args[0].equalsIgnoreCase("p") || args[0].equalsIgnoreCase("w")) { mj = new MusicJob(); mj.setRepeatPause(2.0); mj.setRepeats(5); mj.addStartPlayable(new MessagePrinter("Starts")); mj.addRepeatPlayable(new com.softsynth.jmsl.util.TimePrinter()); mj.addStopPlayable(new MessagePrinter("Stops")); if (args[0].equalsIgnoreCase("w")) { System.out.println("Writing a new MusicJob to file " + filename); FileOutputStream ostream = new FileOutputStream(filename); ObjectOutputStream p = new ObjectOutputStream(ostream); p.writeObject(mj); p.flush(); ostream.close(); System.out.println("saved " + filename); } mj.print(); mj.launch(JMSL.now()); } if (args[0].equalsIgnoreCase("r")) { System.out.println("Read MusicJob from file: " + filename); FileInputStream istream = new FileInputStream(filename); ObjectInputStream p = new ObjectInputStream(istream); mj = (MusicJob) p.readObject(); istream.close(); System.out.println("done. \nNow we'll print the object's state when it was saved, and launch it"); mj.print(); mj.launch(JMSL.now()); } } catch (Exception e) { System.out.println("Error in MusicJob.main(): " + e); } } }