forked from monome-community/nc01-drone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eclipse.lua
220 lines (190 loc) · 5.47 KB
/
eclipse.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
-- Eclipse (nc01-drone)
-- @wheelersounds
--
-- E1 volume
-- E2 brightness
-- (levels of top buffers)
-- E3 density
-- K2 evolve (change mix of
-- octaves, position in files)
-- K3 change worlds
-- TODO --
-- implement params?
function init()
re=metro.init()
re.time = 1.0/15
re.event = function()
redraw()
end
re:start()
file1 = _path.code .. "nc01-drone/lib/dd.wav" -- notes, buff pos: 0
file2 = _path.code .. "nc01-drone/lib/bc.wav" -- wind noise, buf_pos: 10
file3 = _path.code .. "nc01-drone/lib/eb.wav" -- cello drone, buf_pos: 20
softcut.buffer_clear()
softcut.buffer_read_mono(file1,0,0,-1,1,1) -- file,file_start,buf_pos,dur,file_ch,buf_num
softcut.buffer_read_mono(file2,0,20,-1,1,1)
softcut.buffer_read_mono(file3,0,40,-1,1,1)
mode_number = 1
mode_buff_offset = {0, 20, 40}
rates = {0.5, 1, 4, 8}
levels = {0.4, 0.4, 0.4, 0.4}
master_volume = 1
brightness = 1.
density = 1.
filter_freq = 12000.0
fadetime = 0.1
-- ### softcut init
for i=1,4 do
softcut.enable(i,1)
softcut.buffer(i,1)
softcut.level(i,math.random()*0.5+0.2)
softcut.level_slew_time(i, 1)
softcut.fade_time(i,fadetime)
softcut.loop(i,1)
softcut.loop_start(i,1)
softcut.loop_end(i,1.1)
softcut.position(i,1)
softcut.rate(i,rates[i])
softcut.play(i,1)
softcut.post_filter_dry(i,0.0)
softcut.post_filter_lp(i,1.0)
softcut.post_filter_fc(i,filter_freq)
softcut.post_filter_rq(i,5)
end
-- ### screen init
screen_x=128
screen_y=64
-- print("approaching...")
end
function enc(n,d)
if n == 1 then
-- volume
for i=1,4 do
master_volume = util.clamp(master_volume + d/100, 0, 1)
softcut.level(i, levels[i] * master_volume)
end
elseif n == 2 then
--"brightness"
for i=1,4 do
brightness = util.clamp(brightness + (d/100), 0., 1.)
filter_freq = brightness * 11500 + 500 --
-- print(filter_freq)
softcut.post_filter_fc(i,filter_freq)
end
elseif n == 3 then
--"density"
for i=1,4 do
density = util.clamp(density + (d/100), 0., 1.)
fadetime = density * 0.75 + 0.01 --
softcut.fade_time(i,fadetime)
end
end
end
function key(n,z)
if n == 2 then
-- evolve
if z == 1 then
for i=1,4 do
levels[i] = math.random()*0.5 + 0.2
softcut.level(i, levels[i] * master_volume)
-- also rand positions
local new_pos=math.random()*20
softcut.loop_start(i,new_pos + mode_buff_offset[mode_number] + 1)
softcut.loop_end(i,new_pos + mode_buff_offset[mode_number] + 1.1)
end
end
elseif n == 3 then
-- new world (mode_number from 1..3)
if z == 1 then
mode_number = (mode_number %3) + 1
-- mode_number = mode_number + 1
for i=1,4 do
local new_pos=math.random()*20
softcut.loop_start(i,new_pos + mode_buff_offset[mode_number] + 1)
softcut.loop_end(i,new_pos + mode_buff_offset[mode_number] + 1.1)
end
end
end
redraw()
end
function redraw()
screen.clear()
screen.aa(1)
if mode_number == 1 then
for i=1,10 do
local bright = math.random(10)
screen.level(math.floor(util.clamp(density * 15 - bright,3,15))) --density
local coin = math.random(2)
screen.move(screen_x * (1/i), screen_y * (1/i))
if coin == 1 then
screen.line(screen_x * (1/i), 0)
else
screen.line(0, screen_y * (1/i))
end
screen.stroke()
end
screen.level(math.floor(brightness * 15)) --brightness
screen.circle(screen_x * 0.15, screen_y * 0.15, 10)
screen.fill()
screen.stroke()
screen.level(5)
screen.circle(screen_x * 0.15, screen_y * 0.15, 10)
screen.stroke()
elseif mode_number==2 then
for i=1,(math.floor(density*100)+20) do --density
local rand_x=math.random(128)
local rand_y=math.random(64)
local bright=math.random(15)
screen.level(bright)
screen.pixel(rand_x,rand_y)
screen.fill()
screen.stroke()
end
screen.level(util.clamp(math.floor(brightness*15),0,15)) --brightness
screen.circle(screen_x*0.5, 1, 30)
screen.fill()
screen.stroke()
screen.level(15)
screen.circle(screen_x*0.5, 1, 30)
screen.stroke()
-- screen.display_png(png2,0,0)
elseif mode_number==3 then
screen.level(util.clamp(math.floor(brightness*15),1,13))
screen.circle(screen_x*0.5, screen_y*0.5, 20)
screen.fill()
screen.stroke()
screen.level(0)
screen.circle(screen_x*0.5-(density*15), screen_y*0.5, 20)
screen.fill()
screen.stroke()
screen.level(util.clamp(math.floor(filter_freq/1000) + 2,5,15))
screen.circle(screen_x*0.5+(density*15), screen_y*0.5, 20)
screen.stroke()
-- screen.display_png(png3,0,0)
end
screen.font_face(1)
screen.font_size(8)
screen.move(screen_x*0.9,screen_y*0.9)
screen.level(0)
screen.text_center('vol')
screen.move(screen_x*0.91,screen_y*0.9)
screen.level(10)
screen.text_center('vol')
screen.move(screen_x*0.92,screen_y*0.9)
screen.level(15)
screen.text_center('vol')
screen.line_width(1)
screen.move(screen_x*0.89 + 1, screen_y*0.8)
screen.level(0)
screen.line_rel(0,master_volume * -50)
screen.stroke()
screen.move(screen_x*0.9, screen_y*0.8)
screen.level(5)
screen.line_rel(0,master_volume * -50)
screen.stroke()
screen.move(screen_x*0.91, screen_y*0.8)
screen.level(15)
screen.line_rel(0,master_volume * -50)
screen.stroke()
screen.update()
end