diff options
| author | Jake Zerrer <him@jakezerrer.com> | 2025-10-13 19:04:26 -0400 |
|---|---|---|
| committer | Jake Zerrer <him@jakezerrer.com> | 2025-10-13 19:05:14 -0400 |
| commit | ebbfd10cb80ee61de047d7afafea0513b290ab82 (patch) | |
| tree | 2ccdcbac9ee5165250dd99ca2fab14d767cfc363 /src | |
Initial commit
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.clj | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/main.clj b/src/main.clj new file mode 100644 index 0000000..fdb306f --- /dev/null +++ b/src/main.clj @@ -0,0 +1,45 @@ +(ns main + (:require [missionary.core :as m] + [clojure.set :refer [difference]])) + +;; How many times per second are output continuous values sampled and turned +;; into events? +(def sample-rate (atom 1)) + +;; Temporary atom to explore the concept of note state as a continuous value +(def notes-on (atom #{})) +(def >notes-on (m/signal (m/watch notes-on))) + +(defn play-note [v] (swap! notes-on conj v)) + +(defn stop-note [v] (swap! notes-on disj v)) + +(def clock + (m/ap + (loop [] + (m/amb + (m/? + (m/sleep (/ 1000 @sample-rate))) + :tick + (recur))))) + +#_(play-note 1) +#_(stop-note 1) + +;; convert the continuous time >notes-on flow to a series of discrete midi note on and off events +(def output + (m/eduction (map (fn [{:keys [note-on note-off]}] {:note-on note-on :note-off note-off})) + (m/reductions (fn [{:keys [active note-on note-off]} [curr _]] + {:note-on (difference (difference curr active) note-on) + :note-off (difference (difference active curr) note-off) + :active curr}) + #{} + (m/sample + vector + >notes-on + clock)))) + +(def cancel + ((m/reduce prn output) {} {})) + +(cancel) |
