Our last algorithmic composition tutorial introduced random walks in Max and PureData. Today's algorithmic composition tutorial follows on from this with a small extension: we'll apply random walk to dynamics and walk through a scale rather than chromatic pitches.
I'll assume that you've read through some of the previous Algorithmic Composition Tutorials for Max and PureData here.
Random Walk Through a Major Scale: PureData
This patch differs from the the last random walk in PureData in that we're walking through a scale. The scale is defined here, using the intervals of a major scale.
Our scale is only 7 digits long (0 2 4 5 7 9 11) but our drunk object is walking between 0 and 24. Here we've used a modulo object (this is the % symbol in both PD and Max), this gives remainder when we divide by 7, keeping the number in the same range as the length of our scale.
The tabread object reads through our stored major scale. To get the octave, we divide by 7 then pass the result through an int object and multiply the result by 12 (12 semitones in an octave).
These two sections are added together and then added to a base pitch of 48 to bring the result in to a useful MIDI range.
Here's a screenshot of the completed algorithmic composition patch in PureData:
Creating the random walk patch in Max is very similar creating it in PureData, there however a couple of differences: notably how Max and PureData store and retrieve data from tables.
As with the PureData patch, a metronome is triggering the drunk object every 100ms.
The output of drunk is sent to a modulo object [%] this gives us the remainder when the input is divided by 7. Dividing the output of drunk by 7 (the length of our scale) gives us the octave. These two values are added together, allowing us to take random walk through several octaves of the scale even though we have only specified one octave in our table.
Here's a screenshot of the final patch. When storing the intervals of the major scale to a table object in Max we also have to provide the index, this is the number that's used to retrieve our stored value. The data is stored in pairs index1 value 1, index 2 value 2 etc.
Using Random Walks in PureData for Algorithmic Composition
Try mapping random walk algorithms to other musical parameters, or incorporating alternative musical scales. Random walks together with other techniques are very useful tools for the algorithmic composer. Subscribe and check back soon for more algorithmic composition tutorials in Max, PureData, OpenMusic, Lisp, Common Music and more.