|
import jm.JMC; import jm.music.data.*; import jm.util.*; /** * A short example which generates a random cloud texture * Inspired by Iannis Xenakis's 'Concert PH' composition * @author Andrew Brown */ public final class CloudX implements JMC { public static void main(String[] args){ Score s = new Score(); Part p = new Part("Cloud", BREATHNOISE, 0); Phrase phr = new Phrase(); double cloudDensity = 0.1; for(int i=1;i<1000;i++) { int rPitch = (int)(Math.random()*127); int rDyn = (int)(Math.random()*127); double rv = Math.random() * cloudDensity; Note n = new Note(rPitch, rv, rDyn); phr.addNote(n); } p.addPhrase(phr); s.addPart(p); View.show(s); Write.midi(s, "CloudX.mid"); } } |
After declaration of the class and main() method the objects to be used by this class are created. The jMusic data type Score, Part and Phrase will be by now familiar to you. The double variable called cloudDensity sets a multiplier for the note rhythm values. The smaller this number, the shorter the notes.
A for-loop creates the notes and adds them to the phrase. The pitch, rhythm values, and dynamic of each note is set randomly within certain parameters.
Finally the phrase is packed into a score, displayed and written out as a MIDI file.
|
|
|
|
|
|