-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathFader.lua
More file actions
192 lines (166 loc) · 4.6 KB
/
Copy pathFader.lua
File metadata and controls
192 lines (166 loc) · 4.6 KB
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
local app = app
local Class = require "Base.Class"
local Base = require "Unit.ViewControl.EncoderControl"
local Encoder = require "Encoder"
local ply = app.SECTION_PLY
-- Fader Class
local Fader = Class {
type = "Fader",
canEdit = false,
canMove = true
}
Fader:include(Base)
function Fader:init(args)
Base.init(self)
self:setClassName("Unit.ViewControl.Fader")
-- required arguments
local button = args.button or
app.logError("%s.init: button is missing.", self)
self:setInstanceName(button)
local description = args.description or
app.logError("%s.init: description is missing.", self)
local param = args.param or app.logError("%s.init: param is missing.", self)
-- optional arguments
self:setDefaults(args)
local map = args.map
local units = args.units
local precision = args.precision
local scaling = args.scaling
local monitor = args.monitor
local graphic
param:enableSerialization()
if args.initial then
param:hardSet(args.initial)
end
self.description = description
graphic = app.Fader(0, 0, ply, 64)
graphic:setParameter(param)
graphic:setAttributes(units, map, scaling)
graphic:setPrecision(precision)
graphic:setLabel(button)
self.fader = graphic
self:setMainCursorController(graphic)
self:setControlGraphic(graphic)
self:addSpotDescriptor{
center = 0.5 * ply
}
self.subGraphic = app.Graphic(0, 0, 128, 64)
if monitor then
self:setScopeTarget(monitor)
end
end
function Fader:setDefaults(args)
if args.map == nil then
args.map = Encoder.getMap("default")
end
if args.units == nil then
args.units = app.unitNone
end
if args.scaling == nil then
args.scaling = app.linearScaling
end
if args.precision == nil then
args.precision = 3
end
self.defaults = args
end
function Fader:getDefaults()
return self.defaults
end
function Fader:getPinControl()
local PinFader = require "PinView.Fader"
local control = PinFader {
delegate = self,
name = self.fader:getLabel(),
valueParam = self.fader:getValueParameter(),
units = self.defaults.units,
map = self.defaults.map,
scaling = self.defaults.scaling,
precision = self.defaults.precision
}
return control
end
function Fader:createPinMark()
local Drawings = require "Drawings"
local graphic = app.Drawing(-8, 0, app.SECTION_PLY, 64)
graphic:add(Drawings.Control.Pin)
self.controlGraphic:addChildOnce(graphic)
self.pinMark = graphic
end
function Fader:setScopeTarget(monitor)
if monitor then
self.hasMonitor = true
if monitor.channelCount == 1 then
local outlet = monitor:getMonitoringOutput(1)
self:setMonoScopeTarget(outlet)
else
local left = monitor:getMonitoringOutput(1)
local right = monitor:getMonitoringOutput(2)
self:setStereoScopeTarget(left, right)
end
else
self:setMonoScopeTarget()
self:setStereoScopeTarget()
self.hasMonitor = false
end
end
function Fader:onInsert()
if not self.hasMonitor then
self:setScopeTarget(self.parent)
end
end
function Fader:getScope()
if self.scope == nil then
self.scope = app.MiniScope(0, 0, 128, 64)
self.subGraphic:addChild(self.scope)
end
return self.scope
end
function Fader:setMonoScopeTarget(outlet)
self.leftScopeTarget = outlet
self.rightScopeTarget = nil
end
function Fader:setStereoScopeTarget(leftOutlet, rightOutlet)
self.leftScopeTarget = leftOutlet
self.rightScopeTarget = rightOutlet
end
function Fader:setMonoMeterTarget(outlet)
self.fader:watchOutlets(outlet, nil)
end
function Fader:setStereoMeterTarget(left, right)
self.fader:watchOutlets(left, right)
end
function Fader:setTextBelow(value, text)
self.fader:setTextBelow(value, text)
end
function Fader:setTextAbove(value, text)
self.fader:setTextAbove(value, text)
end
function Fader:onCursorEnter(spot)
Base.onCursorEnter(self, spot)
local left = self.leftScopeTarget
local right = self.rightScopeTarget
local scope = self:getScope()
local Channels = require "Channels"
if Channels.isRight() then
scope:watchOutlet(right)
else
scope:watchOutlet(left)
end
end
function Fader:zeroPressed()
self.fader:zero()
return true
end
function Fader:cancelReleased(shifted)
self.fader:restore()
return true
end
function Fader:encoder(change, shifted)
self.fader:encoder(change, shifted, self.encoderState == Encoder.Fine)
return true
end
function Fader:onFocused()
self.fader:save()
end
return Fader