@kairotic/controls 0.2.0 → 0.2.3

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/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  // Generated by packages/build.mjs
2
2
  export default {
3
3
  "package": "@kairotic/controls",
4
- "version": "0.2.0",
4
+ "version": "0.2.3",
5
5
  "api": 1,
6
6
  "author": "bonuoq",
7
7
  "license": "MPL-2.0",
@@ -21,8 +21,8 @@ export default {
21
21
  {
22
22
  "class": "scale",
23
23
  "license": "MPL-2.0",
24
- "doc": "A number from one range (in-lo…in-hi, 0…1 by default) to another (out-lo…out-hi): straight, or with log in equal ratios (for frequencies, a cutoff, a speed: equal moves are equal intervals); clipped to the range, and reversed when out-hi is under out-lo. With ms, it glides there in that time (a jumpy sensor made smooth). It takes a number, a list whose last element is the number ([:lx 0.3] from gamepad), or a map with :value. learn: the next values it gets make the input range (move the controller from end to end), learn off stops. Between a controller (control, knob, motion…) and whatever it moves.",
25
- "source": ";; scale · a number from one range to another, straight or logarithmic, smoothed if asked\n;; Part of @kairotic/controls. Written against the Kairotic API (api/…). Discussion #135.\n(let [lin (fn [v a b] (if (== a b) 0 (/ (- v a) (- b a))))\n out-of (fn [u {:keys [out-lo out-hi log]}]\n (let [u (api/clamp u 0 1)]\n (if (and log (pos? out-lo) (pos? out-hi))\n (* out-lo (js/Math.pow (/ out-hi out-lo) u))\n (+ out-lo (* u (- out-hi out-lo))))))\n ;; the number in a message: a number, the last number of a list ([:lx 0.3] from gamepad), or :value of a map\n number-in (fn [v] (cond (number? v) v\n (map? v) (let [x (:value v)] (when (number? x) x))\n (sequential? v) (let [x (last v)] (when (number? x) x))\n :else nil))\n tick 0.02]\n {;; ── about ──\n :class \"scale\"\n :license \"MPL-2.0\"\n :doc \"A number from one range (in-lo…in-hi, 0…1 by default) to another (out-lo…out-hi): straight, or with log in equal ratios (for frequencies, a cutoff, a speed: equal moves are equal intervals); clipped to the range, and reversed when out-hi is under out-lo. With ms, it glides there in that time (a jumpy sensor made smooth). It takes a number, a list whose last element is the number ([:lx 0.3] from gamepad), or a map with :value. learn: the next values it gets make the input range (move the controller from end to end), learn off stops. Between a controller (control, knob, motion…) and whatever it moves.\"\n :usage \"scale [in-lo in-hi out-lo out-hi] [log] [ms]\"\n :io [1 1]\n :size [130 24]\n :args [[:in-lo 0] [:in-hi 1] [:out-lo 0] [:out-hi 1] [:log false] [:ms 0]]\n :help {:inlets [\"a number (or [name value], or {:value v}); learn; learn off\"]\n :outlets [\"the number in the new range\"]\n :messages [[\"learn\" \"the next values make the input range\"] [\"learn off\" \"keeps the range learnt\"]]\n :example \"(box :b1 \\\"knob\\\" 40 30)\\n(box :b2 \\\"scale 0 1 220 880 log 200\\\" 40 120)\\n(box :b3 \\\"number\\\" 40 160)\\n(connect :b1 0 :b2 0)\\n(connect :b2 0 :b3 0)\"\n :try \"Turn the knob: 220 to 880 Hz in equal steps of pitch, gliding 200 ms.\"\n :see [\"control\" \"knob\" \"mtof\"]}\n\n ;; ── logic ──\n :receive (fn [{:keys [inlet value state args at]}]\n (let [st (or state {})\n lo (or (:lo st) (:in-lo args)) hi (or (:hi st) (:in-hi args))\n ms (max 0 (:ms args))]\n (cond\n (#{:learn \"learn\"} value) {:state (assoc st :learning true :lo nil :hi nil :seen nil) :show {:learn true}}\n (and (sequential? value) (#{:learn \"learn\"} (first value)) (#{:off \"off\" 0} (second value)))\n {:state (dissoc st :learning) :show {:learn false}}\n ;; a glide: one step of it, scheduled to itself\n (and (= inlet 0) (vector? value) (= :scale-step (first value)))\n (let [[_ gen] value]\n (if (and (= gen (:gen st)) (:target st))\n (let [k (min 1 (/ tick (max 0.001 (/ ms 1000))))\n cur (+ (:cur st) (* k (- (:target st) (:cur st))))\n done (< (js/Math.abs (- (:target st) cur)) (* 1e-4 (max 1 (js/Math.abs (:target st)))))\n cur (if done (:target st) cur)]\n (cond-> {:state (assoc st :cur cur) :out [[0 (api/nice cur)]] :show {:v cur}}\n (not done) (assoc :later [[(+ at tick) 0 [:scale-step gen]]])))\n {:state st}))\n :else\n (if-let [v (number-in value)]\n (let [st (if (:learning st)\n (let [s (vec (take-last 512 (conj (or (:seen st) []) v)))]\n (assoc st :seen s :lo (apply min s) :hi (apply max s)))\n st)\n lo (or (:lo st) (:in-lo args)) hi (or (:hi st) (:in-hi args))\n target (out-of (lin v lo hi) args)]\n (if (and (pos? ms) (number? (:cur st)))\n (let [gen (inc (or (:gen st) 0))]\n {:state (assoc st :target target :gen gen) :later [[(+ at tick) 0 [:scale-step gen]]] :show {:v (:cur st)}})\n {:state (assoc st :cur target :target target) :out [[0 (api/nice target)]] :show {:v target}}))\n {:state st}))))\n\n ;; ── view ──\n :derive (fn [{:keys [shown args]}]\n {:label (str (if (:learn shown) \"learning… \" \"\")\n (api/nice (:in-lo args)) \"…\" (api/nice (:in-hi args)) \" → \" (api/nice (:out-lo args)) \"…\" (api/nice (:out-hi args))\n (when (:log args) \" log\"))\n :w (* 126 (api/clamp (if (number? (:v shown)) (lin (:v shown) (:out-lo args) (:out-hi args)) 0) 0 1))})\n :view [[:rect {:x 1 :y 1 :w 128 :h 22 :r 3 :stroke :accent :fill :bg}]\n [:rect {:x 2 :y 19 :w :$w :h 3 :r 1 :stroke nil :fill :accent}]\n [:text {:x 6 :y 15 :size 10.5} :$label]]})\n"
24
+ "doc": "A number from one range (in-lo…in-hi, 0…1 by default) to another (out-lo…out-hi): straight, or with log in equal ratios (for frequencies, a cutoff, a speed: equal moves are equal intervals); clipped to the range, and reversed when out-hi is under out-lo. With ms, it glides there in that time (a jumpy sensor made smooth). It takes a number, a list whose last element is the number ([:lx 0.3] from gamepad), or a map with :value. :learn: the next values it gets make the input range (move the controller from end to end), :learn :off stops. Between a controller (control, knob, motion…) and whatever it moves.",
25
+ "source": ";; scale · a number from one range to another, straight or logarithmic, smoothed if asked\n;; Part of @kairotic/controls. Written against the Kairotic API (api/…). Discussion #135.\n(let [lin (fn [v a b] (if (== a b) 0 (/ (- v a) (- b a))))\n out-of (fn [u {:keys [out-lo out-hi log]}]\n (let [u (api/clamp u 0 1)]\n (if (and log (pos? out-lo) (pos? out-hi))\n (* out-lo (js/Math.pow (/ out-hi out-lo) u))\n (+ out-lo (* u (- out-hi out-lo))))))\n ;; the number in a message: a number, the last number of a list ([:lx 0.3] from gamepad), or :value of a map\n number-in (fn [v] (cond (number? v) v\n (map? v) (let [x (:value v)] (when (number? x) x))\n (sequential? v) (let [x (last v)] (when (number? x) x))\n :else nil))\n tick 0.02]\n {;; ── about ──\n :class \"scale\"\n :license \"MPL-2.0\"\n :doc \"A number from one range (in-lo…in-hi, 0…1 by default) to another (out-lo…out-hi): straight, or with log in equal ratios (for frequencies, a cutoff, a speed: equal moves are equal intervals); clipped to the range, and reversed when out-hi is under out-lo. With ms, it glides there in that time (a jumpy sensor made smooth). It takes a number, a list whose last element is the number ([:lx 0.3] from gamepad), or a map with :value. :learn: the next values it gets make the input range (move the controller from end to end), :learn :off stops. Between a controller (control, knob, motion…) and whatever it moves.\"\n :usage \"scale [in-lo in-hi out-lo out-hi] [log] [ms]\"\n :io [1 1]\n :size [130 24]\n :args [[:in-lo 0] [:in-hi 1] [:out-lo 0] [:out-hi 1] [:log false] [:ms 0]]\n :help {:inlets [\"a number (or [name value], or {:value v}); :learn; :learn :off\"]\n :outlets [\"the number in the new range\"]\n :messages [[\":learn\" \"the next values make the input range\"] [\":learn :off\" \"keeps the range learnt\"]]\n :example \"(box :b1 \\\"knob\\\" 40 30)\\n(box :b2 \\\"scale 0 1 220 880 log 200\\\" 40 120)\\n(box :b3 \\\"number\\\" 40 160)\\n(connect :b1 0 :b2 0)\\n(connect :b2 0 :b3 0)\"\n :try \"Turn the knob: 220 to 880 Hz in equal steps of pitch, gliding 200 ms.\"\n :see [\"control\" \"knob\" \"mtof\"]}\n\n ;; ── logic ──\n :receive (fn [{:keys [inlet value state args at]}]\n (let [st (or state {})\n lo (or (:lo st) (:in-lo args)) hi (or (:hi st) (:in-hi args))\n ms (max 0 (:ms args))]\n (cond\n (#{:learn} value) {:state (assoc st :learning true :lo nil :hi nil :seen nil) :show {:learn true}}\n (and (sequential? value) (#{:learn} (first value)) (#{:off 0} (second value)))\n {:state (dissoc st :learning) :show {:learn false}}\n ;; a glide: one step of it, scheduled to itself\n (and (= inlet 0) (vector? value) (= :scale-step (first value)))\n (let [[_ gen] value]\n (if (and (= gen (:gen st)) (:target st))\n (let [k (min 1 (/ tick (max 0.001 (/ ms 1000))))\n cur (+ (:cur st) (* k (- (:target st) (:cur st))))\n done (< (js/Math.abs (- (:target st) cur)) (* 1e-4 (max 1 (js/Math.abs (:target st)))))\n cur (if done (:target st) cur)]\n (cond-> {:state (assoc st :cur cur) :out [[0 (api/nice cur)]] :show {:v cur}}\n (not done) (assoc :later [[(+ at tick) 0 [:scale-step gen]]])))\n {:state st}))\n :else\n (if-let [v (number-in value)]\n (let [st (if (:learning st)\n (let [s (vec (take-last 512 (conj (or (:seen st) []) v)))]\n (assoc st :seen s :lo (apply min s) :hi (apply max s)))\n st)\n lo (or (:lo st) (:in-lo args)) hi (or (:hi st) (:in-hi args))\n target (out-of (lin v lo hi) args)]\n (if (and (pos? ms) (number? (:cur st)))\n (let [gen (inc (or (:gen st) 0))]\n {:state (assoc st :target target :gen gen) :later [[(+ at tick) 0 [:scale-step gen]]] :show {:v (:cur st)}})\n {:state (assoc st :cur target :target target) :out [[0 (api/nice target)]] :show {:v target}}))\n {:state st}))))\n\n ;; ── view ──\n :derive (fn [{:keys [shown args]}]\n {:label (str (if (:learn shown) \"learning… \" \"\")\n (api/nice (:in-lo args)) \"…\" (api/nice (:in-hi args)) \" → \" (api/nice (:out-lo args)) \"…\" (api/nice (:out-hi args))\n (when (:log args) \" log\"))\n :w (* 126 (api/clamp (if (number? (:v shown)) (lin (:v shown) (:out-lo args) (:out-hi args)) 0) 0 1))})\n :view [[:rect {:x 1 :y 1 :w 128 :h 22 :r 3 :stroke :accent :fill :bg}]\n [:rect {:x 2 :y 19 :w :$w :h 3 :r 1 :stroke nil :fill :accent}]\n [:text {:x 6 :y 15 :size 10.5} :$label]]})\n"
26
26
  }
27
27
  ]
28
28
  };
