summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/unheard/instrument/minilab3.clj39
-rw-r--r--src/unheard/instrument/omx_27.clj11
-rw-r--r--src/unheard/instrument/util.clj39
-rw-r--r--src/unheard/midi.clj23
4 files changed, 66 insertions, 46 deletions
diff --git a/src/unheard/instrument/minilab3.clj b/src/unheard/instrument/minilab3.clj
index 4973be2..3a60058 100644
--- a/src/unheard/instrument/minilab3.clj
+++ b/src/unheard/instrument/minilab3.clj
@@ -1,41 +1,10 @@
(ns unheard.instrument.minilab3
- (:require [missionary.core :as m])
- (:import [javax.sound.midi ShortMessage]))
+ (:require [unheard.instrument.util :refer [matching-control]]))
-(def matching-control-change
- (filter (fn [^ShortMessage m] (= (.getCommand m) ShortMessage/CONTROL_CHANGE))))
+(def device-name
+ "CoreMIDI4J - Minilab3 MIDI")
-(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))))
-
-(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
+(def config
{:knob
{1 (matching-control 0 0 74)
2 (matching-control 0 0 71)
diff --git a/src/unheard/instrument/omx_27.clj b/src/unheard/instrument/omx_27.clj
new file mode 100644
index 0000000..33c18c8
--- /dev/null
+++ b/src/unheard/instrument/omx_27.clj
@@ -0,0 +1,11 @@
+(ns unheard.instrument.omx-27
+ (:require [unheard.instrument.util :refer [matching-control]]))
+
+(def device-name "CoreMIDI4J - omx-27")
+(def omx-27
+ {:knob
+ {1 (matching-control 0 0 21)
+ 2 (matching-control 0 0 22)
+ 3 (matching-control 0 0 23)
+ 4 (matching-control 0 0 24)
+ 5 (matching-control 0 0 61)}})
diff --git a/src/unheard/instrument/util.clj b/src/unheard/instrument/util.clj
new file mode 100644
index 0000000..0faa5b5
--- /dev/null
+++ b/src/unheard/instrument/util.clj
@@ -0,0 +1,39 @@
+(ns unheard.instrument.util
+ (:require [missionary.core :as m])
+ (:import [javax.sound.midi ShortMessage]))
+
+(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))))
+
+(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]
+ ;; TODO: Should be signal
+ (m/stream
+ (m/reductions {} init
+ (m/eduction
+ (comp
+ matching-control-change
+ (matching-channel ch)
+ (matching-data-1 k)
+ get-data-2
+ ;; TODO git-bug f109911
+ (dedupe))
+ f)))))
diff --git a/src/unheard/midi.clj b/src/unheard/midi.clj
index 174fec2..b9f20c4 100644
--- a/src/unheard/midi.clj
+++ b/src/unheard/midi.clj
@@ -79,16 +79,17 @@
(m/? (m/via m/blk (.setReceiver transmitter receiver)))
(log/log! {:level :debug, :id :midi/receiver-set})
(m/?
- (t (m/ap
- (loop []
- (m/amb
- (do
- (log/log! {:level :debug, :id :midi/tx-awaiting-value})
- (m/amb))
- (let [v (m/? rv)]
- (log/log! {:level :debug, :id :midi/tx-received-value, :data {:value (str v)}})
- v)
- (recur))))))
+ (t (m/stream
+ (m/ap
+ (loop []
+ (m/amb
+ (do
+ (log/log! {:level :debug, :id :midi/tx-awaiting-value})
+ (m/amb))
+ (let [v (m/? rv)]
+ (log/log! {:level :debug, :id :midi/tx-received-value, :data {:value (str v)}})
+ v)
+ (recur)))))))
(finally
(log/log! {:level :info, :id :midi/closing-tx})
(m/? (m/via m/blk (.close transmitter)))
@@ -206,5 +207,5 @@
(into {}
(map (fn [[group instance]]
- {group (into {} (map (fn [[id flow]] {id (flow f)}) instance))})
+ {group (into {} (map (fn [[id flow]] {id (flow f)}) instance))})
config)))