Last active
May 4, 2019 21:38
-
-
Save jellea/e7c877991b6db5a8762ddb2ef870b79b to your computer and use it in GitHub Desktop.
modulo matrix sequencing
This file contains hidden or 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
-- div | |
-- modulo matrix sequencing | |
-- with variable divisions | |
-- by lijnenspel | |
-- | |
-- grid needed | |
-- x = tracks, y = division | |
-- add samples via param menu | |
-- | |
-- enc 2 | |
-- tempo | |
-- | |
-- enc 3 | |
-- lin to exponential divisions | |
-- | |
-- divisions: | |
-- linear: 1 2 3 4 5 6 7 ... | |
-- full exp: 1 4 9 16 25 36 49 ... | |
local Ack = require '../ack/lib/ack' | |
engine.name = 'Ack' | |
local DATA_FILE_PATH = _path.data .. "lijnenspel/div2.data" | |
local PSET = "lijnenspel-div.pset" | |
steps = {} | |
position = 1 | |
div = {} | |
local save_data = {version = 1, toggles = {}, curve = 1.2, tempo = 128} | |
font_size = 20 | |
local function read_data() | |
params:read(PSET) | |
params:bang() | |
local disk_data = tab.load(DATA_FILE_PATH) | |
if disk_data then | |
if disk_data.version then | |
if disk_data.version == 1 then | |
save_data = disk_data | |
else | |
print("Unrecognized data, version " .. disk_data.version) | |
end | |
end | |
end | |
end | |
local function write_data() | |
tab.save(save_data, DATA_FILE_PATH) | |
params:write(PSET) | |
end | |
function cleanup() | |
write_data() | |
end | |
function bpmtometro(bpm) | |
return 60000/(bpm*192*32) | |
end | |
function init() | |
for y=1,8 do | |
save_data.toggles[y] = {} | |
end | |
Ack.add_params() | |
read_data() | |
div = divisions(save_data.curve) | |
for i=1,17 do | |
table.insert(steps,1) | |
end | |
grid_redraw() | |
counter = metro.init(count, bpmtometro(save_data.tempo), -1) | |
counter:start() | |
screen.font_face(9) | |
screen.font_size(font_size) | |
screen.aa(0) | |
end | |
g = grid.connect() | |
function g.key(x,y,z) | |
-- print("grid x"..x.." y"..y.." z"..z) | |
if z==1 then | |
save_data.toggles[y][x] = not save_data.toggles[y][x] | |
end | |
g:refresh() | |
end | |
function grid_redraw() | |
g:all(0) | |
for key, value in pairs(div) do | |
if position % value == 1 then | |
g:led(key-1,1,2) | |
end | |
end | |
for track, togs in pairs(save_data.toggles) do | |
for modu, bool in pairs(togs) do | |
if bool==true then | |
if position % div[modu+1] == 1 then | |
engine.kill(track-1) | |
engine.trig(track-1) | |
g:led(modu,track,15) | |
else | |
g:led(modu,track,5) | |
end | |
end | |
end | |
end | |
g:refresh() | |
end | |
function draw_spread() | |
local y_max = (font_size-1)*2+5 | |
local y_min = (font_size-1)*3 | |
local x_mix = util.linlin(1, 2, 95, 128, save_data.curve) | |
screen.move(95, y_min) | |
screen.curve(95, y_min, x_mix, y_min, 128, y_max) | |
screen.stroke() | |
end | |
function redraw() | |
screen.clear() | |
-- future idea: presets | |
-- screen.move(0,(font_size-1)-1) | |
-- screen.text("preset") | |
-- screen.move(126,(font_size-1)-1) | |
-- screen.text_right(1) | |
screen.move(0,(font_size-1)*2) | |
screen.text("tempo") | |
screen.move(126,(font_size-1)*2) | |
screen.text_right(save_data.tempo) | |
screen.move(0,(font_size-1)*3) | |
screen.text("spread") | |
-- screen.move(126,(font_size-1)*2) | |
-- screen.text_right(save_data.curve) | |
draw_spread() | |
screen.update() | |
end | |
function curve(x,t) | |
return (x-1)^t | |
end | |
function divisions(t) | |
divs = {} | |
for i=1,17 do | |
divs[i] = math.floor(curve(i+1,t)) | |
print(divs[i]) | |
end | |
return divs | |
end | |
function count() | |
position = position + 1 | |
grid_redraw() | |
end | |
function key(n, z) | |
print("key n"..n.." z"..z ) | |
redraw() | |
end | |
function enc(n, d) | |
print("enc n"..n.." d"..d ) | |
if n == 2 then | |
save_data.tempo = save_data.tempo+d | |
counter.time = bpmtometro(save_data.tempo) | |
elseif n == 3 then | |
save_data.curve = util.clamp(save_data.curve+(d/100),1,2) | |
div = divisions(save_data.curve) | |
end | |
write_data() | |
redraw() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment