See complete source here.
Essential code here:
class WeightedMelodyMusicJob extends MusicJob { WeightedIntegerSequence weightedIntegerSequence; double pitch = 60; double duration = 0.25; public WeightedIntegerSequence getWeightedIntegerSequence() { return weightedIntegerSequence; } public void setWeightedIntegerSequence(WeightedIntegerSequence sequence) { weightedIntegerSequence = sequence; } public double repeat(double playTime) { int interval = weightedIntegerSequence.next(); // 0, 1, 2 int change = interval - 1; // -1, 0, 1 System.out.println("change=" + change); pitch += change; // System.out.println(pitch); double[] data = { duration, pitch, 0.6, duration * 0.8 }; return getInstrument().play(playTime, 1, data); } }
(C) Phil Burk and Nick Didkovsky, All Rights Reserved JMSL is based upon HMSL (C) Phil Burk, Larry Polansky and David Rosenboom.