16
Aug
Reddit, Arduino, Trackers and a Music Theory Package for Python
Thanks to the great, helpful folks at Reddit, I have been playing with an Arduino this summer. Getting out of the purely abstract world of building computer programs and into the 'real' world of electronics and mechanics was like a breath of fresh air for me and I would advise other programmers to do the same; it's great fun and the entry point is pretty low (added bonus: if you happen to use (void *)'s, you will be regarded as some sort of arcane wizzard.)

The thing I have been most interested in is sound syntesis, which is thankfully a well discussed topic on the net. So I set off to build some drum machines and synthesizers. First from tutorials, later by experimenting.

Arduino Synthesizer
Click for better resolution


Finally after some long days of write-compile-run cycles, I got to the point where I was fed up with hand-feeding the microcontroller audio data (be it samples or a composition) and I got sidetracked again: I needed a tracker!

Writing a tracker is a hard task, but when you don't need the computer to play back the composition and when you set FastTracker out of your mind for a few seconds it becomes pretty easy. Using Python and curses (this is a library -you shouldn't curse!-) I hacked something together in a couple of hours:

Arduino Python Tracker
Click for a better resolution.


The tracker, imaginatively called Arduino Python Tracker (I know, I know), is a pearl of modal editing, a dream of touch type composers and most of all... completely useless. Because you can't save and load anything. Brilliant!

Why?

After meandering a bit, I'm at the point where I can start writing the post I originally wanted to write. You see, musical notation and programming are a hard match. A pet peeve of mine about FastTracker for instance was that there was no notion of keys. There seemed to be an enum or simple list at work behind the scenes, looking something like this in Python:

human_notes = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']

Which meant that when you were writing tunes in F, your Bb would always be an A#. Outrageous!

In my homebrew tracker I started out doing the same thing because it's just easier to work with. Octaves are easily added and just work like a multiplier (eg C in octave 5 is 0 + 12*5 =60). Life is good.

However, I started adding more and more keyboard shortcuts and modes to my tracker allowing for quick editing of intervals and chords and just couldn't handle the theoretical mess anymore. The six months I had spent studying
musicology in an ancient, dusty building with ancient, dusty people* in Utrecht had changed me forever! The A# needed to be a Bb!

* The oldest student in my class was 82, mind you.

So there he was again. My old friend. Mister Sidetrack. He was here to tell me I needed a fundamental Music Theory package to fix this once and for all. He also wanted to be able to work in exotic keys like G########bb#b when he pleased, so work began.

Weaponed with the table of fifths and a bunch of unittests I went to battle. At first it wasn't pretty. Corner cases were lurking everywhere! Lambda and map provided great help and covered the bases. The note to integer converter and vice versa were easily done. Getting the intervals right proved itself to be the hardest part. After that, it was just a breeze.

This is not the place, nor the time to post about the specifics of the package, since I just finished the code for the notes, diatonics, intervals and scales modules and I need at least a chords module and a catchy, dead composer's name for a good release if anyone is interested.

I have some plans with the module after release. The first one is of course to finish my tracker, but besides that I plan to incorperate more and more theory into the module (like bars, rhytm, progressions, substitutions, counterpoint, etc) and hopefully a graphical representation as well, so that you can create sheet music using python, which would be cool and might help other open source developers writing music applications.

Update: I haven't had time to write up an entry for my blog, but I finished the chords module and thought of a good name: mingus. Development of mingus can be followed at mingus' google code page, where you can also find the 0.1 release and a couple of tutorials.



No Comments

Be the first to leave a comment for this article ;)


Leave a comment
Name*
E-mail
Website
Title*
Comment*
Notify me when somebody else comments on this article