package jmslexamples.jsyn; import com.softsynth.jsyn.*; import com.softsynth.jmsl.*; import com.softsynth.jmsl.jsyn.*; import com.softsynth.jmsl.score.*; import com.softsynth.jmsl.util.*; import com.softsynth.jmsl.view.*; import java.awt.*; import java.awt.event.*; import java.util.*; /** * This applet generates pitches using JMSL's 1/F sequence generator. It loads a * MusicShape with this data first, and displays it in a MusicShapeEditor. It * adds notes to a JScore by pulling the data from the MusicShape.
*
* * @author Nick Didkovsky, copyright 2000 Nick Didkovsky */ public class JScoreOofDemo extends java.applet.Applet { Score score; ScoreFrame scoreFrame; MusicShape oofShape; /** * Build a MusicShape of 32nd notes whose pitches are generated by 1/F * sequence. 1/F sequence ranges from 0..127. Here we scale it to half that * range, starting 2 octaves below middle C */ void buildOofShape() { oofShape = new MusicShape(4); Oof oof = new Oof(7); // duration is set at 32nd notes double dur = 1 / 8.0; for (int i = 0; i < 64; i++) { double pitch = (oof.next() / 2.0) + 36; double amplitude = JMSLRandom.choose(0.5, 1.0); double hold = dur * 0.8; oofShape.add(dur, pitch, amplitude, hold); } } /** * call score.addNote() for each element in MusicShape, to add * algorithmically generated data to notated score */ void buildOofScore() { score.addMeasure(); int kount = 0; for (Enumeration e = oofShape.elements(); e.hasMoreElements();) { Note n = score.addNote((double[]) e.nextElement()); n.setBeamedOut(kount % 8 != 7); kount++; } } public void init() { } Orchestra orch; public void start() { setLayout(new BorderLayout()); add("North", new Label("1/F")); initMusicDevices(); initJMSL(); buildScore(); buildOrchestra(); buildShapeEditor(); buildScoreFrame(); JMSL.setIsApplet(true); getParent().validate(); getToolkit().sync(); } private void buildScoreFrame() { // score.setSystemWrap(false); scoreFrame = new ScoreFrame("JMSL Score JSyn Demo by Nick Didkovsky, copyright 2000 Nick Didkovsky"); scoreFrame.addScore(score); score.getScoreLayoutManager().setZoom(0.5); score.getControlPanel().setZoom(0.5); // force netscape to size window ok //scoreFrame.setSize(1000, h+100); scoreFrame.setVisible(true); } private void buildShapeEditor() { MusicShapeEditor se = new MusicShapeEditor(); se.addMusicShape(oofShape); add("Center", se.getComponent()); } private void buildScore() { int numStaves = 1; score = new Score(numStaves, "1/F Demo by Nick Didkovsky, copyright 2000 Nick Didkovsky"); buildOofShape(); oofShape.print(); buildOofScore(); } private void buildOrchestra() { orch = new Orchestra(); // resonance, noiseamp, halflife SuperNoiseSwoop ins = new SuperNoiseSwoop(0.05, 0.5, 0.03); orch.addInstrument(ins, "Wood"); // build a mixer gui with a SynthMixer // orch.buildMixer(); score.setOrchestra(orch); } private void initMusicDevices() { JSynMusicDevice.instance().open(); } private void initJMSL() { JMSL.clock.setAdvance(1.0); JMSL.scheduler = new EventScheduler(); JMSL.scheduler.start(); } public ScoreFrame getScoreFrame() { return scoreFrame; } public void stop() { removeAll(); scoreFrame.setVisible(false); scoreFrame.dispose(); Score.deleteCanvas(); termJMSL(); } /** * */ private void termJMSL() { JMSL.scheduler.stop(); JMSL.closeMusicDevices(); } /* Can be run as either an application or as an applet. */ public static void main(String args[]) { JScoreOofDemo applet = new JScoreOofDemo(); AppletFrame frame = new AppletFrame("1/F JScore demo", applet); frame.setSize(800, 300); frame.show(); frame.test(); JMSL.setIsApplet(false); applet.getScoreFrame().addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { JMSL.closeMusicDevices(); System.exit(0); } }); } }