aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-05-12 15:05:45 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:23:21 +0000
commitae6a5ba773f4a3a82e1a44518c9b240c06c61a9e (patch)
treeecf2c16e9c3e76fb7d8386e577e7f0bc7f1d389a
parentEvtStream:set(nil) doesnt set :dirty (diff)
downloadalive-ae6a5ba773f4a3a82e1a44518c9b240c06c61a9e.tar.gz
alive-ae6a5ba773f4a3a82e1a44518c9b240c06c61a9e.zip
fix alv-lib
-rw-r--r--alv-lib/midi.moon19
-rw-r--r--alv-lib/midi/launchctl.moon44
-rw-r--r--alv-lib/osc.moon4
-rw-r--r--alv-lib/pilot.moon4
-rw-r--r--alv-lib/time.moon32
-rw-r--r--alv-lib/util.moon20
6 files changed, 52 insertions, 71 deletions
diff --git a/alv-lib/midi.moon b/alv-lib/midi.moon
index e3bbe01..503b91c 100644
--- a/alv-lib/midi.moon
+++ b/alv-lib/midi.moon
@@ -23,13 +23,12 @@ gate = Constant.meta
if note\dirty! or chan\dirty!
@out\set false
- if port\dirty!
- for msg in *port!
- if msg.a == note! and (chan! == -1 or msg.chan == chan!)
- if msg.status == 'note-on'
- @out\set true
- elseif msg.status == 'note-off'
- @out\set false
+ if msg = port!
+ if msg.a == note! and (chan! == -1 or msg.chan == chan!)
+ if msg.status == 'note-on'
+ @out\set true
+ elseif msg.status == 'note-off'
+ @out\set false
trig = Constant.meta
meta:
@@ -50,10 +49,10 @@ trig = Constant.meta
tick: =>
{ :port, :note, :chan } = @inputs
- for msg in *port!
+ if msg = port!
if msg.a == note! and (chan! == -1 or msg.chan == chan!)
if msg.status == 'note-on'
- @out\add true
+ @out\set true
cc = Constant.meta
meta:
@@ -83,7 +82,7 @@ cc = Constant.meta
tick: =>
{ :port, :cc, :chan, :range } = @inputs
- for msg in *port!
+ if msg = port!
if msg.status == 'control-change' and
(chan! == -1 or msg.chan == chan!) and
msg.a == cc!
diff --git a/alv-lib/midi/launchctl.moon b/alv-lib/midi/launchctl.moon
index 3f47a5d..f3c0295 100644
--- a/alv-lib/midi/launchctl.moon
+++ b/alv-lib/midi/launchctl.moon
@@ -48,15 +48,13 @@ range can be one of:
table.remove @state
curr_i = i! % #@state
- if port\dirty!
- changed = false
- for msg in *port!
- if msg.status == 'control-change' and msg.chan == chan!
- rel_i = msg.a - start!
- if rel_i >= 0 and rel_i < #@state
- @state[rel_i+1] = msg.b
- changed = rel_i == curr_i
- @out\set apply_range range, @state[curr_i+1] if changed
+ if msg = port!
+ if msg.status == 'control-change' and msg.chan == chan!
+ rel_i = msg.a - start!
+ if rel_i >= 0 and rel_i < #@state
+ @state[rel_i+1] = msg.b
+ if rel_i == curr_i
+ @out\set apply_range range, @state[curr_i+1]
else
@out\set apply_range range, @state[curr_i+1]
@@ -107,13 +105,12 @@ Send `true` or `false` for the `i`-th note-button (MIDI-notes starting from
curr_i = i! % #@state
- if port\dirty!
- for msg in *port!
- if msg.status == 'note-on' and msg.chan == chan!
- rel_i = msg.a - start!
- if rel_i >= 0 and rel_i < #@state
- @state[rel_i+1] = not @state[rel_i+1]
- @display rel_i, rel_i == curr_i
+ if msg = port!
+ if msg.status == 'note-on' and msg.chan == chan!
+ rel_i = msg.a - start!
+ if rel_i >= 0 and rel_i < #@state
+ @state[rel_i+1] = not @state[rel_i+1]
+ @display rel_i, rel_i == curr_i
if i\dirty!
prev_i = (curr_i - 1) % #@state
@@ -170,13 +167,12 @@ Send bangs for the `i`-th note-button (MIDI-notes starting from `start`).
curr_i = i! % #@state
- if port\dirty!
- for msg in *port!
- if msg.status == 'note-on' and msg.chan == chan!
- rel_i = msg.a - start!
- if rel_i >= 0 and rel_i < #@state
- @state[rel_i+1] = not @state[rel_i+1]
- @display rel_i, rel_i == curr_i
+ if msg = port!
+ if msg.status == 'note-on' and msg.chan == chan!
+ rel_i = msg.a - start!
+ if rel_i >= 0 and rel_i < #@state
+ @state[rel_i+1] = not @state[rel_i+1]
+ @display rel_i, rel_i == curr_i
if i\dirty!
prev_i = (curr_i - 1) % #@state
@@ -185,7 +181,7 @@ Send bangs for the `i`-th note-button (MIDI-notes starting from `start`).
@display prev_i, false
if @state[curr_i+1]
- @out\add true
+ @out\set true
{
'cc-seq': cc_seq
diff --git a/alv-lib/osc.moon b/alv-lib/osc.moon
index bbf07a1..97c955b 100644
--- a/alv-lib/osc.moon
+++ b/alv-lib/osc.moon
@@ -48,8 +48,8 @@ send = Constant.meta
tick: =>
{ :socket, :path, :value } = @unwrap_all!
- for val in *value
- msg = pack path, if 'table' == type val then unpack val else val
+ if value
+ msg = pack path, if 'table' == type value then unpack value else value
socket\send msg
sync = Constant.meta
diff --git a/alv-lib/pilot.moon b/alv-lib/pilot.moon
index e2103c6..fb68121 100644
--- a/alv-lib/pilot.moon
+++ b/alv-lib/pilot.moon
@@ -37,9 +37,7 @@ play = Constant.meta
args: [Input.cold a for a in *args]
tick: =>
- { :trig, :args } = @inputs
- for _ in *trig!
- send [a! for a in *@inputs.args]
+ send @unwrap_all!.args
play_ = Constant.meta
meta:
diff --git a/alv-lib/time.moon b/alv-lib/time.moon
index 5818c31..c79c430 100644
--- a/alv-lib/time.moon
+++ b/alv-lib/time.moon
@@ -14,7 +14,7 @@ class Clock extends IOStream
time = monotime!
@dt = time - @last
if @dt >= @frametime
- @add { dt: @dt, :time }
+ @set { dt: @dt, :time }
@last = time
class ScaledClock extends EvtStream
@@ -68,9 +68,8 @@ scale_time = Constant.meta
scale: Input.cold scale
tick: =>
- scale = @inputs.scale!
- for evt in *@inputs.clock!
- @out\add {k, v*scale for k,v in pairs evt}
+ { :clock, :scale } = @unwrap_all!
+ @out\set {k, v*scale for k,v in pairs clock}
lfo = Constant.meta
meta:
@@ -103,7 +102,7 @@ lfo = Constant.meta
tau = math.pi * 2
tick: =>
- for tick in *@inputs.clock!
+ if tick = @inputs.clock!
@state += tick.dt * @inputs.freq!
@out\set switch @inputs.wave!
@@ -138,11 +137,10 @@ ramp = Constant.meta
max: max and Input.cold max
tick: =>
- for tick in *@inputs.clock!
- period = @inputs.period!
- max = (@inputs.max or @inputs.period)!
- @phase += tick.dt / period
+ { :clock, :period, :max } = @unwrap_all!
+ max or= period
+ @phase += clock.dt / period
while @phase >= 1
@phase -= 1
@@ -173,10 +171,9 @@ tick = Constant.meta
period: Input.cold period
tick: =>
- for tick in *@inputs.clock!
- @state.phase += tick.dt / @inputs.period!
+ @state.phase += @inputs.clock!.dt / @inputs.period!
- while @state.phase >= 1
+ if @state.phase >= 1
@state.phase -= 1
@state.count += 1
@out\set @state.count
@@ -208,12 +205,11 @@ every = Constant.meta
@out = @inputs.evt\type!\mk_evt!
tick: =>
- for tick in *@inputs.clock!
- @state += tick.dt / @inputs.period!
+ @state += @inputs.clock!.dt / @inputs.period!
- while @state >= 1
+ if @state >= 1
@state -= 1
- @out\add @inputs.evt!
+ @out\set @inputs.evt!
sequence = Constant.meta
meta:
@@ -251,7 +247,7 @@ Emits `evt1`, `evt2`, … as events with delays `delay0`, `delay1`, … in betwe
steps: [inputify step for step in *steps]
tick: =>
- for tick in *@inputs.clock!
+ if tick = @inputs.clock!
@state.t += tick.dt
change, current = false, nil
@@ -265,7 +261,7 @@ Emits `evt1`, `evt2`, … as events with delays `delay0`, `delay1`, … in betwe
break
if current.value and (change or current.value\dirty!)
- @out\add current.value!
+ @out\set current.value!
{
:clock
diff --git a/alv-lib/util.moon b/alv-lib/util.moon
index f4fda89..2323377 100644
--- a/alv-lib/util.moon
+++ b/alv-lib/util.moon
@@ -24,9 +24,7 @@ switch_ = Constant.meta
setup: (inputs) =>
{ i, values } = pattern\match inputs
- @state = values[1].result.metatype ~= '!'
-
- @out = if @state
+ @out = if values[1].result.metatype ~= '!'
values[1]\type!\mk_sig!
else
values[1]\type!\mk_evt!
@@ -45,12 +43,8 @@ switch_ = Constant.meta
else
i = 1 + (math.floor i!) % #values
values[i]
- if @state
- @out\set active and active!
- else
- if active and active\dirty!
- for event in *active!
- @out\add event
+
+ @out\set active and active!
edge = Constant.meta
meta:
@@ -67,7 +61,7 @@ edge = Constant.meta
tick: =>
now = @inputs.value!
if now and not @state
- @out\add true
+ @out\set true
@state = now
change = Constant.meta
@@ -85,7 +79,7 @@ change = Constant.meta
tick: =>
now = @inputs.value!
if now != @state
- @out\add @inputs.value!
+ @out\set @inputs.value!
@state = now
hold = Constant.meta
@@ -100,9 +94,7 @@ hold = Constant.meta
@out or= event\type!\mk_sig!
super event: Input.hot event
- tick: =>
- for val in *@inputs.event!
- @out\set val
+ tick: => @out\set @inputs.event!
{
'switch': switch_