git.s-ol.nu alive / 0fc02d6
lib: add time/smooth s-ol 6 months ago
1 changed file(s) with 37 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
327327 else
328328 break
329329
330 if bang
331 @out
332
333330 vis: => step: @state.i\set true
331
332 smooth = Constant.meta
333 meta:
334 name: 'smooth'
335 summary: "Smooth out value transitions"
336 examples: { '(smooth [clock] value rate)' }
337 description: "
338 Creates smooth transitions when `value` changes.
339
340 - `clock` should be a `time/clock!` stream. This argument can be omitted
341 and the stream be passed as a dynamic definition in `*clock*` instead.
342 - `value` should be a num~ or num! stream.
343 - `rate` is a num~ or num= value."
344
345 value: class extends Op
346 new: (...) =>
347 super ...
348 @out = T.num\mk_sig!
349
350 pattern = -evt.clock + sig.num + (sig.num / evt.num)
351 setup: (inputs, scope) =>
352 { clock, rate, value } = pattern\match inputs
353
354 super
355 clock: Input.hot clock or scope\get '*clock*'
356 rate: Input.cold rate
357 value: Input.cold value
358
359 @out\set @inputs.value! unless @.out!
360
361 tick: =>
362 { :clock, :rate, :value } = @unwrap_all!
363 if clock
364 current = @.out!
365 delta = value - current
366 @out\set current + delta * rate
334367
335368 RTNode
336369 children: { default_clock }
349382 :every
350383 'val-seq': val_seq
351384 'bang-seq': bang_seq
385 :smooth
352386
353387 '*clock*': default_clock