@kairotic/app 0.0.0-stage → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/index.html +1101 -0
- package/kairotic/api.cljs +362 -0
- package/kairotic/assistant.cljs +505 -0
- package/kairotic/backends/gun-backend.js +371 -0
- package/kairotic/canvas.cljs +751 -0
- package/kairotic/code.cljs +108 -0
- package/kairotic/components.cljs +838 -0
- package/kairotic/core.cljs +96 -0
- package/kairotic/corefns.cljs +473 -0
- package/kairotic/docs.mjs +2 -0
- package/kairotic/engine.cljs +482 -0
- package/kairotic/examples.mjs +96 -0
- package/kairotic/faust.cljs +225 -0
- package/kairotic/help.cljs +1036 -0
- package/kairotic/hiccup.cljs +566 -0
- package/kairotic/input.cljs +271 -0
- package/kairotic/kfile.mjs +138 -0
- package/kairotic/library.cljs +214 -0
- package/kairotic/links.cljs +41 -0
- package/kairotic/mt.cljs +1604 -0
- package/kairotic/mtboxes.cljs +276 -0
- package/kairotic/packages/analysis.mjs +64 -0
- package/kairotic/packages/controls.mjs +28 -0
- package/kairotic/packages/data.mjs +22 -0
- package/kairotic/packages/faust-units/cmaes.mjs +82 -0
- package/kairotic/packages/faust-units/graph.mjs +212 -0
- package/kairotic/packages/faust-units/listen.mjs +125 -0
- package/kairotic/packages/faust-units/notation.mjs +139 -0
- package/kairotic/packages/faust-units/parse.mjs +439 -0
- package/kairotic/packages/faust-units/recipe.mjs +195 -0
- package/kairotic/packages/faust-units/render.mjs +69 -0
- package/kairotic/packages/faust-units/units.mjs +130 -0
- package/kairotic/packages/faust-units/view.mjs +353 -0
- package/kairotic/packages/faust-units.mjs +9 -0
- package/kairotic/packages/io.mjs +58 -0
- package/kairotic/packages/net.mjs +28 -0
- package/kairotic/packages/patterns.mjs +34 -0
- package/kairotic/packages/spatial.mjs +22 -0
- package/kairotic/packages/spectral/shift.mjs +169 -0
- package/kairotic/packages/spectral.mjs +16 -0
- package/kairotic/packages/synth.mjs +28 -0
- package/kairotic/packages/theory/counterpoint.mjs +798 -0
- package/kairotic/packages/theory/mirror.mjs +221 -0
- package/kairotic/packages/theory.mjs +46 -0
- package/kairotic/patterns.cljs +538 -0
- package/kairotic/presets.cljs +227 -0
- package/kairotic/quantize.cljs +782 -0
- package/kairotic/record.cljs +169 -0
- package/kairotic/release.cljs +90 -0
- package/kairotic/ring.cljs +129 -0
- package/kairotic/ringaudio.cljs +232 -0
- package/kairotic/ringcore.mjs +270 -0
- package/kairotic/score.cljs +176 -0
- package/kairotic/shapes.cljs +283 -0
- package/kairotic/signal.cljs +327 -0
- package/kairotic/sounds.cljs +565 -0
- package/kairotic/sounds.mjs +108 -0
- package/kairotic/span.cljs +129 -0
- package/kairotic/spell.cljs +281 -0
- package/kairotic/structure.cljs +145 -0
- package/kairotic/talk.cljs +115 -0
- package/kairotic/tempo.cljs +226 -0
- package/kairotic/treecanvas.cljs +299 -0
- package/kairotic/tutorials.mjs +1283 -0
- package/kairotic/vendor/codemirror.mjs +23 -0
- package/package.json +23 -4
- package/page/00-work.cljs +862 -0
- package/page/01-commands.cljs +1219 -0
- package/page/02-patch-view.cljs +1051 -0
- package/page/03-history-view.cljs +481 -0
- package/page/04-panels.cljs +448 -0
- package/page/05-gestures.cljs +1247 -0
- package/page/06-connection.cljs +219 -0
- package/page/07-claude.cljs +430 -0
- package/page/08-sessions.cljs +423 -0
- package/page/09-learn.cljs +602 -0
- package/page/10-embed.cljs +469 -0
- package/page/11-startup.cljs +61 -0
- package/page/12-feedback.cljs +172 -0
- package/page/13-perform.cljs +325 -0
- package/page/14-editor.cljs +656 -0
- package/page/15-presets.cljs +230 -0
- package/page/16-release.cljs +242 -0
- package/page/17-sounds.cljs +147 -0
- package/page/18-lines.cljs +594 -0
- package/page/19-files.cljs +247 -0
- package/page/19-html.cljs +152 -0
- package/page/20-talk.cljs +527 -0
- package/page/21-net.cljs +110 -0
- package/page/22-learn.cljs +303 -0
- package/page/23-ids.cljs +233 -0
- package/page/24-clipboard.cljs +136 -0
- package/page/25-tidy.cljs +74 -0
- package/page/26-probes.cljs +111 -0
- package/sources.mjs +2 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
;; SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
;; Kairotic · code boxes
|
|
3
|
+
;; The base of any programmable component: a box whose data is a source text in some
|
|
4
|
+
;; language. The text is part of the work (it travels through the history and the rooms); each tab
|
|
5
|
+
;; compiles it locally with the compiler registered for its language, and keeps the result in
|
|
6
|
+
;; a cache keyed by source. Faust and ClojureScript are the first two languages; others (JavaScript,
|
|
7
|
+
;; GLSL, a rule language…) only have to register their compiler and their component.
|
|
8
|
+
|
|
9
|
+
(ns kairotic.code
|
|
10
|
+
(:refer-clojure :exclude [empty])
|
|
11
|
+
(:require [clojure.string :as str]
|
|
12
|
+
[kairotic.components :as comp]))
|
|
13
|
+
|
|
14
|
+
;; ───────── data (with history) ─────────
|
|
15
|
+
|
|
16
|
+
(def empty {:source ""})
|
|
17
|
+
;; a code box may hold a whole package (a component box with every component of @kairotic/analysis is
|
|
18
|
+
;; about 26 000 characters): longer sources are cut, and cut code does not read
|
|
19
|
+
(def max-source 100000)
|
|
20
|
+
|
|
21
|
+
(defn step [d [op & args]]
|
|
22
|
+
(let [d (or d empty)]
|
|
23
|
+
(case op
|
|
24
|
+
:source (let [[s] args] (if (string? s) (assoc d :source (subs s 0 (min (count s) max-source))) d))
|
|
25
|
+
:load (let [[x] args] (if (and (map? x) (string? (:source x))) {:source (subs (:source x) 0 (min (count (:source x)) max-source))} d))
|
|
26
|
+
d)))
|
|
27
|
+
|
|
28
|
+
(defn ->code [id d]
|
|
29
|
+
(when (seq (str/trim (str (:source d))))
|
|
30
|
+
[(str "(code " id " " (pr-str (:source d)) ")")]))
|
|
31
|
+
|
|
32
|
+
(def model {:empty empty :step step :load (fn [x] (step empty [:load x])) :code ->code})
|
|
33
|
+
|
|
34
|
+
;; ───────── compilation ─────────
|
|
35
|
+
;; compilers: language → (fn [source] promise of {:value x :info {…}})
|
|
36
|
+
|
|
37
|
+
(defonce compilers (atom {}))
|
|
38
|
+
(defonce cache (atom {})) ; [language source] → {:status :compiling|:ok|:error :error :value :info :n}
|
|
39
|
+
(defonce listeners (atom {})) ; key → (fn []) to notify when a compilation finishes
|
|
40
|
+
(defonce counter (atom 0))
|
|
41
|
+
|
|
42
|
+
(defn notify! [] (doseq [[_ f] @listeners] (try (f) (catch :default e (js/console.error e)))))
|
|
43
|
+
|
|
44
|
+
(defn register-language! [language f] (swap! compilers assoc language f) language)
|
|
45
|
+
|
|
46
|
+
(defn prune! []
|
|
47
|
+
(when (> (count @cache) 60)
|
|
48
|
+
(swap! cache (fn [c] (into {} (take-last 40 (sort-by (fn [[_ v]] (:n v)) c)))))))
|
|
49
|
+
|
|
50
|
+
(defn compiled
|
|
51
|
+
"Compilation status of a source; if it has not been requested yet, requests it (and notifies when done)."
|
|
52
|
+
[language source]
|
|
53
|
+
(let [source (str source) k [language source]]
|
|
54
|
+
(cond
|
|
55
|
+
(str/blank? source) {:status :empty}
|
|
56
|
+
(get @cache k) (get @cache k)
|
|
57
|
+
:else
|
|
58
|
+
(if-let [f (get @compilers language)]
|
|
59
|
+
(let [n (swap! counter inc)]
|
|
60
|
+
(swap! cache assoc k {:status :compiling :n n})
|
|
61
|
+
(prune!)
|
|
62
|
+
(-> (js/Promise.resolve nil)
|
|
63
|
+
(.then (fn [_] (f source)))
|
|
64
|
+
(.then (fn [r] (swap! cache assoc k (assoc r :status :ok :n n)) (notify!)))
|
|
65
|
+
(.catch (fn [e] (swap! cache assoc k {:status :error :n n :error (or (.-message e) (str e))}) (notify!))))
|
|
66
|
+
(get @cache k))
|
|
67
|
+
{:status :error :error (str "No compiler for " language)}))))
|
|
68
|
+
|
|
69
|
+
(defn forget-language! [language]
|
|
70
|
+
(swap! cache (fn [c] (into {} (remove (fn [[[l _] _]] (= l language)) c)))))
|
|
71
|
+
|
|
72
|
+
;; ───────── script: ClojureScript inside the patch ─────────
|
|
73
|
+
;; The source is a function (fn [m] …) with the same contract as any component: it receives
|
|
74
|
+
;; {:inlet :value :state :args :at} and returns {:state :out [[o v]] :later … :effects …}.
|
|
75
|
+
;; A script runs its writer's code inside this page, so in a shared room
|
|
76
|
+
;; it is not evaluated until this tab allows it: (trust-scripts true).
|
|
77
|
+
|
|
78
|
+
(defonce trust (atom false))
|
|
79
|
+
;; sources this page brought itself from the official library (Study 22): they run without asking
|
|
80
|
+
(defonce trusted (atom #{}))
|
|
81
|
+
(defn allowed? [source] (or @trust (contains? @trusted source)))
|
|
82
|
+
|
|
83
|
+
(register-language! "clojurescript"
|
|
84
|
+
(fn [source]
|
|
85
|
+
(js/Promise.
|
|
86
|
+
(fn [res rej]
|
|
87
|
+
(if-not (allowed? source)
|
|
88
|
+
(rej (js/Error. "not run: this work is shared; (trust-scripts true) to evaluate its scripts"))
|
|
89
|
+
(try
|
|
90
|
+
(let [f (js/scittle.core.eval_string (str "(do " source "\n)"))]
|
|
91
|
+
(if (fn? f) (res {:value f :info {:summary "ready"}}) (rej (js/Error. "a script is a function (fn [m] …)"))))
|
|
92
|
+
(catch :default e (rej e))))))))
|
|
93
|
+
|
|
94
|
+
(defn whole [x d] (if (number? x) (max 0 (js/Math.round x)) d))
|
|
95
|
+
|
|
96
|
+
(comp/define! "script"
|
|
97
|
+
{:doc "ClojureScript code box: its source is a function (fn [m] …) that receives and returns messages like any component."
|
|
98
|
+
:usage "script [inlets] [outlets]"
|
|
99
|
+
:display :code :language "clojurescript" :model model
|
|
100
|
+
:io (fn [c] (let [[i o] (:args c)] [(max 1 (whole i 1)) (whole o 1)]))
|
|
101
|
+
:template "(fn [{:keys [inlet value state]}]\n ;; return {:out [[outlet value]] :state …}\n {:out [[0 value]]})"
|
|
102
|
+
:receive (fn [m]
|
|
103
|
+
(let [r (compiled "clojurescript" (get-in m [:data :source]))]
|
|
104
|
+
(if (= :ok (:status r))
|
|
105
|
+
(try
|
|
106
|
+
(let [x ((:value r) m)] (if (map? x) x {}))
|
|
107
|
+
(catch :default e {:effects [[:print (str "script: " (or (.-message e) e))]]}))
|
|
108
|
+
{})))})
|