Whether the element is interpreted as a Midi note, a set of synthesis parameters, or RGB colors, is entirely up to the Instrument.
Instrument is an interface. JMSL provides a convenient InstrumentAdapter class which already implements Instrument. You can extend InstrumentAdapter and override its various method to provide custom behavior.
For example, we could just print the element by declaring our own subclass
of InstrumentAdapter and override play() like so:
/** A simple Instrument subclass that just prints out the data it is handed, interprets element[0] as duration */
public class PrintingInstrument extends InstrumentAdapter { /** Overridden for custom interpretation */ public double play(double playTime, double timeStretch, double dar[]) { JMSL.out.println("Instrument.play() is handed the following array of doubles:"); JMSL.printDoubleArray(dar); JMSL.out.println(); return playTime + dar[0]*timeStretch; // interpret dar[0] as duration } }It is your responsibility to return the correctly updated time. Note that the method above interprets the first member of dar[] as duration, and adds it to the original playTime after scaling it up or down with timeStretch. timeStretch provides a way to scale time up or down (slower or faster).
Next we will revisit the MusicShape created in an earlier tutorial, and interpret it with the play() method above.
Previous | Tutorial Index | Tutorial Contents | Next |
(C) 1997 Phil Burk and Nick Didkovsky, All Rights Reserved JMSL is based upon HMSL (C) Phil Burk, Larry Polansky and David Rosenboom.