mp4chaps Lua script: don't clutter global environment
[ardour.git] / scripts / _route_template_generic_midi.lua
1 ardour {
2         ["type"]    = "EditorAction",
3         name        = "Generic MIDI 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         return
13         {
14                 -- keys control which AddRouteDialog controls are made sensitive.
15                 -- The following keys accept a default value to pre-seed the dialog.
16                 ['how_many'] = 1,
17                 ['name'] = 'MIDI',
18                 ['channels'] = nil,
19                 ['track_mode'] = nil,
20                 ['strict_io'] = true,
21                 -- these keys just need to be set (to something other than nil)
22                 -- in order to set the control sensitives
23                 ['insert_at'] = ARDOUR.PresentationInfo.max_order,
24                 ['group'] = false, -- return value will be a RouteGroup*
25                 ['instrument'] = true, -- return value will be a PluginInfoPtr
26         }
27 end
28
29 -- The Script can be used as EditorAction in which case it can
30 -- optionally provide instantiation parmaters
31 function action_params ()
32         return
33         {
34                 ['how_many']   = { title = "How Many tracks to add", default = "1" },
35                 ["name"]       = { title = "Track Name Prefix", default = "MIDI" },
36                 ["instrument"] = { title = "Add Instrument", default = "true" },
37         }
38 end
39
40
41 function factory (params) return function ()
42         -- When called from the AddRouteDialog, 'params' will be a table with
43         -- keys as described in route_setup() above.
44
45         local p          = params or route_setup ()
46         local name       = p["name"] or 'Audio'
47         local how_many   = p["how_many"] or 1
48         local insert_at  = p["insert_at"] or ARDOUR.PresentationInfo.max_order;
49         local group      = p["group"] or nil
50         local strict_io  = p["strict_io"] or false
51         local instrument = p["instrument"] or nil
52
53         -- used in 'action-script mode'
54         if instrument == "true" then
55                 instrument = ARDOUR.LuaAPI.new_plugin_info ("http://gareus.org/oss/lv2/gmsynth", ARDOUR.PluginType.LV2) -- general midi synth
56                 if instrument:isnil () then
57                         instrument = ARDOUR.LuaAPI.new_plugin_info ("https://community.ardour.org/node/7596", ARDOUR.PluginType.LV2) -- reasonable synth
58                 end
59                 if instrument:isnil () then
60                         LuaDialog.Message ("MIDI track add", "Cannot find instrument plugin",
61                                 LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run ()
62                         return
63                 end
64         end
65
66         -- add no instrument
67         if type (instrument) ~= "userdata" then
68                 instrument = ARDOUR.PluginInfo ()
69         end
70
71         Session:new_midi_track(
72                 ARDOUR.ChanCount(ARDOUR.DataType ("midi"), 1),
73                 ARDOUR.ChanCount(ARDOUR.DataType ("audio"), 2),
74                 strict_io,
75                 instrument, nil,
76                 group, how_many, name, insert_at, ARDOUR.TrackMode.Normal)
77
78 end end