Category Programming

ClojureScript for Max


I’ve been writing graphics widgets in Javascript for MaxMSP using JSUI for a few years (things like the TextBrick and the Nixie tube display, as well as the Forbidden Planet-inspired Krell Mixer Panel which I really must release some time), and I’ve also been working in Clojure for a while, so the arrival of ClojureScript, targetting Javascript as its back end, prompted an investigation of using Clojure to develop user interface panels and scripting extensions for Max without writing any Javascript directly.

Summary: despite a few niggles it all hangs together rather nicely, but be wary of thinking in Javascript terms when coding in ClojureScript, especially when porting example code, otherwise it can all go a bit pear-shaped.

Morse Code for Overtone


We’ve just uploaded a Morse code generator for Overtone.

I’ve never been much of a fan of SuperCollider largely because of its front-end language, which I first encountered around 15 years ago (before SuperCollider even existed) and had various issues with, but Overtone (a Clojure environment for driving the SuperCollider audio engine) is a different proposition.

I’m working on a project involving online avatars and audio-rate control systems, and since Clojure+Overtone can clearly do both web interfacing and audio (all with decent multithreading semantics) it avoids the need for separate programs hooked together via OSC or any kind of plug-in or hosting setup. (We’ve already implemented Clojure for MaxMSP, and that was lined up as our Plan B.)

This Morse code generator is very much My First Overtone Program, drawing just on basic Overtone/SuperCollider idioms which I can hack together without getting too lost. Most of it is plain old Clojure coding with a bit of event scheduling, familiar from realtime media applications.

I wonder how much SuperCollider I’d have to learn to add synthetic shortwave radio interference?

Fusion Programming: From Python to Clojure and Back


Recently we’ve been working on several digital art projects using Field as a development and presentation platform but with Clojure running the core, domain-specific algorithmic code. This choice is, admittedly, partly because Clojure is new and shiny, but we also like the Emacs- and Leiningen-based development environment (complete with continuous integration testing), and Clojure’s clean functional semantics lends itself to realtime, evolutionary artworks. Since Field works at the level of Python-on-Java (via Jython), and Clojure runs in the JVM, the Python and Clojure worlds inevitably collide.

Clojure in MaxMSP


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.