summaryrefslogtreecommitdiff
path: root/src/unheard/midi_test.clj
blob: cbf3d5aaf6306a827f7071ce27ee6576888e0d01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(ns unheard.midi-test
  (:require [unheard.midi :as sut]
            [hyperfiddle.rcf :refer [tests]])
  (:import [javax.sound.midi ShortMessage]))

(defn test-msg [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]]))]
         (into []
               (transduce
                sut/short-message->notes
                conj
                []
                (conj
                 msgs
                 (ShortMessage. ShortMessage/CONTROL_CHANGE 0 123 0))))
         := [#{1} #{1 2} #{1} #{} #{3} #{4 3} #{}]))