Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

ClojureScript for MaxMSP

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 doc
Octocat-spinner-32 projects
Octocat-spinner-32 src-cljs
Octocat-spinner-32 src
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.md
Octocat-spinner-32 project.clj
README.md

jsui-cljs

splash

JSUI graphics in ClojureScript.

Introduction

This is a small collection of examples of some simple MaxMSP JSUI graphics scripting where the Javascript is generated using ClojureScript:

Usage

To build the example, install Leiningen and the cljsbuild plugin. Then:

$ lein deps
$ lein cljsbuild once dev
  (or)
$ lein cljsbuild once prod

There are two build targets: dev runs the Google Closure compiler backend in minimal optimisation mode, whereas prod turns on further optimisation for "production" output. (This is what Google Closure refers to as "simple" optimisation; the full-blown "advanced" mode seems to be throwing up code generation errors in the ClojureScript libraries.)

The dev mode compiles faster, but prod is fast enough to be usable since we've taken out the "advanced" optimisation mode (which is slow).

The output of dev, in this project, is _main-dev.js; the prod target writes _main.js. Once one of these is built, you can open any of the patchers in jsui-cljs.maxproj in Max 6 to see the result. (Any non-msgraphics code would probably run in Max 5, but you'd need to fix up the search path and load the patcher files manually, and Max 5's Javascript engine is much slower than that in Max 6.)

All the patcher files load the same Javascript file: the code executed is determined by the JSUI argument. Look at core to see the selection on the ClojureScript side.

For general development, consider running

$ lein cljsbuild auto dev

(or prod) in the background: this automatically recompiles whenever any (ClojureScript) sources are changed. If the source sets autowatch to 1 (as in our examples), then changes to sources will automatically be recompiled and reloaded into Max.

Documentation

The example code is documented here (using Marginalia). To build the documentation:

$ lein marg src-cljs/

Notes

"Advanced" optimisation in Google Closure merits some discussion. One of the optimisations munges variable names, to make them shorter and more efficient. We need to prevent munging of names we're using implicitly from the Max world (mgraphics, autowatch etc.), and also make sure that we can plant names for JSUI to use which themselves won't get munged. There's more detail here, but the upshot is that we need to provide a mock externals file declaring stubs which shadow the things we need, or export, at the Javascript level. We have one in src-cljs/externs.js, although it's currently far from complete.

(For "simple" optimisation, there's no top-level variable renaming.)

License

Copyright © 2012 Nick Rothwell, nick@cassiel.eu

Distributed under the Eclipse Public License, the same as Clojure.

Something went wrong with that request. Please try again.