1 ardour { ["type"] = "EditorAction", name = "Bounce+Replace Regions",
3 author = "Ardour Team",
4 description = [[Bounce selected regions with processing and replace region]]
7 function factory (params) return function ()
8 -- there is currently no direct way to find the track
9 -- corresponding to a [selected] region
10 function find_track_for_region (region_id)
11 for route in Session:get_tracks():iter() do
12 local track = route:to_track();
13 local pl = track:playlist ()
14 if not pl:region_by_id (region_id):isnil () then
18 assert (0); -- can't happen, region must be in a playlist
22 -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Selection
23 local sel = Editor:get_selection ()
25 -- prepare undo operation
26 Session:begin_reversible_command ("Bounce+Replace Regions")
27 local add_undo = false -- keep track if something has changed
29 -- Iterate over Regions part of the selection
30 -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:RegionSelection
31 for r in sel.regions:regionlist ():iter () do
32 -- each of the items 'r' is a
33 -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Region
35 local track = find_track_for_region (r:to_stateful():id())
36 local playlist = track:playlist ()
38 -- clear existing changes, prepare "diff" of state for undo
39 playlist:to_stateful ():clear_changes ()
41 -- bounce the region with processing
42 local region = track:bounce_range (r:position (), r:position() + r:length (), ARDOUR.InterThreadInfo (), track:main_outs (), false);
44 -- remove old region..
45 playlist:remove_region (r);
46 -- ..and add the newly bounced one
47 playlist:add_region (region, r:position (), 1, false, 0, false)
49 -- create a diff of the performed work, add it to the session's undo stack
50 -- and check if it is not empty
51 if not Session:add_stateful_diff_command (playlist:to_statefuldestructible ()):empty () then
56 -- all done, commit the combined Undo Operation
58 -- the 'nil' Command here mean to use the collected diffs added above
59 Session:commit_reversible_command (nil)
61 Session:abort_reversible_command ()