/** 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.BorderLayout; import java.awt.Dimension; import java.awt.TextArea; import javax.swing.JFrame; import javax.swing.JPanel; import com.softsynth.jmsl.JMSL; import com.softsynth.jmsl.JMSLRandom; import com.softsynth.jmsl.MusicShape; public class InsToot05 extends JFrame { MusicShape myMusicShape; TextArea myTextArea; JPanel colorPanel; /* * Build data and send JMSL's STDOut to a TextArea */ public void init() { setLayout(new BorderLayout()); // initialize the TextArea myTextArea = new TextArea(15, 20); colorPanel = new JPanel(); colorPanel.setSize(new Dimension(600, 300)); // Add the TextArea to the layout add(BorderLayout.NORTH, myTextArea); add(BorderLayout.CENTER, colorPanel = new JPanel()); // 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 BackgroundColorInstrument(colorPanel)); myMusicShape.print(); } /* When app starts up, launch the MusicShape */ public void start() { JMSL.clock.setAdvance(0.3); myMusicShape.launch(JMSL.now()); } public void stop() { myMusicShape.finish(); } public static void main(String[] args) { InsToot05 toot = new InsToot05(); toot.init(); toot.setSize(new Dimension(800, 600)); toot.setVisible(true); toot.start(); toot.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { toot.stop(); System.exit(0); } }); } }