1 ardour { ["type"] = "EditorAction", name = "Marker Split",
3 author = "Ardour Team",
4 description = [[Split regions on selected tracks at all locations markers]]
7 function factory (params) return function ()
9 local loc = Session:locations () -- all marker locations
11 -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Selection
12 local sel = Editor:get_selection ()
14 -- prepare undo operation
15 -- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Session
16 Session:begin_reversible_command ("Auto Region Split")
17 local add_undo = false -- keep track if something has changed
19 -- Track/Bus Selection -- iterate over all Editor-GUI selected tracks
20 -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:TrackSelection
21 for r in sel.tracks:routelist ():iter () do
22 -- each of the items 'r' is-a
23 -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Route
25 local track = r:to_track () -- see if it's a track
26 if track:isnil () then
31 -- get track's playlist
32 -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Playlist
33 local playlist = track:playlist ()
35 -- clear existing changes, prepare "diff" of state for undo
36 playlist:to_stateful ():clear_changes ()
38 -- iterate over all location markers
39 for l in loc:list ():iter () do
41 -- get all regions on the given track's playlist (may be stacked)
42 for reg in playlist:regions_at (l:start ()):iter () do
43 playlist:split_region (reg, l:start (), 0)
44 -- the above operation will invalidate the playlist's region list:
45 -- split creates 2 new regions.
47 -- Hence this script does it the way it does: the inner-most loop
48 -- is over playlist-regions.
54 if not Session:add_stateful_diff_command (playlist:to_statefuldestructible ()):empty () then
55 -- is something has changed, we need to save it at the end.
62 -- all done, commit the combined Undo Operation
64 -- the 'nil' Command here mean to use the collected diffs added above
65 Session:commit_reversible_command (nil)
67 Session:abort_reversible_command ()