Created
May 31, 2011 21:10
-
-
Save cassiel/1001293 to your computer and use it in GitHub Desktop.
monome arc animation 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 monome.display | |
(:refer monome.listener :only [a])) | |
(def my-block (.fill (net.loadbang.shado.Block. 64 4) (net.loadbang.shado.types.LampState. 0.05 0.0))) | |
(def mini-block (doto (net.loadbang.shado.Block. 4 4) (.fill net.loadbang.shado.types.LampState/ON))) | |
(def renderer (net.loadbang.shado.VariableRenderer. | |
64 4 | |
(net.loadbang.shado.ArcVariableOSCOutputter. "localhost" 10332 "/example"))) | |
;; Output agent: | |
(def out (agent nil)) | |
;; Watcher: expects a shado renderable. | |
(defn output-watch-fn [_k _ref _old new] | |
(.render renderer new)) | |
(add-watch out :out-key output-watch-fn) | |
(remove-watch out :out-key) | |
(restart-agent out nil :clear-actions true) | |
(defn xmit [x] (send out (fn [_] x))) | |
(xmit my-block) | |
(xmit (net.loadbang.shado.Frame.)) | |
(defn frf [n] (doto (net.loadbang.shado.Frame.) (.add mini-block n 0))) | |
(xmit (frf 32)) | |
@out | |
(defn watch-fn [_k _ref _old {encoders :encoders}] | |
"A side-effecting watcher which creates and dispatches a renderable." | |
(let [{v :value b :button} (nth encoders 0) | |
pos (mod v 64)] | |
(cond | |
(= b :on) (xmit my-block) | |
:else (xmit (frf pos))))) | |
(add-watch a :my-key watch-fn) | |
(remove-watch a :my-key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment