Home Mythic Beasts, shell accounts, cvs
hosting, co-location, virtual servers

But It Doesn't Mean Anything

tl;dr A demonstration of the value of computer code in the form of a musical e-card for Jeremy Paxman.

In what has to be a contender for the worst interview in the history of Newsnight, Jeremy Paxman interviewed Lottie Dexter, Director of the Year of Code campaign that is set to teach primary school children to code.

Jeremy Paxman: So what is code?

Lottie Dexter: Code is... the language you use to instruct computers. I think that's the best way to describe it. So it's how you tell computers to do things.

Paxman: So it's different symbols... But it doesn't mean anything!

Dexter: It doesn't mean anything to you, or to me yet, but it's the set of instructions that you type into a computer to get an output. So, for example, when this goes onto the schools' curriculum, every pupil from the age of five will learn how to code, and they will pop in a set of instructions into a box, and they will create an e-card. And they will see that what you put in is what you get out. It is how you make computers do things.

Paxman: What's an e-card?

Dexter: What's an e-card? It's a virtual birthday card, or valentine's day card...

Paxman: (scathing) You could make a virtual birthday card. There's a national initiative to teach people how to make computerised birthday cards.

Dexter: And websites. And apps. These are all fun ways of learning an important skill that you really need.



What angers me here is Paxman's attempt to make a virtue of his own ignorance. So it's different symbols, But doesn't mean anything!

So what I'd like to do is give a guide to some different symbols that don't mean anything. I'm going to start with a clip from a music practice session where local singer Nathalie Flower and I were preparing for a charity show. We played for about an hour and the entire set basically consisted of repeating the joke from the Axis Of Awesome Four Chord Song. In every song we changed from a rock classic to either Britney Spears or Lady Gaga. So here's us attempting the switch from Journey- Don't Stop Believing into Lady Gaga's Edge of Glory.

What does this have to do with code?

Now you can write music down as a set of instructions for the musician. This one starts like this:

The piano starts at a tempo of 100 crotchets per minute. 

Bar 1

It's the key of E major. 

The left had plays E two octaves below middle C for two and a
half beats. Meanwhile the right hand plays E & B above middle C for
a quaver, then B below middle C for a quaver. Again the right hand plays
E & B above middle C for a quaver than B below middle C for a
quaver. On the third beat the right hand plays E &B above middle C
for a quaver, then on the next quaver the left hand comes to B below
middle C and the right hand B beneath middle C. On the fourth beat for a
quaver the right hand plays E & B above middle C for a quaver while
the left hand plays C sharp below middle C. For the final quaver the
right hand plays B below middle C and the left hand B an octave down
from that.

Bar 2

...

No, wait. That's not how musicians write music at all. That would be insane. What musicians have done is to develop a whole system of notation that makes it much easier to communicate with other musicians about what to play. The actual music corresponding to that text looks like this...

So it's different symbols, but it doesn't mean anything.

Now I don't believe that Jeremy Paxman is so ignorant he'd advocate that music notation is actually meaningless. It's quite a clever notation. Height indicates pitch, distance left to right and the stems of each note give timing information and it's easily read by a skilled musician at a glance. The same cannot be said of the wordy representation in English.

Unfortunately, music notation is remarkably hard to type into a computer. To generate the above score I used Lilypond which has a textual representation of the music. The above clip looks like this in Lilypond,

