-
-
Save dndrks/9e52afaa410a20621a8428e3c1571057 to your computer and use it in GitHub Desktop.
lfo library tests
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
-- lfo test 1 | |
-- can 60 lfos run without any failures? | |
-- K3: start/stop | |
-- K2: changes rate randomly (via API) | |
_l = require 'lfo' | |
lfos = {} | |
passed_values = {} | |
function init() | |
for i = 1,60 do | |
lfos[i] = _l:add{min = -i, max = i} | |
-- while we can use lfos[i]:get('scaled') to get the scaled value, | |
-- i want to confirm that the function-passed values are working as intended: | |
passed_values[i] = 0 | |
lfos[i]:set('action', function(s,r) passed_values[i] = s end) | |
end | |
_redraw = clock.run( | |
function() | |
while true do | |
clock.sleep(1/15) | |
redraw() | |
end | |
end | |
) | |
end | |
function key(n,z) | |
if n == 3 and z == 1 then | |
for i = 1,60 do | |
if lfos[i].enabled == 0 then | |
lfos[i]:start() | |
else | |
lfos[i]:stop() | |
lfos[i]:set('period',4) | |
end | |
end | |
elseif n == 2 and z == 1 then | |
for i = 1,60 do | |
lfos[i]:set('period', math.random(1,30)) | |
end | |
end | |
end | |
function redraw() | |
screen.clear() | |
for i = 1,60 do | |
local x = util.wrap(i,1,10) - 1 | |
local y = util.round_up(i/10) | |
screen.move(4 + (x) * 13, 10 * y) | |
screen.level(lfos[i]:get('scaled') >= 0 and 15 or 3) | |
screen.text_center(math.abs(util.round(passed_values[i]))) | |
end | |
screen.update() | |
end |
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
-- lfo test 2 | |
-- 60 parameter sets | |
-- w/nested group | |
-- K3: start/stop | |
-- K2: changes rate randomly (via params) | |
_l = require 'lfo' | |
lfos = {} | |
passed_values = {} | |
function init() | |
params:add_group('all the lfos',15*60) | |
for i = 1,60 do | |
lfos[i] = _l:add{min = -i, max = i} | |
-- while we can use lfos[i]:get('scaled') to get the scaled value, | |
-- i want to confirm that the function-passed values are working as intended: | |
passed_values[i] = 0 | |
lfos[i]:set('action', function(s,r) passed_values[i] = s end) | |
if i ~= 60 then | |
lfos[i]:add_params(i, 'LFO '..i) | |
else | |
-- this won't show up as a group within the 'all the lfos' group, | |
-- because paramset cannot nest groups within groups. | |
-- however, we *will* see the parameters as normal (with hiding, etc). | |
lfos[i]:add_params(i, 'LFO '..i, 'special nest for LFO 60') | |
end | |
end | |
_redraw = clock.run( | |
function() | |
while true do | |
clock.sleep(1/15) | |
redraw() | |
end | |
end | |
) | |
end | |
function key(n,z) | |
if n == 3 and z == 1 then | |
for i = 1,60 do | |
if lfos[i].enabled == 0 then | |
-- switched to params:set so changes show up in UI: | |
params:set('lfo_'..i,2) | |
params:set('lfo_depth_'..i, 100) | |
if lfos[i]:get('mode') == 'clocked' then | |
params:set('lfo_clocked_'..i, 9) | |
else | |
params:set('lfo_free_'..i, 1) | |
end | |
else | |
-- switched to params:set so changes show up in UI: | |
params:set('lfo_'..i,1) | |
params:set('lfo_depth_'..i, 0) | |
end | |
end | |
elseif n == 2 and z == 1 then | |
for i = 1,60 do | |
if lfos[i]:get('mode') == 'clocked' then | |
params:set('lfo_clocked_'..i, math.random(6,13)) | |
else | |
params:set('lfo_free_'..i, math.random(1,10)) | |
end | |
end | |
end | |
end | |
function redraw() | |
screen.clear() | |
for i = 1,60 do | |
local x = util.wrap(i,1,10) - 1 | |
local y = util.round_up(i/10) | |
screen.move(4 + (x) * 13, 10 * y) | |
screen.level(lfos[i]:get('scaled') >= 0 and 15 or 3) | |
screen.text_center(util.round(passed_values[i])) | |
end | |
screen.update() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment