summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake Zerrer <him@jakezerrer.com>2025-11-05 16:45:22 -0500
committerJake Zerrer <him@jakezerrer.com>2025-11-06 11:08:24 -0500
commit2d956a3a779672ab3acfc1bc542ebba855522d06 (patch)
tree37c5f1eb7e549e2662bfb6abbe932136aa53cdf0
parentbee77914483da25831093e0475e4a71f1383253b (diff)
Organize namespaces
-rw-r--r--.nrepl-port1
-rw-r--r--src/scratch.clj3
-rw-r--r--src/unheard/clock.clj11
-rw-r--r--src/unheard/dsl.clj (renamed from src/notation.clj)47
-rw-r--r--src/unheard/midi.clj (renamed from src/midi.clj)12
-rw-r--r--src/unheard/midi/percussion.clj (renamed from src/midi/percussion.clj)2
-rw-r--r--src/unheard/theory.clj34
7 files changed, 56 insertions, 54 deletions
diff --git a/.nrepl-port b/.nrepl-port
deleted file mode 100644
index 9a32db3..0000000
--- a/.nrepl-port
+++ /dev/null
@@ -1 +0,0 @@
-52896 \ No newline at end of file
diff --git a/src/scratch.clj b/src/scratch.clj
index ed2d464..7c305aa 100644
--- a/src/scratch.clj
+++ b/src/scratch.clj
@@ -1,5 +1,6 @@
(ns scratch
- (:require [midi :as midi]
+ (:require [unheard.midi :as midi]
+ [unheard.midi.percussion :refer [kick snare]]
[missionary.core :as m]))
#_(print-all-midi-devices)
diff --git a/src/unheard/clock.clj b/src/unheard/clock.clj
new file mode 100644
index 0000000..4011919
--- /dev/null
+++ b/src/unheard/clock.clj
@@ -0,0 +1,11 @@
+(ns unheard.clock
+ (:require [missionary.core :as m]))
+
+(defn clock
+ "Returns a tuple of [`>clock` `clock`].
+ `clock` is an atom representing the current time.
+ `>clock` is a signal representing the current time."
+ []
+ (let [clock (atom 0)
+ >clock (m/signal (m/watch clock))]
+ [>clock clock]))
diff --git a/src/notation.clj b/src/unheard/dsl.clj
index 6e266ce..e111725 100644
--- a/src/notation.clj
+++ b/src/unheard/dsl.clj
@@ -1,4 +1,4 @@
-(ns notation
+(ns unheard.dsl
(:require [missionary.core :as m]
[clojure.set :refer [union]]))
@@ -58,47 +58,4 @@
[1 (loop1) 2 3]
;; Middle arguments are variable names
- (=loop2 dur ([1 2 3] dur))
-
-;; TODO:
- ;; - Note literals turn into numbers
- ;; - Represent keyboard as byte array of shorts
- ;; - play a note increments, stop a note decrements
- ;; - Multiple instruments
- ;; - Mapping inputs to vars
- ;; - Inputs get declared at the top of a track
- ;; - Devices get mapped to declared inputs
- ;; - Notion of scenes that change mapping of inputs to vars
- ;; - Loops
- )
-
-;; TODO: Move elsewhere
-(defn clock []
- (let [clock (atom 0)
- >clock (m/signal (m/watch clock))]
- [>clock (fn [v] (reset! clock v))]
- ))
-
-(defn note [clock start duration value]
- (m/cp
- (if (m/?< (m/latest #(<= start % (dec (+ start duration))) clock))
- #{value}
- #{})))
-
-(defn poly [& notes]
- (m/ap
- (apply union (m/?< (apply m/latest vector notes)))))
-
-;; TODO: Group could actually wrap note, rather than using explicitly
-;; WIll introduce a lot of GC churn, though
-(defn group
- [clock start end content]
- (m/cp
- (let [content (m/signal content)]
- (if (m/?< (m/latest #(<= start % end) clock))
- (m/?< content)
- (m/amb #{})))))
-
-#_(reset! clock 0)
-#_(swap! clock inc)
-#_(swap! clock dec)
+ (=loop2 dur ([1 2 3] dur)))
diff --git a/src/midi.clj b/src/unheard/midi.clj
index 8e56b08..1e135a2 100644
--- a/src/midi.clj
+++ b/src/unheard/midi.clj
@@ -1,4 +1,4 @@
-(ns midi
+(ns unheard.midi
(:require [missionary.core :as m]
[taoensso.trove :as log])
(:import [javax.sound.midi MidiSystem Receiver ShortMessage MidiDevice$Info MidiDevice Transmitter MidiMessage]
@@ -257,13 +257,13 @@
first
(m/ap
(let [[ch ch-messages]
- (m/?> 128 (midi/|group-by-channel (midi/|short-messages (m/stream f))))
+ (m/?> 128 (|group-by-channel (|short-messages (m/stream f))))
ch-messages (m/stream ch-messages)]
(m/amb=
(let [[note note-messages]
(m/?> 128 (-> ch-messages
- (midi/|matching-commands note-commands)
- (midi/|group-by-data-1)))]
+ (|matching-commands note-commands)
+ (|group-by-data-1)))]
;; TODO: Where to relieve in here?
[:key ch note
(m/?<
@@ -281,8 +281,8 @@
(let [[control-number control-messages]
(m/?> 128 (-> ch-messages
- (midi/|matching-commands control-commands)
- (midi/|group-by-data-1)))]
+ (|matching-commands control-commands)
+ (|group-by-data-1)))]
[:control ch control-number (.getData2 ^ShortMessage (m/?< control-messages))])))))))
#_(defn >ch-stream [>device ch]
diff --git a/src/midi/percussion.clj b/src/unheard/midi/percussion.clj
index 21fcee9..700b2e6 100644
--- a/src/midi/percussion.clj
+++ b/src/unheard/midi/percussion.clj
@@ -1,4 +1,4 @@
-(ns midi.percussion
+(ns unheard.midi.percussion
"General MIDI percussion instrument mappings (MIDI notes 35-81).
In General MIDI, channel 10 is reserved for percussion where each
diff --git a/src/unheard/theory.clj b/src/unheard/theory.clj
new file mode 100644
index 0000000..5d5805b
--- /dev/null
+++ b/src/unheard/theory.clj
@@ -0,0 +1,34 @@
+(ns unheard.theory
+ (:require [missionary.core :as m]
+ [clojure.set :refer [union]]))
+
+(defn note [clock start duration value]
+ (m/cp
+ (if (m/?< (m/latest #(<= start % (dec (+ start duration))) clock))
+ #{value}
+ #{})))
+
+(defn poly [& notes]
+ (m/ap
+ (apply union (m/?< (apply m/latest vector notes)))))
+
+;; TODO: Group could actually wrap note, rather than using explicitly
+;; WIll introduce a lot of GC churn, though
+(defn group
+ [clock start end content]
+ (m/cp
+ (let [content (m/signal content)]
+ (if (m/?< (m/latest #(<= start % end) clock))
+ (m/?< content)
+ (m/amb #{})))))
+
+;; TODO:
+;; - Note literals turn into numbers
+;; - Represent keyboard as byte array of shorts
+;; - play a note increments, stop a note decrements
+;; - Multiple instruments
+;; - Mapping inputs to vars
+;; - Inputs get declared at the top of a track
+;; - Devices get mapped to declared inputs
+;; - Notion of scenes that change mapping of inputs to vars
+;; - Loops