vpot above metronome button controls click gain; master gain knob now works correctly
[ardour.git] / scripts / split_all_markers.lua
1 ardour { ["type"] = "EditorAction", name = "Marker Split",
2         license     = "MIT",
3         author      = "Ardour Team",
4         description = [[Split regions on selected tracks at all locations markers]]
5 }
6
7 function factory (params) return function ()
8
9         local loc = Session:locations () -- all marker locations
10
11         -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Selection
12         local sel = Editor:get_selection ()
13
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
18
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
24
25                 local track = r:to_track () -- see if it's a track
26                 if track:isnil () then
27                         -- if not, skip it
28                         goto continue
29                 end
30
31                 -- get track's playlist
32                 -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Playlist
33                 local playlist = track:playlist ()
34
35                 -- clear existing changes, prepare "diff" of state for undo
36                 playlist:to_stateful ():clear_changes ()
37
38                 -- iterate over all location markers
39                 for l in loc:list ():iter () do
40                         if l:is_mark() then
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.
46                                         --
47                                         -- Hence this script does it the way it does: the inner-most loop
48                                         -- is over playlist-regions.
49                                 end
50                         end
51                 end
52
53                 -- collect undo data
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.
56                         add_undo = true
57                 end
58
59                 ::continue::
60         end
61
62         -- all done, commit the combined Undo Operation
63         if add_undo then
64                 -- the 'nil' Command here mean to use the collected diffs added above
65                 Session:commit_reversible_command (nil)
66         else
67                 Session:abort_reversible_command ()
68         end
69
70 end end