summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dev/scratch.clj15
-rw-r--r--src/unheard/instrument/minilab3.clj31
-rw-r--r--src/unheard/instrument_utils.clj13
-rw-r--r--src/unheard/midi_util.clj4
4 files changed, 57 insertions, 6 deletions
diff --git a/dev/scratch.clj b/dev/scratch.clj
index 9bfac2c..9775320 100644
--- a/dev/scratch.clj
+++ b/dev/scratch.clj
@@ -1,6 +1,8 @@
(ns scratch
(:require [unheard.midi :as midi]
[unheard.midi.percussion :refer [kick snare hat]]
+ [unheard.instrument.minilab3 :as minilab3]
+ [unheard.midi-util :as mu]
[unheard.clock :refer [clock]]
[unheard.theory :refer [note poly]]
[missionary.core :as m]))
@@ -55,18 +57,19 @@
p (song >c >tonic)]
(m/amb=
(let [[t f] (m/?> 2 (midi/keyboard v))
- [ch k v] (rest (m/?< f))]
- (if (= t :control)
+ [ch k v] (rest (m/?< f))
+ chkv [ch k v]]
+ (if (mu/control-message? t)
(m/amb
- (if (and (= ch 0) (= k 74))
+ (if (minilab3/is-knob 1 chkv)
(do (reset! c v) (m/amb))
(m/amb))
- (if (and (= ch 0) (= k 71))
+ (if (minilab3/is-knob 2 chkv)
(do (reset! tonic v) (m/amb))
(m/amb)))
(m/amb)))
- [:n (m/?< (m/eduction (dedupe) p))]
- [:c (m/?< (m/eduction (dedupe) >c))]))))))
+ [:n (m/?< (m/eduction (dedupe) p))]
+ [:c (m/?< (m/eduction (dedupe) >c))]))))))
(def cancel
(run prn prn))
diff --git a/src/unheard/instrument/minilab3.clj b/src/unheard/instrument/minilab3.clj
new file mode 100644
index 0000000..11da62e
--- /dev/null
+++ b/src/unheard/instrument/minilab3.clj
@@ -0,0 +1,31 @@
+(ns unheard.instrument.minilab3
+ (:require [unheard.instrument-utils :as iu]))
+
+(def minilab3
+ {:knobs
+ {1 [0 74]
+ 2 [0 71]
+ 3 [0 76]
+ 4 [0 77]
+ 5 [0 93]
+ 6 [0 18]
+ 7 [0 19]
+ 8 [0 16]}
+ :faders
+ {1 [0 82]
+ 2 [0 83]
+ 3 [0 85]
+ 4 [0 17]}
+ :pads
+ {1 [9 36]
+ 2 [9 37]
+ 3 [9 38]
+ 4 [9 39]
+ 5 [9 40]
+ 6 [9 41]
+ 7 [9 42]
+ 8 [9 43]}})
+
+(def is-knob (iu/is-knob minilab3))
+(def is-fader (iu/is-fader minilab3))
+(def is-pad (iu/is-pad minilab3))
diff --git a/src/unheard/instrument_utils.clj b/src/unheard/instrument_utils.clj
new file mode 100644
index 0000000..1ceae6b
--- /dev/null
+++ b/src/unheard/instrument_utils.clj
@@ -0,0 +1,13 @@
+(ns unheard.instrument-utils)
+
+(defn is-knob [inst]
+ (fn [n [ch k _v]]
+ (= [ch k] (get-in inst [:knobs n]))))
+
+(defn is-fader [inst]
+ (fn [n [ch k _v]]
+ (= [ch k] (get-in inst [:faders n]))))
+
+(defn is-pad [inst]
+ (fn [n [ch k _v]]
+ (= [ch k] (get-in inst [:pads n]))))
diff --git a/src/unheard/midi_util.clj b/src/unheard/midi_util.clj
new file mode 100644
index 0000000..382fe87
--- /dev/null
+++ b/src/unheard/midi_util.clj
@@ -0,0 +1,4 @@
+(ns unheard.midi-util)
+
+(defn control-message? [msg-type]
+ (= :control msg-type))