-
Notifications
You must be signed in to change notification settings - Fork 1
/
tetrabobo.lua
269 lines (259 loc) · 7.22 KB
/
tetrabobo.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
---TetraBobo
---
---triangle wave organ
---with variable slope
---for norns & shbobo shnth
---
---E1: master chaos (circular FM)
---E2: master rise time
---E3: master fall time
---
---K1: hold for fine tuning
---K2: alt behavior for E2 & E3
---K3: alt behavior for E2 & E3
---
---K2 + E2: bar 0 time (pitch)
---K2 + E3: bar 1 time (pitch)
---K3 + E2: bar 2 time (pitch)
---K3 + E3: bar 3 time (pitch)
---
---shnth minors halve the time
---of their corresponding bars
---
---shnth majors double the time
---of their corresponding bars
---
---version 1.0.1
Tetrabobo = include('lib/Tetrabobo_engine')
engine.name = 'Tetrabobo'
sh = hid.connect(1)
if sh.device then
shnth = include("shnth/lib/shnth")
sh.event = shnth.event
else shnth = {}
end
_lfos = require 'lfo'
doubling = {}
halving = {}
going = {}
times_lfo = {}
for i=1,4 do
doubling[i] = false
halving[i] = false
going[i] = nil
end
function init()
Tetrabobo.add_params() -- adds params via the `.add params()` function defined in TetraBobo_engine.lua
rise_lfo = _lfos:add{min = 0.00005, max = 0.03125}
fall_lfo = _lfos:add{min = 0.00005, max = 0.03125}
chaos_lfo = _lfos:add{min = -100, max = 100}
for i=0,3 do
params:hide('Tetrabobo_pan_'..i)
times_lfo[i] = _lfos:add{min = 0.00005, max = 0.03125}
end
params:add_group('LFOs',105)
rise_lfo:add_params('rise_lfo', 'rise')
rise_lfo:set('action', function(scaled, raw) params:set('Tetrabobo_rise',scaled) end)
fall_lfo:add_params('fall_lfo', 'fall')
fall_lfo:set('action', function(scaled, raw) params:set('Tetrabobo_fall',scaled) end)
chaos_lfo:add_params('chaos_lfo', 'chaos')
chaos_lfo:set('action', function(scaled, raw) params:set('Tetrabobo_chaos',scaled) end)
for i=0,3 do
times_lfo[i]:add_params('times['..i..']_lfo', 'time '..i)
times_lfo[i]:set('action', function(scaled, raw) params:set('Tetrabobo_time_'..i,scaled) end)
end
print("tetrabobo")
end
function key(n,z)
if n==1 then
if z==1 then
fine = true
else fine = false
end
elseif n==2 then
if z==1 then
bars_1 = true
redraw()
else bars_1 = false
redraw()
end
elseif n==3 then
if z==1 then
bars_2 = true
redraw()
else bars_2 = false
redraw()
end
end
end
function enc(n,d)
if n==1 then
if fine then
params:delta('Tetrabobo_chaos',d/200)
else params:delta('Tetrabobo_chaos',d/20)
redraw()
end
elseif n==2 then
if bars_1 then
if fine then
params:delta('Tetrabobo_time_0',d/10)
else params:delta('Tetrabobo_time_0',d)
redraw()
end
elseif bars_2 then
if fine then
params:delta('Tetrabobo_time_2',d/10)
else params:delta('Tetrabobo_time_2',d)
redraw()
end
elseif fine then
params:delta('Tetrabobo_rise',d/10)
else params:delta('Tetrabobo_rise',d)
redraw()
end
elseif n==3 then
if bars_1 then
if fine then
params:delta('Tetrabobo_time_1',d/10)
else params:delta('Tetrabobo_time_1',d)
redraw()
end
elseif bars_2 then
if fine then
params:delta('Tetrabobo_time_3',d/10)
else params:delta('Tetrabobo_time_3',d)
redraw()
end
elseif fine then
params:delta('Tetrabobo_fall',d/10)
else params:delta('Tetrabobo_fall',d)
redraw()
end
end
end
function shnth.major(n, z)
for i=1,4 do
if n==i then
if z==1 then
doubling[i] = true
redraw()
else doubling[i] = false
redraw()
end
end
end
end
function shnth.minor(n, z)
for i=1,4 do
if n==i then
if z==1 then
halving[i] = true
redraw()
else halving[i] = false
redraw()
end
end
end
end
function shnth.bar(n, d)
if math.abs(d) > 0.2 then
for i=1,4 do
if n==i then
if going[i]==nil then
if doubling[i] then
if d > 0.2 then
params:set('Tetrabobo_pan_' .. (i-1), 1)
elseif d < -0.2 then
params:set('Tetrabobo_pan_' .. (i-1), -1)
end
params:set('Tetrabobo_time_' .. (i - 1),(params:get('Tetrabobo_time_' .. (i - 1))*2))
Tetrabobo.trig(util.linlin(-1,1,0.03,1,d),i)
params:set('Tetrabobo_time_' .. (i - 1),(params:get('Tetrabobo_time_' .. (i - 1))/2))
going[i] = clock.run(function()
clock.sleep(util.linlin(-1,1,0.03,1,d)*2)
clock.cancel(going[i])
going[i] = nil
end)
elseif halving[i] then
if d > 0.2 then
params:set('Tetrabobo_pan_' .. (i-1), 1)
elseif d < -0.2 then
params:set('Tetrabobo_pan_' .. (i-1), -1)
end
params:set('Tetrabobo_time_' .. (i - 1),(params:get('Tetrabobo_time_' .. (i - 1))/2))
Tetrabobo.trig(util.linlin(-1,1,0.03,1,d),i)
params:set('Tetrabobo_time_' .. (i - 1),(params:get('Tetrabobo_time_' .. (i - 1))*2))
going[i] = clock.run(function()
clock.sleep(util.linlin(-1,1,0.03,1,d)*2)
clock.cancel(going[i])
going[i] = nil
end)
else
if d > 0.2 then
params:set('Tetrabobo_pan_' .. (i-1), 1)
elseif d < -0.2 then
params:set('Tetrabobo_pan_' .. (i-1), -1)
end
Tetrabobo.trig(util.linlin(-1,1,0.03,1,d),i)
going[i] = clock.run(function()
clock.sleep(util.linlin(-1,1,0.03,1,d)*2)
clock.cancel(going[i])
going[i] = nil
end)
end
end
end
end
end
end
function redraw()
screen.clear()
screen.level(10)
screen.move(44,15)
screen.text("chaos: " .. params:get('Tetrabobo_chaos'))
if not bars_1 and not bars_2 then
screen.level(10)
else screen.level(1)
end
screen.move(0,5)
screen.text("rise: " .. params:get('Tetrabobo_rise'))
screen.move(76,5)
screen.text("fall: " .. params:get('Tetrabobo_fall'))
if bars_1 then
screen.level(10)
else screen.level(1)
end
screen.move(0,30)
if doubling[1] then
screen.text("bar 0 time: " .. params:get('Tetrabobo_time_0')*2)
elseif halving[1] then
screen.text("bar 0 time: " .. params:get('Tetrabobo_time_0')/2)
else screen.text("bar 0 time: " .. params:get('Tetrabobo_time_0'))
end
screen.move(0,40)
if doubling[2] then
screen.text("bar 1 time: " .. params:get('Tetrabobo_time_1')*2)
elseif halving[2] then
screen.text("bar 1 time: " .. params:get('Tetrabobo_time_1')/2)
else screen.text("bar 1 time: " .. params:get('Tetrabobo_time_1'))
end
if bars_2 then
screen.level(10)
else screen.level(1)
end
screen.move(0,50)
if doubling[3] then
screen.text("bar 2 time: " .. params:get('Tetrabobo_time_2')*2)
elseif halving[3] then
screen.text("bar 2 time: " .. params:get('Tetrabobo_time_2')/2)
else screen.text("bar 2 time: " .. params:get('Tetrabobo_time_2'))
end
screen.move(0,60)
if doubling[4] then
screen.text("bar 3 time: " .. params:get('Tetrabobo_time_3')*2)
elseif halving[4] then
screen.text("bar 3 time: " .. params:get('Tetrabobo_time_3')/2)
else screen.text("bar 3 time: " .. params:get('Tetrabobo_time_3'))
end
screen.update()
end