Skip to content

Instantly share code, notes, and snippets.

@cassiel
Created July 31, 2011 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cassiel/1117219 to your computer and use it in GitHub Desktop.
Save cassiel/1117219 to your computer and use it in GitHub Desktop.
A stopwatch for MaxMSP, written in Clojure
(ns maxmsp-clojure-stopwatch.core
(:gen-class
:name clojure.Stopwatch
:prefix max-
:extends com.cycling74.max.MaxObject
:state lastsample
:init init)
(:import (com.cycling74.max Atom)))
(defn max-init []
[[] (atom nil)])
(defn- interval! [state]
"Update a state to current time, return interval from last state."
(let [now (System/currentTimeMillis)
oldState @state]
(do
(swap! state (fn [_] now))
(if oldState
(- now oldState)
0))))
(defn max-bang [this]
"Output time in msec since last bang, or 0 if this is the first bang."
(.outlet this 0 (interval! (.lastsample this))))
@hems
Copy link

hems commented Aug 4, 2011

sexy stuff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment