aboutsummaryrefslogtreecommitdiffstats
path: root/lib/envelope.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-02-16 11:47:24 +0000
committers-ol <s-ol@users.noreply.github.com>2020-02-16 11:47:24 +0000
commit2953f1e56b408fc26eb54fa65935505dd128ce82 (patch)
tree8c7c513ccf03df06c4e9e2e70ba68031d2d0b7a5 /lib/envelope.moon
parentadd ==, mod (diff)
downloadalive-2953f1e56b408fc26eb54fa65935505dd128ce82.tar.gz
alive-2953f1e56b408fc26eb54fa65935505dd128ce82.zip
major refactoring: Const, Stream + ResultNode
Diffstat (limited to 'lib/envelope.moon')
-rw-r--r--lib/envelope.moon13
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