summaryrefslogtreecommitdiff
path: root/src/unheard/cycles.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/unheard/cycles.clj')
-rw-r--r--src/unheard/cycles.clj26
1 files changed, 25 insertions, 1 deletions
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))))
@@ -49,6 +63,10 @@
(= :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)))))
(defn unfold-node [node start end iteration]
@@ -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.