bf895dccf24a599238cd72864fc0e9cbf40a32bc
[ardour.git] / scripts / _template_example.lua
1 ardour {
2         ["type"]    = "SessionSetup",
3         name        = "Recording Session",
4         description = [[Add as many mono tracks to the new session as there are physical audio inputs and optionally record-arm them.]]
5 }
6
7 ---- For use with templates: Session Template setup-hook
8 --
9 -- If a script named 'template.lua' exists in a session-template folder
10 -- the `session_setup` function of the script is called after
11 -- creating the session from the template.
12 --
13 -- (e.g. ~/.config/ardour5/templates/Template-Name/template.lua)
14 --
15 --
16 ---- For use as meta-session
17 --
18 -- Every Lua script in the script-folder of type "SessionSetup"
19 -- is listed as implicit template in the new-session dialog.
20 -- The scripts 'session_setup' function  is called once after
21 -- creating a new, empty session.
22 --
23
24 function session_setup ()
25         local e = Session:engine()
26         -- from the engine's POV readable/capture ports are "outputs"
27         local _, t = e:get_backend_ports ("", ARDOUR.DataType("audio"), ARDOUR.PortFlags.IsOutput | ARDOUR.PortFlags.IsPhysical, C.StringVector())
28         -- table 't' holds argument references. t[4] is the C.StringVector (return value)
29         local tracks = t[4]:size();
30
31         local dialog_options = {
32                 { type = "heading", title = "Customize Session: " .. Session:name () },
33                 { type = "number", key = "tracks", title = "Create Tracks",  min = 1, max = 128, step = 1, digits = 0, default = tracks },
34                 { type = "checkbox", key = "recarm", default = false, title = "Record Arm Tracks" },
35         }
36
37         local dlg = LuaDialog.Dialog ("Template Setup", dialog_options)
38         local rv = dlg:run()
39         if (not rv or rv['tracks'] == 0) then
40                 return
41         end
42
43         -- create tracks
44         local tl = Session:new_audio_track (1, 2, nil, rv['tracks'], "",  ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
45         -- and optionally record-arm them
46         if rv['recarm'] then
47                 for track in tl:iter() do
48                         track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)
49                 end
50         end
51
52         Session:save_state("");
53 end