Created
June 13, 2024 21:31
-
-
Save jhsu/93801fb3969d1e73eaf9b48430a796cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Number of steps in the sequence | |
num_steps = 8 | |
-- Length of each step in seconds | |
step_length = 0.125 | |
-- Maximum pitch variation per step | |
pitch_variation = 0.02 | |
-- Filter cutoff frequency range (Hz) | |
filter_min = 100 | |
filter_max = 5000 | |
function init() | |
softcut.buffer_clear() | |
-- Setup for micro-loop sequencer | |
for i = 1, num_steps do | |
softcut.enable(i, 1) | |
softcut.buffer(i, 1) | |
softcut.level(i, 0.5 / num_steps) -- Adjust level based on num_steps | |
softcut.loop(i, 1) | |
softcut.loop_start(i, 0) | |
softcut.loop_end(i, step_length) | |
softcut.play(i, 1) | |
-- Set initial filter parameters for each step | |
softcut.post_filter_fc(i, math.random(filter_min, filter_max)) | |
softcut.post_filter_rq(i, 1.0) | |
softcut.post_filter_lp(i, 1.0) | |
end | |
-- Route audio input to buffer | |
softcut.level_input_cut(1, 1, 1.0) | |
softcut.level_input_cut(2, 1, 1.0) | |
softcut.rec_level(1, 1.0) | |
softcut.rec(1, 1) | |
-- Enable softcut output | |
softcut.play(1, 1) | |
softcut.play(2, 1) | |
-- Route input to main output | |
softcut.level(1, 1.0) | |
softcut.level(2, 1.0) | |
end | |
function enc(n, delta) | |
if n == 1 then | |
step_length = util.clamp(step_length + delta * 0.01, 0.01, 0.5) | |
for i = 1, num_steps do | |
softcut.loop_end(i, step_length) | |
end | |
elseif n == 2 then | |
pitch_variation = util.clamp(pitch_variation + delta * 0.001, 0.0, 0.2) | |
end | |
redraw() | |
end | |
function redraw() | |
screen.clear() | |
screen.move(10, 30) | |
screen.text("step length: "..step_length) | |
screen.move(10, 50) | |
screen.text("pitch variation: "..pitch_variation) | |
screen.update() | |
end | |
clock.run(function() | |
local step = 1 | |
while true do | |
clock.sync(step_length) -- Sync to step length | |
-- Trigger the current step | |
softcut.position(step, 0) | |
-- Move to the next step | |
step = step % num_steps + 1 | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment