Skip to content

Instantly share code, notes, and snippets.

@dndrks
Last active May 14, 2022 01:46
Show Gist options
  • Save dndrks/6ceb443d39cc1bf516510b130674984b to your computer and use it in GitHub Desktop.
Save dndrks/6ceb443d39cc1bf516510b130674984b to your computer and use it in GitHub Desktop.
cheat codes user script: delay sequencer example
-- cheat codes user script: delay sequencer example
-- required container, do not change this:
local user_script = {}
my_delays = {} -- use unique variables to reduce conflicts with the rest of cheat codes
-- this function is called whenever a loaded collection has a 'user_script.lua' file in the collection:
function user_script.init()
my_delays[1] = { -- sequence delay L's snapshots
steps = { -- fill whichever steps you want with the snapshot you want to call using [step] = snapshot
[1] = 1,
[17] = 2
},
start_point = 1,
end_point = 64,
current_step = 1,
sync_val = 1/4, -- 1/4 = 1/4th of a beat, which in 4/4 means sixteenth notes
active = true
}
my_delays[2] = { -- sequence delay R's snapshots
steps = {
[9] = 1,
[33] = 2
},
start_point = 1,
end_point = 64,
current_step = 1,
sync_val = 1/4,
active = true
}
print("hello from the user script")
end
-- this function is called whenever the transport starts:
function user_script.transport_start()
print("user script started")
-- you can add your own code to execute when the transport starts:
for i = 1,#my_delays do
if my_delays[i].active then
user_script.start_clock(i)
end
end
end
-- this function is called whenever the transport stops:
function user_script.transport_stop()
print("user script stopped")
-- you can add your own code to execute when the transport stops:
for i = 1,#my_delays do
my_delays[i].current_step = my_delays[i].start_point
user_script.stop_clock(i)
end
end
-- you can add any other functions you want, just prepend them with 'user_script.'
-- this one starts the sequence clocks
function user_script.start_clock(i)
my_delays[i].clock = clock.run(
function()
while true do
local step = my_delays[i].current_step
if my_delays[i].steps[step] ~= nil then
del.restore_bundle(i,my_delays[i].steps[step]) -- del.restore_bundle(1 for L or 2 or R, which snapshot)
end
clock.sync(my_delays[i].sync_val)
user_script.advance_step(i)
end
end
)
end
-- this one advances the sequence step
function user_script.advance_step(i)
my_delays[i].current_step = util.wrap(
my_delays[i].current_step+1,
my_delays[i].start_point,
my_delays[i].end_point
)
end
-- this one clears the sequence clocks, called when the transport stops
function user_script.stop_clock(i)
if my_delays[i].clock ~= nil then
clock.cancel(my_delays[i].clock)
end
end
-- required return, do not change this:
return user_script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment