diff options
| author | Jake Zerrer <him@jakezerrer.com> | 2025-10-16 19:43:42 -0400 |
|---|---|---|
| committer | Jake Zerrer <him@jakezerrer.com> | 2025-10-17 19:24:11 -0400 |
| commit | 4ff62448f9adbb75e79f528ca4528e0faf4399a3 (patch) | |
| tree | afcb1bcc5961197b8e4775a215bb445867fdece4 /src/notation.clj | |
| parent | a36b60a8ee2a293d0c9783cbe59da2a8d9c1b195 (diff) | |
Improve poly; pass clock as argument
Diffstat (limited to 'src/notation.clj')
| -rw-r--r-- | src/notation.clj | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/src/notation.clj b/src/notation.clj index 7cf4e86..6e266ce 100644 --- a/src/notation.clj +++ b/src/notation.clj @@ -1,5 +1,4 @@ (ns notation - "Experimental notation" (:require [missionary.core :as m] [clojure.set :refer [union]])) @@ -73,26 +72,22 @@ ;; - Loops ) -(def clock (atom 0)) -(def >clock (m/signal (m/watch clock))) +;; TODO: Move elsewhere +(defn clock [] + (let [clock (atom 0) + >clock (m/signal (m/watch clock))] + [>clock (fn [v] (reset! clock v))] + )) (defn note [clock start duration value] (m/cp - (if (m/?< (m/latest #(<= start % (dec (+ start duration))) clock)) + (if (m/?< (m/latest #(<= start % (dec (+ start duration))) clock)) #{value} #{}))) -(defmacro poly - [& notes] - (let [atoms (repeatedly (count notes) gensym) - let-bindings (vec (mapcat (fn [atom] [atom `(atom #{})]) atoms)) - reset-forms (map (fn [atom note] `(m/amb (reset! ~atom (m/?< ~note)))) atoms notes) - union-form (cons `union (map (fn [atom] `(deref ~atom)) atoms))] - `(m/relieve {} - (m/ap - (let ~let-bindings - (m/amb= ~@reset-forms) - ~union-form))))) +(defn poly [& notes] + (m/ap + (apply union (m/?< (apply m/latest vector notes))))) ;; TODO: Group could actually wrap note, rather than using explicitly ;; WIll introduce a lot of GC churn, though @@ -104,16 +99,6 @@ (m/?< content) (m/amb #{}))))) -(def melody - (m/signal - (poly (note >clock 0 4 1) - (note >clock 0 5 3) - (note >clock 0 3 5)))) - -#_(def cancel - ((m/reduce prn #{} melody) {} {})) - -#_(cancel) #_(reset! clock 0) #_(swap! clock inc) #_(swap! clock dec) |
