From 2fdb7ce022b521b93ed314c1d33369bfa5d2bd0e Mon Sep 17 00:00:00 2001 From: Jake Zerrer Date: Fri, 17 Oct 2025 19:24:36 -0400 Subject: Working on getting supervision tree right --- src/midi.clj | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/midi.clj') diff --git a/src/midi.clj b/src/midi.clj index ca70273..4c10de0 100644 --- a/src/midi.clj +++ b/src/midi.clj @@ -58,21 +58,22 @@ "Returns a device for given device name. Returns nil if device not found." [device-name with-device] (m/ap - (when-let [device-info (m/?< (>device-info device-name))] - (let [^MidiDevice device (MidiSystem/getMidiDevice ^MidiDevice$Info device-info)] - ;; Essential problem: Combining taking element from flow to put in - ;; conditional, and cleaning up in catch. - ;; NOTE: You need the MidiDevice type hint when you call open and close! - (try - (println "Opening device") - (m/? (m/via m/blk (.open device))) - (println "Device opened") - (m/?< (with-device device)) - (finally - (println "Closing device") - (m/compel (m/? (m/via m/blk (.close device)))) - (println "Device closed") - )))))) + (let [device-info + (m/?< (>device-info device-name)) + ^MidiDevice device (MidiSystem/getMidiDevice ^MidiDevice$Info device-info)] + ;; Essential problem: Combining taking element from flow to put in + ;; conditional, and cleaning up in catch. + ;; NOTE: You need the MidiDevice type hint when you call open and close! + (try + (println "Opening device") + (m/? (m/via m/blk (.open device))) + (println "Device opened") + (m/?< (with-device device)) + (finally + (println "Closing device") + (m/compel (m/? (m/via m/blk (.close device)))) + (println "Device closed") + ))))) (defn new-device "Generate a new midi device. @@ -111,7 +112,7 @@ (def run (m/ap (prn (m/?< (>device (m/?< >bus-sel) - (fn [v] (m/ap (m/amb (m/?< v))))))) + >midi-messages))) )) (def close ((m/reduce prn {} run) {} {})) -- cgit v1.2.3