diff options
| author | Jake Zerrer <him@jakezerrer.com> | 2025-11-12 16:03:18 -0500 |
|---|---|---|
| committer | Jake Zerrer <him@jakezerrer.com> | 2025-11-13 11:36:52 -0500 |
| commit | 58ab3414c7dfa8d978d51a8dec6c269224921643 (patch) | |
| tree | c7a491c9c0ff5da1bda44bf40df0c75b0c65f076 /src | |
| parent | 2d751c6c89d6f95c568e4ce050ea63af0e1c3cc4 (diff) | |
Create test for channel-based short-message fn
Diffstat (limited to 'src')
| -rw-r--r-- | src/unheard/midi_test.clj | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/src/unheard/midi_test.clj b/src/unheard/midi_test.clj index cbf3d5a..bcfde3c 100644 --- a/src/unheard/midi_test.clj +++ b/src/unheard/midi_test.clj @@ -3,24 +3,50 @@ [hyperfiddle.rcf :refer [tests]]) (:import [javax.sound.midi ShortMessage])) -(defn test-msg [cmd ch d1 d2] +(defn short-message [cmd ch d1 d2] (ShortMessage. cmd ch d1 d2)) (tests "short-message->notes" - (let [msgs (into [] (map (fn [[cmd d1]] (test-msg cmd 0 d1 9)) - [[ShortMessage/NOTE_ON 1] - [ShortMessage/CONTROL_CHANGE 1] - [ShortMessage/NOTE_ON 2] - [ShortMessage/NOTE_OFF 2] - [ShortMessage/NOTE_OFF 1] - [ShortMessage/NOTE_ON 3] - [ShortMessage/NOTE_ON 4]]))] + (let [msgs + [(short-message ShortMessage/NOTE_ON 0 1 100) + ;; Irrelevant messages don't appear + (short-message ShortMessage/CONTROL_CHANGE 0 1 100) + (short-message ShortMessage/NOTE_ON 0 2 100) + ;; Notes are removed + (short-message ShortMessage/NOTE_OFF 0 2 100) + (short-message ShortMessage/NOTE_OFF 0 1 100) + (short-message ShortMessage/NOTE_ON 0 3 100) + (short-message ShortMessage/NOTE_ON 0 4 100) + ;; Specifying channel works + (short-message ShortMessage/NOTE_ON 1 1 100) + (short-message ShortMessage/NOTE_ON 1 2 100) + ;; All notes off works + (short-message ShortMessage/CONTROL_CHANGE 0 123 0) + (short-message ShortMessage/CONTROL_CHANGE 1 123 0)]] + (into [] (transduce sut/short-message->notes conj [] - (conj - msgs - (ShortMessage. ShortMessage/CONTROL_CHANGE 0 123 0)))) - := [#{1} #{1 2} #{1} #{} #{3} #{4 3} #{}])) + msgs)) + := [{0 {1 100}} + {0 {1 100 + 2 100}} + {0 {1 100}} + {0 {}} + {0 {3 100}} + {0 {3 100 + 4 100}} + {0 {3 100 + 4 100} + 1 {1 100}} + {0 {3 100 + 4 100} + 1 {1 100 + 2 100}} + {0 {} + 1 {1 100 + 2 100}} + {0 {} + 1 {}}])) |
