diff options
author | Robin Gareus <robin@gareus.org> | 2017-11-23 15:27:29 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2017-11-23 15:27:29 +0100 |
commit | 406f9fa1ef5d64738f145fd5edaebfa2e5a10f3b (patch) | |
tree | c5f1178a8f4e6bdf225fd224a3aa97c59cf599ca /scripts | |
parent | a07bd2d5853aa7d383e325f0f5c1d88218e303c7 (diff) |
Example Lua script to move regions (insert gaps)
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/_insert_region_gaps.lua | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/scripts/_insert_region_gaps.lua b/scripts/_insert_region_gaps.lua new file mode 100644 index 0000000000..3a7f5ed8e9 --- /dev/null +++ b/scripts/_insert_region_gaps.lua @@ -0,0 +1,62 @@ +ardour { + ["type"] = "EditorAction", + name = "Insert Gaps", + license = "MIT", + author = "Ardour Team", + description = [[Insert gaps between all regions on selected tracks]] +} + +function action_params () + return + { + ["gap"] = { title = "Gap size (in sec)", default = "2" }, + } +end + +function factory () return function () + -- get configuration + local p = params or {} + local gap = p["gap"] or 2 + if gap <= 0 then gap = 2 end + + local sel = Editor:get_selection () -- get current selection + + local add_undo = false -- keep track of changes + Session:begin_reversible_command ("Insert Gaps") + + -- iterate over all selected tracks + for route in sel.tracks:routelist ():iter () do + local track = route:to_track () + if track:isnil () then goto continue end + + -- get track's playlist + local playlist = track:playlist () + local offset = 0 + + -- iterate over all regions in the playlist + for region in playlist:region_list():iter() do + + -- preare for undo operation + region:to_stateful ():clear_changes () + + -- move region + region:set_position (region:position() + offset, 0) + offset = offset + Session:nominal_sample_rate () * gap + + -- 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 (region:to_statefuldestructible ()):empty () then + add_undo = true + end + end + ::continue:: + 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 |