This document discusses a tool called Aeolian that analyzes source code metrics and converts them into musical notation. It summarizes the tool's design choices, where it maps various code metrics like line length, complexity, and duplication to musical elements like notes, tempo, and key. These mappings are used to generate MIDI files representing code quality as music. The document concludes by listing some of the specific mappings from code to music elements used by Aeolian.
7. @andee_marks
Java source metrics ⇨ “music”
“the aeolian tonic chord is the submediant minor triad”
One note per line of code
Make good quality code pleasant to listen to
Make poor quality code unpleasant to listen to
9. @andee_marks
Aeolian/Hello World
public class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
X:1
T:HelloWorld.metrics
C:AEOLIAN
M:4/4
L:1/8
Q:1/4=140
K:C
%%MIDI gchord c
| "C"E c b E, E, E, |
X:1
T:HelloWorld.metrics
C:AEOLIAN
M:4/4
L:1/8
Q:1/4=140
K:C
%%MIDI gchord c
| "C"E c b E, E, E, |
17. @andee_marks
Design Choices #6/Lyrics
(if (not (= current-source-file (get-source-file)))
(lyrics-for current-source-file)
clojure
Lyrics
“Doe - a deer
A female deer
Ray - a drop
Of golden sun
Me - a name
To call myself”...
“Doe - a deer
A female deer
Ray - a drop
Of golden sun
Me - a name
To call myself”...
Can I just start by saying “isn’t it good that we’re tackling the BIG issues here at YOW?” From Mars Exploration to the Meaning of Life to the ultimate question of our time really: Does Smelly Code Also Sound Bad?
Still, I guess it beats more conversations around microservices… so 2015 right!?!
So I work at ThoughtWorks and this talk is about two concepts which are near and dear to my heart, but it’s also a demonstration of some software that I inflicted upon this world from a hack day back in 2015, which we’ll get to.
So what brings me here today? Well I have a more than a passing interest in both code quality and music quality. I’ve worked as a professional programmer for the best part of my career, producing lots of code of various degrees of quality, depending on my capabilities and external circumstances but I’m also a very strictly non-professional musician who produces music of various degrees of quality… again, depending on my capabilities an external circumstances such as how much I’ve had to drink before playing and whether the guitarists keeps standing on my instrument lead.
[TX] I play bass with a bunch of colleages from ThoughtWorks in a band, so in the grand tradition of bass playing, here’s a picture of me being obscured by the more important members of our band.
But it was a couple of moments like this which inevitably push me towards writing the software I’ll be talking about today - moments of sitting on conference audiences watching speakers talk about geek-y stuff that really interests them.
[TX] Moment 1 was seeing Sau Sheng Cheong, who ran the R&D group for Hewlett Packard in Singapore talk at the RedDotRuby Conf in Singapore in 2012. Sau Sheng had written a nice little Ruby DSL for producing WAV files from Ruby which, because it produced lots of squawks and chirps during the presentation was a really interesting deviation from the other talks at the conf.
[TX] Moment 2 leading to today and still the most enjoyable conference talk I’ve ever seen is stumbling onto this man - Andrew Sorensen - presenting at YOW 2013. It was one of those moments of the schedule where there was no clear winner as to which talk I most wanted to go to and the talk blurbs didn’t really reveal too much so I mentally flipped a coin and when to see Andrew. His talk “Programming in Time” was about the live coding community, a movement where programming musicians - or musical programmers - will write code to produce music in a live setting. Much of his talk was a live demo of him producing music using Extemporare, a lisp-based DSL of his own devising. And to me, it was astonishing to watch someone hack away at what looked like Clojure in Emacs and have beautiful atmospheric music come out the other end. More than anything, it was that experience which has resulted in me standing here today,
TW Hack day
[TX] Ultimately what I’m going to demonstrate is a method for mapping code quality to sound… dare I say music, although possibly not music as you know it.
[TX] Along the way we’ll talk a bit about music theory (but not too much - after all, I’m a bass player so by definition I’m not going to have too much to say on this matter), various code metrics and how to make music sound bad… which is possibly a cue for another bass player joke as well come to think of it.
[TX] And there’ll be lots of audio examples of good and bad code as well.
Which brings us to my little primer on music theory - and I’ve really limited this to what you need to know to understand how Aeolian works.
[TX] Firstly, we have the concept of music notes, which - if you remember back to your first introduction to music theory at school, consist of pitch and duration light a quarter note C, or an eighth note A sharp.
[TX] Next we have the meter of the song which dictates how many notes you’ll hear in each measure and
[TX] Next we have the tempo of the song, telling us how many of the fundamental notes will be played each minute
[TX] And finally the key of the song, which gives some guidance to note selection and suggests the overall mood of the song, specifically with major keys sounding upbeat and happy whilst minor keys sound more menacing and sombre.
There’s a whole lot more to music theory than just these concepts, but this should be enough to get you through to the end of this presentation.
So let’s take Aeolian for a spin around the block and see what it can do.
That’s where you can find it should you want to play by yourself at home. There are a small number of dependencies which are listed in the Readme.
One big limitation is that it’s only capable of evaluating Java source code at the moment: Why Java? I hear you ask. Well, the snarky person in me says that that’s where all the smelly code in the world lives, but the truth is far more mundane than that… Java is a static language which makes lexical analysis for code quality easier than some of my preferred languages and I know Checkstyle quite well, which is what I use to derive my sense of code quality.
And what’s in the name “aeolian”? Well, it’s a term from a more advanced level of music theory than I covered before but a common definition is “the aeolian tonic chord is the submediant minor triad”. TO be honest, I’m not sure if that’s a common definition or not, but it sounds so much like a functional programmer saying that a monad is “a monoid in the category of endofunctors” that I couldn’t resist… and hello to all my Haskell friends out there :-)
And here’s how it all hangs together
[TX] We start with a bunch of script-y magic clone-ing a specified repo and running Checkstyle over it
[TX] Checkstyle is running a bunch of specific metric checks and producing a load of customised file output
[TX] The same Bash scripts pass the generated Checkstyle output files into a Clojure program which does most of the hard lifting of producing the music, using a textual, reasonably readable format called ABC Notation.
[TX] A program called abc2midi does exactly what the name suggest - MIDI standing for Musical Instrument Device Interface, a very common standard for the exchange of electronic music information
[TX] And timidity in this case plays the resultant MIDI file
So what does our old friend Hello World sound like via Aeolian?
[DEMO]
I know, I know - it’s overwhelming isn’t it? I get that reaction a lot :-)
Unfortunately, Hello World is nowhere near smelly enough or long enough to produce something worthy of our ears, although I will show you the ABC Notation it generated.[TX] [TX] It’s really only the last line that plays the music and for those who are interested, that a directive to play a A minor chord and underneath that play an E, then a C, then a B (all as quarter notes), then a quarter note rest.
So let’s take Aeolian for a spin around the block and see what it can do.
That’s where you can find it should you want to play by yourself at home. There are a small number of dependencies which are listed in the Readme.
One big limitation is that it’s only capable of evaluating Java source code at the moment: Why Java? I hear you ask. Well, the snarky person in me says that that’s where all the smelly code in the world lives, but the truth is far more mundane than that… Java is a static language which makes lexical analysis for code quality easier than some of my preferred languages and I know Checkstyle quite well, which is what I use to derive my sense of code quality.
And what’s in the name “aeolian”? Well, it’s a term from a more advanced level of music theory than I covered before but a common definition is “the aeolian tonic chord is the submediant minor triad”. TO be honest, I’m not sure if that’s a common definition or not, but it sounds so much like a functional programmer saying that a monad is “a monoid in the category of endofunctors” that I couldn’t resist… and hello to all my Haskell friends out there :-)