From b1c47cbd73bfe1dccc4ecb3b355407043212bb9f Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Wed, 15 Aug 2018 07:50:24 -0400 Subject: [PATCH] Fix the bugs, fully implement performance --- src/performance.clj | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/performance.clj b/src/performance.clj index 64ffaaa..d265d08 100644 --- a/src/performance.clj +++ b/src/performance.clj @@ -101,7 +101,7 @@ :volume 50 ;; volume of performance :key [:C :major]}) ;; current key signature -(defn merge-perfs ;; TODO what if p1 and p2 are single notes? +(defn merge-perfs "Merges two performances" [p1 p2] (if (nil? (seq p1)) @@ -119,26 +119,33 @@ (defn perf "Implementation of perform, returns a tuple of (performance, duration)" [player-map context music] - (let [{:keys [player duration-t]} context] + (let [{:keys [player duration-t time]} context] (match music {:duration duration - :pitch pitch} [((:play-note player) - context - music) + :pitch pitch} [[((:play-note player) + context + music)] (* duration duration-t)] {:duration duration} [[] (* duration duration-t)] - [:+ & ms] (reduce (fn [[events-acc dur-acc] m] - (let [[events dur] (perf player-map - context - m)] - [(concat events-acc events) - (+ dur-acc dur)])) - [[] 0] - ms) + [:+ & ms] (let [[{events :events} dur] + (reduce (fn [[{events-acc :events time-acc :time} dur-acc] m] + (let [[events dur] + (perf player-map + (assoc context + :time + (+ (:time context) time-acc)) + m)] + [{:events (concat events-acc events) + :time (+ time-acc dur)} + (+ dur-acc dur)])) + [{:events [] :time time} 0] + ms)] + [events dur]) [:= & ms] (reduce (fn [[merged-events max-dur] m] (let [[events dur] (perf player-map context m)] + (prn events) [(merge-perfs merged-events events) (max max-dur dur)])) [[] 0]