From f8506819af6f5101e23310ca7e9a3f3607ef269f Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Thu, 9 Aug 2018 22:10:05 -0400 Subject: [PATCH] Implement := operator --- src/performance.clj | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/performance.clj b/src/performance.clj index 39784cc..ecb0bb8 100644 --- a/src/performance.clj +++ b/src/performance.clj @@ -35,6 +35,19 @@ :volume 50 ;; volume of performance :key [:C :major]}) ;; current key signature +(defn merge-perfs + "Merges two performances" + [p1 p2] + (if (nil? (seq p1)) + p2 + (if (nil? (seq p2)) + p1 + (let [e1 (first p1) + e2 (first p2)] + (if (< (:duration e1) (:duration e2)) + (into [e1] (merge-perfs (rest p1) p2)) + (into [e2] (merge-perfs p1 (rest p2)))))))) + (defn perform "Convert a music value to a performance value" [player-map context music] @@ -56,11 +69,18 @@ (let [[events dur] (perf player-map context m)] - [(concat events-acc dur-acc) + [(concat events-acc events) (+ dur-acc dur)])) [[] 0] ms) - [:= & ms] :TODO + [:= & ms] (reduce (fn [[merged-events max-dur] m] + (let [[events dur] (perf player-map + context + m)] + [(merge-perfs merged-events events) + (max max-dur dur)])) + [[] 0] + ms) [:modify control m] :TODO))) (defn metro