1 ardour { ["type"] = "Snippet", name = "plugin automation2" }
3 function factory () return function ()
4 local playhead = Session:transport_frame ()
5 local samplerate = Session:nominal_frame_rate ()
7 local r = Session:route_by_remote_id(3)
8 -- get AutomationControList, ControlList and ParameterDescriptor
9 local acl, cl, pd = ARDOUR.LuaAPI.plugin_automation (r:nth_plugin (0), 0)
11 if not acl:isnil() then
12 print ("Parameter Range", pd.lower, pd.upper)
13 print ("Current value", cl:eval(playhead))
15 -- prepare undo operation
16 Session:begin_reversible_command ("Automatix")
17 local before = acl:get_state()
19 -- remove future automation
20 cl:truncate_end (playhead)
22 -- add new data points after the playhead 1 sec min..max
23 -- without guard-points, but with initial (..., false, true)
25 cl:add (playhead + i * samplerate / 10,
26 pd.lower + math.sqrt (i / 10) * (pd.upper - pd.lower),
31 local after = acl:get_state()
32 Session:add_command (acl:memento_command(before, after))
33 Session:commit_reversible_command (nil)