Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ardour {
["type"] = "EditorAction",
name = "Close Gaps",
license = "MIT",
author = "Ardour Team",
description = [[Same as Region > Edit > Close Gaps, but for all regions on selected tracks]]
function factory () return function ()
-- settings
local pull_back = 0.030 * Session:sample_rate()
local crossfade = 0.005 * Session:sample_rate()
-- get configuration
local sel = Editor:get_selection () -- get current selection
local add_undo = false -- keep track of changes
Session:begin_reversible_command ("Close Gaps")
-- iterate over all selected tracks
for route in sel.tracks:routelist ():iter () do
local track = route:to_track ()
if track:isnil () then goto skip end
local prev_region
-- iterate over all regions in the track's playlist
for this_region in track:playlist():region_list():iter() do
if prev_region ~= nil then
-- preare for undo operation
this_region:to_stateful ():clear_changes ()
prev_region:to_stateful ():clear_changes ()
-- close gaps
local position = this_region:position()
this_region:trim_front (position - pull_back, 0)
prev_region:trim_end (position - pull_back + crossfade, 0)
-- create a diff of the performed work, add it to the session's undo stack
if not Session:add_stateful_diff_command (this_region:to_statefuldestructible ()):empty () then add_undo = true end
if not Session:add_stateful_diff_command (prev_region:to_statefuldestructible ()):empty () then add_undo = true end
prev_region = this_region
-- all done, commit the combined Undo Operation
if add_undo then
-- the 'nil' Command here mean to use the collected diffs added above
Session:commit_reversible_command (nil)
Session:abort_reversible_command ()
end end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment