     [overtone.inst.sampled-piano :only [sampled-piano] :rename {sampled-piano piano#}]))
 
 (defn => [val & fs] (reduce #(apply %2 [%1]) val fs))
-
-(defn update-all [m [& ks] f]
-    (if ks
-      (-> m
-        (update-all (rest ks) f)
-        (update-in [(first ks)] f))
-      m))
-
-(defn natural-map [ys] (zipmap (-> ys count range) ys))
-(defn connect [f1 f2] #(if-let [y2 (f2 %)] (f1 y2) nil))
-
 (defn sum-n [series n] (reduce + (take n series)))
 (defn sums [series] (cons 0 (reductions + series)))
 (defn scale [intervals]
   #(if (neg? %)
-     (let [downward-scale (connect - (scale (reverse intervals)))]
+     (let [downward-scale (comp - (scale (reverse intervals)))]
        (-> % - downward-scale))
      (sum-n (cycle intervals) %)))
 
-(defn translate [f x y] #(-> % (+ x) f (+ y)))
-(defn shift [f x] (connect #(+ x %) f))
+(defn translate [point deltas] (map + point deltas))
+(defn map-in [m k f] (map #(update-in % [k] f) m)) 
+(defn transform [key f] #(update-in % [key] f))
+(defn transform-y [f] #(map-in % 1 f))
+(defn transform-x [f] #(map-in % 0 f))
+
 (def major (scale [2 2 1 2 2 2 1]))
-(def g-major (translate major 0 74))
-(defn update [k f] #(update-in % [k] f))
+(defn add [x] (partial + x))
+(def g-major (comp (add 74) major)) 
+
 
 (defn bpm [per-minute] #(-> % (/ per-minute) (* 60) (* 1000)))
 (defn run [a & bs] 

      (concat (up-or-down a (first bs)) (apply run bs))
      [a])))

(defn melody [notes]
  (let [functionalise #(update-all % [:time :pitch] natural-map)
        accumulate-time (update :time sums)
        add-count #(assoc % :count (count (:pitch notes)))]
    (-> notes accumulate-time functionalise add-count)))

(def leader 
  (let [call
          {:time (mapcat repeat [2 1 14 1] [1/4 1/2 1/4 3/2])
           :pitch (concat (run 0 -1 3 0) [4] (run 1 8))}

           :pitch (concat [4 4] (run 2 -3) [-1 -2 0] (run 3 5) (repeat 3 1) [2] (run -1 1 -1) (run 5 0))}
        line
          (merge-with concat call response development)]
    (=> line #(update-in % [:time] sums) #(map vector (:time %) (:pitch %)))))

(defn play# [notes] 
  (let [play-at# #(at (% 0) (piano# (% 1)))]
    (->> notes (map play-at#) dorun)))

(defn canone-alla-quarta# []
  (let [in #(transform-y %)
        after #(transform-x (add %))
        from-now (after (now))
        tempo #(transform-x %) 
        mirror (transform-y -)
        transpose #(transform-y (add %)) 
        leader #(=> % (after 1/2) (in g-major) (tempo (bpm 120)) from-now)
        follower #(=> % mirror (transpose -3) (after 3) leader)]
    (=> melody leader play#)
    (=> melody follower play#)
    ))

(canone-alla-quarta#)
