/* * Created by Nick on Jan 3, 2005 * */ package jmslexamples.simple; import java.net.MalformedURLException; import java.net.URL; import com.softsynth.jmsl.*; import com.softsynth.jmsl.midi.MidiIO_JavaSound; import com.softsynth.jmsl.score.*; import com.softsynth.jmsl.score.midi.MidiScoreInstrument; /** * Build a simple Score with a JavaSound Midi orchestra * * If the Java installation that is running this applet does not have a JavaSound MIDI soundbank, * your classes folder (ie your applet's codebase) must contain a folder called javasound containing * a soundbank called soundbank-min.gm (or call subfolder and the soundbank whatever you want and * change the name in the initJavaSoundMidi() method below * * @author Nick Didkovsky, (c) 2004 All rights reserved, Email: didkovn@mail.rockefeller.edu * */ public class MIDIScore 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() { JMSL.scheduler = new EventScheduler(); JMSL.scheduler.start(); JMSL.clock.setAdvance(0.1); } private void initMusicDevices() { JMSL.clock = new DefaultMusicClock(); initJavaSoundMidi(); } private void initJavaSoundMidi() { JMSL.midi = MidiIO_JavaSound.instance(); try { ((MidiIO_JavaSound) JMSL.midi).setSoundbankURL(new URL(getCodeBase(), "javasound/soundbank-min.gm")); } catch (MalformedURLException e) { e.printStackTrace(); } JMSL.midi.edit(new java.awt.Frame()); JMSL.midi.open(); } private void buildOrchestra() { orchestra = new Orchestra(); // use MidiScoreInstrument, a subclass of MidiInstrument which uses amplitude 0..1 for // velocity, for compatibility with JSyn instruments in the same score Instrument ins = new MidiScoreInstrument(1); // midi ch 1 orchestra.addInstrument(ins); score.setOrchestra(orchestra); } void buildMeasure() { 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 < 2; i++) { score.addNote(1.0, 60, 0.6, 0.8); score.addNote(1.0, 62, 0.6, 0.8); Note n = score.addNote(0.50, 63, 0.6, 0.8); n.setBeamedOut(true); score.addNote(0.50, 66, 0.6, 0.8); score.addNote(2.0, 72, 0.6, 0.8); } } void buildScore() { score = new Score(1, 800, 600); buildMeasure(); } 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(); } } }