aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2016-01-25 18:50:11 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2016-01-25 18:50:11 +0100
commit162e0a0d2f6cbbf747c91876a213451c08a59e72 (patch)
treed82a8fb39a45df36dec14e487a771e02c708fb1a
parent9eb3c1ae817dd5853fa27bdc8da4b6d2f4992a8c (diff)
downloadapplause2-162e0a0d2f6cbbf747c91876a213451c08a59e72.tar.gz
added line(), curve() and curves(): RTCmix-like "curve" generators
* In contrast to RTcmix, they are calculated on-demand. Like any stream, they can be turned into a "lookup table" using :eval()
-rw-r--r--applause.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/applause.lua b/applause.lua
index b1c55d2..06e3242 100644
--- a/applause.lua
+++ b/applause.lua
@@ -1656,6 +1656,38 @@ end
function iota(...) return IotaStream:new(...) end
+function line(v1, t, v2)
+ return iota(t):mul((v2-v1)/t):add(v1)
+end
+
+-- Derived from RTcmix' "curve" table
+-- Generates a single linear or logarithmic line segment
+-- See http://www.music.columbia.edu/cmc/Rtcmix/docs/scorefile/maketable.html#curve
+function curve(v1, alpha, t, v2)
+ v2 = v2 or 0
+ if not alpha or alpha == 0 then return line(v1, t, v2) end
+
+ local exp = math.exp
+ local denom = 1/(1 - exp(alpha))
+ local delta = v2 - v1
+
+ return iota(t):map(function(x)
+ return v1 + delta*(1 - exp(x/t * alpha))*denom
+ end)
+end
+
+-- Generates a variable number of concatenated line segments
+-- E.g. curves(0, 0, sec(1), 1, 0, sec(1), 0)
+function curves(...)
+ local args = {...}
+ local ret
+ for i = 1, #args-1, 3 do
+ local c = curve(unpack(args, i, i+3))
+ ret = ret and ret..c or c
+ end
+ return ret
+end
+
--
-- Filters
--