Add some convenient public editor methods (for lua-bindings)
[ardour.git] / scripts / s_pluginutils.lua
1 ardour { ["type"] = "Snippet", name = "Plugin Utils" }
2
3 function factory () return function ()
4
5         -------------------------------------------------------------------------------
6         -- add a Plugin (here LV2) to all mono tracks that contain the pattern "dru"
7         -- and load a plugin-preset (if it exists)
8         for r in Session:get_routes():iter() do
9                 if (string.match (r:name(), "dru") and r:n_inputs():n_audio() == 1) then
10                         local proc = ARDOUR.LuaAPI.new_plugin(Session, "http://gareus.org/oss/lv2/fil4#mono", ARDOUR.PluginType.LV2, "cutbass");
11                         assert (not proc:isnil())
12                         r:add_processor_by_index(proc, 0, nil, true)
13                 end
14         end
15
16
17         -------------------------------------------------------------------------------
18         -- load a plugin preset
19         route = Session:get_remote_nth_route(2)
20         assert (route)
21         -- to 4th plugin (from top), ardour starts counting at zero
22         plugin = route:nth_plugin(3):to_insert():plugin(0)
23         assert (not plugin:isnil())
24         ps = plugin:preset_by_label("cutbass") -- get preset by name
25         assert (ps)
26         print (ps.uri)
27         plugin:load_preset (ps)
28
29
30         -------------------------------------------------------------------------------
31         -- add a LuaProcessor (here "Scope") to all tracks
32         for t in Session:get_tracks():iter() do
33                 local pos = 0 -- insert at the top
34
35                 -- the following two lines are equivalent
36                 --local proc = ARDOUR.LuaAPI.new_luaproc(Session, "a-Inline Scope");
37                 local proc = ARDOUR.LuaAPI.new_plugin (Session, "a-Inline Scope", ARDOUR.PluginType.Lua, "");
38                 assert (not proc:isnil())
39
40                 t:add_processor_by_index(proc, pos, nil, true)
41                 -- optionally set some parameters
42                 ARDOUR.LuaAPI.set_processor_param (proc, 0, 5) -- timescale 5sec
43         end
44
45 end end