/** * Add algorithmically generated notes to a JMSL score. Notice that when there * are more notes than there are measures to accomodate them, that measures are * added as needed. * * @author Phil Burk and Nick Didkovsky */ /* * (C) 1997 Phil Burk and Nick Didkovsky, All Rights Reserved JMSL is based upon * HMSL (C) Phil Burk, Larry Polansky and David Rosenboom. */ package jmsltutorial; import java.awt.Color; import java.awt.Label; import com.softsynth.jmsl.*; import com.softsynth.jmsl.score.*; public class JScoreToot02 extends java.applet.Applet { Score score; ScoreFrame scoreFrame; /* * Build data when the applet initializes, and send JMSL's STDOut to a * TextArea */ public void init() { JMSL.setIsApplet(true); setBackground(Color.yellow); add(new Label("Your JMSL score will open in a new window")); } /** generate 40 random notes and add to current staff # */ void generateNotes() { int[] possibleIntervals = { 3, 4, 7, 9, 12 }; int numNotes = 40; for (int i = 0; i < numNotes; i++) { double dur = 0.25; Note note = score.addNote(dur, NoteFactory.MIDDLE_C + JMSLRandom.choose(12), 0.5, dur * 0.8); note.setBeamedOut(i % 2 == 0); // beam out even numbered notes // occasionally add an interval above the last added note. if (JMSLRandom.choose(4) == 0) note.addInterval(possibleIntervals[JMSLRandom.choose(possibleIntervals.length)] + note.getPitchData()); } } /* When applet starts up, display the scoreframe */ public void start() { synchronized (JMSL.class) { JMSL.clock = new DefaultMusicClock(); JMSL.clock.setAdvance(0.1); JMSL.scheduler = new EventScheduler(); JMSL.scheduler.start(); // 2 staves, width, height score = new Score(2, 800, 400); scoreFrame = new ScoreFrame(); scoreFrame.addScore(score); score.addMeasure(10, 16); score.addMeasure(3, 4); score.addMeasure(3, 8); score.addMeasure(5, 8); // now add some algorithmically generated notes. // default insertion point is measure 0, staff 0 generateNotes(); score.rewind(); score.setCurrentStaffNumber(1); generateNotes(); scoreFrame.setVisible(true); scoreFrame.setSize(900, 600); score.render(); } } /* When applet stops, hide the scoreframe */ 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(); } } }