/* * Created by Nick on Jan 3, 2005 * */ package jmslexamples.simple; import com.softsynth.jmsl.*; /** * Use a MusicJob to turn an Instrument on() for two seconds, update its amplitude numerous times, * then shut it off(). Turn it on in MusicJob.start(). Turn it off in MusicJob.stop(). Cause the * initial delay with musicJob's startPause. Call the updates in MusicJob.repeat() * * Note that you could apply the update() to more interesting timbral dimensions (greater than * dimension #3) with SynthNoteAllPortsInstrument and a SynthNote that had public SynthInputs other * than frequency and amplitude. * * @author Nick Didkovsky, (c) 2004 All rights reserved, Email: didkovn@mail.rockefeller.edu * */ public class InstrumentOnOffUpdate extends InstrumentOnOff { protected void buildMusicJob() { myMusicJob = new MusicJob() { public double start(double playTime) { JMSL.out.println("MusicJob.start() is calling instrument.on() "); if (getInstrument() != null) { double[] data = MusicShape.getDefaultArray(getInstrument().getDimensionNameSpace()); getInstrument().on(playTime, 1.0, data); } return playTime; } public double repeat(double playTime) { JMSL.out.println("MusicJob.repeat() is calling instrument.update() with a random amplitude"); if (getInstrument() != null) { double[] data = MusicShape.getDefaultArray(getInstrument().getDimensionNameSpace()); data[2] = JMSLRandom.choose(); // amplitude is array position 2 by convention getInstrument().update(playTime, 1.0, data); } return playTime; } public double stop(double playTime) { JMSL.out.println("MusicJob.stop() is calling instrument.off() "); if (getInstrument() != null) { double[] data = MusicShape.getDefaultArray(getInstrument().getDimensionNameSpace()); getInstrument().off(playTime, 1.0, data); } return playTime; } }; myMusicJob.setStartPause(2); myMusicJob.setInstrument(instrument); myMusicJob.setRepeats(20); myMusicJob.setRepeatPause(0.3); myMusicJob.setStopDelay(2); } }