I’m having a strange problem that seems to be related to the norns clock and I’d appreciate any advice anyone has.
I’m working on a sequencer for 16n and grid where the step length is selected on grid columns from 1-8 pulses. I’m a Lua beginner, but as far as I can tell I’m passing clock.sync() a value ranging from 0.25-2.0. Most of the time this is working well, but sometimes the clock seems to ignore the duration. I haven’t found a pattern for when it happens but I’ve found a way to consistently reproduce the problem:
In this screen recording you can see that when I enter a new value for time it creates the correct rhythm on the first pass (pausing on step 6), but on each following pass it continues as if there is a value of 1.
My only uses of clock are line 33 in the video: clock.sync(syncTime)
and in my init() where line 50 is: clock.run(step)
.
Any ideas for what I might be doing wrong here?
EDIT: forgot to mention I have a factory norns running 221214
-- 16ngrid seq
-- seq using 16n pitch and grid rhythms
m = midi.connect()
g = grid.connect()
minimum = 1
maximum = 16
running = true
octaves = 3 --set range of each slider. add a scale thing here - i can probably get it from another script
syncSpeed = 0.25
m.event = function(data)
local d = midi.to_msg(data)
local p = d.cc - 31
seq.notes[p] = d.val
end
seq = {
pos = 1,
length = 16,
notes = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
times = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
}
function step()
while true do
local length = lengthLoop(seq.pos)
local syncTime = (syncSpeed * seq.times[length])
print("step:",length, " time:",seq.times[length]," syncTime:",syncTime,"tempo:",clock.get_tempo())
clock.sync(syncTime)
gridredraw()
redraw()
if running then
seq.pos = seq.pos + 1
end
if seq.pos > seq.length then
seq.pos = 1
end
end
end
function init()
clock.run(step)
end
function clock.transport.start()
running = true
end
function clock.transport.stop()
running = false
end
function gridredraw()
--local grid_h = g.rows
g:all(0)
for i=1,16 do
g:led(i,seq.times[i],7)
end
g:led(seq.pos,seq.times[seq.pos],15)
g:refresh()
end
function redraw()
screen.clear()
screen.update()
end
function g.key(x,y,z)
if z == 1 then
seq.times[x] = y
end
gridredraw()
end
function lengthLoop(l)
local l = (seq.pos - 1)
if l < minimum then l = maximum end
return l
end
function cleanup()
end