> Music Algorithms > Generating > Rhythmic Automata | ||||||||||||
Rhythmic AutomataIn this tutorial Cellular Automata 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 between 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. Depending upon the number of active neighbours this cell either lives
or 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. 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 |
||||||||||||