> Music Algorithms > Modifying > Scatter Phrases | ||||||
Scatter Phrases: Stochastic phrase positionsThis tutorial creates phrases across 16 channels and sets their start
positions at random over 100 beats. Click here to hear the output from
the Scatter class. Below is the source code for the last example. Lets have a closer look.
Phrase phr = new Phrase((Math.random()*400) * SQ); The start time is multiplied by a Semiquaver so that a phrase always starts on a semiquaver subdivision. This stochastic generation of the phrase start time is what spreads the phrases over the music creating a changing, but overall similar, texture. You will notice how the word "makePhrase()" is used to fill
the Phrase "phrase".
You will also notice that there is another method in this
class that is not a main method. It is called makePhrase():
As the code is executing, it goes through each line, from
top to bottom. When it gets to phrase = makePhrase(); It goes straight into
the makePhrase method. In the makePhrase method, it makes a new
Phrase, and returns it to the place where "makePhrase()" was called. Programs
are organised like this so that you can organise things more easily and
reuse code multiple times. Now for the actual algorithms: The notes in each phrase start at a random pitch between 30 and 90 (60 + 30), int pitch = (int)(Math.random()*60+30); Pitch movement is by a random interval from note to note (a Random walk), pitch += (int)(Math.random()*10-5); Becase this happens 50 time, the chances are that the pitch will eventually
exceed it's boundaries. if(pitch <6 || pitch > 94) pitch = 60; This says: if the pitch becomes lower than 6 (just one step away from becoming negative) or higher than 94 (you can set this to be as high as 122 if you like!), set it back to 60, which is middle C. |
||||||