I’ld try to abstract over lpb. Personally i have lpb set to 8 or more, quantize will probaly not work too well on a lines basis, if you work with settings like that.
Sth. like:
-- lines to beat
local beat = (line_index - 1) / lpb
if note_column.delay_value > 0 then
local beat_delay =
(note_column.delay_value / 255) * (1 / lpb)
beat = beat + beat_delay
end
-- beat to lines
local new_line = math.floor(new_beat * lpb) + 1
local new_delay = (new_beat - ((new_line - 1) / lpb)) * lpb * 255
… or sth.
That doesn’t answer the question about what to do with note data that “doesn’t match” the pattern ofc (:
Don’t think there some general solution to that, you could simply leave it alone (with a threshold value, if the distance to a matching note in the quantize pattern is too big), or quantize it to some (fine resolution) groove grid instead. Or get crazy trying to recognize rhytmic patterns (triplets, flams, whatever) and make up interpolation functions according to the quantize pattern
maybe also look at the time sig bender tools code, a tool which can divide a pattern up in chunks and tries to fit the content in whatever set pattern length;
Take a pattern track with all delays, quantise it with renoise tools to a perfect grid, then using BPM automation recreate the delays.
Fully BPM dependant stuff will go crazy, but if the changes are small the general stuff won’t, and we get all the benefits of usinga perfect grid and a tracker in general.
I will combine it with a fancier automation curve drawing tool as well. BPM changes by 0.1-3 are quite nasty in the current system. (any other bpm/tpl automation will cause rendering issues)