   which have access to all the classes that Afterglow needs."
   [msg]
   (try
-    (thread (>!! @channel msg))
+    (.add midi-queue msg)
     (catch Throwable t
       (error t "Problem trasferring MIDI event to core.async channel"))))
 

(ns afterglow.midi
  "Handles MIDI communication, including syncing a show metronome to MIDI clock pulses."
  (:require [afterglow.rhythm :refer :all]
            [clojure.core.async :refer [chan go <! >!! thread]]
            [amalloy.ring-buffer :refer [ring-buffer]]
            [overtone.at-at :refer [now]]
            [overtone.midi :as midi]
            [taoensso.timbre :refer [info error]])
  (:import [java.util.regex Pattern]))

(def ^:private max-clock-intervals
  "How many MIDI clock pulses should be kept around for averaging?"

            (not (mmj-descriptions (:name device))))))
    identity))

(defn- start-handoff-thread
  "Creates the thread used to deliver MIDI events when needed."
  [old-thread]
  (or old-thread
      (doto (Thread. delegated-message-handler)
        (.setDaemon true)
        (.start))))

;; TODO: This and open-outputs will have to change once hot-plugging works.
(defn open-inputs-if-needed!
  "Make sure the MIDI input ports are open and ready to distribute events.
  Returns the opened inputs."
  []
  (swap! midi-transfer-thread start-handoff-thread)
  (let [port-filter (create-midi-port-filter)
        result (swap! midi-inputs #(if (empty? %)
                                     (map connect-midi-in
