Greg Gillis, also known as Girl Talk, is an impressive DJ who creates mega-mashups consisting of hundreds of samples. His sample selections span 7 decades and dozens of genres. Listening to his albums is a bit like having a concentrated dump of music history injected right into your brain.
I became a little obsessed with his work last year and I wanted a better way to experience his albums, so I created an annotated player using Clojure and d3 that shows relevant data and links about every track as it plays:
I have versions of this player for his two most recent albums:
Unfortunately, they only really work on the desktop right now.
Parsing Track Data
I’ve released all the code that I used to collect the data and to generate the visualizations, but in this post I’m just going to talk about the first stage of the process: getting the details of which tracks were sampled at each time.
There’s an excellent (totally legal!) crowd-sourced wiki called Illegal Tracklist that has information about most of the samples displayed like this:
- “Oh No” - 5:39
- 0:03 - 2:08 Black Sabbath - ”War Pigs”
- 0:13 - 0:15 2Pac featuring K-Ci & JoJo - ”How Do U Want It”
- 0:15 - 0:15 Jay-Z - ”99 Problems”
- 0:20 - 2:02 Ludacris featuring Mystikal and I-20 - ”Move Bitch” ⋮
- 4:45 - 4:55 Trina featuring Killer Mike - “Look Back at Me”
- 4:53 - 4:53 N.W.A - “Appetite for Destruction” (portion sampled samples “Get Me Back on Time, Engine #9” by Wilson Pickett)
- 4:56 - 5:39 Missy Elliott - ”Get Ur Freak On”
- “Let It Out” - 6:29
- 0:00 - 0:01 Ramones - ”Blitzkrieg Bop”
- 0:00 - 0:05 Missy Elliott - ”Get Ur Freak On”
- 0:00 - 0:10 Busta Rhymes featuring Sean Paul and Spliff Star - ”Make It Clap” ⋮
At first, I used Enlive to suck down the HTML versions of the wiki pages, but I realized it might be cleaner to operate off the raw wiki markup which looks like this:
1 2 3 4 5 6 |
|
I wrote a few specialized functions to pull the details out of the strings and into a data structure, but it quickly became unwieldy and unreadable. I then saw that this was a perfect opportunity to use Instaparse. Instaparse is a library that makes it easy to build parsers in Clojure by writing context-free grammars.
Here’s the Instaparse grammar that I used that parses the Illegal Tracklists’ markup format:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
The high level structure is practically self-documenting: each line in the wiki source is either a title track line, a sample track line, or a blank line and each type of line is pretty clearly broken down into named components that are separated by string literals to be ignored in the output. It does, however, become a bit nasty when you get to the terminal rules that are defined as regular expressions. Instaparse truly delivers on its tagline:
What if context-free grammars were as easy to use as regular expressions?
The only problem is that regular expressions aren’t always easy to use, especially when you have to start worrying about not greedily matching the text that is going to be used by Instaparse.
Some people, when confronted with a problem, think “I know, I'll use Instaparse.” Now they have three problems. #clojure
— Matt Adereth (@adereth) October 24, 2014
Despite some of the pain of regular expressions and grammar debugging, Instaparse was awesome for this part of the project and I would definitely use it again. I love the organization that it brought to the code and the structure I got out was very usable:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|