Video-Frame (not sample)
[ardour.git] / scripts / jump_to_marker.lua
1 ardour { ["type"] = "EditorAction", name = "Jump to Marker",
2         license     = "MIT",
3         author      = "Ardour Team",
4         description = [[Jump to the first marker matching a given pattern]]
5 }
6
7 function factory () return function ()
8         local keep = false
9
10         ::restart::
11
12         local dlg = LuaDialog.Dialog ("Search and Jump to Marker",
13                 {
14                         { type = "entry",    key = "marker", default = '',   title = "Marker Prefix" },
15                         { type = "checkbox", key = "keep",   default = keep, title = "Keep Dialog Open" },
16                 })
17
18         local rv = dlg:run()
19         if not rv then return end
20
21         keep = rv['keep']
22
23         if (rv['marker'] == "") then
24                 if keep then goto restart end
25                 return
26         end
27
28         for l in Session:locations():list():iter() do
29                 if l:is_mark() and string.find (l:name(), "^" .. rv['marker'] .. ".*$") then
30                         Session:request_locate (l:start())
31                         if keep then goto restart end
32                         return
33                 end
34         end
35
36         LuaDialog.Message ("Jump to Marker", "No marker matching the given pattern was found.", LuaDialog.MessageType.Warning, LuaDialog.ButtonType.Close):run ()
37
38         if keep then goto restart end
39 end end
40
41
42 function icon (params) return function (ctx, width, height, fg)
43         local mh = height - 3.5;
44         local m3 = width / 3;
45         local m6 = width / 6;
46
47         ctx:set_line_width (.5)
48
49         -- compare to gtk2_ardour/marker.cc "Marker"
50         ctx:set_source_rgba (.6, .6, .6, 1.0)
51         ctx:move_to (width / 2 - m6, 2)
52         ctx:rel_line_to (m3, 0)
53         ctx:rel_line_to (0, mh * 0.4)
54         ctx:rel_line_to (-m6, mh * 0.6)
55         ctx:rel_line_to (-m6, -mh * 0.6)
56         ctx:close_path ()
57         ctx:fill_preserve ()
58         ctx:set_source_rgba (.0, .0, .0, 1.0)
59         ctx:stroke ()
60
61         ctx:set_source_rgba (ARDOUR.LuaAPI.color_to_rgba (fg))
62         local txt = Cairo.PangoLayout (ctx, "ArdourMono ".. math.ceil(math.min (width, height) * .5) .. "px")
63         txt:set_text ("txt")
64         local tw, th = txt:get_pixel_size ()
65         ctx:move_to (.5 * (width - tw), .5 * (height - th))
66         txt:show_in_cairo_context (ctx)
67 end end