/* * Created by Nick on Jan 28, 2006 * */ package jmslexamples.simple; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JApplet; import javax.swing.JLabel; import com.jsyn.swing.JAppletFrame; import com.softsynth.jmsl.*; import com.softsynth.jmsl.jsyn2.JSynMusicDevice; import com.softsynth.jmsl.jsyn2.JSynUnitVoiceInstrument; import com.softsynth.jmsl.score.*; /** * Build a simp le Score with an orchestra of JSyn instruments. Also shows * quarter tones. * * @author Nick Didkovsky, (c) 2006 All rights reserved, Email: * nick@didkovsky.com * */ public class JSynScore { Score score; ScoreFrame scoreFrame; Orchestra orchestra; public void start() { 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 JSynUnitVoiceInstrument(8, com.softsynth.jmsl.jsyn2.unitvoices.AutoPanningSawtoothBL.class.getName()); orchestra.addInstrument(ins, "Stereo 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 static void main(String[] args) { JSynScore demo = new JSynScore(); demo.start(); } }