Terry Riley’s “In C” (in Perl)

The composer Terry Riley was experimenting with generative forms of music and came up with an interesting technique: Give fragments of musical phrases (motifs) to musicians to play in order, but looping however many times they desire.  This results in a sort of “free-form round” – like “Row Your Boat”, only schizophrenic with phrases appearing and reappearing at varying offsets.

His composition is called, “In C.”  Here is a great write-up on it, including the motifs he uses.  And here is his original recording.

Naturally, my mind immediately said, “Program!” and I set to work…

The code took a bit of head scratching but is very simple in the end.

Basically, it proceeds over a long set of phrases (53 to be exact) that each have a built-in loop-randomizer (repeating 1-4 times).  The number of voices can be up to 16 (limited by MIDI channels), and each independently plays the list of phrases.

Here is the meat of the code:

(MIDIUtil is a little module of mine that performs basic setup.  Check it out at github.)

This results in a similar but dynamic computer composition.  Here is the MIDI file, in-c, with 4 voices.  And here it is re-orchestrated with my DAW:

(On Soundcloud)


Here is the followup version of the program I made, that randomizes and limits the number of motifs used: in-c-randomized.