Here we show how to generate a MusicShape algorithmically, without knowing the details of a SynthNote's DimensionNameSpace. For our SynthNote, we will use FilteredSawtoothBL, which has three SynthInput ports: Rate, cutoff, and frequency. For these ports, we will generate data by chosing a value randomly between the low and high limits for each.
The applet below plays an algorithmically generated MusicShape with a SynthNoteAllPortsInstrument that uses FilteredSawtoothBL
The essential code follows:
ins = new SynthNoteAllPortsInstrument(8, "com.softsynth.jsyn.circuits.FilteredSawtoothBL");
double[] data = new double[myShape.dimension()];
double duration = JMSLRandom.choose();
double pitch = JMSLRandom.choose(40, 80);
double amplitude = JMSLRandom.choose();
double hold = duration * JMSLRandom.choose(2.0);
data[0] = duration;
data[1] = pitch;
data[2] = amplitude;
data[3] = hold;
// TRICKY: we will choose random values for dimensions higher than 3 by using high/low limits
for (int dim = 4; dim < myShape.dimension(); dim++) {
double value = JMSLRandom.choose(myShape.getLowLimit(dim), myShape.getHighLimit(dim));
data[dim] = value;
}
myShape.add(data);
View complete source
| 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.