summaryrefslogtreecommitdiff
path: root/dev/scratch.clj
blob: ef7241a60251680e9ddc0ae3c9f1d538558097b7 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(ns scratch
  (:require [unheard.midi :as midi]
            [unheard.midi.percussion :refer [kick snare hat]]
            [unheard.clock :refer [clock]]
            [unheard.theory :refer [note poly]]
            [missionary.core :as m]))

#_(print-all-midi-devices)

(def midi-keyboard  "CoreMIDI4J - Minilab3 MIDI")

(def run
  (midi/<bus midi-keyboard
             (fn [v]
               (m/ap
                 ;; 2 is the number of message types, e.g. :key
                (let [[>c c] (clock)
                      p (poly
                         (note >c 0 1 kick)
                         (note >c 8 1 kick)
                         (note >c 16 1 kick)
                         (note >c 24 1 kick)

                         (note >c 0 1 hat)
                         (note >c 4 1 hat)
                         (note >c 8 1 hat)
                         (note >c 12 1 hat)
                         (note >c 16 1 hat)
                         (note >c 20 1 hat)
                         (note >c 24 1 hat)
                         (note >c 28 1 hat)

                         (note >c 4 1 snare)
                         (note >c 12 1 snare)
                         (note >c 20 1 snare)
                         (note >c 28 1 snare))]
                  (m/amb=
                   (let [[t f] (m/?> 2 (midi/keyboard v))
                         [ch k v] (rest (m/?< f))]
                     (if (and (= t :control) (= ch 0) (= k 74))
                       (do (reset! c v) (m/amb))
                       (m/amb)))
                   [:n  (m/?< (m/eduction (dedupe) p))]
                   [:c  (m/?< (m/eduction (dedupe) >c))]))))))

(def cancel
  (run prn prn))

(cancel)