From 57469fcc5297a0a2a2a29b47d7bd26c4e58176ed Mon Sep 17 00:00:00 2001 From: s-ol Date: Mon, 22 Sep 2025 18:40:53 +0200 Subject: lib/link-time: add fade --- alv-lib/link-time.moon | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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 -- cgit v1.2.3