-
Notifications
You must be signed in to change notification settings - Fork 3
/
MathsUnit.lua
202 lines (171 loc) · 4.04 KB
/
MathsUnit.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
local app = app
local Class = require "Base.Class"
local libAccents = require "Accents.libAccents"
local Unit = require "Unit"
local ModeSelect = require "Unit.ViewControl.OptionControl"
local InputGate = require "Unit.ViewControl.InputGate"
local OutputScope = require "Unit.ViewControl.OutputScope"
local GainBias = require "Unit.ViewControl.GainBias"
local BranchMeter = require "Unit.ViewControl.BranchMeter"
local Task = require "Unit.MenuControl.Task"
local MenuHeader = require "Unit.MenuControl.Header"
local Encoder = require "Encoder"
local ply = app.SECTION_PLY
local Maths = Class{}
Maths:include(Unit)
function Maths:init(args)
args.title = "Maths"
args.mnemonic = "Ma"
Unit.init(self,args)
end
function Maths:onLoadGraph()
local maths = self:addObject("maths",libAccents.Maths())
local a = self:addObject("a",app.ConstantGain())
local b = self:addObject("b",app.ConstantGain())
a:hardSet("Gain",1.0)
b:hardSet("Gain",1.0)
a:setClampInDecibels(-59.9)
b:setClampInDecibels(-59.9)
self:addMonoBranch("inA", a, "In", a,"Out")
self:addMonoBranch("inB", b, "In", b,"Out")
connect(a,"Out",maths,"a")
connect(b,"Out",maths,"b")
connect(maths,"Out",self,"Out1")
end
local views = {
expanded = {"a","b"},
collapsed = {},
input = {}
}
function Maths:onLoadViews(objects,branches)
local controls = {}
controls.a = BranchMeter {
button = "a",
branch = branches.inA,
faderParam = objects.a:getParameter("Gain")
}
controls.b = BranchMeter {
button = "b",
branch = branches.inB,
faderParam = objects.b:getParameter("Gain")
}
self:addToMuteGroup(controls.a)
self:addToMuteGroup(controls.b)
return controls, views
end
local menu = {
"setHeader",
"min",
"max",
"mean",
"div",
"inv",
"mod",
"tanh",
"atan",
"inlv",
"infoHeader",
"rename",
"load",
"save",
"edit"
}
function Maths:setOp(op)
local objects = self.objects
self.op = op
if op=="MIN" then
objects.maths:setOptionValue("Operation",1)
elseif op=="MAX" then
objects.maths:setOptionValue("Operation",2)
elseif op=="MEAN" then
objects.maths:setOptionValue("Operation",3)
elseif op=="DIV" then
objects.maths:setOptionValue("Operation",4)
elseif op=="INV" then
objects.maths:setOptionValue("Operation",5)
elseif op=="MOD" then
objects.maths:setOptionValue("Operation",6)
elseif op=="TANH" then
objects.maths:setOptionValue("Operation",7)
elseif op=="ATAN" then
objects.maths:setOptionValue("Operation",8)
elseif op=="INLV" then
objects.maths:setOptionValue("Operation",9)
end
end
function Maths:onShowMenu(objects,branches)
local controls = {}
controls.setHeader = MenuHeader {
description = string.format("Current op is: %s.", self.op)
}
controls.max = Task {
description = "MAX",
task = function()
self:setOp("MAX")
end
}
controls.min = Task {
description = "MIN",
task = function()
self:setOp("MIN")
end
}
controls.mean = Task {
description = "MEAN",
task = function()
self:setOp("MEAN")
end
}
controls.div = Task {
description = "DIV",
task = function()
self:setOp("DIV")
end
}
controls.inv = Task {
description = "INV",
task = function()
self:setOp("INV")
end
}
controls.mod = Task {
description = "MOD",
task = function()
self:setOp("MOD")
end
}
controls.tanh = Task {
description = "TANH",
task = function()
self:setOp("TANH")
end
}
controls.atan = Task {
description = "ATAN",
task = function()
self:setOp("ATAN")
end
}
controls.inlv = Task {
description = "INLV",
task = function()
self:setOp("INLV")
end
}
return controls, menu
end
function Maths:onLoadFinished()
self:setOp("MIN")
end
function Maths:serialize()
local t = Unit.serialize(self)
t.mathOp = self.op
return t
end
function Maths:deserialize(t)
Unit.deserialize(self,t)
if t.mathOp then
self:setOp(t.mathOp)
end
end
return Maths