-
Notifications
You must be signed in to change notification settings - Fork 9
/
scarlet.lua
executable file
·282 lines (252 loc) · 7.22 KB
/
scarlet.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
-- scarlet (nc03 - dressed in sequins)
-- @dndrks
--
-- E1 volume
-- E2 cadence (hold K1)
-- E3 horizon
-- K1 stability
-- K2 relax
-- K3 bind
sc_prm = include 'lib/sc_params' -- param-based controls over softcut
sc_fn = include 'lib/sc_helpers' -- helper functions for different softcut actions, used by 'sc_params'
lfo = require 'lfo' -- parameter-based lfo library
local period_screen = false
local global_period = 1
local pre_script_level = params:get('softcut_level')
s = require 'sequins'
function init()
-- initliaze our softcut parameters:
sc_prm.init()
-- build LFOs:
lfos = {level = {}, pan = {}, semitone_offset = {}, pitch_control = {}, post_filter_fc = {}}
-- to restore our pre-lfo states, we'll capture the current values for each of our lfo destinations:
pre_lfo_values = {level = {}, pan = {}, semitone_offset = {}, pitch_control = {}, post_filter_fc = {}}
for i = 1,softcut.VOICE_COUNT do
lfos.level[i] = lfo:add{
-- for each lfo, we'll use the current value as the center of the movement:
action = function(scaled,raw)
scaled = util.linlin(0,1,0,-1,scaled)
params:set('level_'..i,pre_lfo_values.level[i] + scaled)
end
}
lfos.pan[i] = lfo:add{
min = -1,
max = 1,
action = function(scaled,raw)
local scaled_min = pre_lfo_values.pan[i] - lfos.pan[i].depth
local scaled_max = pre_lfo_values.pan[i] + lfos.pan[i].depth
raw = util.linlin(0,1,scaled_min, scaled_max, raw)
params:set('pan_'..i,raw)
end
}
lfos.semitone_offset[i] = lfo:add{
min = -48,
max = 48,
action = function(scaled,raw)
local centroid = 96 * (lfos.semitone_offset[i].depth/2)
local scaled_min = pre_lfo_values.semitone_offset[i] - centroid
local scaled_max = pre_lfo_values.semitone_offset[i] + centroid
raw = util.linlin(0,1,scaled_min, scaled_max, raw)
params:set('semitone_offset_'..i, raw)
end
}
lfos.pitch_control[i] = lfo:add{
min = -25,
max = 25,
action = function(scaled,raw)
local centroid = 50 * (lfos.pitch_control[i].depth/2)
local scaled_min = pre_lfo_values.pitch_control[i] - centroid
local scaled_max = pre_lfo_values.pitch_control[i] + centroid
raw = util.linlin(0,1,scaled_min, scaled_max, raw)
params:set('pitch_control_'..i, raw)
end
}
lfos.post_filter_fc[i] = lfo:add{
min = 20,
max = 12000,
action = function(scaled,raw)
local centroid = 11980 * (lfos.post_filter_fc[i].depth/2)
local scaled_min = pre_lfo_values.post_filter_fc[i] - centroid
local scaled_max = pre_lfo_values.post_filter_fc[i] + centroid
raw = util.linlin(0,1,scaled_min, scaled_max, raw)
params:set('post_filter_fc_'..i, raw)
end
}
for k,v in pairs(lfos) do
lfos[k][i]:set('ppqn', 16)
end
end
-- build some sequins-based trigger sequencers:
trigger_seqs = {
{
s{1,0,0,0,1,0,0,0,s{1,1,0,1}},
s{0,1,0,1,1,0,1,0,0,s{0,1,1,0,1,1,0}},
s{1,0,1,0,0,1,0,1,0,0},
s{0,0,0,0,0,0,0,1},
s{0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
s{0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
},
{
s{0},
s{1,0,1,s{0,0,1,1,0,0,1}},
s{1,0,1,0,0,0,0,0,1,1,0,0},
s{0,1,0,s{1,1,1,0}},
s{0,s{1,0,0,1}},
s{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
},
{
s{1,0,0,0,0,0,1,0,0,0,0,0,0,0},
s{0,1,0,0,0,0,1,1,0,0},
s{0,0,0,0,0,0,0,0,1,0,0,0},
s{0,0,0,0,1,0},
s{0,0,0,1,0,s{0,1,0,0,1,0,0,1,1,1}},
s{0},
},
}
selected_seq = 1
queued_seq = 1
-- pre-load audio files:
-- kits: 'default-1', 'default-2', 'fltr-amod-eq', 'fm-lite', 'heavy', 'mods-1', 'mods-2', 'verb-long', 'verb-short'
sc_fn.load_kit('default-1')
-- load a longer decay kick:
params:set("voice 1 sample",_path.audio.."nc03-ds/01-bd/01-bd_default-2.flac")
screen_dirty = true
screen_redraw = metro.init(draw_screen, 1/15, -1)
screen_redraw:start()
for i = 1,6 do
params:set("post_filter_dry_"..i, 0)
params:set("post_filter_lp_"..i, 1)
params:set("post_filter_rq_"..i, math.random(50,80))
end
end
function randomize_lfos()
for k,v in pairs(lfos) do
for i = 1,6 do
pre_lfo_values[k][i] = params:get(k.."_"..i)
lfos[k][i]:set('depth', math.random(100)/100)
local shapes = {'sine','saw','square'}
lfos[k][i]:set('shape', shapes[math.random(#shapes)])
lfos[k][i]:set('period', global_period)
lfos[k][i]:start()
end
end
end
function zero_lfos()
for k,v in pairs(lfos) do
for i = 1,6 do
lfos[k][i]:stop()
params:set(k.."_"..i,pre_lfo_values[k][i])
end
end
end
function enc(n,d)
if n == 1 then
params:delta('softcut_level', d)
elseif n == 2 then
if randomizing then
if not period_screen then
period_screen = true
else
global_period = util.clamp(global_period + d,1,10)
for k,v in pairs(lfos) do
for i = 1,6 do
lfos[k][i]:set('period', global_period)
end
end
end
end
elseif n == 3 then
queued_seq = util.clamp(queued_seq+d, 1, #trigger_seqs)
end
screen_dirty = true
end
function key(n,z)
if n == 3 and z == 1 then
play(queued_seq)
elseif n == 2 and z == 1 then
stop()
elseif n == 1 then
if z == 1 then
randomize_lfos()
randomizing = true
else
period_screen = false
zero_lfos()
randomizing = false
end
end
screen_dirty = true
end
function play(seq)
stop()
reset_indices()
seq_clock = clock.run(
function()
while true do
local _c = trigger_seqs[seq]
clock.sync(1/4)
for i = 1,#_c do
local val = _c[i]()
if val == 1 then
sc_fn.play_slice(i,1)
end
end
screen_dirty = true
end
end
)
selected_seq = queued_seq
seq_active = true
end
function stop()
if seq_clock then
clock.cancel(seq_clock)
seq_active = false
end
end
function reset_indices()
for i = 1,#trigger_seqs[selected_seq] do
trigger_seqs[selected_seq][i]:reset()
end
screen_dirty = true
end
function draw_screen()
if screen_dirty then
redraw()
screen_dirty = false
end
end
function redraw()
screen.clear()
screen.level(5)
screen.move(128,10)
screen.text_right("queued seq: "..queued_seq)
if not period_screen then
for i = 1,#trigger_seqs[selected_seq] do
local current_ix = trigger_seqs[selected_seq][i].ix
local current_val = trigger_seqs[selected_seq][i].data[current_ix]
if type(current_val) ~= "table" then
screen.level(current_val == 1 and 15 or 3)
screen.move((18*(i-1))+15,30)
screen.text_center(i)
screen.move((18*(i-1))+15,40)
screen.text_center(current_val)
end
end
else
screen.move(64,32)
screen.level(15)
screen.text_center('lfo period: '..global_period..' beats')
end
screen.level(5)
screen.move(0,60)
screen.text(seq_active and "K2: stop" or "")
screen.move(128,60)
screen.text_right("K3: load seq "..queued_seq)
screen.move(0,12)
screen.text(randomizing and "~~~" or "")
screen.update()
end
function cleanup()
params:set('softcut_level', pre_script_level)
end