Cont'd work on route-templates
[ardour.git] / scripts / route_template_interactive_audio.lua
1 ardour {
2         ["type"]    = "EditorAction",
3         name        = "Create Audio Tracks Interactively",
4         description = [[
5 This template creates audio tracks.
6
7 You will be prompted for:
8 ... the number of tracks to add
9 ... the name of the tracks ( default: Audio %d )
10 ... whether they are mono or stereo (default mono)
11 ... whether to record-arm the tracks (default: no)
12 ]]
13 }
14
15 function route_setup ()
16         return
17         {
18                 ['Insert_at'] = ARDOUR.PresentationInfo.max_order;
19         }
20 end
21
22 function factory (params) return function ()
23         local p         = params or route_setup ()
24         local insert_at = p["insert_at"] or ARDOUR.PresentationInfo.max_order;
25
26         local e = Session:engine()
27         -- from the engine's POV readable/capture ports are "outputs"
28         local _, t = e:get_backend_ports ("", ARDOUR.DataType("audio"), ARDOUR.PortFlags.IsOutput | ARDOUR.PortFlags.IsPhysical, C.StringVector())
29         -- table 't' holds argument references. t[4] is the C.StringVector (return value)
30         local tracks = t[4]:size();
31
32         local dialog_options = {
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, 1, nil, rv['tracks'], "", insert_at, 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 end end