(defonce memory (agent {}))
(on-event [:midi :note-on]
(fn [m]
(send memory
(fn [mem]
(let [n (:note m)
s (pad2 :freq (midi->hz n))]
(assoc mem n s)))))
::play-note)(defn midi-agent-for-control "Returns an agent representing the current value of a controller-specific control identified by a fully-qualified MIDI event key such as that generated by midi-mk-full-control-event-key. If the agent doesn't exist, it is created and cached. Subsequent calls with the same control-key will return the same agent. Agents are used because the event to update them can be safely handled synchronously (with on-sync-event) without watchers being able to block the thread generating the MIDI events. This also means that incoming events are sent to the agent in the correct order whereas if the thread pool were used (via on-event), the incoming events may be arbitrarily ordered."