/** ColToot03.java Put three MusicJobs in a SequentialCollection that acts behaviorally, ie. chooses a new child each repeat. * @author Nick Didkovsky and Phil Burk */ /* * (C) 1997 Phil Burk and Nick Didkovsky, All Rights Reserved * JMSL is based upon HMSL (C) Phil Burk, Larry Polansky and David Rosenboom. */ package jmsltutorial; import java.awt.Frame; import java.awt.TextArea; import com.softsynth.jmsl.*; public class ColToot03 extends java.applet.Applet { SequentialCollection mySequentialCollection; MusicJob mj1; MusicJob mj2; MusicJob mj3; TextArea myTextArea; /* Build our hierarchy when the applet initializes, and send JMSL's STDOut to a TextArea */ public void init() { // initialize the TextArea with 15 rows, 40 columns myTextArea = new TextArea(15, 40); // Add the TextArea to the applet's layout add(myTextArea); // Hand this TextArea to a new TextAreaSTDOut, and use it for JMSL.out JMSL.setSTDOut(new TextAreaSTDOut(myTextArea)); // initialize collection with vanilla MusicJobs mySequentialCollection = new SequentialCollection(); mySequentialCollection.setBehavior(new TutorialBehavior()); mj1 = new MusicJob(); mj2 = new MusicJob(); mj3 = new MusicJob(); MessagePrintingPlayable mppf = new MessagePrintingPlayable("Repeating"); mj1.addRepeatPlayable(mppf); mj2.addRepeatPlayable(mppf); mj3.addRepeatPlayable(mppf); mj1.setRepeatPause(1.0); mj2.setRepeatPause(1.5); mj3.setRepeatPause(2.0); mySequentialCollection.add(mj1); mySequentialCollection.add(mj2); mySequentialCollection.add(mj3); mySequentialCollection.setRepeats(20); //mySequentialCollection.printHierarchy(); // set seed from clock JMSLRandom.randomize(); } /* When applet starts up, launch collection */ public void start() { JMSL.clock = new DefaultMusicClock(); mySequentialCollection.launch(JMSL.now()); } /* Shut down the Collection when applet stops */ public void stop() { mySequentialCollection.finish(); } public static void main(String args[]) { Frame frame = new Frame(); frame.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); ColToot03 applet = new ColToot03(); applet.init(); applet.start(); frame.add(applet); frame.setSize(600, 500); frame.setVisible(true); } } class TutorialBehavior implements Behavior { /* Implement your own Behavior here. This one chooses a child uniformly randomly */ public Composable choose(SequentialCollection col) { int index = JMSLRandom.choose(col.size()); JMSL.out.println("TutorialBehavior chooses index " + index); return col.get(index); } }