diff options
author | Robin Gareus <robin@gareus.org> | 2016-05-05 23:49:44 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2016-05-05 23:49:44 +0200 |
commit | e89e799eb5c74920aa2b610dfdd20c70df048ff1 (patch) | |
tree | e136fb15410ab8519c7f4fdc7c0dc038520e5ef6 /scripts/bounce_replace.lua | |
parent | 7fed1ce085eb6372e721f40abb92463ad72ee493 (diff) | |
download | ardour-e89e799eb5c74920aa2b610dfdd20c70df048ff1.zip ardour-e89e799eb5c74920aa2b610dfdd20c70df048ff1.tar.gz ardour-e89e799eb5c74920aa2b610dfdd20c70df048ff1.tar.bz2 |
lua script to bounce regions w/processing and replace the region
Diffstat (limited to 'scripts/bounce_replace.lua')
-rw-r--r-- | scripts/bounce_replace.lua | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/scripts/bounce_replace.lua b/scripts/bounce_replace.lua new file mode 100644 index 0000000..d383a87 --- /dev/null +++ b/scripts/bounce_replace.lua @@ -0,0 +1,66 @@ +ardour { ["type"] = "EditorAction", name = "Bounce+Replace Regions", + license = "MIT", + author = "Robin Gareus", + email = "robin@gareus.org", + site = "http://gareus.org", + description = [[Bounce selected regions with processing and replace region]] +} + +function factory (params) return function () + -- there is currently no direct way to find the track + -- corresponding to a [selected] region + function find_track_for_region (region_id) + for route in Session:get_tracks():iter() do + local track = route:to_track(); + local pl = track:playlist () + if not pl:region_by_id (region_id):isnil () then + return track + end + end + assert (0); -- can't happen, region must be in a playlist + end + + -- get selection + -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Selection + local sel = Editor:get_selection () + + -- prepare undo operation + Session:begin_reversible_command ("Bounce+Replace Regions") + local add_undo = false -- keep track if something has changed + + -- Iterate over Regions part of the selection + -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:RegionSelection + for r in sel.regions:regionlist ():iter () do + -- each of the items 'r' is a + -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Region + + local track = find_track_for_region (r:to_stateful():id()) + local playlist = track:playlist () + + -- clear existing changes, prepare "diff" of state for undo + playlist:to_stateful ():clear_changes () + + -- bounce the region with processing + local region = track:bounce_range (r:position (), r:position() + r:length (), ARDOUR.InterThreadInfo (), track:main_outs (), false); + + -- remove old region.. + playlist:remove_region (r); + -- ..and add the newly bounced one + playlist:add_region (region, r:position (), 1, false) + + -- create a diff of the performed work, add it to the session's undo stack + -- and check if it is not empty + if not Session:add_stateful_diff_command (playlist:to_statefuldestructible ()):empty () then + add_undo = true + end + 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 |