diff options
| author | Jake Zerrer <him@jakezerrer.com> | 2025-11-20 20:28:45 -0500 |
|---|---|---|
| committer | Jake Zerrer <him@jakezerrer.com> | 2025-11-21 12:00:35 -0500 |
| commit | 715f427e11a6b33111cbcd06bbb816f042455035 (patch) | |
| tree | 990422bbff10ddf895e674a0456cc356f76c38d5 /src | |
| parent | 338ada91c1fccfe29f5e67e14c258a887f44bdd2 (diff) | |
Test wrapping note in time object
Diffstat (limited to 'src')
| -rw-r--r-- | src/unheard/theory.clj | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/src/unheard/theory.clj b/src/unheard/theory.clj index d63532f..e9e4ad5 100644 --- a/src/unheard/theory.clj +++ b/src/unheard/theory.clj @@ -1,28 +1,44 @@ (ns unheard.theory (:require [missionary.core :as m] + [unheard.time-object :refer [time-object]] [clojure.set :refer [union]])) -(defn note [>clock start duration >value] - (m/cp - (let [[c v] (m/?< (m/latest vector >clock >value))] - (if (<= start c (dec (+ start duration))) - #{v} - #{})))) +(defn note + [>clock start duration >value] + (time-object start + duration + (m/cp (let [[c v] (m/?< (m/latest vector >clock >value))] + (if (<= start c (dec (+ start duration))) #{v} #{}))))) -(defn poly [& notes] - (m/signal - (m/cp - (apply union (m/?< (apply m/latest vector notes)))))) +(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 cancel ((m/reduce prn nil r) prn prn)) + (cancel) + (swap! c dec) + (swap! c inc) + (swap! v inc) + (swap! v dec)) + +(defn poly + [& notes] + (m/signal (m/cp (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 (defn group [clock start end content] - (m/cp - (let [content (m/signal content)] - (if (m/?< (m/latest #(<= start % end) clock)) - (m/?< content) - (m/amb #{}))))) + (m/cp (let [content (m/signal content)] + (if (m/?< (m/latest #(<= start % end) clock)) + (m/?< content) + (m/amb #{}))))) ;; TODO: ;; - Note literals turn into numbers |
