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)
dur: JMSL's score package will search for the duration closest to
dur, and build a Note object from it. It will then insert the Note into
the current Staff of the current Measure. Supported durations include core
durations: whole, half, quarter, eighth, sixteenth, 32nd, 64th, and 128th,
where quarter = 1.0. Also supported are the dotted versions of these core
durations, and 3, 5, 7, 11 tuplet versions of these core durations.
pitch: an int 0..127 (midi style), where C6 (middle C) is 60, and
0 implies a rest.
amp: a double 0..1 where 0 is silent and 1.0 is max loudness
hold: the sustain duration for this note
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());
(C) Nick Didkovsky and Phil Burk, All Rights Reserved JMSL is based upon HMSL (C) Phil Burk, Larry Polansky and David Rosenboom.