Implement := operator

This commit is contained in:
Jeremy Dormitzer 2018-08-09 22:10:05 -04:00
parent 83524851fd
commit f8506819af

View File

@ -35,6 +35,19 @@
:volume 50 ;; volume of performance :volume 50 ;; volume of performance
:key [:C :major]}) ;; current key signature :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 (defn perform
"Convert a music value to a performance value" "Convert a music value to a performance value"
[player-map context music] [player-map context music]
@ -56,11 +69,18 @@
(let [[events dur] (perf player-map (let [[events dur] (perf player-map
context context
m)] m)]
[(concat events-acc dur-acc) [(concat events-acc events)
(+ dur-acc dur)])) (+ dur-acc dur)]))
[[] 0] [[] 0]
ms) 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))) [:modify control m] :TODO)))
(defn metro (defn metro