2 ["type"] = "EditorAction",
3 name = "Generic Audio Track",
4 description = [[Add Audio tracks, by default as many as there are physical inputs]]
7 -- If a route_setup function is present in an Editor Action Script
8 -- the script is also listed in the "add track/bus" dialog as meta-template
10 -- The function is expected to return a Lua table. The table may be empty.
11 function route_setup ()
12 local e = Session:engine()
13 local _, t = e:get_backend_ports ("", ARDOUR.DataType("audio"), ARDOUR.PortFlags.IsOutput | ARDOUR.PortFlags.IsPhysical, C.StringVector())
16 -- keys control which AddRouteDialog controls are made sensitive.
17 -- The following keys accept a default value to pre-seed the dialog.
18 ['how_many'] = t[4]:size(),
21 ['track_mode'] = ARDOUR.TrackMode.Normal,
23 -- these keys just need to be set (to something other than nil)
24 -- in order to set the control sensitives
25 ['insert_at'] = ARDOUR.PresentationInfo.max_order,
26 ['group'] = false, -- return value will be a RouteGroup*
27 ['instrument'] = nil, -- return value will be a PluginInfoPtr
31 -- The Script can be used as EditorAction in which case it *could*
32 -- optionally provide instantiation parmaters..
34 function action_params ()
37 ['how_many'] = { title = "How Many tracks to add", default = "1" },
38 ["name"] = { title = "Track Name Prefix", default = "Audio" },
45 -- when used from the AddRouteDialog (or w/action_params)
46 if type (p) == 'table' and p['how_many'] ~= nil then
48 -- When called from the AddRouteDialog, 'p' will be a table with
49 -- keys as described in route_setup() above.
50 local name = p["name"] or 'Audio'
51 local how_many = p["how_many"] or 1
52 local channels = p["channels"] or 1
53 local insert_at = p["insert_at"] or ARDOUR.PresentationInfo.max_order;
54 local group = p["group"] or nil
55 local mode = p["track_mode"] or ARDOUR.TrackMode.Normal
56 local strict_io = p["strict_io"] or false
59 if ARDOUR.config():get_output_auto_connect() == ARDOUR.AutoConnectOption.AutoConnectMaster then
60 if not Session:master_out():isnil() then
61 chan_out = Session:master_out():n_inputs ():n_audio ()
69 local tl = Session:new_audio_track (channels, chan_out, group, how_many, name, insert_at, mode)
73 t:set_strict_io (true)
78 -- when used as standalone (no action parameters): interactive
80 local e = Session:engine()
81 local _, t = e:get_backend_ports ("", ARDOUR.DataType("audio"), ARDOUR.PortFlags.IsOutput | ARDOUR.PortFlags.IsPhysical, C.StringVector())
82 local tracks = t[4]:size();
84 local dialog_options = {
85 { type = "number", key = "tracks", title = "Create Tracks", min = 1, max = 128, step = 1, digits = 0, default = tracks },
86 { type = "entry", key = "name", default = 'Audio', title = "Name Prefix" },
87 { type = "checkbox", key = "stereo", default = false, title = "Stereo" },
88 { type = "checkbox", key = "recarm", default = false, title = "Record Arm Tracks" },
91 local dlg = LuaDialog.Dialog ("Create Audio Tracks", dialog_options)
93 if (not rv or rv['tracks'] == 0) then
97 local chan_in = stereo and 2 or 1
100 if ARDOUR.config():get_output_auto_connect() == ARDOUR.AutoConnectOption.AutoConnectMaster then
101 if not Session:master_out():isnil() then
102 chan_out = Session:master_out():n_inputs ():n_audio ()
106 if chan_out == 0 then
111 local tl = Session:new_audio_track (chan_in, chan_out, nil, rv['tracks'], "", ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal)
112 -- and optionally record-arm them
114 for track in tl:iter() do
115 track:rec_enable_control ():set_value (1, PBD.GroupControlDisposition.NoGroup)