|
import jm.music.data.*; |
In this composition one part is created and filled with numerous phrases. Each phrase is similar but varies due to some random selection of pitches and rhythms. The randomness is limited to those values in the mode and rhythm arrays. This is an effective technique to constrain the stochastic process within certain limits.
static int[] mode = {0,1,3,7,8};
static double[] rhythm = {1.0,2.0};
The loop in the main method calls the makePhrase() method each time around and adds the newly created phrase to the part p.
The part is then added to a score which is translated to a MIDI file format and saved as a MIDI file called "gamelan.mid".
public static Phrase makePhrase(int howManyNotes) { |
The internal loop and if statement looks a little complex but, in short, checks to see if the chosen note is in the pitch class set specified by the mode array. 0 = any C, 1 = any C#, 3 = any D#, and so on. The internal for loop goes through each element in the mode array, and if it finds a match the note is added to the phrase, otherwise a new pitch is selected.
Because the "scale" required is non-western this process is necessary in full. jMusic has a Mod method called isScale() to check if pitches are in many of the standard western modes - major, minor, etc.
Notice the return statement at the end of the makePhrase() method. It indicates that this method sends back an object (a phrase in this case) to the calling method (main() in this case). When declaring a method that returns an object is type of the returned object must be specified in the declaration, as this one does by declaring the return type to be Phrase.
public static Phrase makePhrase(int howManyNotes) {
If a method does not return a value - like the main() method does not - then the return type is declared to be void.
|
|
|
|
|
|