forked from mattb/beets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeets.lua
215 lines (190 loc) · 4.85 KB
/
beets.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
-- MoBeets
-- 0.1.0 @Lemmy
--
-- Forked from
-- Beets
-- 1.1.1 @mattbiddulph
--
-- Probabilistic performance
-- drum loop re-sequencer
--
-- Put one-bar or two-bar WAVs in folders
-- in dust/audio/beets
--
-- K2 : Quantized mute toggle
-- K3 : Instant mute while held
-- Enc2: Switch between Voice 1 and Voice 2
--
-- Use a Grid, or map
-- MIDI controller to params
--
-- thanks to @vcvcvc_val
-- for demo loops!
local ENABLE_CROW = false -- not finished, and may stomp over clock Crow controls if enabled
local Beets = include('lib/libbeets')
local beets_audio_dir = _path.audio .. 'beets'
local Passthrough = include('lib/passthrough')
local Arcify = include('lib/arcify')
local arcify = Arcify.new()
local current_voice = 1
local previous_voice = 1
local beets = Beets.new {softcut_voice_id = 1, current_voice = current_voice}
local beets2 = Beets.new {softcut_voice_id = 2, current_voice = current_voice}
local editing = false
local g = grid.connect()
-- handle grid inputs
g.key = function(x, y, z)
if params:get('orientation') == 1 then -- horizontal
if y == 1 then
-- editing loop start and end in top row
if current_voice == 1 then
beets:grid_key(x, y, z)
else
beets2:grid_key(x, y, z)
end
elseif x < 9 then
beets:grid_key(x, y, z)
else
beets2:grid_key(x - 8, y, z)
end
else -- vertical
if beets.bars_per_loop > 1 or beets2.bars_per_loop > 1 then
beets.status = 'Horizontal orientation required'
return
elseif y < 9 then
beets:grid_key(x, y, z)
else
beets2:grid_key(x, y - 8, z)
end
end
end
local function init_crow()
crow.output[2].action = 'pulse(0.001, 5, 1)'
crow.output[3].action = 'pulse(0.001, 5, 1)'
crow.output[4].action = 'pulse(0.001, 5, 1)'
end
local function multibar_loops_in_use()
return (beets.bars_per_loop > 1 or beets2.bars_per_loop > 1)
end
local function beat()
while true do
clock.sync(1 / 2)
local beatstep = math.floor(clock.get_beats() * 2) % beets.beat_count
beets:advance_step(beatstep, clock.get_tempo())
beets2:advance_step(beatstep, clock.get_tempo())
redraw()
if current_voice ~= previous_voice then
g:all(0) -- clear the grid
previous_voice = current_voice
end
if multibar_loops_in_use() == false then
if params:get('orientation') == 1 then -- horizontal
beets:drawGridUI(g, 1, 1, current_voice)
beets2:drawGridUI(g, 9, 1, current_voice)
else
beets:drawGridUI(g, 1, 1, current_voice)
beets2:drawGridUI(g, 1, 9, current_voice)
end
else
beets:drawGridUI(g, 1, 1, current_voice)
beets2:drawGridUI(g, 9, 1, current_voice)
end
g:refresh()
end
end
function redraw()
if current_voice == 1 then
beets:drawUI(multibar_loops_in_use(), current_voice)
else
beets2:drawUI(multibar_loops_in_use(), current_voice)
end
end
function enc(n, d)
if editing then
beets:enc(n, d)
elseif n == 2 then
current_voice = util.clamp(current_voice + d, 1, 2)
end
end
function key(n, z)
-- if n == 1 and z == 1 then
-- editing = true
-- beets:edit_mode_begin()
-- end
if editing then
if n == 1 and z == 0 then
editing = false
beets:edit_mode_end()
else
beets:key(n, z)
end
else
if n == 1 and z == 1 then
editing = true
beets:show_edit_screen()
end
if n == 2 and z == 0 then
beets:toggle_mute()
end
if n == 3 then
beets:instant_toggle_mute()
end
end
end
function init_beets_dir()
if util.file_exists(beets_audio_dir) == false then
util.make_dir(beets_audio_dir)
local demodir = _path.code .. 'beets/demo-loops'
if util.file_exists(demodir) then
for _, dirname in ipairs(util.scandir(demodir)) do
local from_dir = demodir .. '/' .. dirname
local to_dir = beets_audio_dir .. '/' .. dirname
util.make_dir(to_dir)
util.os_capture('cp ' .. from_dir .. '* ' .. to_dir)
end
end
end
end
function init()
init_beets_dir()
params:add_separator('BEETS')
audio.level_cut_rev(0)
beets.on_beat = function()
end
if ENABLE_CROW then
beets.on_beat_one = function()
crow.output[2]()
end
beets.on_kick = function()
crow.output[3]()
end
beets.on_snare = function()
crow.output[4]()
end
end
params:add {
type = 'option',
id = 'orientation',
name = 'Grid orientation',
options = {'horizontal', 'vertical'},
action = function(val)
if val == 1 then
g:rotation(0)
else
g:rotation(3)
end
g:all(0) -- clear the grid for a full redraw after orientation change
end
}
beets:add_params(arcify)
beets2:add_params(arcify)
params:add_separator('UTILITIES')
Passthrough.init()
arcify:add_params()
clock.run(beat)
if ENABLE_CROW then
init_crow()
end
beets:start()
beets2:start()
end