summaryrefslogtreecommitdiff
path: root/src/unheard/instrument
diff options
context:
space:
mode:
authorJake Zerrer <him@jakezerrer.com>2025-11-07 15:42:03 -0500
committerJake Zerrer <him@jakezerrer.com>2025-11-07 15:51:27 -0500
commit945eb221209a6c3c00b2f0fcbbc7e19b343ee9d9 (patch)
treebadb4423a670751101ac84b25c80eee32cc9151c /src/unheard/instrument
parent6b25663be05e32a856dfa64dc9dbc92990ccbc56 (diff)
Add new instrument
Diffstat (limited to 'src/unheard/instrument')
-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
3 files changed, 54 insertions, 35 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)))))