diff options
Diffstat (limited to 'src/unheard/instrument/minilab3.clj')
| -rw-r--r-- | src/unheard/instrument/minilab3.clj | 86 |
1 files changed, 58 insertions, 28 deletions
diff --git a/src/unheard/instrument/minilab3.clj b/src/unheard/instrument/minilab3.clj index 11da62e..4973be2 100644 --- a/src/unheard/instrument/minilab3.clj +++ b/src/unheard/instrument/minilab3.clj @@ -1,31 +1,61 @@ (ns unheard.instrument.minilab3 - (:require [unheard.instrument-utils :as iu])) + (:require [missionary.core :as m]) + (:import [javax.sound.midi ShortMessage])) -(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 matching-control-change + (filter (fn [^ShortMessage m] (= (.getCommand m) ShortMessage/CONTROL_CHANGE)))) + +(defn matching-channel [ch] + (filter (fn [^ShortMessage m] (= (.getChannel m) ch)))) + +(defn matching-data-1 [d1] + (filter (fn [^ShortMessage m] (= (.getData1 m) d1)))) + +(def get-data-2 + (map (fn [^ShortMessage m] (.getData2 m)))) -(def is-knob (iu/is-knob minilab3)) -(def is-fader (iu/is-fader minilab3)) -(def is-pad (iu/is-pad minilab3)) +(defn matching-control + "Returns a function filtering flow of ShortMessage `f` down to control + change messages where channel is `ch` and data-1 is `k`, and then returning + a signal of values for data-2. Initial value of signal will be `init`. + + Though a little esoteric sounding, this is actually quite useful. + The signal returned by this is useful for representing knobs, faders, and + pads on a midi controller. + " + [init ch k] + (fn [f] + (m/signal + (m/reductions {} init + (m/eduction + (comp + matching-control-change + (matching-channel ch) + (matching-data-1 k) + get-data-2) + f))))) + +(def minilab3 + {:knob + {1 (matching-control 0 0 74) + 2 (matching-control 0 0 71) + 3 (matching-control 0 0 76) + 4 (matching-control 0 0 77) + 5 (matching-control 0 0 93) + 6 (matching-control 0 0 18) + 7 (matching-control 0 0 19) + 8 (matching-control 0 0 16)} + :fader + {1 (matching-control 0 0 82) + 2 (matching-control 0 0 83) + 3 (matching-control 0 0 85) + 4 (matching-control 0 0 17)} + :pad + {1 (matching-control 0 9 36) + 2 (matching-control 0 9 37) + 3 (matching-control 0 9 38) + 4 (matching-control 0 9 39) + 5 (matching-control 0 9 40) + 6 (matching-control 0 9 41) + 7 (matching-control 0 9 42) + 8 (matching-control 0 9 43)}}) |
