/** ShapeToot05.java Fill a MusicShape with various Interpolators. * @author Phil Burk and Nick Didkovsky */ /* * (C) 1997 Phil Burk and Nick Didkovsky, All Rights Reserved * JMSL is based upon HMSL (C) Phil Burk, Larry Polansky and David Rosenboom. */ package jmsltutorial; import com.softsynth.jmsl.MusicShape; import com.softsynth.jmsl.util.*; import com.softsynth.jmsl.view.MusicShapeEditor; public class ShapeToot05 extends java.applet.Applet { MusicShape expDecayShape; MusicShape expShape; MusicShape linearShape; MusicShape halfCosineShape; MusicShapeEditor myShapeEditor; /* Build our data when the applet initializes */ public void init() { buildExpDecayShape(); buildExpShape(); buildLinearShape(); buildHalfCosineShape(); myShapeEditor = new MusicShapeEditor(); myShapeEditor.addMusicShape(expDecayShape); myShapeEditor.addMusicShape(expShape); myShapeEditor.addMusicShape(linearShape); myShapeEditor.addMusicShape(halfCosineShape); add(myShapeEditor.getComponent()); } /** Build exponentially decaying curves */ void buildExpDecayShape() { ExponentialDecayInterpolator exp = new ExponentialDecayInterpolator(0.0, 100.0, 600.0, 0.0); expDecayShape = new MusicShape(20); // 20 dimensions, to illustrate steepness expDecayShape.setName("Exponential Decay"); // first fill MusicShape with blank data for (int i = 0; i < 600; i++) { double dar[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; expDecayShape.add(dar); } // now load the shape up with real data, increasing the steepness for each dimension for (int dim = 0; dim < 20; dim++) { exp.setSteepness(dim + 1.0); for (int el = 0; el < 600; el++) { expDecayShape.set(exp.interp((double) el), el, dim); } } } /** Build a a set of exponentially increasing MusicShape data */ void buildExpShape() { ExponentialInterpolator exp = new ExponentialInterpolator(0.0, 0.0, 600.0, 100.0); expShape = new MusicShape(20); // 20 dimensions, to illustrate steepness expShape.setName("Exponential Increase"); // first fill MusicShape with blank data for (int i = 0; i < 600; i++) { double dar[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; expShape.add(dar); } // now load the shape up with real data, increasing the steepness for each dimension for (int dim = 0; dim < 20; dim++) { exp.setSteepness(dim + 1.0); for (int el = 0; el < 600; el++) { expShape.set(exp.interp((double) el), el, dim); } } } void buildLinearShape() { LinearInterpolator line = new LinearInterpolator(0.0, 0.0, 600.0, 40.0); linearShape = new MusicShape(1); linearShape.setName("Linear"); // first fill MusicShape with blank data for (int i = 0; i < 600; i++) { double dar[] = { 0 }; linearShape.add(dar); } // now load the shape up with real data, decreasing the steepness for each dimension for (int dim = 0; dim < linearShape.dimension(); dim++) { line.setInterp(0.0, 0.0, 600.0, 100.0 - 2.0 * dim); for (int el = 0; el < 600; el++) { linearShape.set(line.interp((double) el), el, dim); } } } void buildHalfCosineShape() { HalfCosineInterpolator hcos = new HalfCosineInterpolator(0.0, 0.0, 600.0, 40.0); halfCosineShape = new MusicShape(1); halfCosineShape.setName("Half Cosine"); // first fill MusicShape with blank data for (int i = 0; i < 600; i++) { double dar[] = { 0 }; halfCosineShape.add(dar); } // now load the shape up with real data, decreasing the steepness for each dimension for (int dim = 0; dim < halfCosineShape.dimension(); dim++) { hcos.setInterp(0.0, 0.0, 600.0, 100.0 - 2.0 * dim); for (int el = 0; el < 600; el++) { halfCosineShape.set(hcos.interp((double) el), el, dim); } } } }