1 ardour { ["type"] = "Snippet", name = "Plugin automation" }
3 function factory () return function ()
4 -- query playhead position and session sample-rate
5 local playhead = Session:transport_sample ()
6 local samplerate = Session:nominal_sample_rate ()
8 -- get Track/Bus with RID 3
9 local r = Session:get_remote_nth_route(3)
10 -- make sure the track object exists
11 assert (not r:isnil ())
13 -- get AutomationList, ControlList and ParameterDescriptor
14 -- of the first plugin's first parameter
15 -- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:LuaAPI
16 local al, cl, pd = ARDOUR.LuaAPI.plugin_automation (r:nth_plugin (0), 0)
18 if not al:isnil () then
19 print ("Parameter Range", pd.lower, pd.upper)
20 print ("Current value", cl:eval (playhead))
22 -- prepare undo operation
23 Session:begin_reversible_command ("Automatix")
24 -- remember current AutomationList state
25 local before = al:get_state()
27 -- remove future automation
28 cl:truncate_end (playhead)
30 -- add new data points after the playhead 1 sec, min..max
31 -- without guard-points, but with initial (..., false, true)
33 cl:add (playhead + i * samplerate / 10,
34 pd.lower + math.sqrt (i / 10) * (pd.upper - pd.lower),
39 local after = al:get_state()
40 Session:add_command (al:memento_command(before, after))
41 Session:commit_reversible_command (nil)