 ;;                  (random '(2 7 10))
 ;;                  (random '(0 8))))))
 
-;;Piano samples downloaded from: http://blackhole12.newgrounds.com/news/post/92464
-(def piano-samples (load-samples "~/Desktop/samples/MIS_Stereo_Piano/Piano/*"))
-
-(defn matching-notes
-  [note]
-  (filter #(if-let [n (match-note (:name %))]
-             (= note (:midi-note n)))
-          piano-samples))
-
-(defn sampled-piano
-  ([note] (sampled-piano note 1))
-  ([note vol]
-     (if-let [sample (first (matching-notes note))]
-       (stereo-player sample :vol vol))))
-
 (def chord-prog
   [#{[2 :minor7] [7 :minor7] [10 :major7]}
    #{[0 :minor7] [8 :major7]}])
 
 (def beat-offsets [0 0.1 0.2 1/3  0.7 0.9])
 
-(def instrument sampled-piano)
 (def metro (metronome 20))
-;;(metro :bpm 10)
+;;(metro :bpm 30)
 
 (def root 40)
 (def max-range 35)

(ns examples.extemp-piano
  (:use [overtone.live]
        [overtone.inst synth]))

;; This example has been translated from the Extempore code demonstrated in
;; http://vimeo.com/21956071 (found around the 10 minute mark)

(defn beat-loop
  [metro beat chord-idx]
  (let [[tonic chord-name] (choose (seq (nth chord-prog chord-idx)))
        nxt-chord-idx      (mod (inc chord-idx) (count chord-prog))]
    (dorun
     (map (fn [note offset]
            (at (metro (+ beat offset)) (sampled-piano note 0.3)))
          (rand-chord (+ root tonic) chord-name (count beat-offsets) (cosr beat range-variation  max-range range-period))
          beat-offsets))
    (apply-at (metro (inc beat)) #'beat-loop [metro (inc beat) nxt-chord-idx])))

;;start the music:
(beat-loop metro (metro) 0)
