JMSL Tutorial: MusicShape


Let's have a look at Interpolators, which are another powerful way of generating MusicShape data (or any data for that matter).

An Interpolator defines a function intersecting two points, and calculates values for you anywhere along that function.

For example, you may define a LinearInterpolator to interpolate along the line containing the two points (0,5) and (10,100). Here's how:
    LinearInterpolator myLine = new LinearInterpolator(0.0, 5.0, 10.0, 100.0);

From then on, the LinearInterpolator's interp() method can be fed an x value, and will return the corresponding y along the line defined by those two points. Here's how:
   double x = 1.414213562373095;
   double y = myLine.interp(x);

You can also change an existing Interpolator's values with the setInterp(x1, y1, x2, y2) method.

JMSL's util package contains a number of Interpolators, including the LinearInterpolator, ExponentialInterpolator, and ExponentialDecayInterpolator. These latter two Interpolators have additional methods to set the steepness of their curvature.

This applet illustrates a MusicShape whose data is defined by a variety of different Interpolators.

You need a Java-enabled browser to view this applet.
View the source of this applet here.

You have seen that MusicShapes can be created in a number of interesting ways. Take a moment to review the MusicShape docs, which detail the methods that a MusicShape has to manipulate its own data internally. Methods include sorting, scrambling, randomizing, reversing, inverting, and scaling.

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.