-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.lua
198 lines (156 loc) · 5.89 KB
/
display.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
format_version = "1.0"
local maxArraySize = 256
local softClippingOffset = 256
local hardClippingValue = 500
-------------------------------------------------
local mainLCDWidth = 256
local mainLCDHeight = 118
local colorMainLCDLine = { r = 0, g = 255, b = 0 }
local colorMainLCDHardClipping = { r = 255, g = 0, b = 0 }
local colorMainLCDSoftClipping = { r = 248, g = 122, b = 0 }
local maxLevelWindow1 = {
lineColor = { r = 255, g = 255, b = 0 },
lineTop = mainLCDHeight - 6,
textColor = { r = 0, g = 0, b = 0},
}
local maxLevelWindow2 = {
lineColor = { r = 105, g = 122, b = 244 },
lineTop = mainLCDHeight - 4,
textColor = { r = 255, g = 255, b = 255},
}
local maxLevelWindow3 = {
lineColor = { r = 230, g = 9, b = 196 },
lineTop = mainLCDHeight - 2,
textColor = { r = 255, g = 255, b = 255},
}
local zoomLevel = {
lineColor = { r = 123, g = 123, b = 123 },
textColor = { r = 255, g = 255, b = 255},
}
local propMainLCDSoftClippingLevelDisplay = 1
local propMainLCDHUDAlpha = 2
local propMainLCDMaxLevelWindow1Size = 3
local propMainLCDMaxLevelWindow2Size = 4
local propMainLCDMaxLevelWindow3Size = 5
local propMainLCDArrayStartIdx = 6
local propMainLCDArraySizeIdx = 7
local propMainLCDArrayIdx = 8
local propMaxLevelWindowValue = 1
local propMaxLevelWindowState = 2
local propMaxLevelWindowSize = 3
local propMaxLevelWindowSizeAsTextZoomLevel = 1
local propMaxLevelWindowSizeAsTextSize = 2
local maxLevelStateOk = 0
local maxLevelStateSoftClipping = 1
local maxLevelStateHardClipping = 2
local maxLevelColors = {
[maxLevelStateOk] = colorMainLCDLine,
[maxLevelStateSoftClipping] = colorMainLCDSoftClipping,
[maxLevelStateHardClipping] = colorMainLCDHardClipping
}
-------------------------------------------------
--- MainLCD
-------------------------------------------------
function drawMaxLevelWindow(propSize, window, lcdHUDAlpha)
if propSize > 0 then
local left = mainLCDWidth - propSize
local color = {r = window.lineColor.r, g = window.lineColor.g, b = window.lineColor.b, a = lcdHUDAlpha }
-- draw the line
jbox_display.draw_rect({left = left, top = window.lineTop, right = mainLCDWidth, bottom = window.lineTop + 2 },
color)
end
end
MainLCDDraw = function(props, di, dr)
-- jbox.trace("draw")
local idx = props[propMainLCDArrayStartIdx]
local size = props[propMainLCDArraySizeIdx]
local left = 0
local volume
while size > 0 do
-- we increase first as the latest entry should be at the right edge of the display => latest value to
-- be displayed
idx = idx + 1
if idx >= maxArraySize then
idx = 0
end
volume = props[propMainLCDArrayIdx + idx]
local lineColor = colorMainLCDLine
if(volume == hardClippingValue) then
lineColor = colorMainLCDHardClipping
else
if volume >= softClippingOffset then -- -6dB
lineColor = colorMainLCDSoftClipping
volume = volume - softClippingOffset
end
end
local top = mainLCDHeight - volume
jbox_display.draw_rect({left = left, top = top, right = left + 1, bottom = mainLCDHeight }, lineColor)
left = left + 1
size = size - 1
end
local softClippingLine = mainLCDHeight - props[propMainLCDSoftClippingLevelDisplay]
jbox_display.draw_rect({left = 0, top = softClippingLine, right = mainLCDWidth, bottom = softClippingLine + 1 },
{r = 200, g = 200, b = 200, a = 123})
local lcdHUDAlpha = props[propMainLCDHUDAlpha]
if lcdHUDAlpha > 0 then
drawMaxLevelWindow(props[propMainLCDMaxLevelWindow1Size], maxLevelWindow1, lcdHUDAlpha)
drawMaxLevelWindow(props[propMainLCDMaxLevelWindow2Size], maxLevelWindow2, lcdHUDAlpha)
drawMaxLevelWindow(props[propMainLCDMaxLevelWindow3Size], maxLevelWindow3, lcdHUDAlpha)
end
end
-------------------------------------------------
--- MaxLevelWindowValueDraw
-------------------------------------------------
MaxLevelWindowValueDraw = function(props, di, dr)
if props[propMaxLevelWindowSize] > 0 then
local value = props[propMaxLevelWindowValue]
local state = props[propMaxLevelWindowState]
-- jbox.trace("draw " .. tostring(value))
local textValue = "---.--"
if value > 0 then
if state == maxLevelStateHardClipping then
value = 1.0 / value
end
textValue = string.format("%+.2f", 20 * math.log10(value))
end
jbox_display.draw_text({left = 0, top = 0, right = 49, bottom = 19},
"center",
textValue,
"Bold LCD font",
maxLevelColors[state]
)
end
end
-------------------------------------------------
--- MaxLevelWindowXSizeAsTextDraw
-------------------------------------------------
function drawMaxLevelWindowSizeAsText(zoomLevel, propSize, window)
-- we draw the background no matter what
jbox_display.draw_rect({left = 0, top = 0, right = 50, bottom = 16}, window.lineColor)
-- we write the text
if propSize > 0 then
local windowSizeInSeconds = 0.2 * zoomLevel + 5.0
-- draw the text value
jbox_display.draw_text({left = 0, top = 0, right = 50, bottom = 16},
"center",
string.format("%.3fs", windowSizeInSeconds * propSize / maxArraySize),
"Bold LCD font",
window.textColor
)
end
end
MaxLevelWindow1SizeAsTextDraw = function(props, di, dr)
drawMaxLevelWindowSizeAsText(props[propMaxLevelWindowSizeAsTextZoomLevel],
props[propMaxLevelWindowSizeAsTextSize],
maxLevelWindow1)
end
MaxLevelWindow2SizeAsTextDraw = function(props, di, dr)
drawMaxLevelWindowSizeAsText(props[propMaxLevelWindowSizeAsTextZoomLevel],
props[propMaxLevelWindowSizeAsTextSize],
maxLevelWindow2)
end
MaxLevelWindow3SizeAsTextDraw = function(props, di, dr)
drawMaxLevelWindowSizeAsText(props[propMaxLevelWindowSizeAsTextZoomLevel],
props[propMaxLevelWindowSizeAsTextSize],
maxLevelWindow3)
end