-
Notifications
You must be signed in to change notification settings - Fork 3
/
Compare.lua
85 lines (73 loc) · 2.24 KB
/
Compare.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
-- GLOBALS: app, os, verboseLevel, connect, tie
local app = app
local Class = require "Base.Class"
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 Encoder = require "Encoder"
local ply = app.SECTION_PLY
local CompareUnit = Class{}
CompareUnit:include(Unit)
function CompareUnit:init(args)
args.title = "Compare"
args.mnemonic = "Cp"
Unit.init(self,args)
end
function CompareUnit:onLoadGraph()
-- create objects
local compare = self:createObject("Comparator","compare")
local threshold = self:createObject("ParameterAdapter","threshold")
local hysteresis = self:createObject("ParameterAdapter","hysteresis")
-- connect inputs/outputs
connect(self,"In1",compare,"In")
connect(compare,"Out",self,"Out1")
tie(compare,"Hysteresis",hysteresis,"Out")
self:createMonoBranch("hyst",hysteresis,"In",hysteresis,"Out")
tie(compare,"Threshold", threshold, "Out")
self:createMonoBranch("thresh",threshold,"In",threshold,"Out")
end
local views = {
expanded = {"mode","input", "thresh", "hyst"},
collapsed = {},
input = {"scope","input"}
}
function CompareUnit:onLoadViews(objects,branches)
local controls = {}
controls.mode = ModeSelect {
button = "o",
description = "Type",
option = objects.compare:getOption("Mode"),
choices = {"toggle","gate","trigger"},
muteOnChange = true
}
controls.input = InputGate {
button = "input",
description = "Unit Input",
unit = self,
comparator = objects.compare,
}
controls.hyst = GainBias {
button = "hyst",
description = "Hysteresis",
branch = branches.hyst,
gainbias = objects.hysteresis,
range = objects.hysteresis,
biasMap = Encoder.getMap("unit"),
-- biasUnits = app.unitSecs,
initialBias = 0.03
}
controls.thresh = GainBias {
button = "thresh",
description = "Threshold",
branch = branches.thresh,
gainbias = objects.threshold,
range = objects.threshold,
biasMap = Encoder.getMap("default"),
biasUnits = app.unitNone,
initialBias = 0.10
}
return controls, views
end
return CompareUnit