summaryrefslogtreecommitdiff
path: root/src/unheard/midi.clj
diff options
context:
space:
mode:
authorJake Zerrer <him@jakezerrer.com>2025-11-12 16:03:18 -0500
committerJake Zerrer <him@jakezerrer.com>2025-11-13 12:23:39 -0500
commit42b1a01f1165ce04cd2addbc44da9e597fcf4ea7 (patch)
tree575bd1fcc47594a237c1d0da183d37e00962496b /src/unheard/midi.clj
parent58ab3414c7dfa8d978d51a8dec6c269224921643 (diff)
Fix undefined continuous flow
Diffstat (limited to 'src/unheard/midi.clj')
-rw-r--r--src/unheard/midi.clj45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/unheard/midi.clj b/src/unheard/midi.clj
index a44c01b..c3759fe 100644
--- a/src/unheard/midi.clj
+++ b/src/unheard/midi.clj
@@ -175,13 +175,14 @@
Calls `flow-handler` with a flow of midi messages.
`flow-handler` should return a flow."
- [>name flow-handler]
+ [name flow-handler]
(m/ap
(try
(let [device
(first
(select-devices (get-all-midi-device-info)
- (m/?< >name) true false))]
+ name
+ true false))]
(if device
(m/?
(with-device device
@@ -283,25 +284,27 @@
(defn short-messages
[>device-name]
(m/stream
- (m/ap
- (let [short-messages (atom nil)
- >short-messages (m/watch short-messages)]
- (m/amb=
- (do (reset! short-messages nil)
- (m/?
- (<bus >device-name
- (fn [v]
- (m/ap
- (try (let [msg (m/?< v)]
- (reset! short-messages msg))
- (catch missionary.Cancelled c
- ;; When the upstream flow is cancelled, we emit "All notes off" to consumers
- (doseq [ch (range 0 16)]
- (reset! short-messages (ShortMessage. ShortMessage/CONTROL_CHANGE ch 123 0)))
- (throw c))))))))
- (if-let [m (m/?< >short-messages)]
- m
- (m/amb)))))))
+ (m/reductions {} nil
+ (m/ap
+ (let [device-name (m/?< >device-name)
+ short-messages (atom nil)
+ >short-messages (m/watch short-messages)]
+ (m/amb=
+ (do (reset! short-messages nil)
+ (m/?
+ (<bus device-name
+ (fn [v]
+ (m/ap
+ (try (let [msg (m/?< v)]
+ (reset! short-messages msg))
+ (catch missionary.Cancelled c
+ ;; When the upstream flow is cancelled, we emit "All notes off" to consumers
+ (doseq [ch (range 0 16)]
+ (reset! short-messages (ShortMessage. ShortMessage/CONTROL_CHANGE ch 123 0)))
+ (throw c))))))))
+ (if-let [m (m/?< >short-messages)]
+ m
+ (m/amb))))))))
(defn notes [short-messages]
(m/signal