2 ["type"] = "EditorAction",
5 author = "Ardour Team",
6 description = [[Insert gaps between all regions on selected tracks]]
9 function action_params ()
12 ["gap"] = { title = "Gap size (in sec)", default = "2" },
16 function factory () return function ()
18 local p = params or {}
19 local gap = p["gap"] or 2
20 if gap <= 0 then gap = 2 end
22 local sel = Editor:get_selection () -- get current selection
24 local add_undo = false -- keep track of changes
25 Session:begin_reversible_command ("Insert Gaps")
27 -- iterate over all selected tracks
28 for route in sel.tracks:routelist ():iter () do
29 local track = route:to_track ()
30 if track:isnil () then goto continue end
32 -- get track's playlist
33 local playlist = track:playlist ()
36 -- iterate over all regions in the playlist
37 for region in playlist:region_list():iter() do
39 -- preare for undo operation
40 region:to_stateful ():clear_changes ()
43 region:set_position (region:position() + offset, 0)
44 offset = offset + Session:nominal_sample_rate () * gap
46 -- create a diff of the performed work, add it to the session's undo stack
47 -- and check if it is not empty
48 if not Session:add_stateful_diff_command (region:to_statefuldestructible ()):empty () then
55 -- all done, commit the combined Undo Operation
57 -- the 'nil' Command here mean to use the collected diffs added above
58 Session:commit_reversible_command (nil)
60 Session:abort_reversible_command ()