/* * Created on Jan 3, 2005 * */ package jmslexamples.simple; import com.softsynth.jmsl.*; import com.softsynth.jmsl.jsyn.JSynMusicDevice; import com.softsynth.jmsl.jsyn.SynthNoteAllPortsInstrument; /** * Play all input ports of a JSyn SynthNote with a MusicShape * * @author Nick Didkovsky, didkovn@mail.rockefeller.edu * */ public class TimbralMusicShape extends java.applet.Applet { JMSLMixerContainer mixer; Instrument instrument; MusicShape myMusicShape; public void init() { JMSL.setIsApplet(true); } public void start() { synchronized (JMSL.class) { initJMSL(); initMusicDevices(); buildMixer(); buildInstrument(); buildMusicShape(); launchMusicShape(); } } private void launchMusicShape() { myMusicShape.launch(JMSL.now()); } private void buildInstrument() { instrument = new SynthNoteAllPortsInstrument(8, com.softsynth.jsyn.circuits.FilteredSawtoothBL.class.getName()); mixer.addInstrument(instrument); } private void initMusicDevices() { JSynMusicDevice.instance().open(); } private void buildMixer() { mixer = new JMSLMixerContainer(); mixer.start(); } private void initJMSL() { JMSL.scheduler = new EventScheduler(); JMSL.scheduler.start(); JMSL.clock.setAdvance(0.1); } void buildMusicShape() { myMusicShape = new MusicShape(instrument.getDimensionNameSpace()); myMusicShape.setInstrument(instrument); myMusicShape.print(); // we happen to know that the timbral ports of FilteredSawtoothBL are named "rate", // "resonance", and "cutoff", but we don't know which dimensions they are mapped to, so find out now.. // if you don't know the names, just print() the MusicShape after you create it from the instrument's // dimensionNameSpace as is done above int dimensionOfRate = myMusicShape.getDimension("rate"); int dimensionOfCutoff = myMusicShape.getDimension("cutoff"); int dimensionOfResonance = myMusicShape.getDimension("resonance"); for (int i = 0; i < 15; i++) { double duration = 1.0; double pitch = JMSLRandom.choose(40.0, 45.0); double amplitude = 0.5; double hold = 3.0; double rate = JMSLRandom.choose(0.1, 1.9); double resonance = JMSLRandom.choose(0.05, 0.9); double cutoff = JMSLRandom.choose(500, 3000); double[] data = new double[myMusicShape.dimension()]; data[0] = duration; data[1] = pitch; data[2] = amplitude; data[3] = hold; data[dimensionOfCutoff] = cutoff; data[dimensionOfRate] = rate; data[dimensionOfResonance] = resonance; myMusicShape.add(data); } } public void stop() { synchronized (JMSL.class) { myMusicShape.finishAll(); try { myMusicShape.waitForDone(); } catch (InterruptedException e) { e.printStackTrace(); } JMSL.scheduler.stop(); JMSL.closeMusicDevices(); } } }