some more example lua scripts
[ardour.git] / scripts / s_plugin_automation.lua
1 ardour { ["type"] = "Snippet", name = "plugin automation2" }
2
3 function factory () return function ()
4         local playhead = Session:transport_frame ()
5         local samplerate = Session:nominal_frame_rate ()
6
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)
10
11         if not acl:isnil() then
12                 print ("Parameter Range", pd.lower, pd.upper)
13                 print ("Current value", cl:eval(playhead))
14
15                 -- prepare undo operation
16                 Session:begin_reversible_command ("Automatix")
17                 local before = acl:get_state()
18
19                 -- remove future automation
20                 cl:truncate_end (playhead)
21
22                 -- add new data points after the playhead 1 sec min..max
23                 -- without guard-points, but with initial (..., false, true)
24                 for i=0,10 do
25                         cl:add (playhead + i * samplerate / 10,
26                                  pd.lower + math.sqrt (i / 10) * (pd.upper - pd.lower),
27                                  false, true)
28                 end
29
30                 -- save undo
31                 local after = acl:get_state()
32                 Session:add_command (acl:memento_command(before, after))
33                 Session:commit_reversible_command (nil)
34         end
35 end end