summaryrefslogtreecommitdiff
path: root/src/unheard/theory.clj
blob: 5d5805b1069b652f25672e7a1bd00f32d4d5a8a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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