anchor.diff:  
   (defun play-midi (event &optional task)
     (declare (ignore task))
  -  (let* ((channel (alexandria:clamp (or (event-value event :channel)
  -                                        0)
  -                                    0 15))
  -         (pgm (alexandria:clamp (and (typep (event-value event :instrument) 'number)
  -                                     (truncate (event-value event :instrument)))
  -                                0 127))
  -         (pan (alexandria:clamp (ceiling (* 63.5 (1+ (event-value event :pan)))) 0 127))
  -         (note (alexandria:clamp (truncate (event-value event :midinote)) 0 127))
  -         (velocity (alexandria:clamp (round (* 127 (event-value event :amp))) 0 127)) ;; FIX: maybe this shouldn't be linear?
  +  (let* ((channel (midi-truncate-clamp (or (event-value event :channel) 0) 15))
  +         (pgm (midi-truncate-clamp (event-value event :instrument)))
  +         (note (midi-truncate-clamp (event-value event :midinote)))
  +         (velocity (unipolar-1-to-midi (event-value event :amp))) ;; FIX: maybe this shouldn't be linear?
            (time (local-time:timestamp+ (or (raw-event-value event :timestamp-at-start) (local-time:now))
                                         (truncate (* (or (raw-event-value event :latency) *latency*) 1000000000))
  -                                      :nsec)))
  +                                      :nsec))
  +         (extra-params (loop :for key :in (keys event)
  +                          :for cc-mapping = (get-cc-mapping key)
  +                          :if cc-mapping
  +                          :collect (list (car cc-mapping) (funcall (nth 3 cc-mapping) (event-value event key))))))
       (bt:make-thread (lambda ()
                         (sleep (local-time:timestamp-difference time (local-time:now)))
                         (when (and pgm
                                    (not (= pgm (nth channel *midi-channels-instruments*))))
                           (midihelper:send-event (midihelper:ev-pgmchange channel pgm)))
  -                      (midihelper:send-event (midihelper:ev-cc channel 10 pan))
  +                      (loop :for i :in extra-params
  +                         :do (midihelper:send-event (midihelper:ev-cc channel (car i) (cadr i))))
                         (midihelper:send-event (midihelper:ev-noteon channel note velocity))
                         (sleep (dur-time (sustain event)))
                         (midihelper:send-event (midihelper:ev-noteoff channel note velocity)))
  
positive.code: 
  (midihelper:start-midihelper)
  
  (defparameter *midi-channels-instruments* (make-list 16 :initial-element 0))
  
  ;;; backend functions
  
  
negative.code:                   :release-at 'release-midi-at)
  
  (enable-backend :midi)
  
  (export '(midi-truncate-clamp bipolar-1-to-midi unipolar-1-to-midi frequency-to-midi midi-panic set-cc-mapping get-cc-mapping))
  