audio MIDI Music Algorithms Interfaces Programming Acoustics Context
> MIDI > Musical Data > Gamelan    
 
   

Gamelan

The music of the Balinese Gamelan is a loop-based music which lends itself well to computer music implementations.
This example makes pitch and rhythm selections at random from a limited set of each, stored in the 'mode' and 'rhythm' arrays.
The class creates a few parts (the number of which can be easily adapted) which are identical in algorithm, but each slightly different
because of the random choices. The phrases are looped, and the resulting repetition provides a sense of structure and cohesion.
A bell-like general MIDI timbre is used to mimic the gong timbres of the Gamelan.

This is what the result of this tutorial file sounds like:

Click here to view source ..

Let's have a closer look.
import jm.music.data.*;
import jm.JMC;
import jm.midi.*;   /* * A class which creates a polyphonic texture of bell tone * based on the [pitch class and rhythmic style of * Indonesian gamelan music. * @author Natalie Rouillon and Andrew R. Brown */   public final class Gamelan implements JMC{ static int[] mode = {0,1,3,7,8}; static double[] rhythm = {1.0,2.0}; public static void main(String[] args){ Score s = new Score("gamelan"); Part p = new Part("gong", BELLS, 0); //make phrases for(int i=0;i<2;i++) { Phrase phr = makePhrase(24); phr.setStartTime(0.0); p.addPhrase(phr); } s.addPart(p);   Write.midi(s, "gamelan.mid"); }  

This class has two methods: The main() method above, and the makePhrase() method below that does most of the work.

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) {
Phrase tempPhrase = new Phrase();
int temp; //variable to store random number int num; for(short i=0;i<howManyNotes;){ // generate a random number between 65 and 77.
temp = (int)(Math.random()*12 + 53);
//check that it is a note in the mode
for (short j=0; j< mode.length; j++) {
if ( temp%12 == mode[j]) {
//We have a valid pitch now,
// called temp
//Pick a random rhythm from
// the rhythm array
num = (int)(Math.random()
*rhythm.length); //if it is then add it to the
// phrase and move to the next
// note in the phrase Note n = new Note(temp,rhythm[num],
(int)(Math.random()*40+60));
tempPhrase.addNote(n);
i++;
}
}
}
return tempPhrase;

}  

This method takes an argument that determines the number of notes to put in the phrase.
The for-loop repeats the required number of times to create a note each time around.

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.

 

jMusic Australia Council Queensland University of Technology Sitemap Contact Home Home http://www.qut.com http://explodingart.com/jmusic http://www.ozco.gov.au

Digital Instrument making Home