diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-03-02 12:06:17 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-03-02 12:06:17 +0000 |
| commit | 3dc95c8f30206b4310be67173b02b6c3329bce43 (patch) | |
| tree | de798bc6260001a1bb76dd0f6f85ad7fd0c1b51c | |
| parent | log errors differently (diff) | |
| download | alive-3dc95c8f30206b4310be67173b02b6c3329bce43.tar.gz alive-3dc95c8f30206b4310be67173b02b6c3329bce43.zip | |
convert lib.time to IO
| -rw-r--r-- | core/base.moon | 1 | ||||
| -rw-r--r-- | core/value.moon | 4 | ||||
| -rw-r--r-- | lib/midi/core.moon | 1 | ||||
| -rw-r--r-- | lib/time.moon | 54 |
4 files changed, 42 insertions, 18 deletions
diff --git a/core/base.moon b/core/base.moon index 6af4913..cf3d146 100644 --- a/core/base.moon +++ b/core/base.moon @@ -44,6 +44,7 @@ class EventInput extends Input -- -- lifts streams of IO objects to events class IOInput extends Input + impure: true dirty: => @stream\unwrap!\dirty! class IO diff --git a/core/value.moon b/core/value.moon index 0e72486..d4a0de3 100644 --- a/core/value.moon +++ b/core/value.moon @@ -36,8 +36,8 @@ class Result if @op for input in @op\all_inputs! - continue if is_child[input.stream] - @side_inputs[input.stream] = true + if input.impure or not is_child[input.stream] + @side_inputs[input] = true is_const: => not next @side_inputs diff --git a/lib/midi/core.moon b/lib/midi/core.moon index e0a3334..aeef861 100644 --- a/lib/midi/core.moon +++ b/lib/midi/core.moon @@ -67,7 +67,6 @@ class PortOp extends Op out = out and find_port RtMidiOut, out! @port = MidiPort inp, out Registry.active!\add_io @port - @out\set @port class input extends PortOp diff --git a/lib/time.moon b/lib/time.moon index 31fad58..f93258a 100644 --- a/lib/time.moon +++ b/lib/time.moon @@ -1,21 +1,45 @@ -import Registry, Value, Result, Op, ValueInput, EventInput, match +import Registry, Value, IO, Op, ValueInput, IOInput, match from require 'core' import monotime from require 'system' -class clock extends Op - new: => - super 'clock', { dt: 0, time: monotime! } - - setup: => +class Clock extends IO + new: (@frametime) => @last = monotime! - super kr: EventInput Registry.active!.kr + @dt = 0 + @is_dirty = false tick: => time = monotime! - dt = time - @last - if dt >= 1/60 - @out\set :dt, :time + @dt = time - @last + @is_dirty = if @dt >= @frametime @last = time + true + else + false + + dirty: => @is_dirty + +class clock extends Op + @doc: "(clock [fps]) - a clock source + +IO that triggers other operators at a fixed frame rate. +fps defaults to 60 and has to be an eval-time constant" + + new: => super 'clock' + + setup: (inputs) => + { 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 class lfo extends Op @doc: "(lfo [clock] freq [wave]) - low-frequency oscillator @@ -30,11 +54,11 @@ wave selects the wave shape from the following: super 'num' @phase = 0 - default_wave = Result value: Value.str 'sin' + default_wave = Value.str 'sin' setup: (inputs, scope) => { clock, freq, wave } = match 'clock? num any?', inputs super - clock: EventInput clock or scope\get '*clock*' + clock: IOInput clock or scope\get '*clock*' freq: ValueInput freq wave: ValueInput wave or default_wave @@ -62,7 +86,7 @@ ramps from 0 to max (default same as ramp) once every period seconds." setup: (inputs, scope) => { clock, period, max } = match 'clock? num num?', inputs super - clock: EventInput clock or scope\get '*clock*' + clock: IOInput clock or scope\get '*clock*' period: ValueInput period max: max and ValueInput max @@ -90,7 +114,7 @@ counts upwards by one every period seconds and returns the number of completed t setup: (inputs, scope) => { clock, period } = match 'clock? num', inputs super - clock: EventInput clock or scope\get '*clock*' + clock: IOInput clock or scope\get '*clock*' period: ValueInput period tick: => @@ -114,7 +138,7 @@ returns true once every period seconds." setup: (inputs, scope) => { clock, period } = match 'clock? num', inputs super - clock: EventInput clock or scope\get '*clock*' + clock: IOInput clock or scope\get '*clock*' period: ValueInput period tick: => |
