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, ARDOUR.MusicFrame (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 ()
73 -- render an icon for the toolbar action-button
74 -- this is genrally square width == height.
75 -- The background is set according to the theme (leave transparent when drawing).
76 -- A foreground color is passed as parameter 'fg'
78 -- ctx is-a http://manual.ardour.org/lua-scripting/class_reference/#Cairo:Context
79 -- 2D vector graphics http://cairographics.org/
80 function icon (params) return function (ctx, width, height, fg)
81 local mh = height - 3.5;
85 ctx:set_line_width (.5)
87 -- compare to gtk2_ardour/marker.cc "Marker"
88 ctx:set_source_rgba (.8, .8, .2, 1.0)
89 ctx:move_to (width / 2 - m6, 2)
90 ctx:rel_line_to (m3, 0)
91 ctx:rel_line_to (0, mh * 0.4)
92 ctx:rel_line_to (-m6, mh * 0.6)
93 ctx:rel_line_to (-m6, -mh * 0.6)
96 ctx:set_source_rgba (.0, .0, .0, 1.0)
99 -- draw an arrow <--|--> on top, using the foreground color
100 ctx:set_source_rgba (ARDOUR.LuaAPI.color_to_rgba (fg))
101 ctx:set_line_width (1)
103 ctx:move_to (width * .5, height * .4)
104 ctx:line_to (width * .5, height * .6)
107 ctx:move_to (2, height * .5)
108 ctx:line_to (width - 2, height * .5)
111 ctx:move_to (width - 2, height * .5)
112 ctx:rel_line_to (-m6, -m6)
113 ctx:rel_line_to (0, m3)
117 ctx:move_to (2, height * .5)
118 ctx:rel_line_to (m6, -m6)
119 ctx:rel_line_to (0, m3)