This tutorial demonstrates how to add algorithmically generated
notes to a score.
Comment: Here we explicitly add software-generated note events one at
a time, specifying their duration. But JMSL also has a powerful transcriber
which quantizes and notates musical events with arbitrary timestamps.
See the transcribe tutorial.
The method signature of addNote() is as follows: public Note addNote(double dur, double pitch, double amp, double hold)
addNote() creates a Note, adds it to the Score, and returns the
new Note.
For example:
score.addNote(1.0, NoteFactory.MIDDLE_C, 0.5, 0.8); // add C qtr note score.addNote(0.5, NoteFactory.MIDDLE_C+1, 0.5, 0.4); // add C# 8th note score.addNote(0.33333, NoteFactory.MIDDLE_C+2, 0.5, 0.2); // add D 8th note triplet score.addNote(0.33333, 0, 0, 0.2); // add 8th note triplet rest
score.rewind(); score.setCurrentStaffNumber(1); score.addNote(...);Notice that you can add as many notes as you like, and measures will automatically get added as needed (inheriting the time sig from the last specified measure). You may also jump to any measure and add notes into it with a call to score.setCurrentMeasureNumber(int n); However it is your responsibility that this measure exists (call score.size() to see how many measures are there).
Note note = score.addNote(0.5, NoteFactory.MIDDLE_C+1, 0.5, 0.4); note.setBeamedOut(true); // beam to next noteIn this demo, we set the beamed out flag on all even numbered notes, so that the notes entered are beamed in pairs. This will save the composer editing time.
You may also build a chord with a call to:
note.addInterval(pitch);In this demo, we add a random interval above notes, deciding to do so or not with a 1/4 probability. The following line chooses a random interval from a predefined array of int[], and adds it as an interval above the last added note.
int[] possibleIntervals = {3, 4, 7, 9, 12}; ... note.addInterval(possibleIntervals[JMSLRandom.choose(possibleIntervals.length)] + score.getLastAddedNote().getPitchData());
View the complete source here.
Previous | Tutorial Index | Tutorial Contents | Next |
(C) 2000 Nick Didkovsky and Phil Burk, All Rights Reserved JMSL is based upon HMSL (C) Phil Burk, Larry Polansky and David Rosenboom.