13
0
livetrax/scripts/s_plugin_automation.lua

44 lines
1.4 KiB
Lua
Raw Normal View History

2016-04-11 08:36:57 -04:00
ardour { ["type"] = "Snippet", name = "Plugin automation" }
2016-04-10 14:57:24 -04:00
function factory () return function ()
2016-04-11 08:36:57 -04:00
-- query playhead position and session sample-rate
2016-04-10 14:57:24 -04:00
local playhead = Session:transport_frame ()
local samplerate = Session:nominal_frame_rate ()
2016-04-11 08:36:57 -04:00
-- get Track/Bus with RID 3
local r = Session:get_remote_nth_route(3)
2016-04-11 08:36:57 -04:00
-- make sure the track object exists
assert (not r:isnil ())
2016-04-10 14:57:24 -04:00
2016-04-11 08:36:57 -04:00
-- get AutomationList, ControlList and ParameterDescriptor
-- of the first plugin's first parameter
-- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:LuaAPI
local al, cl, pd = ARDOUR.LuaAPI.plugin_automation (r:nth_plugin (0), 0)
if not al:isnil () then
2016-04-10 14:57:24 -04:00
print ("Parameter Range", pd.lower, pd.upper)
2016-04-11 08:36:57 -04:00
print ("Current value", cl:eval (playhead))
2016-04-10 14:57:24 -04:00
-- prepare undo operation
Session:begin_reversible_command ("Automatix")
2016-04-11 08:36:57 -04:00
-- remember current AutomationList state
local before = al:get_state()
2016-04-10 14:57:24 -04:00
-- remove future automation
cl:truncate_end (playhead)
2016-04-11 08:36:57 -04:00
-- add new data points after the playhead 1 sec, min..max
2016-04-10 14:57:24 -04:00
-- without guard-points, but with initial (..., false, true)
for i=0,10 do
cl:add (playhead + i * samplerate / 10,
pd.lower + math.sqrt (i / 10) * (pd.upper - pd.lower),
false, true)
end
-- save undo
2016-04-11 08:36:57 -04:00
local after = al:get_state()
Session:add_command (al:memento_command(before, after))
2016-04-10 14:57:24 -04:00
Session:commit_reversible_command (nil)
end
end end