How can I use clm-play like a sampler?

By default, clm-play cycles through the sound files of its given group and transposes according to the pitch-synchronous or non-pitch-synchronous routines. But assuming you have pitched samples and can determine their fundamentals, clm-play can be made to act like a traditional sampler. Below is an example of how to do this:

;;; auto-create a sndfile-palette by reading a kontakt instrument file with
;;; the NKI tool from
(let ((tp (kontakt-to-sfp
           :group 'tp :converter "/Users/michael/bin/nki")))
  (flet ((tp-name (name)              ; extract the note info from the file name
           (when name
             ;; file name is e.g. TpMt_sus_g#4_6.aif so skip the first 9
             ;; characters 
             (let* ((note (subseq name 9)))
               ;; change # to s character
               (setq note (substitute #\s #\# note)
                     ;; now skip the gunk after note info
                     note (subseq note 0 (if (char= #\s (elt note 1))
                                             3 2)))
               ;; samples notes use middle C = C3 so have to transpose up an 8ve
               (+ (note-to-midi (read-from-string note))
    ;; get the note info and set the frequency slot of each sndfile object in
    ;; the palette
    (set-frequency-from-filename tp :name-fun #'tp-name)
    ;; replace any existing sndfile-palette in my slippery-chicken object and
    ;; also give it a new place to write sound files
    (setf (sndfile-palette +hyperboles+) tp
          (snd-output-dir +hyperboles+) "/projects/dark-light/clm/")
    ;; generate the piece with my trumpet samples
    (clm-play +hyperboles+ 1 '(solo computer-a computer-b computer-c)
              'tp :channels 4 :srate 44100
              :amp-env '(0 1 70 1 100 0) :src-scaler 1.0 :pitch-synchronous t
              ;; this is the all-important argument to override the cycling of
              ;; sndfile in the group and use selection by closest pitch instead
              :snd-selector #'(lambda (sflist pitch event)
                                (declare (ignore event))
                                 (frequency pitch) (data sflist)))
              :inc-start nil :src-width 100)))