/** InsToot05.java Fill a MusicShape with random numbers, play it with a custom Instrument that sets the background color of the applet by interpreting MusicShape data as RGB colors. * @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 InsToot05 extends java.applet.Applet { MusicShape myMusicShape; TextArea myTextArea; /* Build data when the applet initializes, and send JMSL's STDOut to a TextArea */ public void init() { // initialize the TextArea myTextArea = new TextArea(15, 55); // 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)); myMusicShape = new MusicShape(4); for (int i = 0; i < 20; i++) { // choose a duration between 0.25 and 3.0 seconds, in qtr second intervals double duration = JMSLRandom.choose(12) * 0.25 + 0.25; double r = (double) JMSLRandom.choose(256); double g = (double) JMSLRandom.choose(256); double b = (double) JMSLRandom.choose(256); myMusicShape.add(duration, r, g, b); } // Now let's name the dimensions with human-friendly monikers myMusicShape.setDimensionName(0, "Duration"); myMusicShape.setDimensionName(1, "Red"); myMusicShape.setDimensionName(2, "Green"); myMusicShape.setDimensionName(3, "Blue"); // Finally, let's set up a custom Interpreter //myMusicShape.getInstrument().setInterpreter(new AppletColorInterpreter(this)); myMusicShape.setInstrument(new AppletColorInstrument(this)); myMusicShape.print(); } /* When applet starts up, launch the MusicShape */ public void start() { JMSL.clock = new DefaultMusicClock(); myMusicShape.launch(JMSL.now()); } public void stop() { myMusicShape.finish(); } }