-
Notifications
You must be signed in to change notification settings - Fork 0
/
ad.lua
107 lines (91 loc) · 3.2 KB
/
ad.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
local libcore = require "core.libcore"
local app = app
local Class = require "Base.Class"
local Unit = require "Unit"
local GainBias = require "Unit.ViewControl.GainBias"
local ply = app.SECTION_PLY
local AD = Class{}
AD:include(Unit)
function AD:init(args)
args.title = "ad"
args.mnemonic = "Ad"
Unit.init(self,args)
end
function AD:onLoadGraph(channelCount)
local trig = self:addObject("trig", app.Comparator())
trig:setTriggerMode()
local pre_env = self:addObject("env", libcore.SkewedSineEnvelope())
local adsr = self:addObject("adsr", libcore.ADSR())
local attack = self:addObject("attack", app.GainBias())
local decay = self:addObject("decay", app.GainBias())
local attackRange = self:addObject("attackRange", app.MinMax())
local decayRange = self:addObject("decayRange", app.MinMax())
local pre_env_level = self:addObject("pre_env_level", app.Constant())
local pre_env_dur_bias = self:addObject("pre_env_dur_bias", app.Constant())
local pre_env_dur_sum = self:addObject("pre_env_dur_sum", app.Sum())
local duration = self:addObject("duration", app.ParameterAdapter())
-- setup trigger route: in -> pre_env -> adsr
connect(self,"In1",trig,"In")
connect(trig,"Out",pre_env,"Trigger")
connect(pre_env,"Out",adsr,"Gate") --needed to trigger pre_env
-- setup pre_env
pre_env_dur_bias:hardSet("Value",.02)
connect(attack, "Out", pre_env_dur_sum, "Left")
connect(pre_env_dur_bias, "Out", pre_env_dur_sum, "Right")
pre_env:hardSet("Skew", -1)
pre_env_level:hardSet("Value", 1)
connect(pre_env_level, "Out", pre_env, "Level")
-- connect to adapter
tie(pre_env,"Duration",duration,"Out")
connect(pre_env_dur_sum, "Out", duration, "In")
duration:hardSet("Gain",1)
-- setup adsr
connect(attack,"Out",adsr,"Attack")
connect(decay,"Out",adsr,"Decay")
connect(decay,"Out",adsr,"Release")
adsr:hardSet("Sustain",0)
connect(attack,"Out",attackRange,"In")
connect(decay,"Out",decayRange,"In")
connect(adsr,"Out",self,"Out1")
if channelCount==2 then
connect(adsr,"Out",self,"Out2")
end
self:addMonoBranch("attack",attack,"In",attack,"Out")
self:addMonoBranch("decay",decay,"In",decay,"Out")
end
local views = {
expanded = {"attack","decay"},
collapsed = {},
}
function AD:onLoadViews(objects,branches)
local controls = {}
local createMap = function (min, max, superCourse, course, fine, superFine, rounding)
local map = app.LinearDialMap(min, max)
map:setSteps(superCourse, course, fine, superFine)
map:setRounding(rounding)
return map
end
local time_map = createMap(.002, 2, 0.1, 0.01, 0.001, 0.001, 0.001)
controls.attack = GainBias {
button = "A",
branch = branches.attack,
description = "Attack",
gainbias = objects.attack,
range = objects.attackRange,
biasMap = time_map,
biasUnits = app.unitSecs,
--initialBias = 0
}
controls.decay = GainBias {
button = "D",
branch = branches.decay,
description = "Decay",
gainbias = objects.decay,
range = objects.decayRange,
biasMap = time_map,
biasUnits = app.unitSecs,
initialBias = 0.050
}
return controls, views
end
return AD