/* * Created by Nick on Jan 3, 2005 * */ package jmslexamples.simple; import com.softsynth.jmsl.*; import com.softsynth.jmsl.jsyn.JSynInsFromClassName; import com.softsynth.jmsl.jsyn.JSynMusicDevice; /** * Use a SequentialCollection to play ABABB "song form" with a JSyn SynthNote instrument * * @author Nick Didkovsky, (c) 2004 All rights reserved, Email: didkovn@mail.rockefeller.edu * */ public class JSynSong extends java.applet.Applet { JMSLMixerContainer mixer; Instrument instrument; SequentialCollection mySong; public void init() { JMSL.setIsApplet(true); } public void start() { synchronized (JMSL.class) { initJMSL(); initMusicDevices(); buildMixer(); buildInstrument(); buildSong(); launchSong(); } } private void initJMSL() { JMSL.scheduler = new EventScheduler(); JMSL.scheduler.start(); JMSL.clock.setAdvance(0.1); } private void initMusicDevices() { JSynMusicDevice.instance().open(); } private void buildMixer() { mixer = new JMSLMixerContainer(); mixer.start(); } private void buildInstrument() { instrument = new JSynInsFromClassName(8, com.softsynth.jsyn.circuits.FilteredSawtoothBL.class.getName()); mixer.addInstrument(instrument); } protected void buildSong() { MusicShape verse = new MusicShape(4); verse.setInstrument(instrument); verse.add(0.25, 60, 0.6, 0.5); verse.add(0.25, 60.5, 0.6, 0.25); verse.add(0.75, 65, 0.6, 0.2); verse.setRepeats(4); MusicShape chorus = new MusicShape(4); chorus.setInstrument(instrument); chorus.add(0, 50, 0.5, 0.75); chorus.add(1.0, 59, 0.5, 0.75); chorus.add(0, 53, 0.5, 0.75); chorus.add(1.0, 57, 0.5, 0.75); chorus.setRepeats(2); MusicShape rest = new MusicShape(4); rest.add(2.0, 0, 0, 0); mySong = new SequentialCollection(); mySong.add(verse); mySong.add(chorus); mySong.add(verse); mySong.add(chorus); mySong.add(rest); mySong.add(chorus); } private void launchSong() { mySong.launch(JMSL.now()); } public void stop() { synchronized (JMSL.class) { mySong.finishAll(); try { mySong.waitForDone(); } catch (InterruptedException e) { e.printStackTrace(); } JMSL.scheduler.stop(); JMSL.closeMusicDevices(); } } }