Just to demonstrate that arbitrary interpretation of data is a hallmark
of JMSL, let's whip together an Instrument that changes the background color
of a JPanel. It will interpret MusicShape data as (R,G,B) color values. The zeroth
dimension of the MusicShape shall be interpreted as duration (this is a standard interpretation), while dimensions 1..3 are respectively the
intensity values of red, green, and blue.
The Instrument class, shown below, simply extracts RGB data from its double[]
parameter, and communicates the color change to a JPanel.
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;
}
}
This MusicShape is loaded with random data,
and prints itself out in the TextArea before it starts performing as shown in the video below.