Cont'd work on route-templates
[ardour.git] / scripts / _route_template_generic_audio.lua
1 ardour {
2         ["type"]    = "EditorAction",
3         name        = "Generic Audio Track",
4         description = [[Example ]]
5 }
6
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
9 --
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())
14         return
15         {
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(),
19                 ['name'] = 'Audio',
20                 ['channels'] = 2,
21                 ['track_mode'] = ARDOUR.TrackMode.Normal,
22                 ['strict_io'] = true,
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
28         }
29 end
30
31 -- The Script can be used as EditorAction in which case it can
32 -- optionally provide instantiation parmaters
33 function action_params ()
34         return
35         {
36                 ['how_many'] = { title = "How Many tracks to add", default = "1" },
37                 ["name"]     = { title = "Track Name Prefix", default = "Audio" },
38         }
39 end
40
41
42 function factory (params) return function ()
43         -- When called from the AddRouteDialog, 'params' will be a table with
44         -- keys as described in route_setup() above.
45
46         local p         = params or route_setup ()
47         local name      = p["name"] or 'Audio'
48         local how_many  = p["how_many"] or 1
49         local channels  = p["channels"] or 1
50         local insert_at = p["insert_at"] or ARDOUR.PresentationInfo.max_order;
51         local group     = p["group"] or nil
52         local mode      = p["track_mode"] or ARDOUR.TrackMode.Normal
53         local strict_io = p["strict_io"] or false
54         local chan_out  = 0
55
56         if ARDOUR.config():get_output_auto_connect() == ARDOUR.AutoConnectOption.AutoConnectMaster then
57                 if not Session:master_out():isnil() then
58                         chan_out = Session:master_out():n_inputs ():n_audio ()
59                 end
60         end
61
62         if chan_out == 0 then
63                 chan_out = channels;
64         end
65
66         local tl = Session:new_audio_track (channels, chan_out, group, how_many, name, insert_at, mode)
67
68         if strict_io then
69                 for t in tl:iter() do
70                         t:set_strict_io (true)
71                 end
72         end
73
74 end end