summaryrefslogtreecommitdiff
path: root/src/unheard/theory.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/unheard/theory.clj')
-rw-r--r--src/unheard/theory.clj53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/unheard/theory.clj b/src/unheard/theory.clj
index 6ceff3e..e7ed9eb 100644
--- a/src/unheard/theory.clj
+++ b/src/unheard/theory.clj
@@ -1,39 +1,42 @@
(ns unheard.theory
(:require [missionary.core :as m]
- [unheard.time-object :refer [time-object]]
- [clojure.set :refer [union]]))
+ [unheard.time-object :refer
+ [time-object lift phrase timeline point-query]]
+ [clojure.set :refer [union]]
+ [unheard.util.missionary :refer [reconcile-merge]]))
(defn note
[>clock start duration >value]
- (time-object start
- duration
- [(gensym)
- (m/cp (let [[c v] (m/?< (m/latest vector >clock >value))]
- (if (<= start c (dec (+ start duration))) #{v} #{})))]))
+ (lift (time-object start
+ duration
+ (m/stream
+ (m/ap
+ (let [[c v] (m/?> (m/relieve
+ (m/latest vector >clock >value)))]
+ v))))))
-;; Reducing function that returns diffs :add v :remove v
-;; Reducing function that unfolds to values
+;; BUG: 2d7f861
+(defn read
+ [>clock timeline]
+ (m/relieve
+ (m/reductions {} nil
+ (m/eduction (map vals)
+ (m/reductions
+ (fn [acc {:keys [id state value]}]
+ (if (= :up state)
+ (assoc acc id value)
+ (dissoc acc id)))
+ {}
+ (reconcile-merge (point-query timeline >clock)))))))
(comment
- (require '[unheard.time-object :refer [lift phrase timeline point-query]])
(def c (atom 0))
(def >c (m/signal (m/watch c)))
(def v (atom 0))
- (def >v (m/watch v))
- (def n (note >c 4 8 >v))
- (def song (phrase (lift n)))
- (def t (timeline (song 0)))
- (def r (point-query t >c))
- (def r
- (m/ap (try (m/?<
- ;; TODO: Simplify
- (apply m/latest
- vector
- (point-query t >c)
- (vals (m/?< (m/eduction (map #(into {} %))
- (point-query t >c))))))
- (catch missionary.Cancelled _ (m/amb)))))
- (def cancel ((m/reduce prn nil r) prn prn))
+ (def >v (m/signal (m/watch v)))
+ (def song (phrase (note >c 4 8 >v) (note >c 6 6 >v)))
+ (def t (timeline song))
+ (def cancel ((m/reduce prn nil (read >c t)) prn prn))
(cancel)
(swap! c dec)
(swap! c inc)