Tag Programming

Clojure in MaxMSP

AquamacsScreenSnapz001

One of the things moving up my to-do list is an environment for hosting the Clojure language inside MaxMSP. Clojure is hosted on the Java JVM, just like the languages for my other MaxMSP hosting projects, Python and Groovy, although the Clojure interpreter is rather an odd beast compared to the other two. Specifically, it’s not clear to me (yet) exactly what it means to build a Max patcher with several Clojure objects inside it, and one of the strengths of Clojure is its ability to deal cleanly with concurrency and interaction between decoupled computations, so there should only really be “one” Clojure environment which everything somehow shares and uses for communication.

That aside, Clojure is good at Java interoperability, and has a built-in compiler which generates real class files for synthesised Java classes matching interfaces or extending existing classes, so getting a Clojure program into MaxMSP is just a case of configuring this machinery. (The Leiningen build tool does most of the work.)

So, proof of concept: a simple stopwatch for MaxMSP in Clojure. It’s quite stateful, and doesn’t do much with data structures or higher-order functions, so it’s a feeble example of Clojure’s power and not a very convincing use case, but it gets the ball rolling.