   [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?)


  "
  [path & args]
  (let [{:keys [path args] :as s} (apply load-sample path args)
        player (fn [& pargs]
                 (let [{: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))))]
    (with-meta
      (callable-map s player)
      {:type ::playable-sample})))

(defmethod buffer-id ::sample [sample] (:id sample))



(defonce loaded-samples* (ref {}))

(defrecord Sample [id size n-channels rate allocated-on-server path args name])

(defn- load-sample*
  [path & args]
  (let [path (canonical-path path)
