aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-07-11 17:25:50 +0000
committers-ol <s-ol@users.noreply.github.com>2020-07-11 17:37:04 +0000
commitc6fa7aa7657647fffbbe8a0507e29bcd9a980dba (patch)
tree9b58942e0d5c2ad4be70fd7f628893e7f984dfc7
parentrename time/sequence to time/val-seq and add time/bang-seq (diff)
downloadalive-c6fa7aa7657647fffbbe8a0507e29bcd9a980dba.tar.gz
alive-c6fa7aa7657647fffbbe8a0507e29bcd9a980dba.zip
add vis field to Ops
-rw-r--r--alv-lib/midi.moon2
-rw-r--r--alv-lib/time.moon15
-rw-r--r--alv/base/op.moon16
-rw-r--r--alv/builtins.moon1
-rw-r--r--alv/copilot/udp.moon13
5 files changed, 30 insertions, 17 deletions
diff --git a/alv-lib/midi.moon b/alv-lib/midi.moon
index 3944392..30acc33 100644
--- a/alv-lib/midi.moon
+++ b/alv-lib/midi.moon
@@ -80,6 +80,7 @@ cc = Constant.meta
range: Input.cold range or Constant.str 'uni'
@out or= T.num\mk_sig apply_range @inputs.range, 0
+ @vis.bar = 0
tick: =>
{ :port, :cc, :chan, :range } = @inputs
@@ -88,6 +89,7 @@ cc = Constant.meta
(chan! == -1 or msg.chan == chan!) and
msg.a == cc!
@out\set apply_range range, msg.b
+ @vis.bar = msg.b / 127
{
:input
diff --git a/alv-lib/time.moon b/alv-lib/time.moon
index daa14ad..aeab467 100644
--- a/alv-lib/time.moon
+++ b/alv-lib/time.moon
@@ -110,6 +110,7 @@ lfo = Constant.meta
when 'saw' then @state % 1
when 'tri' then math.abs (2*@state % 2) - 1
else error Error 'argument', "unknown wave type '#{wave}'"
+ @vis.bar = @out!
ramp = Constant.meta
meta:
@@ -140,11 +141,12 @@ ramp = Constant.meta
{ :clock, :period, :max } = @unwrap_all!
max or= period
- @phase += clock.dt / period
- while @phase >= 1
- @phase -= 1
+ @state += clock.dt / period
+ while @state >= 1
+ @state -= 1
- @out\set @phase * max
+ @vis.bar = @state
+ @out\set @state * max
tick = Constant.meta
meta:
@@ -162,6 +164,7 @@ tick = Constant.meta
super ...
@state or= { phase: 0, count: 0 }
@out or= T.num\mk_sig @state.count
+ @vis.onchange = true
pattern = -evt.clock + sig.num
setup: (inputs, scope) =>
@@ -228,6 +231,7 @@ Emits `evt1`, `evt2`, … as events with delays `delay0`, `delay1`, … in betwe
new: (...) =>
super ...
@state or= { i: 1, t: 0 }
+ @vis.step = @state.i
pair = (sig! + sig.num)\named('value', 'delay')
pattern = -evt.clock + sig.num + pair*0
@@ -256,6 +260,7 @@ Emits `evt1`, `evt2`, … as events with delays `delay0`, `delay1`, … in betwe
if @state.t >= current.delay!
@state.t -= current.delay!
@state.i = 1 + (@state.i % #@inputs.steps)
+ @vis.step = @state.i
change = true
else
break
@@ -280,6 +285,7 @@ Emits `bang!`s with delays `delay0`, `delay1`, … in between.
super ...
@out = T.bang\mk_evt!
@state or= { i: 1, t: 0 }
+ @vis.step = @state.i
pattern = -evt.clock + sig.num*0
setup: (inputs, scope) =>
@@ -299,6 +305,7 @@ Emits `bang!`s with delays `delay0`, `delay1`, … in between.
if @state.t >= current
@state.t -= current
@state.i = 1 + (@state.i % #@inputs.steps)
+ @vis.step = @state.i
bang = true
else
break
diff --git a/alv/base/op.moon b/alv/base/op.moon
index b152543..625e1a8 100644
--- a/alv/base/op.moon
+++ b/alv/base/op.moon
@@ -22,7 +22,8 @@ class Op
fork: =>
out = if @out then @out\fork!
state = if @state then deep_copy @state
- @@ out, state
+ vis = if @vis then deep_copy @vis
+ @@ out, state, vis
--- internal state of this Op.
--
@@ -31,6 +32,16 @@ class Op
--
-- @tfield table state
+ --- visualisation data of this Op.
+ --
+ -- This may be any simple Lua value, including Lua tables, as long as it has
+ -- no metatables, multiple references/loops, userdata etc.
+ --
+ -- This value is exposed to alv editors in order to render realtime
+ -- visualisations overlaid onto the program text.
+ --
+ -- @tfield table vis
+
--- `Result` instance representing this Op's computed output value.
--
-- Must be set to a `Result` instance once `setup` finishes. Must not change
@@ -107,7 +118,8 @@ class Op
-- @classmethod
-- @tparam ?Result out `out`
-- @tparam ?table state `state`
- new: (@out, @state) =>
+ -- @tparam ?table vis `vis`
+ new: (@out, @state, @vis={}) =>
do_setup = (old, cur) ->
for k, cur_val in pairs cur
diff --git a/alv/builtins.moon b/alv/builtins.moon
index 9fffabc..12e78ba 100644
--- a/alv/builtins.moon
+++ b/alv/builtins.moon
@@ -331,6 +331,7 @@ switch_ = Constant.meta
when false then 1
else (math.floor i!) % #values
+ @vis.step = ii
@out\set if v = values[ii + 1] then v!
trace_ = Constant.meta
diff --git a/alv/copilot/udp.moon b/alv/copilot/udp.moon
index c0ea86e..5bf2ad4 100644
--- a/alv/copilot/udp.moon
+++ b/alv/copilot/udp.moon
@@ -2,7 +2,7 @@ import udp from require 'socket'
import encode, decode from require 'dkjson'
import fn_invoke, op_invoke from require 'alv.invoke'
-encode_res = (copilot) =>
+encode_res = =>
return unless @
{
@@ -45,22 +45,13 @@ class UDPServer
if builtin and builtin.__class.__name ~= 'DummyReg'
res.head_meta = builtin.head.meta
res.result = encode_res builtin.node.result
+ res.vis = if builtin.op then builtin.op.vis
res.kind = switch builtin.__class
when op_invoke then 'op'
when fn_invoke then 'fn'
else 'builtin'
else
res.error = 'not_registered'
- when 'state'
- res.tag = msg.tag
- res.module = msg.module or '__root'
- mod = @copilot.last_modules[res.module]
- builtin = mod.registry\last msg.tag
- if builtin and builtin.__class.__name ~= 'DummyReg'
- res.value = encode_res builtin.node.result, @copilot
- res.state = if builtin.op then builtin.op.state
- else
- res.error = 'not_registered'
else
res.error = 'unknown_type'
return res