Add some convenient public editor methods (for lua-bindings)
[ardour.git] / scripts / select_every_2nd_region.lua
1 ardour {
2         ["type"]    = "EditorAction",
3         name        = "Region Select/2",
4         license     = "MIT",
5         author      = "Ardour Team",
6         description = [[select every 2nd region on all selected tracks]]
7 }
8
9 -- select every 2nd region on all selected tracks
10 function factory () return function ()
11
12         local sl = ArdourUI.SelectionList () -- empty selection list
13
14         local sel = Editor:get_selection () -- get current selection
15         -- for each selected track/bus..
16         for route in sel.tracks:routelist ():iter () do
17                 -- consider only tracks
18                 local track = route:to_track ()
19                 if track:isnil() then
20                         goto continue
21                 end
22
23                 local skip = false;
24                 -- iterate over all regions of the given track
25                 for region in track:playlist():region_list():iter() do
26                         if skip then
27                                 -- skip every 2nd region
28                                 skip = false;
29                         else
30                                 skip = true;
31                                 -- get RegionView (GUI object to be selected)
32                                 local rv = Editor:regionview_from_region (region)
33                                 -- add it to the list of Objects to be selected
34                                 sl:push_back (rv);
35                         end
36                 end
37                 ::continue::
38         end
39
40         -- set/replace current selection in the editor
41         Editor:set_selection (sl, ArdourUI.SelectionOp.Set);
42 end end