Add a missing #define to our MSVC project (portaudio_backend)
[ardour.git] / scripts / export_mp4chaps.lua
1 ardour {
2         ["type"] = "EditorAction",
3         name = "Export markers as mp4chaps",
4         author = "Johannes Mueller",
5         description = [[
6 Exports MP4chaps of all markers except xruns. The markers are stored in the
7 export directory of the session in mp4 chapter marks format. The filename
8 is mp4chaps.txt
9
10 Note that there's always a chapter mark "Intro" at 00:00:00.000 as some
11 players can't live without it. If there are no exportable markers, the file
12 is not created.
13
14 This is a bit more convenient than the export option, as one does not
15 have to wait for the export.
16 ]],
17         license = "GPLv2"
18 }
19
20 function factory (unused_params) return function ()
21
22         fr = Session:frame_rate()
23         chaps = {}
24
25         for l in Session:locations():list():iter() do
26                 name = l:name()
27                 if not l:is_mark() or string.find(name, "^xrun%d*$") then
28                         goto next end
29
30                 t = l:start()
31                 h = math.floor(t / (3600*fr))
32                 r = t - (h*3600*fr)
33                 m = math.floor(r / (60*fr))
34                 r = r - m*60*fr
35                 s = math.floor(r / fr)
36                 r = r - s*fr
37                 ms = math.floor(r*1000/fr)
38                 table.insert(chaps, string.format("%02d:%02d:%02d.%03d %s\n", h, m, s, ms, name))
39                 ::next::
40         end
41
42         if next(chaps) == nil then
43                 goto out end
44
45         table.insert(chaps, "00:00:00.000 Intro\n")
46         table.sort(chaps)
47
48         file = io.open(ARDOUR.LuaAPI.build_filename (Session:path(), "export", "mp4chaps.txt"), "w")
49         for i, line in ipairs(chaps) do
50                 file:write(line)
51         end
52         file:close()
53
54         ::out::
55 end end
56
57 function icon (params) return function (ctx, width, height, fg)
58         local mh = height - 3.5;
59         local m3 = width / 3;
60         local m6 = width / 6;
61
62         ctx:set_line_width (.5)
63         ctx:set_source_rgba (ARDOUR.LuaAPI.color_to_rgba (fg))
64
65         ctx:move_to (width / 2 - m6, 2)
66         ctx:rel_line_to (m3, 0)
67         ctx:rel_line_to (0, mh * 0.4)
68         ctx:rel_line_to (-m6, mh * 0.6)
69         ctx:rel_line_to (-m6, -mh * 0.6)
70         ctx:close_path ()
71         ctx:stroke ()
72
73         local txt = Cairo.PangoLayout (ctx, "ArdourMono ".. math.ceil(math.min (width, height) * .5) .. "px")
74         txt:set_text ("MP4")
75         local tw, th = txt:get_pixel_size ()
76         ctx:move_to (.5 * (width - tw), .5 * (height - th))
77         txt:show_in_cairo_context (ctx)
78 end end