summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake Zerrer <him@jakezerrer.com>2025-11-26 15:10:20 -0500
committerJake Zerrer <him@jakezerrer.com>2025-12-02 13:37:21 -0500
commit21447fcbcd3a0a875e21e6eee555f93d0e751da5 (patch)
treeac3e804ab80a1beceaeb0690d558a28429b3de55
parentfa65ce77ced6315b7c12a7ddb51018b008036388 (diff)
Split `timeline` into two functionsHEADmain
`phrase->spans` converts my `phrase` structure to a seq of [start end value] spans.
-rw-r--r--src/unheard/time_object.clj31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/unheard/time_object.clj b/src/unheard/time_object.clj
index 62e84b5..8d07361 100644
--- a/src/unheard/time_object.clj
+++ b/src/unheard/time_object.clj
@@ -37,22 +37,25 @@
(def c (phrase (b 0) (b 3)))
(c 0))
+(defn phrase->spans [phrase]
+ (let [{:keys [time-objects]} (phrase 0)]
+ (map (fn [{:keys [start duration value]}] [start (+ start duration) value])
+ time-objects)))
+
+(comment
+ (phrase->spans c))
+
(defn timeline
"Primary timeline bookkeeping mehanism."
- [phrase]
- (let [{:keys [time-objects]} (phrase 0)
- c (i/create-ratio-interval-collection)]
- (if (seq? time-objects)
- (loop [time-objects time-objects]
- (let [{:keys [start duration value]} (first time-objects)
- rem (rest time-objects)]
- (.add c (i/ratio-interval start (+ start duration) value))
- (if (seq rem) (recur rem) c)))
- c)))
+ [spans]
+ (let [c (i/create-ratio-interval-collection)]
+ (doall
+ (for [[start end value] spans]
+ (.add c (i/ratio-interval start end value))))
+ c))
(comment
- (def t (timeline a))
- (def t (timeline c))
+ (def t (timeline (phrase->spans c)))
(i/find-overlaps t (i/ratio-interval 0 1 nil))
(i/find-overlaps t (i/ratio-interval -1 0 nil)))
@@ -62,8 +65,8 @@
(m/stream (m/ap (let [at (m/?< >at)]
(into #{}
(map #(.value %)
- (i/find-overlaps timeline
- (i/ratio-interval at at nil))))))))
+ (i/find-overlaps timeline
+ (i/ratio-interval at at nil))))))))
(comment
(def at (atom 0))