diff options
| -rw-r--r-- | src/unheard/time_object.clj | 31 |
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)) |
