Created
July 31, 2011 21:17
-
-
Save cassiel/1117219 to your computer and use it in GitHub Desktop.
A stopwatch for MaxMSP, written in Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sexy stuff