diff options
| author | s-ol <s+removethis@s-ol.nu> | 2025-09-22 16:40:53 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-09-24 15:53:53 +0000 |
| commit | 57469fcc5297a0a2a2a29b47d7bd26c4e58176ed (patch) | |
| tree | 4ea9178be585a72e19fb78f6fa2639e255a19dfe | |
| parent | global tag IDs (diff) | |
| download | alive-57469fcc5297a0a2a2a29b47d7bd26c4e58176ed.tar.gz alive-57469fcc5297a0a2a2a29b47d7bd26c4e58176ed.zip | |
lib/link-time: add fade
| -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 |
