   [s]
   (isa? (type s) ::sample))
 
-;; Samples are just audio files loaded into a buffer, so buffer
-;; functions work on samples too.
-(derive ::sample :overtone.sc.buffer/file-buffer)
-(derive ::playable-sample ::sample)
-
 (defn- free-loaded-sample
   [[[path args] buf]]
   (if (server-connected?)

          start    (get arg-map :start 0)
          n-frames (get arg-map :size 0)
          buf      (buffer-alloc-read path start n-frames)]
      (let [sample (with-meta
                     (merge buf
                            {:path path
                             :args args
                             :name f-name})
                     {:type ::sample})]
        (dosync (alter loaded-samples* assoc [path args] sample))
        sample))))


    (free-loaded-sample [[path args] buf])
    :done))

(defn sample-player
  [smpl & pargs]
  {:pre [(sample? smpl)]}
  (let [{:keys [path args]}     smpl
        {:keys [id n-channels]} (get @loaded-samples* [path args])]
    (cond
     (= n-channels 1) (apply mono-player id pargs)
     (= n-channels 2) (apply stereo-player id pargs))))

(defrecord-ifn PlayableSample
  [id size n-channels rate allocated-on-server path args name]
  sample-player)

(defn sample
  "Loads a .wav or .aiff file into a memory buffer. Returns a function capable
   of playing that sample.
