summaryrefslogtreecommitdiff
path: root/src/unheard/midi_test.clj
blob: 790cf6919a026867e4053828888f945920303518 (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
27
28
29
(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 {}}]))