Sunday, October 19, 2008

Archaeopteryx: Activating/Deactivating Live Clips

I made a bold claim about my part of the Ruby music talk at RubyConf.

We'll also demo Archaeopteryx playing drums, switching tempos, and, without any human intervention, creating a live drum and bass remix.

Technically I can get away with that boast just by demoing Arx improvising original drum patterns on top of an 80s song.



But I wanted to do something more interesting than that. One necessary milestone: activating and deactivating clips in Ableton Live while controlling the tempo by sending MIDI to Live's tap tempo control. This was pretty easy to do.



The branch on GitHub.

Tangent: I'm using branches for everything with Arx because the code's a mess and I want it to get even messier. You've got to do some nasty hacking before you make stuff pretty - most of the real ugliness in Archaeopteryx comes from attempts to design the solution before I had built any hacks.

Anyway - the way this code works is it creates a Message class, similar to a MIDI Note, and then sets up several Clip objects, representing Clips in Ableton Live. In practice these are just wrapper classes on Messages. I also created a similar TapTempo class which is essentially a hard-coded MIDI message.

You have to manually set the correlation between MIDI messages and elements of the Live UI. That's a topic for a Live tutorial, but Archaeopteryx includes a script called pulse.rb to handle that. I finally gave it command-line args as part of this branch.

The looping code in Archaeopteryx expects generators to exist, which it can call play on. I expanded this for MIDI messages with send.



I already had a Mix class in Arx for situations where you want more than one generator, so I gave it a send method and then subclassed it as ExclusiveMix for situations where you have a collection of Clips and you only want to play one at a time. (In Ableton, Clips in Tracks can only play one at a time.)

To use this stuff, I wrote a script called fruit_machine.rb (named after "Fruit Machine" by the Ting Tings, which is one of the songs I'm mashing together here).



Here's how it works. First you create a new Clip representing the Clip (A) you want to control in Ableton Live. Next (B) create an ExclusiveMix of all the Clips which run in the same Track. (In fact, ExclusiveMix should be called Track.) Then create a new loop (C), which I call an Arkx for very foolish legacy reasons, and last (D) create a Mix containing your ExclusiveMix objects.

This API will probably change in future, since it sucks.