From acf63cc2308da8708a0bc23877806fa19dac3ad2 Mon Sep 17 00:00:00 2001 From: Jake Zerrer Date: Mon, 1 Dec 2025 15:16:25 -0500 Subject: Add parallel composition --- src/unheard/cycles.clj | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/unheard/cycles.clj b/src/unheard/cycles.clj index 513b090..5511d64 100644 --- a/src/unheard/cycles.clj +++ b/src/unheard/cycles.clj @@ -29,6 +29,20 @@ [& args] {:v (vec args) :type :f}) +(defn p + "Parallel combinator: all children occur simultaneously. + + Each child gets the full time duration of the parent. + All children are active at the same time, producing overlapping intervals. + + Equivalent to TidalCycles/Strudel 'stack' operator. + + Example: + (p :a :b :c) with cycle-length 1 + => [[0 1 :a] [0 1 :b] [0 1 :c]]" + [& args] + {:v (vec args) :type :p}) + (defn scalar? [x] (not (and (map? x) (:type x)))) @@ -48,6 +62,10 @@ (* n (reduce lcm 1 (map compute-cycle children)))) (= :l (:type node)) + (let [children (:v node)] + (reduce lcm 1 (map compute-cycle children))) + + (= :p (:type node)) (let [children (:v node)] (reduce lcm 1 (map compute-cycle children))))) @@ -72,7 +90,13 @@ (let [children (:v node) n (count children) child-idx (mod iteration n)] - (unfold-node (nth children child-idx) start end (quot iteration n)))))) + (unfold-node (nth children child-idx) start end (quot iteration n))) + + (= :p (:type node)) + (let [children (:v node)] + (mapcat (fn [child] + (unfold-node child start end iteration)) + children))))) (defn unfold "Unfolds a pattern tree into concrete time intervals. -- cgit v1.2.3