/** BackgroundColorInstrument.java Fill a MusicShape with random numbers, play it with a custom Instrument that sets the background color of a JComponent 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 javax.swing.JComponent; import com.softsynth.jmsl.InstrumentAdapter; /** * A simple Instrument subclass that interprets element [0] as duration and the rest as rgb color values */ public class BackgroundColorInstrument extends InstrumentAdapter { JComponent jc; BackgroundColorInstrument(JComponent jc) { this.jc = jc; } /** Overridden for custom interpretation */ public double play(double playTime, double timeStretch, double dar[]) { double duration = dar[0]; int r = (int) dar[1]; int g = (int) dar[2]; int b = (int) dar[3]; jc.setBackground(new Color(r, g, b)); jc.repaint(); return playTime + duration * timeStretch; } }