diff options
| -rw-r--r-- | alv-lib/link-time.moon | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/alv-lib/link-time.moon b/alv-lib/link-time.moon index a043516..f6d044f 100644 --- a/alv-lib/link-time.moon +++ b/alv-lib/link-time.moon @@ -403,6 +403,40 @@ Returns a num~ stream that starts at 0. @out\set @state.offset + accum +fade = Constant.meta + meta: + name: 'fade' + summary: "A one-time transition" + examples: { '(fade [clock] duration [to])' } + description: " +Linear fade from last to `to` over `duration` beats whenever `to` changes. +There is no transition on first evaluation." + + value: class extends Op + pattern = -evt.clock + sig.num + -sig.num + -sig.num + setup: (inputs, scope) => + { clock, duration, to } = pattern\match inputs + + super + clock: Input.hot clock or scope\get '*clock*' + duration: Input.cold duration + to: Input.hot to or T.num\mk_const 1 + + @setup_out '~', T.num, @inputs.to! + + tick: (setup) => + { :clock, :duration, :to } = @unwrap_all! + + if @inputs.to\dirty! + @state = frm: @.out! + + if clock + @state.beats or= clock.state\beat_at_time clock.time - clock.dt, 1 + beats = clock.state\beat_at_time clock.time, 1 + + t = math.min 1, (beats - @state.beats) / duration + @out\set @state.frm + t * (to - @state.frm) + Constant.meta meta: name: 'link-time' @@ -418,3 +452,4 @@ Constant.meta :decay :ad :spring + :fade |