package/dist/keyboard.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  // Generated by packages/build.mjs from src/keyboard.cljs
2
2
  export default {
3
3
  "class": "keyboard",
4
- "version": "0.2.0",
4
+ "version": "0.2.3",
5
5
  "author": "bonuoq",
6
6
  "license": "MPL-2.0",
7
7
  "doc": "Virtual MIDI keyboard. Press a key to play it and let go to release it; dragging glides from key to key. ⇧-click toggles a note in a chord that stays after mouse up (⇧-drag adds every key it passes); a plain click starts over; the strip above the keys releases everything. With the word hold every note stays (a latch) until the strip is clicked. Where the key is touched sets the velocity: soft at the top, full at the bottom. Outlets: Hz (0, most recent note first), voice ids = the MIDI numbers (1), gate (2), [:gain velocity] (3). For synth~ connect 0→0 and 1→1; for faust~ connect 0 and 3 to its left inlet.",
package/dist/knob.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  // Generated by packages/build.mjs from src/knob.cljs
2
2
  export default {
3
3
  "class": "knob",
4
- "version": "0.2.0",
4
+ "version": "0.2.3",
5
5
  "author": "bonuoq",
6
6
  "license": "MPL-2.0",
7
7
  "doc": "Rotary knob: drag it up or down (⇧ for fine control). Sends its value between min and max; with log the travel is logarithmic (frequencies), and with a name it sends [:name value] (e.g. a faust~ parameter). A number sets it and sends it on; a bang sends it again.",
package/dist/scale.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  // Generated by packages/build.mjs from src/scale.cljs
2
2
  export default {
3
3
  "class": "scale",
4
- "version": "0.2.0",
4
+ "version": "0.2.3",
5
5
  "author": "bonuoq",
6
6
  "license": "MPL-2.0",
7
- "doc": "A number from one range (in-lo…in-hi, 0…1 by default) to another (out-lo…out-hi): straight, or with log in equal ratios (for frequencies, a cutoff, a speed: equal moves are equal intervals); clipped to the range, and reversed when out-hi is under out-lo. With ms, it glides there in that time (a jumpy sensor made smooth). It takes a number, a list whose last element is the number ([:lx 0.3] from gamepad), or a map with :value. learn: the next values it gets make the input range (move the controller from end to end), learn off stops. Between a controller (control, knob, motion…) and whatever it moves.",
8
- "source": ";; scale · a number from one range to another, straight or logarithmic, smoothed if asked\n;; Part of @kairotic/controls. Written against the Kairotic API (api/…). Discussion #135.\n(let [lin (fn [v a b] (if (== a b) 0 (/ (- v a) (- b a))))\n out-of (fn [u {:keys [out-lo out-hi log]}]\n (let [u (api/clamp u 0 1)]\n (if (and log (pos? out-lo) (pos? out-hi))\n (* out-lo (js/Math.pow (/ out-hi out-lo) u))\n (+ out-lo (* u (- out-hi out-lo))))))\n ;; the number in a message: a number, the last number of a list ([:lx 0.3] from gamepad), or :value of a map\n number-in (fn [v] (cond (number? v) v\n (map? v) (let [x (:value v)] (when (number? x) x))\n (sequential? v) (let [x (last v)] (when (number? x) x))\n :else nil))\n tick 0.02]\n {;; ── about ──\n :class \"scale\"\n :license \"MPL-2.0\"\n :doc \"A number from one range (in-lo…in-hi, 0…1 by default) to another (out-lo…out-hi): straight, or with log in equal ratios (for frequencies, a cutoff, a speed: equal moves are equal intervals); clipped to the range, and reversed when out-hi is under out-lo. With ms, it glides there in that time (a jumpy sensor made smooth). It takes a number, a list whose last element is the number ([:lx 0.3] from gamepad), or a map with :value. learn: the next values it gets make the input range (move the controller from end to end), learn off stops. Between a controller (control, knob, motion…) and whatever it moves.\"\n :usage \"scale [in-lo in-hi out-lo out-hi] [log] [ms]\"\n :io [1 1]\n :size [130 24]\n :args [[:in-lo 0] [:in-hi 1] [:out-lo 0] [:out-hi 1] [:log false] [:ms 0]]\n :help {:inlets [\"a number (or [name value], or {:value v}); learn; learn off\"]\n :outlets [\"the number in the new range\"]\n :messages [[\"learn\" \"the next values make the input range\"] [\"learn off\" \"keeps the range learnt\"]]\n :example \"(box :b1 \\\"knob\\\" 40 30)\\n(box :b2 \\\"scale 0 1 220 880 log 200\\\" 40 120)\\n(box :b3 \\\"number\\\" 40 160)\\n(connect :b1 0 :b2 0)\\n(connect :b2 0 :b3 0)\"\n :try \"Turn the knob: 220 to 880 Hz in equal steps of pitch, gliding 200 ms.\"\n :see [\"control\" \"knob\" \"mtof\"]}\n\n ;; ── logic ──\n :receive (fn [{:keys [inlet value state args at]}]\n (let [st (or state {})\n lo (or (:lo st) (:in-lo args)) hi (or (:hi st) (:in-hi args))\n ms (max 0 (:ms args))]\n (cond\n (#{:learn \"learn\"} value) {:state (assoc st :learning true :lo nil :hi nil :seen nil) :show {:learn true}}\n (and (sequential? value) (#{:learn \"learn\"} (first value)) (#{:off \"off\" 0} (second value)))\n {:state (dissoc st :learning) :show {:learn false}}\n ;; a glide: one step of it, scheduled to itself\n (and (= inlet 0) (vector? value) (= :scale-step (first value)))\n (let [[_ gen] value]\n (if (and (= gen (:gen st)) (:target st))\n (let [k (min 1 (/ tick (max 0.001 (/ ms 1000))))\n cur (+ (:cur st) (* k (- (:target st) (:cur st))))\n done (< (js/Math.abs (- (:target st) cur)) (* 1e-4 (max 1 (js/Math.abs (:target st)))))\n cur (if done (:target st) cur)]\n (cond-> {:state (assoc st :cur cur) :out [[0 (api/nice cur)]] :show {:v cur}}\n (not done) (assoc :later [[(+ at tick) 0 [:scale-step gen]]])))\n {:state st}))\n :else\n (if-let [v (number-in value)]\n (let [st (if (:learning st)\n (let [s (vec (take-last 512 (conj (or (:seen st) []) v)))]\n (assoc st :seen s :lo (apply min s) :hi (apply max s)))\n st)\n lo (or (:lo st) (:in-lo args)) hi (or (:hi st) (:in-hi args))\n target (out-of (lin v lo hi) args)]\n (if (and (pos? ms) (number? (:cur st)))\n (let [gen (inc (or (:gen st) 0))]\n {:state (assoc st :target target :gen gen) :later [[(+ at tick) 0 [:scale-step gen]]] :show {:v (:cur st)}})\n {:state (assoc st :cur target :target target) :out [[0 (api/nice target)]] :show {:v target}}))\n {:state st}))))\n\n ;; ── view ──\n :derive (fn [{:keys [shown args]}]\n {:label (str (if (:learn shown) \"learning… \" \"\")\n (api/nice (:in-lo args)) \"…\" (api/nice (:in-hi args)) \" → \" (api/nice (:out-lo args)) \"…\" (api/nice (:out-hi args))\n (when (:log args) \" log\"))\n :w (* 126 (api/clamp (if (number? (:v shown)) (lin (:v shown) (:out-lo args) (:out-hi args)) 0) 0 1))})\n :view [[:rect {:x 1 :y 1 :w 128 :h 22 :r 3 :stroke :accent :fill :bg}]\n [:rect {:x 2 :y 19 :w :$w :h 3 :r 1 :stroke nil :fill :accent}]\n [:text {:x 6 :y 15 :size 10.5} :$label]]})\n"
7
+ "doc": "A number from one range (in-lo…in-hi, 0…1 by default) to another (out-lo…out-hi): straight, or with log in equal ratios (for frequencies, a cutoff, a speed: equal moves are equal intervals); clipped to the range, and reversed when out-hi is under out-lo. With ms, it glides there in that time (a jumpy sensor made smooth). It takes a number, a list whose last element is the number ([:lx 0.3] from gamepad), or a map with :value. :learn: the next values it gets make the input range (move the controller from end to end), :learn :off stops. Between a controller (control, knob, motion…) and whatever it moves.",
8
+ "source": ";; scale · a number from one range to another, straight or logarithmic, smoothed if asked\n;; Part of @kairotic/controls. Written against the Kairotic API (api/…). Discussion #135.\n(let [lin (fn [v a b] (if (== a b) 0 (/ (- v a) (- b a))))\n out-of (fn [u {:keys [out-lo out-hi log]}]\n (let [u (api/clamp u 0 1)]\n (if (and log (pos? out-lo) (pos? out-hi))\n (* out-lo (js/Math.pow (/ out-hi out-lo) u))\n (+ out-lo (* u (- out-hi out-lo))))))\n ;; the number in a message: a number, the last number of a list ([:lx 0.3] from gamepad), or :value of a map\n number-in (fn [v] (cond (number? v) v\n (map? v) (let [x (:value v)] (when (number? x) x))\n (sequential? v) (let [x (last v)] (when (number? x) x))\n :else nil))\n tick 0.02]\n {;; ── about ──\n :class \"scale\"\n :license \"MPL-2.0\"\n :doc \"A number from one range (in-lo…in-hi, 0…1 by default) to another (out-lo…out-hi): straight, or with log in equal ratios (for frequencies, a cutoff, a speed: equal moves are equal intervals); clipped to the range, and reversed when out-hi is under out-lo. With ms, it glides there in that time (a jumpy sensor made smooth). It takes a number, a list whose last element is the number ([:lx 0.3] from gamepad), or a map with :value. :learn: the next values it gets make the input range (move the controller from end to end), :learn :off stops. Between a controller (control, knob, motion…) and whatever it moves.\"\n :usage \"scale [in-lo in-hi out-lo out-hi] [log] [ms]\"\n :io [1 1]\n :size [130 24]\n :args [[:in-lo 0] [:in-hi 1] [:out-lo 0] [:out-hi 1] [:log false] [:ms 0]]\n :help {:inlets [\"a number (or [name value], or {:value v}); :learn; :learn :off\"]\n :outlets [\"the number in the new range\"]\n :messages [[\":learn\" \"the next values make the input range\"] [\":learn :off\" \"keeps the range learnt\"]]\n :example \"(box :b1 \\\"knob\\\" 40 30)\\n(box :b2 \\\"scale 0 1 220 880 log 200\\\" 40 120)\\n(box :b3 \\\"number\\\" 40 160)\\n(connect :b1 0 :b2 0)\\n(connect :b2 0 :b3 0)\"\n :try \"Turn the knob: 220 to 880 Hz in equal steps of pitch, gliding 200 ms.\"\n :see [\"control\" \"knob\" \"mtof\"]}\n\n ;; ── logic ──\n :receive (fn [{:keys [inlet value state args at]}]\n (let [st (or state {})\n lo (or (:lo st) (:in-lo args)) hi (or (:hi st) (:in-hi args))\n ms (max 0 (:ms args))]\n (cond\n (#{:learn} value) {:state (assoc st :learning true :lo nil :hi nil :seen nil) :show {:learn true}}\n (and (sequential? value) (#{:learn} (first value)) (#{:off 0} (second value)))\n {:state (dissoc st :learning) :show {:learn false}}\n ;; a glide: one step of it, scheduled to itself\n (and (= inlet 0) (vector? value) (= :scale-step (first value)))\n (let [[_ gen] value]\n (if (and (= gen (:gen st)) (:target st))\n (let [k (min 1 (/ tick (max 0.001 (/ ms 1000))))\n cur (+ (:cur st) (* k (- (:target st) (:cur st))))\n done (< (js/Math.abs (- (:target st) cur)) (* 1e-4 (max 1 (js/Math.abs (:target st)))))\n cur (if done (:target st) cur)]\n (cond-> {:state (assoc st :cur cur) :out [[0 (api/nice cur)]] :show {:v cur}}\n (not done) (assoc :later [[(+ at tick) 0 [:scale-step gen]]])))\n {:state st}))\n :else\n (if-let [v (number-in value)]\n (let [st (if (:learning st)\n (let [s (vec (take-last 512 (conj (or (:seen st) []) v)))]\n (assoc st :seen s :lo (apply min s) :hi (apply max s)))\n st)\n lo (or (:lo st) (:in-lo args)) hi (or (:hi st) (:in-hi args))\n target (out-of (lin v lo hi) args)]\n (if (and (pos? ms) (number? (:cur st)))\n (let [gen (inc (or (:gen st) 0))]\n {:state (assoc st :target target :gen gen) :later [[(+ at tick) 0 [:scale-step gen]]] :show {:v (:cur st)}})\n {:state (assoc st :cur target :target target) :out [[0 (api/nice target)]] :show {:v target}}))\n {:state st}))))\n\n ;; ── view ──\n :derive (fn [{:keys [shown args]}]\n {:label (str (if (:learn shown) \"learning… \" \"\")\n (api/nice (:in-lo args)) \"…\" (api/nice (:in-hi args)) \" → \" (api/nice (:out-lo args)) \"…\" (api/nice (:out-hi args))\n (when (:log args) \" log\"))\n :w (* 126 (api/clamp (if (number? (:v shown)) (lin (:v shown) (:out-lo args) (:out-hi args)) 0) 0 1))})\n :view [[:rect {:x 1 :y 1 :w 128 :h 22 :r 3 :stroke :accent :fill :bg}]\n [:rect {:x 2 :y 19 :w :$w :h 3 :r 1 :stroke nil :fill :accent}]\n [:text {:x 6 :y 15 :size 10.5} :$label]]})\n"
9
9
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kairotic/controls",
3
- "version": "0.2.0",
3
+ "version": "0.2.3",
4
4
  "description": "Kairotic control components: knob (a rotary control), keyboard (a virtual MIDI keyboard) and scale (a number from one range to another), with their own views in the patch",
5
5
  "author": "bonuoq",
6
6
  "license": "MPL-2.0",
package/src/scale.cljs CHANGED
@@ -15,14 +15,14 @@
15
15
  {;; ── about ──
16
16
  :class "scale"
17
17
  :license "MPL-2.0"
18
- :doc "A number from one range (in-lo…in-hi, 0…1 by default) to another (out-lo…out-hi): straight, or with log in equal ratios (for frequencies, a cutoff, a speed: equal moves are equal intervals); clipped to the range, and reversed when out-hi is under out-lo. With ms, it glides there in that time (a jumpy sensor made smooth). It takes a number, a list whose last element is the number ([:lx 0.3] from gamepad), or a map with :value. learn: the next values it gets make the input range (move the controller from end to end), learn off stops. Between a controller (control, knob, motion…) and whatever it moves."
18
+ :doc "A number from one range (in-lo…in-hi, 0…1 by default) to another (out-lo…out-hi): straight, or with log in equal ratios (for frequencies, a cutoff, a speed: equal moves are equal intervals); clipped to the range, and reversed when out-hi is under out-lo. With ms, it glides there in that time (a jumpy sensor made smooth). It takes a number, a list whose last element is the number ([:lx 0.3] from gamepad), or a map with :value. :learn: the next values it gets make the input range (move the controller from end to end), :learn :off stops. Between a controller (control, knob, motion…) and whatever it moves."
19
19
  :usage "scale [in-lo in-hi out-lo out-hi] [log] [ms]"
20
20
  :io [1 1]
21
21
  :size [130 24]
22
22
  :args [[:in-lo 0] [:in-hi 1] [:out-lo 0] [:out-hi 1] [:log false] [:ms 0]]
23
- :help {:inlets ["a number (or [name value], or {:value v}); learn; learn off"]
23
+ :help {:inlets ["a number (or [name value], or {:value v}); :learn; :learn :off"]
24
24
  :outlets ["the number in the new range"]
25
- :messages [["learn" "the next values make the input range"] ["learn off" "keeps the range learnt"]]
25
+ :messages [[":learn" "the next values make the input range"] [":learn :off" "keeps the range learnt"]]
26
26
  :example "(box :b1 \"knob\" 40 30)\n(box :b2 \"scale 0 1 220 880 log 200\" 40 120)\n(box :b3 \"number\" 40 160)\n(connect :b1 0 :b2 0)\n(connect :b2 0 :b3 0)"
27
27
  :try "Turn the knob: 220 to 880 Hz in equal steps of pitch, gliding 200 ms."
28
28
  :see ["control" "knob" "mtof"]}
@@ -33,8 +33,8 @@
33
33
  lo (or (:lo st) (:in-lo args)) hi (or (:hi st) (:in-hi args))
34
34
  ms (max 0 (:ms args))]
35
35
  (cond
36
- (#{:learn "learn"} value) {:state (assoc st :learning true :lo nil :hi nil :seen nil) :show {:learn true}}
37
- (and (sequential? value) (#{:learn "learn"} (first value)) (#{:off "off" 0} (second value)))
36
+ (#{:learn} value) {:state (assoc st :learning true :lo nil :hi nil :seen nil) :show {:learn true}}
37
+ (and (sequential? value) (#{:learn} (first value)) (#{:off 0} (second value)))
38
38
  {:state (dissoc st :learning) :show {:learn false}}
39
39
  ;; a glide: one step of it, scheduled to itself
40
40
  (and (= inlet 0) (vector? value) (= :scale-step (first value)))