JMSL Tutorial: MusicJob

A MusicJob has an Instrument. An Instrument's play() method interprets data. So a MusicJob could create double[] data on the fly and hand it to an Instrument for sonification or other, non-musical interpretation.

Here we define a simple Instrument that prints out the data it receives. It interprets data[0] as duration. The essential code in this Instrument is shown below.

    public double play(double playTime, double timeStretch, double[] data) {
        double duration = data[0];
        JMSL.out.println(", playTime=" + playTime);
        for (int i = 0; i < data.length; i++) {
            JMSL.out.println(i + ", " + data[i]);
        return playTime + duration * timeStretch;

Every time the MusicJob repeats, it will generate new data. It will hand it to its Instrument's play() method which will return an updated playTime. The essential code in this MusicJob is shown below.

    public double repeat(double playTime) {
        double[] data = new double[3];
        data[0] = 2.0; // duration
        data[1] = JMSLRandom.choose(); // something else
        data[2] = JMSLRandom.gauss(5, 3); // something else again
        return getInstrument().play(playTime, 1, data);

You need a Java-enabled browser to view this applet.

We have seen that a MusicJob has an Instrument that can be defined and customized by the programmer. We see that a MusicJob can generate arbitrary data on the fly. It can use this Instrument to interpret the data it created. It can use the playTime returned by to delay its repeat() cycle.

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.