JMSL Tutorial: Instruments and Interpreters

So far we have seen a many ways of creating data, printing it, viewing it graphically, etc. Now is the golden moment where we actually interpret this data in a useful way.

A JMSL Instrument has a play() method which interprets an array of double in some customized way, making a sound for example. must also return an updated time stamp.  So its interpretation of double[] includes extracting duration information from it.

Recall that MusicShape's elements are really double[] arrays.  A MusicShape contains an Instrument as well.  When it is launched, it pulls one element at a time, hands it to its Instrument, and calls the Instrument's play() method, passing in a timestamp and this element data. The Instrument's play() method returns the updated time (say, one second later than the incoming timestamp) and passes this updated  time back to the MusicShape.  MusicShape waits until that new time and proceeds with its next element.

The Instrument can interpret the double[] element directly in play(), or it can pass it on to a custom Interpreter. So the programmer can provide custom handling of MusicShape data in one of two ways:

  1. Plugging a custom Interpreter into an Instrument
  2. Subclassing Instrument and overriding its play() method

Next, we will see how this is done.
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.