(ns unheard.midi-test (:require [unheard.midi :as sut] [hyperfiddle.rcf :refer [tests]]) (:import [javax.sound.midi ShortMessage])) (defn short-message [cmd ch d1 d2] (ShortMessage. cmd ch d1 d2)) (tests "short-message->notes" (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 [] 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 {}}]))