\new PianoStaff {<<
 \new Staff = "upper" {
  \key e \major
  \relative c'{<e b'>8 b <e b'>8 b <e b'>8 b <e b'>8 b }
 }
 \new Staff = "lower" {
  \key e \major
  \clef bass
  \relative c,{ e2~ e8 b' cis b~ }
 } >>
}

So it's different symbols, but it doesn't mean anything.

Again it's another notation for music, and this one is legible by me and the computer. <e b'>8, b means play E and B for a quaver, then B below for a further quaver. Lilypond can take this representation and turn it into an image for displaying on the web as above, in a PDF. You can download and print this, or use a midi file which the computer can play itself.

Now I didn't actually just sit down and write a massive file for Lilypond - although many people do. I wrote some computer code in perl, which generates the lilypond source file. You can download it here

Computer code that writes music?

Rewriting that in pseudo-code (an English Text description) it looks like this


song = (intro,dsbv1,dsbv2,transition,edge,end);

if (full score) print full_score(song);
if (vocal score) print vocal_score(song).
if (lyrics) print lyrics(song);

bar(first_note, second_note)
 repeat 4 times {
  add to line of music first_note
  add to line of music second_note
 }
 return line of music


fourchord(n)
 repeat n times {
  add to treble_line bar(E B, B)
  add to treble_line treble bar(F# B, B)
  add to treble_line bar (E G#, C#)
  add to treble_line bar (C# E, A)
 }
 repeat n times {
  add to bass_line 4 bar bassline
 }
 return treble_line, bass_line

#introduction
intro() 
 vocal_line = 4 bars of rests
 lyrics = none
 treble_line, bass_line = fourchord(1)
 return vocal_line, lyrics, treble_line, bass_line


#first verse of don't stop believing
dsbv1()
 vocal_line = eight bars of tune
 lyrics = "Just a small town girl, Living in a Lonely world, She took the midnight train Going Anywhere" 
 treble_line,bass_line = fourchord(2)
 return vocal_line, lyrics, treble_line, bass_line

#second verse of don't stop believing
dsbv2()
 vocal_line = eight bars of tune
 lyrics = "Just a city boy, Born and raised in South Detroi, He took the midnight train going anywhere"
 treble_line,bass_line = fourchord(2)
 return vocal_line, lyrics, treble_line, bass_line

#transition between the two
transition()
 vocal_line = one bar of tune, two bars rest, one bar of tune
 lyrics = "A singer in a... No No I hate Glee, I want to do Gaga, I'm on the"
 treble_line,bass_line = fourchord(2)
 return vocal_line, lyrics, treble_line, bass_line

#First verse of edge of glory
edge()
 vocal_line = four bars of tune
 lyrics = "Edge of Glory and I'm hanging on a moment of Truth"
 treble_line, bass_line = fourchord(1)
 return vocal_line, lyrics, treble_line, bass_line

#Chorus from Pricetag
pricetag()
 vocal_line = eight bars of tune
 lyrics = "It's not a_ bout the mo_ ney, mo_ ney, mo_ ney,We don't need your mo_ ney, mo_ ney, mo_ ney,We just wan_ na make the world dance,For_ get a_ bout the price tag,Ain't a_ bout the cha- ching cha- ching,Ain't a_ bout the ba- bling ba- bling,Wan_ na make the world dance,For_ get a_ bout the price tag"
 treble_line, bass_line = fourchord(2)
 return vocal_line, lyrics, treble_line, bass_line

#Alternative chorus for Jeremy
paxman()
 pricetag()
 lyrics = "It's not a_ bout the co- ding co- ding co- ding, Not a_ bout the e- cards e- cards e- cards, We just wan_ na make the world learn, Learn a little more than Pax- man. Ain't a_ bout the co- ding co- ding, It's a_ bout the out- come out- come, Wan_ na make the world learn, Learn a little more than Pax- man."
 return vocal_line, lyrics, treble_line, bass_line


#A final chord to end on 
end()
 vocal_line = 1 bar rest
 lyrics = none
 treble_line = E chord
 bass_line = E octave
 return vocal_line, lyrics, treble_line, bass_line

#a function that assembles all the music parts into a single score ready
for Lilypond
score(list of bits of music)

Now there are some neat features. If you run it with the 'full' option it generates the full score. If you run with the 'voice' option it generates only a vocal score, and with the lyrics option it just prints the lyrics out on its own. At the same time it also generates the MIDI file so your computer can play to you the score it just generated.

How does this all work?

To offer some explanation, it works as follows: There's a subroutine at the top called bar(first-note,second-note), which does this:

bar(first_note, second_note)
 repeat 4 times {
  add to line of music first_note
  add to line of music second_note
 }
 return line of music
So it's different symbols, but it doesn't mean anything.

That takes a pair of notes, and repeats them four times. So calling

bar("<e b'>8","b");

generates

<e b'>8 b <e b'>8 b <e b'>8 b <e b'>8 b

which is the first four repeated note pairs in the sheet music above.

As Mitch Benn has already told us, that subroutine alone is enough to regenerate the piano part for almost the complete works of Coldplay, Travis, Keane, Embrace, Snow Patrol not to mention Eternal Flame and the guitar part to Don't Speak amongst countless others.

There's then a subroutine called fourchord(n) which generates the whole four-chord sequence as many times in a row as you ask it for.

fourchord(n)
 repeat n times {
  add to treble_line bar(E B, B)
  add to treble_line treble bar(F# B, B)
  add to treble_line bar (E G#, C#)
  add to treble_line bar (C# E, A)
 }
 repeat n times {
  add to bass_line 4 bar bassline
 }
 return treble_line, bass_line

So it's different symbols, but it doesn't mean anything.

This generates the right hand by calling bar(first,second) four times for each of the four chords, then adds in the left hand, so it generates some lilypond script like


\relative c'{<e b'>8 b <e b'>8 b <e b'>8 b <e b'>8 b 
<fis' b>8 b, <fis' b>8 b, <fis' b>8 b, <fis' b>8 b, 
<e gis>8 cis <e gis>8 cis <e gis>8 cis <e gis>8 cis 
<cis e>8 a <cis e>8 a <cis e>8 a <cis e>8 a 
}

\relative c,{
e2~ e8 b' cis b~
b2~ b8 cis dis cis~
cis2~ cis8 dis e a,8~
a1
}

So it's different symbols, but it doesn't mean anything.

which are two blocks to generate a four chord piano part. That's the first four bars from the sheet music.

There are then a series of functions that generate each of the melody blocks e.g. intro(),

#introduction
intro() 
 vocal_line = 4 bars of rests
 lyrics = none
 treble_line, bass_line = fourchord(1)
 return vocal_line, lyrics, treble_line, bass_line

So it's different symbols, but it doesn't mean anything.

which generates four rests and no lyrics over a single four chord sequence, to dsbv2() which generates the second verse of Don't Stop Believing.

#second verse of Don't Stop Believing
dsbv2()
 vocal_line = eight bars of tune
 lyrics = "Just a city boy, Born and raised in South Detroit, He took the midnight train going anywhere"
 treble_line,bass_line = fourchord(2)
 return vocal_line, lyrics, treble_line, bass_line

So it's different symbols, but it doesn't mean anything.

That adds a music block with the tune, a lyrics block with the words, and then generates the piano part by calling fourchord(2) because we need two four-chord sequences in the piano part.

Add a few more functions and you have the magic at the top of the script that generates the whole thing.

song = (intro,dsbv1,dsbv2,transition,edge,end);

So it's different symbols, but it doesn't mean anything.

That generates the sheet music by calling the intro, the first two verses of Don't Stop Believing (dsbv1, dsbv2), the transition between the two songs, the first part of Edge of Glory then a finish. You can easily alter the entire thing by playing around with that one line.

So what does the computer actually do with this?

start creating score
first create intro
create 4 bars of rests for vocals
create no lyrics
create a fourchord(1) sequence
 create a bar (E B, B) sequence
  create E B,B
  create E B,B
  create E B,B
  create E B,B
 create a bar (F# B,B) sequence
  create F# B,B
  create F# B,B
  create F# B,B
  create F# B,B
  create F# B,B
 create a bar (E G#, C#) sequence
  create E G#,C#
  create E G#,C#
  create E G#,C#
  create E G#,C#
 create a bar (C# E, A) sequence
  create C# E,A
  create C# E,A
  create C# E,A
  create C# E,A
 set that as the treble line
 set the bassline to a 4 bar sequence
 return that
We now have 4 bars for each of the four lines of music
intro is created
start creating dsbv1
create 8 bars of tune
create 8 bars of lyrics that fit
create a fourchord(2) sequence
 create a bar (E B, B) sequence
  create E B,B
  create E B,B
....
.... several hundred more lines of things the computer does for you.
....
We now have a completed song.

Now merely by changing that song line, we can re-order all the chunks of music and the computer will generate all the music in a different order.

song = (intro,intro,intro,intro,dsbv1,transition,edge,dsbv2,end);

So it's different symbols, but it doesn't mean anything.

Then you get this version with an extended introduction that flips back to Don't Stop Believing and sheet music to match.

So this is the beauty of the code that Jeremy Paxman is utterly unaware of. Whereas the sheet music just contains a list of notes to play, the code explains how the song is built from smaller and smaller parts - a bar consists of four repeats of a pair of notes, each phrase of one or two repeats of the same four bar piano part. The underlying structure becomes clear. So here we've got six different represenations of the same concept.

YoutubeEasily appreciated by everyone, but contains no instructions on how to play it yourself or what's actually going on.
EnglishIncomprehensible, lengthy and useless
Sheet MusicFully explains how to play for someone who can read the notation, but leaves the musician to identify the structure
LilyPondAn intermediate language for the human to communicate with the computer, not really satisfactory for either.
MIDIAn intermediate language for the computer to tell another computer how to play the music. Useless for people.
Computer Source CodeAn intermediate language for a person to explain to the computer both the details and the structure, and to separate the two parts. Extremely useful for the user.

I've not included the Pseudo Code above, as that only explains how the structure in the Computer Source Code works, but doesn't actually contain the music.

Now the power of computer code should start to become apparent. Once we've explained to the computer once how to do something - play a four chord sequence - we can use that as a building block to build bigger things on top of it. So I picked another four chord song, Jessie J's Price Tag added the vocal line and lyrics and suddenly you can blend that in to the mix too.

A musical e-card for Jeremy

If you happen to show this to formerly unsuccessful University Challenge contestant and talented writer Gytha Lodge, she generates an alternative set of lyrics for you. Then you can change the song line to

song(intro,dsbv1,pricetag,paxman,end)
and you get this sheet music which when performed sounds like this.

So Jeremy Paxman makes a virtue of not understanding code because he doesn't understand it. Clearly, Jeremy already understands everything that's important, so this code business is nonsense - along with Russell Brand, the poetry of Robert Burns and using Blackadder to teach history. But what Jeremy is missing (or in fact, first amongst the great number of things he is missing) is that computers aren't a short-cut to something useless: they are a way of making your single-functioning brain more efficient. They are, in fact, an extension of your brain. You can figure out how to do something, explain it to the computer, and then forget how to do it because the computer now does it for you. Which is how the-world-apart-from-Jeremy now operates.


Footnotes

Of course the Journey fan will spot that actually the seventh chord should be G sharp minor, not C sharp minor, but factual accuracy would spoil the joke. Similarly any talented musician out there will spot that whilst all the sheet music on this page is in E major, Nathalie and I performed in A Major to hit the middle of her vocal range. If you can write code for Lilypond it's just one \transpose to fix it; if you're Jeremy Paxman it's painstaking hours of rewriting your hand-written sheet music.

The computer source code, lilypond files and playback have all been tested on a Raspberry PI, and the PI was used to generate the .mp3 files for the inbrowser players. If you'd like to play with this yourself, install Raspbian, Lilypond, Timidity, libhash-merge-perl and start editing away. If you're experimenting with the PI and music for the first time and you've never had musical training, you're probably better off with SonicPI where you're taught to write python code to generate MIDI directly. Here's a 4chord backing track don't stop believing sonic pi, that doesn't quite keep time properly.

In addition to writing, Gytha Lodge edits and proof reads text, including raw HTML source code because if you can't edit the code, you don't get paid, and sometimes the source code tells you more than the output.

Home Mythic Beasts, shell accounts, cvs
hosting, co-location, virtual servers