/** PlayToot03.java Fill a MusicShape with random numbers, and add it to two different Players. Each Player interprets the same MusicShape differently: one with a custom Interpreter that sets the background color of the applet by interpreting MusicShape data as RGB colors, the other simply prints MusicShape data to a TextArea. * @author Nick Didkovsky, (C) 1997 Nick Didkovsky, All Rights Reserved */ package jmsltutorial; import java.awt.TextArea; import com.softsynth.jmsl.*; public class PlayToot03 extends java.applet.Applet { MusicShape myMusicShape; Player player1; Player player2; 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"); // Build two Players, add the same MusicShape to both. player1 = new Player(); player2 = new Player(); player1.add(myMusicShape); player2.add(myMusicShape); // Set each Interpreter independently player1.setInstrument(new AppletColorInstrument(this)); player2.getInstrument().setInterpreter(new com.softsynth.jmsl.util.SimplePrintingInterpreter()); // Let us know when you're done player1.addStopPlayable(new MessagePrinter("stops")); player2.addStopPlayable(new MessagePrinter("stops")); } /* When applet starts up, launch the Players */ public void start() { JMSL.clock = new DefaultMusicClock(); JMSL.clock.setAdvance(0.5); double when = JMSL.now(); player1.launch(when); player2.launch(when); } public void stop() { player1.finish(); player2.finish(); } }