Add a missing #define to our MSVC project (portaudio_backend)
[ardour.git] / scripts / s_plugin_automation.lua
1 ardour { ["type"] = "Snippet", name = "Plugin automation" }
2
3 function factory () return function ()
4         -- query playhead position and session sample-rate
5         local playhead = Session:transport_frame ()
6         local samplerate = Session:nominal_frame_rate ()
7
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 ())
12
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)
17
18         if not al:isnil () then
19                 print ("Parameter Range", pd.lower, pd.upper)
20                 print ("Current value", cl:eval (playhead))
21
22                 -- prepare undo operation
23                 Session:begin_reversible_command ("Automatix")
24                 -- remember current AutomationList state
25                 local before = al:get_state()
26
27                 -- remove future automation
28                 cl:truncate_end (playhead)
29
30                 -- add new data points after the playhead 1 sec, min..max
31                 -- without guard-points, but with initial (..., false, true)
32                 for i=0,10 do
33                         cl:add (playhead + i * samplerate / 10,
34                                  pd.lower + math.sqrt (i / 10) * (pd.upper - pd.lower),
35                                  false, true)
36                 end
37
38                 -- save undo
39                 local after = al:get_state()
40                 Session:add_command (al:memento_command(before, after))
41                 Session:commit_reversible_command (nil)
42         end
43 end end