diff options
| author | Jake Zerrer <him@jakezerrer.com> | 2025-11-05 16:45:22 -0500 |
|---|---|---|
| committer | Jake Zerrer <him@jakezerrer.com> | 2025-11-06 10:46:22 -0500 |
| commit | bee77914483da25831093e0475e4a71f1383253b (patch) | |
| tree | b0969c3a0fe2b2c9472534eb7a9c0f8912584648 /src/midi.clj | |
| parent | 2a4fce4fef775f6661a625303de9b28b446f1877 (diff) | |
Keyboard in a decent state
Diffstat (limited to 'src/midi.clj')
| -rw-r--r-- | src/midi.clj | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/src/midi.clj b/src/midi.clj index 330402b..8e56b08 100644 --- a/src/midi.clj +++ b/src/midi.clj @@ -229,14 +229,13 @@ [>messages] (m/eduction (filter #(instance? ShortMessage %)) >messages)) -(defn |channels +(defn |group-by-channel [>messages] (m/group-by #(.getChannel ^ShortMessage %) >messages)) (defn |group-by-data-1 [>messages] - (m/group-by #(.getData1 ^ShortMessage %) - >messages)) + (m/group-by #(.getData1 ^ShortMessage %) >messages)) (defn |matching-commands [>messages commands] @@ -253,34 +252,38 @@ (defn keyboard [f] - (m/ap - (let [[ch ch-messages] - (m/?> 128 (midi/|channels (midi/|short-messages (m/stream f)))) - ch-messages (m/stream ch-messages)] - (m/amb= - (let [[note note-messages] - (m/?> 128 (-> ch-messages - (midi/|matching-commands note-commands) - (midi/|group-by-data-1)))] - [:key ch note - (m/?< - (m/relieve - (m/reductions - (fn [_prev curr] - (when (some? curr) - (let [cmd (.getCommand ^ShortMessage curr)] - (cond - (= cmd ShortMessage/NOTE_ON) - (.getData2 ^ShortMessage curr) - (= cmd ShortMessage/POLY_PRESSURE) - (.getData2 ^ShortMessage curr) - (= cmd ShortMessage/NOTE_OFF) - nil)))) nil note-messages)))]) - (let [[control-number control-messages] - (m/?> 128 (-> ch-messages - (midi/|matching-commands control-commands) - (midi/|group-by-data-1)))] - [:control ch control-number (.getData2 ^ShortMessage (m/?< control-messages))]))))) + (m/relieve + (m/group-by + first + (m/ap + (let [[ch ch-messages] + (m/?> 128 (midi/|group-by-channel (midi/|short-messages (m/stream f)))) + ch-messages (m/stream ch-messages)] + (m/amb= + (let [[note note-messages] + (m/?> 128 (-> ch-messages + (midi/|matching-commands note-commands) + (midi/|group-by-data-1)))] + ;; TODO: Where to relieve in here? + [:key ch note + (m/?< + (m/reductions + (fn [_prev curr] + (when (some? curr) + (let [cmd (.getCommand ^ShortMessage curr)] + (cond + (= cmd ShortMessage/NOTE_ON) + (.getData2 ^ShortMessage curr) + (= cmd ShortMessage/POLY_PRESSURE) + (.getData2 ^ShortMessage curr) + (= cmd ShortMessage/NOTE_OFF) + nil)))) nil note-messages))]) + + (let [[control-number control-messages] + (m/?> 128 (-> ch-messages + (midi/|matching-commands control-commands) + (midi/|group-by-data-1)))] + [:control ch control-number (.getData2 ^ShortMessage (m/?< control-messages))]))))))) #_(defn >ch-stream [>device ch] (m/cp (m/?< (second (get >device ch))))) @@ -297,7 +300,7 @@ ;; is a midi channel number and val is a signal of sets representing active ;; notes on that channel. ;; -;; Create a nother function, `(send-to-bus bus-name sigs)`. `bus-name` is the +;; Create another function, `(send-to-bus bus-name sigs)`. `bus-name` is the ;; name of a midi bus on this machine. If a bus with that name exists, it will ;; start reading note values from `sigs`. ;; |
