Uploaded December 2024 | Updated December 2026, 3 hours ago
Plays a SequentialCollection which has a WeightedObjectChooser as its Behavior. The MusicShapes are added to the WeightedObjectChooser, and scrollbars are provided to set their relative weights (ie probabilities of being chosen).
Thanks to Larry Polansky for suggesting WeightedObjectChooser.
algomusic.com
Plays a SequentialCollection which has a WeightedObjectChooser as its Behavior. The MusicShapes are added to the WeightedObjectChooser, and scrollbars are provided to set their relative weights (ie probabilities of being chosen).
Thanks to Larry Polansky for suggesting WeightedObjectChooser.
algomusic.com








![JMSL tutorial “ShapeToot03
This video shows JMSL tutorial “ShapeToot03” running. This video is a part of the Java Music Specification Tutorial series. http://www.algomusic.com
Every element of the MusicShape holds parameters used to build a chord at run time. The MusicShape’s Instrument reads those values and creates and sounds a chord.
private void defineMyMusicShape() {
myMusicShape = new MusicShape(5);
myMusicShape.setRepeats(Integer.MAX_VALUE); // play forever
myMusicShape.setDimensionName(0, Duration”);
myMusicShape.setLimits(0, 0.0, 4.0); // dim, low, high
myMusicShape.setDefault(0, 1.0); // default 1
myMusicShape.setDimensionName(1, Chord Root”);
myMusicShape.setLimits(1, 20.0, 80.0);
myMusicShape.setDefault(1, 60.0);
myMusicShape.setDimensionName(2, Number of Intervals”);
myMusicShape.setLimits(2, 0.0, 8.0);
myMusicShape.setDefault(2, 1.0);
myMusicShape.setDimensionName(3, Harmonic Complexity”);
myMusicShape.setLimits(3, 0.0, 11.0);
myMusicShape.setDefault(3, 1.0);
myMusicShape.setDimensionName(4, Time Window”);
myMusicShape.setLimits(4, 0.0, 1.0);
myMusicShape.setDefault(4, 0.0);
}
private void buildAndSetInstrument() {
Instrument chordMakingInstrument = new InstrumentAdapter() {
public double play(double playTime, double timeStretch, double[] data) {
double duration = data[0];
int root = (int) data[1];
int intervals = (int) data[2];
int harmonicComplexity = (int) data[3];
double timeWindow = data[4];
double offtime = playTime + JMSLRandom.choose(0.5, 1.5) * duration;
JMSL.midi.noteOn(playTime, 1, root, JMSLRandom.choose(20, 80));
JMSL.midi.noteOff(offtime, 1, root, 0);
String msg = New chord playing at + playTime + , root = + root;
if (intervals gt 0) {
msg += , intervals: “;
}
for (int i = 0; i lt intervals; i++) {
int newInterval = root + HarmonicComplexity.gimmeRandomHarmonicComplexity(harmonicComplexity);
newInterval += 12 * JMSLRandom.choose(3); // transpose 8va’s
double timeStampOfInterval = playTime + JMSLRandom.choose(timeWindow);
offtime = timeStampOfInterval + JMSLRandom.choose(0.5, 1.5) * duration;
JMSL.midi.noteOn(timeStampOfInterval, 1, newInterval, JMSLRandom.choose(20, 80));
JMSL.midi.noteOff(offtime, 1, newInterval, 0);
msg += newInterval + “ “;
}
JMSL.out.println(msg);
return playTime + duration * timeStretch;
}
};
myMusicShape.setInstrument(chordMakingInstrument);
} JMSL tutorial “ShapeToot03](https://i.ytimg.com/vi/BgKu-3UCniU/mqdefault.jpg)

