fix issue with initialization of a BBT_Time variable.
[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
43
44 function icon (params) return function (ctx, width, height, fg)
45         local wh = math.min (width, height) * .5
46
47         ctx:set_line_width (1)
48         ctx:rectangle (wh * .25, wh * .75, wh * 1.5 , .5 * wh)
49         ctx:set_source_rgba (0, 0, 0, 1)
50         ctx:stroke_preserve ()
51         ctx:set_source_rgba (.9, .9, .9, 1)
52         ctx:fill ()
53
54         ctx:set_source_rgba (1, 0, 0, 1)
55         ctx:rectangle (.5 + math.ceil(wh * 0.25), .5 + math.ceil(wh * .75), math.floor(wh * .5) - 1, math.floor(.5 * wh) - 1)
56         ctx:stroke_preserve ()
57
58         ctx:rectangle (.5 + math.ceil(wh * 1.25), .5 + math.ceil(wh * .75), math.floor(wh * .5) - 1, math.floor(.5 * wh) - 1)
59         ctx:stroke_preserve ()
60 end end