Songwriting and computer programming

Writing a song is a lot like writing a computer program. They both require clever management of loops and control flow.

The simplest sheet music reads as a straightforward top-to-bottom list of instructions. You start on measure one and read through to the end sequentially. That’s fine unless the music is very repetitive, which most popular music is. The loop is the basic compositional unit of nearly every song you could dance to. The problem is that writing loops out sequentially is very tedious.

Rather than writing the same passage over and over, you can save yourself a lot of laborious writing by using repeat markers. They’re like the GOTO instruction in BASIC. Here are the first four bars of “Chameleon” by Herbie Hancock. This four-bar phrase repeats hundreds of times over the course of the song. You wouldn’t want to write them all out. With repeat markers, you don’t have to. Repeat markers give sheet music the topology of a clock face. 
By default, repeat markers tell you to just play the repeated section once. You can also specify any number of multiple repeats. For “Chameleon”, that wouldn’t help much, because if you said repeat 128 or 256 times, no musicians could count that high. For open-ended music, you’re better off writing “repeat until cue.” This leaves it to the performer to decide how many repeats there should be.

Western music notation also includes more complex repeats, with different conditional instructions waiting for you depending on whether it’s your first, second or third pass. Repeats get combined with special jump instructions like DC, short for Da Capo, “to the head.” DC tells the performer to jump to the beginning of the piece. Coda, “tail”, means “jump to the ending.”

Through clever use of repeat markers and jumps, you can fit elaborately complex musical scores onto a sheet or two of paper, which is very convenient if you’re playing an instrument that makes it hard to turn pages in mid-flight.

Even with its repeats and jumps, European classical music is mostly linear. The scores can be expanded into single rows of measures, like a chain of paper clips. Open-ended loops, the ones marked “repeat until cue”, are another story. A linear expansion of a piece containing open-ended loops will be different for every performance. Who knows how many paper clips you’ll wind up with in your chain?

European classical music can get boring because it isn’t repetitive enough. Outside of western Europe, open-ended repetition is the central organizational element of music. We in America have been wise to pay attention to this lesson. Jazz, country, rock, funk, hip-hop and dance music of all description use some form of “repeat until cue” in almost every song.

James Brown in particular was a master of open-ended loops. Usually bandleaders take the musicians in and out of loops through hand signals or eye contact. James Brown preferred to shout instructions to his band out loud in mid-song, and his shouts became a key element of his music. The most famous example is in “(Get Up I Feel Like Being A) Sex Machine.”

As the band loops on the main E thirteenth chord riff, James Brown and Bobby Byrd debate whether it’s time to take it to the bridge:

James Brown: Bobby! Should I take ’em to the bridge?

Bobby Byrd: Go ahead!

James Brown: Take ’em on to the bridge!

Bobby Byrd: Take ’em to the bridge!

James Brown: Should I take ’em to the bridge?

Bobby Byrd: Yeah!

James Brown: Take ’em to the bridge?

Bobby Byrd: Go ahead!

James Brown: Hit me now!

The band transitions into a loop on A ninth. They play that loop until James Brown orders them back to the main part. At the end of the song comes another debate:

JB: Can we hit it like we did one more time, from the top? Can we hit like that one more time?

BB: One more time!

JB: One more time, let’s hit it and quit!

BB: Go ahead!

JB: Can we hit it and quit?

BB: Yeah!

JB: Can we hit it and quit?

BB: Yeah!

JB: Can we hit it and quit?

BB: Yeah!

JB: Hit it!

Loops are easy to memorize, but not so easy to perform. It takes deep concentration to play James Brown songs. Musicians trained in the Western classical tradition often find reading through a complex linear score to be easier than sustaining an open-ended groove.

Electronic instruments, on the other hand, make looping a breeze. Once you have a drum machine pattern, sample or MIDI sequence set up, you can loop it effortlessly and endlessly. The effort comes in breaking the symmetry, deciding how long the loop should play, when parts should enter or exit. My friend Josh Koppel likes to use the phrase “a digital thing in analog form.” In the hands of James Brown, his band functioned as an analog loop and sample player, one that could improvise to boot.

The computer science equivalent of “repeat until cue” is the for loop, also known as the if-then loop. Instead of explicitly telling the computer how many times to repeat a given instruction, you can have it keep repeating until some condition is met. Let’s say you want the computer to list every number from one to ten thousand. Here’s one way to do it in pseudocode — the second to last statements is the if-then loop.

Input starts at zero.

Input plus one equals output.

Print output to screen.

If output is less than ten thousand, then take output as the new input and repeat.

If output equals ten thousand, then end.

Using a few if-then loops, you can generate huge or even infinite amounts of complexity from very short programs. Fractals like the Mandelbrot set are generated using just a few simple loops.

Computers need to be told explicitly when and how to terminate their loops. Otherwise, they go around and around forever, a condition you experience as a crash. Humans are smarter in this regard: when told to repeat forever, we eventually get bored and stop.

4 thoughts on “Songwriting and computer programming

  1. All in all, pretty good, except for one quote

    “European classical music can get boring because it isn’t repetitive enough.”

    That… is offensive and oh so very painful to read, for three reasons:

    One, classical musicians say exactly the reverse about popular music (i.e., ‘popular music is boring because it’s so reptitive’), and while I don’t necessarily agree with the sentiment, it is far more logical (new things happening shouldn’t, by definition, be boring).

    Two, there are many popular music forms which focus on ‘linear’ composition; a great deal of the progressive rock community took inspiration from such composition styles, and for a more linear example, the ‘stream-of-consciousness’ song format (most notable in ‘Bohemian Rhapsody’).

    Finally, and somewhat contradictarily, Western classical music is repetitive. Consider the rondo, a classical music form, which features a main theme (section ‘A’), interspersed with two other themes; after listening to a rondo for six minutes, about sixty percent of it was repetition. The repeated sections are longer, but that’s only because the pieces are longer too.

    • Sorry to offend and pain you, but I stand by the assertion. Let me direct your attention to the music of Africa, which is far more repetitive than even pop, yet (to my ears) rarely gets boring. There are Fela Kuti songs that sit on one chord over one rhythmic pattern for half an hour. Those songs are as exciting as music gets (if you like that kind of stuff, which I do.) Similarly, there is plenty of epic and ultra-repetitive American dance music with an Afrocentric bent that builds excitement through very extreme repetition.

      “New things happening shouldn’t, by definition, be boring.” But excitement and novelty aren’t the same thing. Too much novelty is just as boring as not enough novelty. Really, what we’re excited by is, well, excitement, and there are a lot of different ways to build excitement. You can do it with Mozart’s method, building long linear chains of melody in predictable patterns, and then sometimes faking people out by altering the patterns. Or you can use James Brown’s method of finding a single densely interlocking pattern and then just riding it and riding it.

      I don’t consider progressive rock to be all that exciting, to be honest. There was a time when I did, but the older I get, the less interested I am. I find myself gravitating in adulthood to rock music that sits in slow-tempo grooves with few or no chord changes. I do like “Bohemian Rhapsody” for its sheer absurdity, but when it comes to emotional involvement, give me Neil Young anytime.

      It’s certainly true that western classical is repetitive. It just isn’t repetitive enough for my taste. Too much melodic information, not enough rhythmic information. Too many lines, not enough grooves. Classical music will always interest me intellectually, but it doesn’t grab me by the brainstem the way Fela Kuti does. Your mileage, of course, may vary.

Leave a Reply