Writing music with an algorithm
I love music. By that I don’t merely mean that I like music, and I don’t mean that I write to a constant background of pop music from Spotify or the radio (on the contrary, I can’t because it distracts me).
The kind of music I like is good music, by which I mean the 1% of every genre that delivers the goods. It started in my teens with rock and R&B (Little Richard, Chuck Berry, Bo Diddley), progressed through blues to jazz, then to classical (the links ran Charlie Parker to Bartók, back to Bach, then forward via Mozart, Beethoven and Schubert to Wagner, Chopin, Ravel and Debussy).
Bluegrass, country, reggae, dubstep, Irish, Indian – anything as long as it’s excellent. I play music, too – guitar, bass guitar and Dobro tolerably well; saxophone crudely – and I’m renowned for being able to extract a tune from any bizarre instrument I encounter, from conch shell to bamboo nose flute.
This being so, it isn’t surprising that I’ve used computers to listen to, store, play and even compose music. As soon as I got a PC with a sound card I was writing programs, first in BASIC, then in Forth, to play tunes.
As soon as I got a PC with a sound card I was writing programs, first in BASIC, then in Forth, to play tunes
But perhaps because I play real instruments it never grabbed me – I’ve never owned a MIDI keyboard or other MIDI instrument. What did grab me was trying to program the computer to generate sounds that may be accepted as music. That’s no mean feat because computers are without musical feeling; they have no sense of melody, harmony or rhythm, so you have to supply all that, one way or another.
The most obvious way is by creating an authoring platform that has the rules of a musical genre built into it. There are dozens of sequencer-like apps available that achieve this for dance music, since computers are good at calculating complicated beat patterns.
There’s also Koan Pro, well known to fans of Brian Eno (I’m not one), which provides a complex grid on which you can compose abstract music by tweaking hundreds of parameters.
I wrestled with it for months years ago, but something still lent everything I tried a regular, dance-like beat. My formative years were spent immersed in bebop, 1960s free jazz and country blues, where beat is vital but flexible, springy, variable – Parker’s lightning scales, Robert Johnson’s frantic strums, a Dannie Richmond drum flurry – and I wanted that sprung-step feeling in my music rather than a BPM metronome.
There was nothing for it but to build my own, so in the early 1990s I wrote myself a MIDI generator. In those days Turbo Pascal was my language of choice, and so I read the MIDI specification, deciphered the file format, and wrote myself an API that let me output streams of valid MIDI events from a Pascal program.
Then I wrote a library of functions to generate phrases, loops, rhythm patterns and other elements. One crucial decision was to separate pitch, duration and volume, so that programs could manipulate them separately.
There were mathematical transforms to reverse or invert a melody, in the manner of Bach or John Adams. I composed “tunes” by expressing an algorithm in a short Pascal program, then compiling and running it to output a playable MIDI file. One effort was based on the first 2,000 prime numbers (my excuse? I’d just read Gödel, Escher, Bach).
These tunes are feeble examples of then-fashionable minimalism, multipart fugues that no human could play, sub-Adams experiments in phase-shifting, piano pieces like Conlon Nancarrow on a bad day.
Windows killed off Turbo Pascal, and although I meant to rewrite an interactive version (that is, cutting out the intermediate MIDI file) in Delphi, I never got around to it. Later I fell for the charms of Ruby and planned to write an interactive composing platform in that: I have the Gem containing the necessary MIDI interface, but that never happened either.
What finally revived my interest was meeting a young American muso who turned me onto SoundCloud, which does for music what Flickr does for photos – and reading Philip Ball’s superb The Music Instinct, which transformed my understanding of harmony by explaining it at both physical and physiological levels.
I can write Turbo Pascal better than ever by installing its command line compiler as a Tool in the TextPad editor. MIDI remains MIDI and tools for mangling it are ten-a-penny.
My latest efforts are closer to free jazz – Gil Evans on tranquilisers rather than Philip Glass. If you like Frank Zappa, or the theme music from South Park, you may be able to tolerate them; if you lean more towards Michael Bublé, they might make you ill. And anyone who mentions Tubular Bells is asking for a punch up the ‘froat.