diff options
Diffstat (limited to 'lib/envelope.moon')
| -rw-r--r-- | lib/envelope.moon | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/envelope.moon b/lib/envelope.moon index 8e8fafe..eb79a64 100644 --- a/lib/envelope.moon +++ b/lib/envelope.moon @@ -1,4 +1,4 @@ -import Const, Op, Scope, eval from require 'core' +import Stream, Op, Scope, eval from require 'core' class ar_core extends Op @doc: "(ar-core attack release gate) @@ -8,21 +8,18 @@ goes from 0 to 1 in attack seconds, holds while gate is on, then goes back to 0 new: (...) => super ... - @value = 0 + @out = Stream 'num', 0 setup: (@a, @r, @gate) => assert @a, "ar requires an attack value" assert @r, "ar requires a release value" assert @gate, "ar requires a gate value" + @out update: (dt) => - @a\update dt - @r\update dt - @gate\update dt + slope = if (@gate\unwrap 'bool') then (@a\unwrap! or 0.1) else -(@r\unwrap! or 0.5) - slope = if @gate\get! then (@a\get! or 0.1) else -(@r\get! or 0.5) - - @value = math.min 1, math.max 0, @value + dt / slope + @out\set math.min 1, math.max 0, @out\unwrap! + dt / slope scope = Scope.from_table { 'ar-core': ar_core } scope\set 'ar', eval '(fn (a r) (fn (gate) (ar-core a r gate)))', scope |
