package jmsltestsuite; import java.awt.FlowLayout; import java.awt.event.*; import javax.swing.JButton; import javax.swing.JFrame; import com.softsynth.jmsl.*; public class MusicJobTest2 extends JFrame { JButton launchButton; JButton haltButton; JButton finishButton; JButton isRunningButton; Composable composable; MusicJob gimmeMusicJob() { MusicJob mj = new MusicJob() { public double repeat(double playTime) { System.out.println(getName() + ", repeat"); return playTime + 2.5; } }; mj.setRepeats(1000); return mj; } void buildComposable() { // composable = new ParallelCollection(gimmeMusicJob(), // gimmeMusicJob()); composable = gimmeMusicJob(); ((MusicJob) composable).addStopPlayable(new Playable() { public double play(double time, Composable parent) throws InterruptedException { System.out.println(parent.getName() + "stopPlayable play() time=" + time + ", JMSL.realTime()=" + JMSL.realTime()); return time; } }); } void build() { setLayout(new FlowLayout()); launchButton = new JButton("launch"); add(launchButton); launchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("launching composable..."); composable.launch(JMSL.now(), null); System.out.println("...DONE launching composable"); } }); haltButton = new JButton("halt"); add(haltButton); haltButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("halting composable..."); composable.halt(); System.out.println("...DONE halting composable"); System.out.println("waitForDone()"); try { composable.waitForDone(); } catch (InterruptedException e1) { e1.printStackTrace(); } System.out.println("DONE"); } }); finishButton = new JButton("finish"); add(finishButton); finishButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("finishing composable..."); composable.finishAll(); System.out.println("...DONE finishing composable"); System.out.println("waitForDone()"); try { composable.waitForDone(); } catch (InterruptedException e1) { e1.printStackTrace(); } System.out.println("DONE"); } }); isRunningButton = new JButton("is Running?"); add(isRunningButton); isRunningButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(composable.getName() + ", isRunning?" + ((MusicJob) composable).isRunning()); } }); } void go() { buildComposable(); build(); System.out.println("LAUNCHING " + composable.getName()); composable.launch(JMSL.now(), null); } public static void main(String[] args) { MusicJobTest2 f = new MusicJobTest2(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.go(); f.pack(); f.setVisible(true); } }