diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-03-02 18:00:54 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-03-02 18:00:54 +0000 |
| commit | 79d483435a70c47c1711b3876d66077b4f1041d2 (patch) | |
| tree | d19181a435bdf3e5ba374c67501df29da2d59d2c | |
| parent | only :tick after :setup if dirty (diff) | |
| download | alive-79d483435a70c47c1711b3876d66077b4f1041d2.tar.gz alive-79d483435a70c47c1711b3876d66077b4f1041d2.zip | |
find IO via Result tree, not Registry
| -rw-r--r-- | copilot.moon | 4 | ||||
| -rw-r--r-- | core/invoke.moon | 2 | ||||
| -rw-r--r-- | core/registry.moon | 4 | ||||
| -rw-r--r-- | core/value.moon | 20 | ||||
| -rw-r--r-- | lib/midi/core.moon | 8 | ||||
| -rw-r--r-- | lib/time.moon | 14 |
6 files changed, 23 insertions, 29 deletions
diff --git a/copilot.moon b/copilot.moon index 607edff..8b3602a 100644 --- a/copilot.moon +++ b/copilot.moon @@ -38,7 +38,9 @@ class Copilot @poll! if @root - L\try "error evaluating:", @registry\wrap_tick @root\tick + L\try "error evaluating:", @registry\wrap_tick -> + @root\tick_io! + @root\tick! tb = (msg) -> debug.traceback msg, 2 poll: => diff --git a/core/invoke.moon b/core/invoke.moon index ba19cc5..3b2ddd5 100644 --- a/core/invoke.moon +++ b/core/invoke.moon @@ -15,7 +15,7 @@ class op_invoke extends Action eval: (scope, tail) => children = L\push -> [L\push expr\eval, scope for expr in *tail] - @op\setup [result for result in *children] + @op\setup [result for result in *children], scope any_dirty = false for input in @op\all_inputs! diff --git a/core/registry.moon b/core/registry.moon index ac1943a..ebe429c 100644 --- a/core/registry.moon +++ b/core/registry.moon @@ -23,10 +23,6 @@ class Registry active: -> assert Registry.active_registry, "no active Registry!" --- IO - add_io: (io) => @io[io] = true - remove_io: (io) => @io[io] = nil - -- public methods wrap_eval: (fn) => (...) -> diff --git a/core/value.moon b/core/value.moon index b882507..b01b28f 100644 --- a/core/value.moon +++ b/core/value.moon @@ -1,9 +1,9 @@ -- ALV Value types -local Scope, Registry, Op, Action, FnDef +local Scope, Registry, Op, Action, IOInput, FnDef load_ = -> import Scope from require 'core.scope' import Registry from require 'core.registry' - import Op, Action, FnDef from require 'core.base' + import Op, Action, IOInput, FnDef from require 'core.base' ancestor = (klass) -> assert klass, "cant find the ancestor of nil" @@ -29,15 +29,15 @@ class Result @side_inputs, is_child = {}, {} for child in *@children - for d in pairs child.side_inputs - @side_inputs[d] = true + for s, d in pairs child.side_inputs + @side_inputs[s] = d if child.value is_child[child.value] = true if @op for input in @op\all_inputs! if input.impure or not is_child[input.stream] - @side_inputs[input] = true + @side_inputs[input.stream] = input is_const: => not next @side_inputs @@ -57,12 +57,20 @@ class Result with Result value: @value .side_inputs = @side_inputs + -- tick all IO instances that are effecting this (sub) tree + -- should be called once per frame on the root, right before tick + tick_io: => + for stream, input in pairs @side_inputs + if input.__class == IOInput + io = input! + io\tick! + -- in depth-first order, tick all Ops who have dirty Stream inputs or impulses -- -- short-circuits if there are no dirty Streams in the entire subtree tick: => any_dirty = false - for input in pairs @side_inputs + for stream, input in pairs @side_inputs if input\dirty! any_dirty = true break diff --git a/lib/midi/core.moon b/lib/midi/core.moon index d91fdcb..156feb2 100644 --- a/lib/midi/core.moon +++ b/lib/midi/core.moon @@ -57,17 +57,11 @@ class MidiPort extends IO class PortOp extends Op new: => super 'midi/port' - destroy: => - Registry.active!\remove_io @port if @port - tick: (inp, out) => if (inp and inp\dirty!) or (out and out\dirty!) - Registry.active!\remove_io @port if @port inp = inp and find_port RtMidiIn, inp! out = out and find_port RtMidiOut, out! - @port = MidiPort inp, out - Registry.active!\add_io @port - @out\set @port + @out\set MidiPort inp, out class input extends PortOp @doc: "(midi/input name) - create a MIDI input port" diff --git a/lib/time.moon b/lib/time.moon index f93258a..d44013e 100644 --- a/lib/time.moon +++ b/lib/time.moon @@ -31,15 +31,9 @@ fps defaults to 60 and has to be an eval-time constant" { fps } = match 'num?', inputs super fps: ValueInput fps or Value.num 60 - destroy: => - Registry.active!\remove_io @clock if @clock - tick: => if @inputs.fps\dirty! - Registry.active!\remove_io @clock if @clock - @clock = Clock 1 / @inputs.fps! - Registry.active!\add_io @clock - @out\set @clock + @out\set Clock 1 / @inputs.fps! class lfo extends Op @doc: "(lfo [clock] freq [wave]) - low-frequency oscillator @@ -97,7 +91,7 @@ ramps from 0 to max (default same as ramp) once every period seconds." max or= period @phase += clock.dt / period - if @phase >= 1 + while @phase >= 1 @phase -= 1 if clock_dirty or (@inputs.max and @inputs.max\dirty!) @@ -122,7 +116,7 @@ counts upwards by one every period seconds and returns the number of completed t { :clock, :period, :max } = @unwrap_all! @phase += clock.dt / period - if @phase >= 1 + while @phase >= 1 @phase -= 1 @count += 1 @out\set @count @@ -146,7 +140,7 @@ returns true once every period seconds." { :clock, :period, :max } = @unwrap_all! @phase += clock.dt / period - if @phase >= 1 + while @phase >= 1 @phase -= 1 @out\set true |
