A simple multi-agent system for music composition

Imagine you're an ant. You're not very intelligent. You don't really think ahead. But you like food. When you find food, you carry it back to the anthill. As you carry it back, you lay out a trail of pheromone. If you're not carrying food and you sense pheromone, you walk towards it. In effect, ants get attracted to sources of food, and as long as there is food, the pheromone trail gets reinforced. When the food runs out, the trail dissipates. This type of collective intelligence is the basis of Brooks' subsumption architecture - some simple, reactive behaviours performed by individuals result in a complex, effective behaviour when performed as a group.

a: ant
f: food
p: pheromone
h: anthill

This is a short simulation of an ants gathering food. Click here to restart.

I wanted to see if I could design a system like this to compose music. I decided to translate the ants in the example to the parts in a polyphonic piece of music. Each of the parts get assigned a voice number, corresponding to their relative vertical position. A low number means low pitch and a high number means high pitch. In a choral setup, a soprano would be a 4, an alto 3, and so on.

Just like the movement and behaviour of individual ants is constrained by the physical capabilities of the ants' bodies and their surrounding environment, I have introduced a number of fairly strict constraints on what each part is capable of doing.

All parts exhibit the same simple rhythmical pattern - a new note every 1/16 beat. The maximum pitch distance from one note to the next is plus/minus four semitones; the minimum distance is zero semitones (no movement). Each part also is also constrained to play notes in a particular scale (more about that later). The next note to be played is decided randomly, but with a bias for either upward or downward motion. The bias is decaying over time. Additionally, there are upper and lower pitch limits. When they are exceeded, the bias of the part is set to the opposite direction, so that it bounces back to where it came from.

Click here for an example of a part with a strong initial upwards bias. The line indicates the upper limit.

 \       /
  \     /  
   \.-./ 
  (o\^/o)  _   _   _     __
   ./ \.\ ( )-( )-( ) .-'  '-.
    {-} \(//  ||   \\/ (   )) '-.
         //-__||__.-\\.       .-'
        (/    ()     \)'-._.-'
        ||    ||      \\
MJP     ('    ('       ')
    

What makes life as an ant interesting is not the fact that you have six legs and an exoskeleton, but that you live in a society with other ants. The same goes for the parts in this system. When two parts collide, they bounce off each other in the same way single parts bounce off walls. This ensures that parts are kept within their pitch bands. Of course, parts can jump over each other, but since the maximum distance is four semitones, it is unlikely that a high part will make it very far down without bouncing into a lower part.

Click here to see how a five-part system behaves. Numerals represent voice numbers.

In order to keep things simple, I'm not going to say anything about tempo, instrumentation, dynamics and a few dozen other things. Instead, I'll finish off by introducing scales and harmony.

Let's say that at different points across the imaginary musical score are variable sized gems. Each gem holds a scale, and when a part "steps" on that gem, it starts playing notes in that scale. When two parts collide, the one who most recently stepped on a gem influences the other part with its scale. This way scales spread across all parts eventually, but not immediately. While a new scale is gradually being introduced, other parts still play the old scale. During this transition you can get really interesting harmonic tension.

Click here to see the an eight-part system with gems spread out across the score. The colour of the part indicates what scale it currently carries. G means gem.

What you hear Icecasted in the background (if you are using a browser that supports Ogg <audio>) is music being generated and synthesised in real-time by this system. The only human involvement, apart from setting variables like upper and lower pitch limits, number of parts, etc., is the placement and size of the gems and what scales they have. In fact, the whole system could be seen as a semi-random instrument that is played by laying out scale gems on a score. It is a bit like creating patterns of ant trails by laying out sugar cubes around an anthill.

-------------------------------------------------------------------------------