Skip to content

Instantly share code, notes, and snippets.

@x42
Created October 17, 2021 12:55
Show Gist options
  • Save x42/43473ecf049b2dd4627b958744df9345 to your computer and use it in GitHub Desktop.
Save x42/43473ecf049b2dd4627b958744df9345 to your computer and use it in GitHub Desktop.
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
end
prev_region = this_region
end
::skip::
end
-- 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)
else
Session:abort_reversible_command ()
end
end end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment