/** AppletColorInstrument.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.Color; import com.softsynth.jmsl.InstrumentAdapter; /** A simple Interpreter subclass that interprets data as rgb color, interprets element[0] as duration */ public class AppletColorInstrument extends InstrumentAdapter { java.applet.Applet applet; /* Constructor initializes the parent Applet */ AppletColorInstrument(java.applet.Applet a) { applet = a; } /** Overridden for custom interpretation */ public double play(double playTime, double timeStretch, double dar[]) { int r = (int) dar[1]; int g = (int) dar[2]; int b = (int) dar[3]; applet.setBackground(new Color(r, g, b)); applet.repaint(); return playTime + dar[0] * timeStretch; } }