summaryrefslogtreecommitdiff
path: root/src/notation.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/notation.clj')
-rw-r--r--src/notation.clj35
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)