Hi there!
I recently encountered the problem that I needed to put space in between many regions. Like fanning them up in time. So I used a mean LLM, because I never had coded LUA before… (Back in the day I was a skilled Java programmer, long time ago, so I’m not a complete idiot, yet the LLM made a fool out of me eventually. It got only about 50% right and behaved like a mean person when being told so, so I spent a lot of time repairing broken generated code…)
So, this is what I came up with: ardour-lua-hacks/space-out-regions.lua at main · DrNI/ardour-lua-hacks · GitHub
It does work quite well, I think. The undo/redo also does work.
However, what doesn’t work is that it operates on regions on multiple tracks successfully. It has this current_shift variable, and this actually should depend on the track the region lives in, then it would be fine.
So, I would want something like this (not on GitHub, since it doesn’t work):
-- iterate over selected regions
for i, r in ipairs(region_table) do
local pos = r:position()
local track = r:track()
-- seeing this region on this track first time, so shift is initialized to 0
if trackShiftMap[track] == nil then
trackShiftMap[track] = 0
end
-- Undo system needs this
r:to_stateful():clear_changes()
-- Do the thing! Move the region!
r:set_position(pos + Temporal.timecnt_t(trackShiftMap[track]))
-- Feed undo system with this change
Session:add_stateful_diff_command(r:to_statefuldestructible ())
-- Re-compute shift for next region
trackShiftMap[track] = trackShiftMap[track] + base_shift
end
However, Region:track() does not exist, it’s a mere fantasy of AI.
So, how could I find the track a region belongs to?
Having reached that point I found that there is another script already doing this, yet it’s undo/redo apparently seems broken and it also is for single tracks only: ardour-scripts/A7/space regions single track.lua at master · davidhealey/ardour-scripts · GitHub
Use cases for this include beats that do not live on a grid, and that you separated into regions using the Rhythm Ferret… and then you want these slower or faster.
Any hints are appreciated.
Best
Niels