diff options
| author | Jake Zerrer <him@jakezerrer.com> | 2025-11-25 14:53:20 -0500 |
|---|---|---|
| committer | Jake Zerrer <him@jakezerrer.com> | 2025-11-25 15:24:39 -0500 |
| commit | 20ce2f424552a6124575c79c1ce5476addbaba95 (patch) | |
| tree | 3230c1c7efd7a212cbcdb0b17b0dad1f622a69b1 /dev | |
| parent | 1a3fefa99bc49f0cbedf0318b802ac334a6be16b (diff) | |
Implement interval tree logic
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/scratch.clj | 113 |
1 files changed, 63 insertions, 50 deletions
diff --git a/dev/scratch.clj b/dev/scratch.clj index d7d0da7..7cc86cc 100644 --- a/dev/scratch.clj +++ b/dev/scratch.clj @@ -2,71 +2,84 @@ (:require [unheard.midi :as midi] [unheard.midi.percussion :refer [kick snare hat]] [unheard.instrument.minilab3 :as minilab3] - [unheard.instrument.omx-27 :as omx-27] - [unheard.theory :refer [note poly]] - [missionary.core :as m]) - (:import [javax.sound.midi ShortMessage])) + [unheard.time-object :refer [phrase timeline]] + [unheard.theory :refer [note read]] + [missionary.core :as m])) #_(print-all-midi-devices) -(defn triad [>c >tonic] - (poly - ;; This is a major cord, - ;; held 32 32nd notes. - ;; The tonic can vary. +(defn triad + [>c >tonic] + (phrase + ;; This is a major cord, + ;; held 32 32nd notes. + ;; The tonic can vary. (note >c 0 32 >tonic) (note >c 0 32 (m/latest #(+ % 4) >tonic)) (note >c 0 32 (m/latest #(+ % 7) >tonic)))) -(defn song - [{:keys [>clock >tonic]}] - (poly - (triad >clock >tonic) - - #_ - (triad >clock (m/latest #(+ % 12) tonic)) - - ;; The rest of the "song" is a drum pattern. - (note >clock 1 1 (m/ap kick)) - (note >clock 9 1 (m/ap kick)) - (note >clock 17 1 (m/ap kick)) - (note >clock 25 1 (m/ap kick)) +(defn drums + [>clock] + (phrase (note >clock 1 1 (m/ap kick)) + (note >clock 9 1 (m/ap kick)) + (note >clock 17 1 (m/ap kick)) + (note >clock 25 1 (m/ap kick)) + (note >clock 1 1 (m/ap hat)) + (note >clock 5 1 (m/ap hat)) + (note >clock 9 1 (m/ap hat)) + (note >clock 13 1 (m/ap hat)) + (note >clock 17 1 (m/ap hat)) + (note >clock 21 1 (m/ap hat)) + (note >clock 25 1 (m/ap hat)) + (note >clock 29 1 (m/ap hat)) + (note >clock 5 1 (m/ap snare)) + (note >clock 13 1 (m/ap snare)) + (note >clock 21 1 (m/ap snare)) + (note >clock 29 1 (m/ap snare)))) - (note >clock 1 1 (m/ap hat)) - (note >clock 5 1 (m/ap hat)) - (note >clock 9 1 (m/ap hat)) - (note >clock 13 1 (m/ap hat)) - (note >clock 17 1 (m/ap hat)) - (note >clock 21 1 (m/ap hat)) - (note >clock 25 1 (m/ap hat)) - (note >clock 29 1 (m/ap hat)) - - (note >clock 5 1 (m/ap snare)) - (note >clock 13 1 (m/ap snare)) - (note >clock 21 1 (m/ap snare)) - (note >clock 29 1 (m/ap snare)))) +(defn song + [>clock >tonic] + (phrase ((triad >clock >tonic) 0) + ((triad >clock (m/latest #(+ % 12) >tonic)) 0) + ((drums >clock) 0))) ;; TODO: Move into /dev ;; Add logging -(defn debug-flow [f] - ((m/reduce prn nil - (m/ap (m/?< f))) prn prn)) +(defn debug-flow [f] ((m/reduce prn nil (m/ap (m/?< f))) prn prn)) (def run (midi/<bus minilab3/device-name (fn [v] - (m/signal - (m/ap - ;; 2 is the number of message types, e.g. :key - (let [controls (midi/controller v minilab3/config) - clock (get-in controls [:knob 1]) - tonic (get-in controls [:knob 2]) - song-config {:clock clock - :tonic tonic} - p (song song-config)] - (m/?< (m/latest vector clock p)))))))) + (m/ap + (let [controls (midi/controller v minilab3/config) + >clock (get-in controls [:knob 1]) + >tonic (get-in controls [:knob 2]) + s (song >clock >tonic) + t (timeline s)] + (m/?< + ;; BUG: + ;; Remove dedupe as part of #2d7f861 + (m/eduction (dedupe) + (m/latest vector + >clock + (read >clock t))))))))) + +#_(def cancel (run {} {})) +#_(cancel) -(def cancel (run {} {})) +(comment + ;; Manual test of read, without reliance on whole midi setup + (def c (atom 0)) + (def >c (m/signal (m/watch c))) + (def t (atom 0)) + (def >t (m/signal (m/watch t))) + (def s (song >c >t)) + (def cancel ((m/reduce prn #{} (read >c (timeline s))) prn prn)) + (cancel) -(cancel) + (reset! c -1) + (reset! c 1) + (reset! c 4) + (reset! t 4) + (swap! t inc)) |
