/* * Created by Nick on Jan 28, 2006 * */ package jmslexamples.simple; import com.softsynth.jmsl.*; import com.softsynth.jmsl.jsyn.JSynInsFromClassName; import com.softsynth.jmsl.jsyn.JSynMusicDevice; import com.softsynth.jmsl.score.*; /** * Build a simple Score with an orchestra of JSyn instruments. Also shows quarter tones. * * @author Nick Didkovsky, (c) 2006 All rights reserved, Email: didkovn@mail.rockefeller.edu * */ public class JSynScore extends java.applet.Applet { Score score; ScoreFrame scoreFrame; Orchestra orchestra; public void init() { JMSL.setIsApplet(true); } public void start() { synchronized (JMSL.class) { initJMSL(); initMusicDevices(); buildScore(); buildOrchestra(); buildScoreFrame(); } } private void initJMSL() { NoteFactory.useQuarterToneAccidentals(true); JMSL.scheduler = new EventScheduler(); JMSL.scheduler.start(); JMSL.clock.setAdvance(0.1); } private void initMusicDevices() { JMSL.clock = new DefaultMusicClock(); initJSynMusicDevice(); } private void initJSynMusicDevice() { MusicDevice dev = JSynMusicDevice.instance(); dev.edit(new java.awt.Frame()); dev.open(); } private void buildOrchestra() { orchestra = new Orchestra(); // use 8 voice polyphonic stereo JSyn instrument Instrument ins = new JSynInsFromClassName(8, com.softsynth.jmsl.jsyn.circuits.AutopanningSawtooth.class.getName()); orchestra.addInstrument(ins, "JSyn Instrument"); score.setOrchestra(orchestra); if (ins.getNumOutputs() == 2) { // pan L/R score.getOrchestra().getJMSLMixerContainer().panAmpChange(0, 0, 0.5); score.getOrchestra().getJMSLMixerContainer().panAmpChange(1, 1, 0.5); } } /** build measures with a whole note chord. Transpose up a quarter tone each measure */ void buildPiece() { Measure m = score.addMeasure(5, 4); m.setTempo(120); // duration (where 1.0 = qtr), pitch (where 60 = middle C), amp, sustain for (int i = 0; i < 4; i++) { double quarterTone = i * 0.5; // 0 first loop, 0.5 second loop, etc double pitch = 60 + quarterTone; // duration 4 == whole note, pitch, amplitude, hold time Note n = score.addNote(4.0, pitch, 0.6, 3.9); n.addInterval(pitch + 7); } } void buildScore() { score = new Score(1, 800, 600); buildPiece(); } void buildScoreFrame() { scoreFrame = new ScoreFrame(); scoreFrame.addScore(score); scoreFrame.pack(); scoreFrame.setVisible(true); } public void stop() { synchronized (JMSL.class) { if (scoreFrame != null) { scoreFrame.setVisible(false); scoreFrame.dispose(); Score.deleteCanvas(); SelectionBuffer.disposeEditFrame(); scoreFrame = null; score = null; } JMSL.scheduler.stop(); JMSL.closeMusicDevices(); } } }