Ever since I played with it at the RadioShack/littleBits event in NYC a few weeks ago, I became obsessed with Manny Alvear’s littleBits music player from RadioShack techspecs, and had endless fun playing Carol of the Bells over the holidays. I picked up some of the littleBits synth modules to make it more trippy: the filter, envelope, and delay.

But still, one song wasn’t enough for me, but I don’t read music, so I’m not likely to transcribe sheet music into hertz any time soon. It wasn’t until I was looking at the Wikipedia page for Coventry Carol and noticed there was a MIDI file I could download. There is some great software for parsing MIDI file formats. I grabbed midicsv, which converts MIDI files to comma-separated-values like this:

2, 192, Note_on_c, 0, 62, 110
2, 192, Note_on_c, 0, 67, 110
2, 384, Note_on_c, 0, 62, 0
2, 384, Note_on_c, 0, 67, 0
2, 384, Note_on_c, 0, 62, 110
2, 384, Note_on_c, 0, 66, 110
2, 576, Note_on_c, 0, 62, 0
2, 576, Note_on_c, 0, 66, 0

I realized I had the solution I was looking for… well, almost.

That's a lot of n-phony!

That’s a lot of n-phony!

I looked at the file in the excellent (and free) Aria Maestosa, and realized this wasn’t a matter of translating a melody. Apparently, music is made of chords! So I wandered in the wilderness of my mind a bit until I realized I could conceivably turn the chords in arpeggios. Dawsons’ What Is an Arpeggiator article opened my mind. I couldn’t find an Arpeggiator I could understand, much less plug into my command-line workflow.

But before I got to that point, I’d tried brute force: I used Aria Maestosa to butcher the song (aka delet notes randomly) into a monophonic piece, and put together a simple program that could convert the CSV into the notes and durations needed by Manny’s program. But it sounded wrong (no surprise, right?); I really needed to play the other notes. But the way I designed my program wasn’t suited to breaking the chords into separate notes across each time range. So I rewrote it to store an array of notes that were to sound at any given time step:

192: 62, 67
384: 62, 66

Looking at the data that way, it was easy for me to convert the MIDI representation into the format required by Manny’s program. I had to apply a conversion to turn a MIDI note number into Hz, and then it was easy to get output like this:

int melody[] = {
392, 294, 392, ...
}

int noteDurations[] = {
96, 96, ...
}

I’ve put my conversion script up on Github, and it includes a modified version of Manny’s sketch. Just drop the output of the script into that sketch (replacing the definitions of melody[], noteDurations[], and count). Here’s how I run the program on my Mac, pipelining the output of midicsv to the midi2littleBits_arp.pl script:

midicsv coventry_carol.mid | ./midi2littleBits_arp.pl 2

The number 2 indicates the track number from within the CSV file that I want to extract, so be sure to view the output of midicsv before you choose the track. In my experience, it’s been number two or higher.

Upload the modified sketch to the littleBits Arduino at Heart bit, and play the music! You should go through Manny’s tutorial first before you try this modified version, just to make sure it works.

The arpeggios are really crude, and they mess with the beat, but it’s still enjoyable. I bet there are some more music-savvy folks out there with ideas to improve this.