Fix ExportFormatSpecification copy-c'tor
[ardour.git] / scripts / _insert_region_gaps.lua
1 ardour {
2         ["type"]    = "EditorAction",
3         name        = "Insert Gaps",
4         license     = "MIT",
5         author      = "Ardour Team",
6         description = [[Insert gaps between all regions on selected tracks]]
7 }
8
9 function action_params ()
10         return
11         {
12                 ["gap"] = { title = "Gap size (in sec)", default = "2" },
13         }
14 end
15
16 function factory () return function ()
17         -- get configuration
18         local p = params or {}
19         local gap = p["gap"] or 2
20         if gap <= 0 then gap = 2 end
21
22         local sel = Editor:get_selection () -- get current selection
23
24         local add_undo = false -- keep track of changes
25         Session:begin_reversible_command ("Insert Gaps")
26
27         -- iterate over all selected tracks
28         for route in sel.tracks:routelist ():iter () do
29                 local track = route:to_track ()
30                 if track:isnil () then goto continue end
31
32                 -- get track's playlist
33                 local playlist = track:playlist ()
34                 local offset = 0
35
36                 -- iterate over all regions in the playlist
37                 for region in playlist:region_list():iter() do
38
39                         -- preare for undo operation
40                         region:to_stateful ():clear_changes ()
41
42                         -- move region
43                         region:set_position (region:position() + offset, 0)
44                         offset = offset + Session:nominal_sample_rate () * gap
45
46                         -- create a diff of the performed work, add it to the session's undo stack
47                         -- and check if it is not empty
48                         if not Session:add_stateful_diff_command (region:to_statefuldestructible ()):empty () then
49                                 add_undo = true
50                         end
51                 end
52                 ::continue::
53         end
54
55         -- all done, commit the combined Undo Operation
56         if add_undo then
57                 -- the 'nil' Command here mean to use the collected diffs added above
58                 Session:commit_reversible_command (nil)
59         else
60                 Session:abort_reversible_command ()
61         end
62 end end