-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstøy.lua
executable file
·359 lines (303 loc) · 7.77 KB
/
støy.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
--
--
--
-- "støy" is noise
--
--
--
-- ...
-- v3.0 / imminent gloom
--
-- K1: shift
-- K2: delay send
-- K2 + shift: latch delay send
-- K3: mute (before eq/del)
--
-- E1: hz
-- E2: choose
-- E3: affect
--
-- E1 + shift: EQ dry/wet
-- E2 + shift: delay rate
-- E3 + shift: feedback
--
-- grid + shift: EQ band decay
-- setup
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
engine.name = "st_y"
g = grid.connect()
include("lib/params")
include("lib/delay")
MusicUtil = require("musicutil")
local save_on_exit = true
local word = "støy"
local prev_word = "hard"
local k1_held = false
local k2_held = false
local k3_held = false
local p_list = {"hard", "soft", "drift", "cut", "res", "fm", "am", "gain"}
local f_list = {"2.8k", "1.5k", "777", "411", "218", "115", "61", "29"}
local p_pos = 1
local p_val
local g_val
local y_buff = {{},{},{},{},{},{},{},{},}
-- init
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function init()
delay_init()
params_init()
if save_on_exit then
params:read(norns.state.data .. "/state.pset")
params:bang()
end
p_val = params:get_raw("hard")
g_val = p_val
redraw()
redraw_grid()
end
-- functions
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
local function g_buffer(buff, val, z)
if z == 1 then
-- add all held buttons to a table in order
table.insert(buff, val)
else
-- remove each button as it is released
for i, v in pairs(buff) do
if v == val then
table.remove(buff, i)
break
end
end
end
end
-- grid: buttons
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
g.key = function(x, y, z)
g_buffer(y_buff[y], x, z)
if not k1_held then
if #y_buff[y] == 1 then -- choose row and set the val to the first button hit
p_pos = y
word = p_list[p_pos]
prev_word = word
if y_buff[y][1] == 1 then
g_val = 0
else
g_val = y_buff[y][1] / g.cols
end
end
if #y_buff[y] > 1 then -- set the val to the second, third etc. release returns to prev val
p_pos = y
word = p_list[p_pos]
prev_word = word
if y_buff[y][#y_buff[y]] == 1 then
g_val = 0
else
g_val = y_buff[y][#y_buff[y]] / g.cols
end
end
params:set_raw(word, g_val)
p_val = params:get_raw(word)
end
if k1_held then
if #y_buff[y] == 1 then -- choose row and set the val to the first button hit
f_pos = y
word = f_list[f_pos]
if y_buff[y][1] == 1 then
f_val = 0.01
else
f_val = y_buff[y][1] / g.cols
end
end
if #y_buff[y] > 1 then -- set the val to the second, third etc. release returns to prev val
f_pos = y
word = f_list[f_pos]
if y_buff[y][#y_buff[y]] == 1 then
f_val = 0.01
else
f_val = y_buff[y][#y_buff[y]] / g.cols
end
end
params:set_raw(word, f_val)
p_val = params:get_raw(word)
end
redraw()
redraw_grid()
end
-- grid: "color" palette
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
local g_scanlines = 1
local g_params = 4
local g_current_bg = 6
local g_current = 15
-- grid: lights
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function row_current(row) -- light up the current row, display val rounded to nearest grid column
if not k1_held then
for n = 1, g.cols do
g:led(n, row, g_current_bg)
end
for n = 1, math.floor(g_val * g.cols, 1) do
g:led(n, row, g_current)
end
end
end
function row_all() -- light up all rows with val rounded to nearest grid column
if not k1_held then
for row = 1, 8 do
for n = 1, math.floor(params:get_raw(p_list[row]) * g.cols, 1) do
g:led(n, row, g_params)
end
end
end
if k1_held then
for row = 1, 8 do
for n = 1, math.floor(params:get_raw(f_list[row]) * g.cols, 1) do
g:led(n, row, g_current)
end
end
end
end
function scanlines_grid() -- draw noisy lines across the grid
for row = 1, 8 do
active = math.random(0, 1) * g_scanlines
-- for n = 1, 16 do
for n = 1, g.cols do
g:led(n, row, active)
end
end
end
function redraw_grid()
g:all(0)
scanlines_grid()
row_all()
row_current(p_pos)
g:refresh()
end
-- norns: screen
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function bargraph() -- val as bargraph
y = math.floor(p_val * 64)
screen.rect(0, 64, 128, -y)
screen.level(1)
screen.fill()
end
function scanlines() -- draw noisy lines across the screen
for n = 0, 64 do
screen.level(math.random(0,1) * 15)
screen.move(0, n)
screen.line(128, n)
screen.stroke()
end
end
function scribe() -- write a word on the screen
screen.level(1)
screen.font_face(11)
screen.font_size(60)
screen.move(3, 48)
screen.font_face(11)
screen.font_size(60)
screen.text(word)
end
function redraw()
screen.aa(0)
screen.clear()
screen.blend_mode(4)
bargraph()
scanlines()
scribe()
screen.update()
end
-- norns: interaction
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function key(n,z)
if n == 1 and z == 1 then
k1_held = true
word = "alt"
p_val = 0
elseif n == 1 and z == 0 then
k1_held = false
word = prev_word
p_val = params:get_raw(word)
end
if n == 2 and z == 1 then
k2_held = true
if not k1_held then
params:set("delay_send", 1)
end
if k1_held then
local val = (params:get("delay_send") + 1) % 2
params:set("delay_send", val)
end
word = "del"
p_val = 0
elseif n == 2 and z == 0 then
k2_held = false
if not k1_held then
params:set("delay_send", 0)
end
word = prev_word
p_val = params:get_raw(word)
end
if n == 3 and z == 1 then
k3_held = true
params:set("level", 0)
word = "null"
p_val = 0
elseif n == 3 and z == 0 then
k3_held = false
params:set("level", 1)
word = prev_word
p_val = params:get_raw(word)
end
if k2_held and k3_held then
word = "dull"
end
redraw()
redraw_grid()
end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function enc(n, d)
if n == 1 and not k1_held then
params:delta("hz", d)
word = "hz"
prev_word = word
p_val = params:get_raw("hz")
elseif n == 1 and k1_held then
params:delta("blend", d)
word = "ping"
p_val = params:get_raw("blend")
end
if n == 2 and not k1_held then
d = util.clamp(d, -1, 1)
p_pos = (((p_pos - 1) + d) % #p_list) + 1
word = p_list[p_pos]
prev_word = word
p_val = params:get_raw(word)
g_val = p_val
elseif n == 2 and k1_held then
params:delta("delay_rate", d)
word = "rate"
p_val = params:get_raw("delay_rate")
end
if n == 3 and not k1_held then
params:delta(p_list[p_pos], d)
word = p_list[p_pos]
prev_word = word
p_val = params:get_raw(word)
g_val = p_val
elseif n == 3 and k1_held then
params:delta("delay_feedback", d)
word = "fb"
p_val = params:get_raw("delay_feedback")
end
redraw()
redraw_grid()
end
-- tidy up before we go
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function cleanup()
if save_on_exit then
params:write(norns.state.data .. "/state.pset")
end
end