last_tick = time()
bpm = 0
function init()
input[1].mode('change',3.0,0.1,'rising')
metro[1].time = 1
metro[1]:start()
metro[1].event = function(c) print(string.format("metro[1] bpm: %d", math.floor(bpm))) end
end
input[1].change = function(state)
local elapsed = time() - last_tick
bpm = 60000/elapsed
metro[1].time = elapsed * 0.001
last_tick = time()
end
That will take an incoming clock and adjust a metronome to be set to the rate of the incoming clock. Then you could just take that metro and fire on every X events to divide or whatever, have another metronome set to be a multiple of it to multiply… Gives you BPM as well if you want to do something with BPM within a range or whatever…
I don’t know if updating the metro speed that often has any drawbacks but it seems to work ok for me.
Actually in the first post Voidstar’s modes.lua sets up his ms-interval checking by calculating a running average of the last 2 numbers cumulatively to smooth out tempo changes that’s a good way to do it.