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