JMSL's Instrument Interface

A JMSL Instrument sonifies abstract numerical data. The interpretation of this data takes place in its play() method. The user overrides play() to provide custom interpretaton.

Whether the element is interpreted as a Midi note, a set of JSyn parameters, or RGB colors, is entirely up to the Instrument.

Instrument is an interface, but we provide an InstrumentAdapter which has all methods implemented. For example, we could just print the data by declaring our own subclass of InstrumentAdapter and override play() like so:

/** A simple InstrumentAdapter subclass that just prints out the data it is handed, interprets element[0] as duration */
class PrintingInstrument extends InstrumentAdapter {
        /** Overridden for custom interpretation */
        public double play(double playTime, double timeStretch, double dar[])
                JMSL.out.println(" is handed the following array of doubles:");
                return playTime + (dar[0]*timeStretch);  // interpret dar[0] as duration

Notice in the code above that the incoming playtime is passed in as an argument to play(). Notice also that the play() method returns an updated time.