Rhythmic AutomataIn an earlier tutorial Cellular Automata were mapped to pitch. In this program they are mapped to rhythm. In my view this is a more musically sucessful mapping and the evolving nature of the automata is more clearly evident becuase a one-dimensional matrix is used (i.e, an array or list of cells). Each cell in the array represents one semi-quaver and, in the score, notes are sounded on 'live' cells while rests are used where the cells are 'dead.' The rules that are applied to update the cells each iteration are the key to the musical style that emerges. These rules are, like traditional CA, based on the number of neighboring cells. Musically this relates to rhythmic density; the more neighbours a semi-quaver has the more densly populated is that area of the bar. So, by varying the rules you can provide sparseness (density) tendencies. As well, rules influence the liklihood of cell change and thus the stability of the rhytmic patterns (how quickly they evolve). This is what the result sounds like. Here is the source file. Let's have a closer look.
We import the jMusic constants, the data types, and the Util package that contains the Write class.
The class is decared and so are a number of class variables. Notice that an array of int's called 'bar' is declared. This holds the once dimensional cell matrix. The 'tempBar' array is used when we apply the rules to evolve the array one genertion.
The main() method creates an instance of this class. Create one part of music bar by bar
The constructor makes a couple of method calls to fill the array (see details below), then sets up a loop that generates 23 bars of music, printing the state of the array to the terminal each time through. Pack parts into the score and export
This should be familiar to jMusic coders. Add the part with 23 phrases of one bar each into a score then translate it into a standard MIDI file. Set up an inital array of cells
The constructor called many methods. The initialise() method is the first of them. It beings our displaying of the data using println statements. The for-loop sets up the values of the cells choosing randomly betwenn 1 and 0. Display the music at the command line
This method prints the contens of the array to the terminal as a string of 1s or 0s. Notice that the System.out.print() method does not add a carrage return, after each cell value is added a System.out.prinln() method adds the 'return' at the end of the line. Apply the CA rules for one generation
This is the guts of the program. In this method the rules are applied. First the number of live (1) cells three palces either side of the current cell are counted. (The variable score here is unfortunate - it is not a jMusic score, but the numbers of 1's that have been encouted). Depending upon the number of active neighbours this cell either lives or dies. If it has 1 or 2 neighbours it is unchanged, if it has 3 neighors and is alive it changes its state, and if it has four neighbours it's getting too crowded and it dies. The 'tempBar' array is used to store the values of the next iteration during this process, once completed its contents are transferred to the 'bar' variable and become the current state. Create one bar of music
The makeMusic() method turns the 1s and 0s into notes and rests. Each phrase thus created is added to the part. Tis method is called once for each bar of music that is required. Things to do to modify this class // Try changing sounds // Try changing tempo // Try changing bar length // Try adding another part // Try capturing bars then playing in reverse order - going from cohesive -> random // Try changing the rules // Try making it take into account 3 neighbours each side rather than 2 // Try starting with composed patterns rather than random patterns |
© 2002 Andrew R Brown |