Update tomsloop script for A6 - Thanks to Tom Brand
[ardour.git] / scripts / set_automation_mode.lua
1 ardour {
2         ["type"] = "EditorAction",
3         name = "Engage Automation",
4         author = "Ardour Team",
5         description = [[Set automation mode of various controls (fader, trim, mute, pan), for all selected tracks.]]
6 }
7
8 function factory() return function()
9         -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR.AutoState
10         local auto_state = ARDOUR.AutoState.Touch
11         local with_plugins = true
12
13         -- Ask user which mode to use, and whether to include plugins
14         local dialog_options = {
15                 { type = "label", align="left", title = "Select automation state to apply all selected tracks:" },
16                 {
17                         type = "dropdown", key = "as", title="", values =
18                         {
19                                 ["Manual"] = ARDOUR.AutoState.Off,
20                                 ["Touch"] = ARDOUR.AutoState.Touch,
21                                 ["Write"] = ARDOUR.AutoState.Write,
22                                 ["Play"] = ARDOUR.AutoState.Play,
23                         },
24                         default = "Touch"
25                 },
26                 { type = "checkbox", key = "plug", default = true, title = "Also set plugin controls" }
27         }
28         local rv = LuaDialog.Dialog ("Select Automation State", dialog_options):run()
29         if not rv then return end
30         auto_state = rv['as']
31         with_plugins = rv['plug']
32
33         -- helper function to check if given ARDOUR:AutomationControl exists
34         function maybe_set_automation_state (ac)
35                 if not ac:isnil() then
36                         ac:set_automation_state (auto_state)
37                 end
38         end
39
40         -- helper function to iterate over all automatable parameters of a plugin
41         function set_plugin_control_mode (pi)
42                 local pc = pi:plugin (0):parameter_count()
43                 for c = 0, pc do
44                         local ac = pi:to_automatable():automation_control (Evoral.Parameter (ARDOUR.AutomationType.PluginAutomation, 0, c), false)
45                         if not ac:isnil () then
46                                 ac:set_automation_state (auto_state)
47                         end
48                 end
49         end
50
51         -- get selected tracks
52         -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Selection
53         local sel = Editor:get_selection ()
54
55         if sel.tracks:routelist ():empty() then
56                 LuaDialog.Message ("Select Automation State", "No Tracks are selected.", LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run ()
57                 return
58         end
59
60         -- iterate over selected tracks
61         -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:TrackSelection
62         for r in sel.tracks:routelist ():iter () do
63                 -- r is-a  http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Route
64                 -- which interhits from ARDOUR:Stripable
65
66                 -- set route's direct control
67                 r:gain_control ():set_automation_state (auto_state)
68                 maybe_set_automation_state (r:trim_control ())
69                 maybe_set_automation_state (r:mute_control ())
70                 maybe_set_automation_state (r:pan_azimuth_control ())
71                 maybe_set_automation_state (r:pan_width_control ())
72
73                 -- for every plugin
74                 local i = 0
75                 while with_plugins do
76                         local proc = r:nth_plugin (i)
77                         if proc:isnil () then break end
78                         set_plugin_control_mode (proc:to_insert ())
79                         i = i + 1
80                 end
81
82         end
83 end end