Video-Frame (not sample)
[ardour.git] / scripts / preare_record_example.lua
1 --[[
2
3 # Example script to prepare the Ardour session for recording
4
5 Usually there's a certain state needed to actually start the recording.  This example
6 script treats the situation of a podcast recording. When starting the recording the
7 following settings have to be ensured.
8
9 * Session has to be recenabled
10 * Tracks have to be recenabled
11 * Gain automation have to set on write in order to record events from mute buttons
12 * The playhead has to be at 00:00:00.000
13 * The last (failed) capture has to be cleared
14 * Location markers have to be cleared
15
16 So this script automizes away the task and lets the podcast moderator by just one
17 action (for example triggerd by a Wiimote) prepare the session for recording.
18
19 It can be used for example with the python script of the Linux podcasting hacks:
20 https://github.com/linux-podcasting-hacks/wiimote-recording-control
21
22 Not that this script is more meant as an demo script to demonstrate the
23 possibilities of the Lua interface.
24
25 --]]
26
27 ardour {
28         ["type"] = "EditorAction",
29         name = "Prepare recording for podcast",
30         author = "Johannes Mueller",
31         description = [[
32 Prepares the Ardour session for podcast recording.
33
34 * Sets the gain automation to "Write" so that muting buttons work.
35 * Recenables all tracks.
36 * Clears all markers.
37 * Erases the last capture (assuming that it was a failed one)
38 * Rewinds the session to starting point.
39 * Recenables the session.
40 ]]
41 }
42
43 function factory (unused) return function()
44         if Session:actively_recording() then
45                 return end
46
47         for t in Session:get_tracks():iter() do
48                 t:gain_control():set_automation_state(ARDOUR.AutoState.Write)
49                 t:rec_enable_control():set_value(1, PBD.GroupControlDisposition.UseGroup)
50         end
51
52         for l in Session:locations():list():iter() do
53                 if l:is_mark() then
54                         Session:locations():remove(l)
55                 end
56         end
57
58         Session:goto_start()
59         Editor:remove_last_capture()
60         Session:maybe_enable_record()
61
62 end end
63
64 function icon (params) return function (ctx, width, height)
65         local x = width * .5
66         local y = height * .5
67         local r = math.min (x, y) * .55
68
69         ctx:arc (x, y, r, 0, 2 * math.pi)
70         ctx:set_source_rgba (.9, .3, .3, 1.)
71         ctx:fill_preserve ()
72         ctx:set_source_rgba (0, 0, 0, .8)
73         ctx:set_line_width (1)
74         ctx:stroke ()
75
76         local txt = Cairo.PangoLayout (ctx, "ArdourMono ".. math.ceil(r * 1.5) .. "px")
77         txt:set_text ("P")
78         local tw, th = txt:get_pixel_size ()
79         ctx:set_source_rgba (0, 0, 0, 1.0)
80         ctx:move_to (.5 * (width - tw), .5 * (height - th))
81         txt:show_in_cairo_context (ctx)
82 end end