/** MJToot09.java Provide functionality to stock MusicJobs by using Playables instead of subclassing and overriding. * @author Phil Burk and Nick Didkovsky */ /* * (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.TextArea; import com.softsynth.jmsl.*; public class MJToot09 extends java.applet.Applet { // two vanilla MusicJobs MusicJob spot; MusicJob puff; TextArea myTextArea; /* Build our MusicJobs when applet initializes, send JMSL's STDOut to a TextArea */ public void init() { // initialize the TextArea with 20 rows, 50 columns myTextArea = new TextArea(20, 50); // 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 a couple of stock MusicJobs spot = new MusicJob(); puff = new MusicJob(); // set their durations spot.setRepeatPause(2.0); puff.setRepeatPause(1.0); // set their repeat counts spot.setRepeats(5); puff.setRepeats(10); // Now build some custom Playables and plug them in! puff.addStartPlayable(new MessagePrintingPlayable("Puff Starting")); puff.addRepeatPlayable(new MessagePrintingPlayable("Puff Repeating (meow)")); puff.addStopPlayable(new MessagePrintingPlayable("Puff Stopped")); spot.addStartPlayable(new MessagePrintingPlayable("Spot Starting")); spot.addRepeatPlayable(new MessagePrintingPlayable("Spot Repeating (bow-wow)")); spot.addStopPlayable(new MessagePrintingPlayable("Spot Stopped")); // alternative way to add a Playable by defining a Playable on the fly spot.addRepeatPlayable(new Playable() { public double play(double playTime, Composable thing) { // do something, anything return playTime; } }); } /* When applet starts up, launch them */ public void start() { JMSL.clock = new DefaultMusicClock(); spot.launch(JMSL.now()); puff.launch(JMSL.now()); } /* Shut down the MusicJobs when applet stops */ public void stop() { puff.finish(); spot.finish(); } }