basics of row/col span for Canvas::Grid
[ardour.git] / scripts / faders_to_trims.lua
1 ardour {
2         ["type"]    = "EditorAction",
3         name        = "Faders to Trims",
4         license     = "MIT",
5         author      = "PSmith",
6         description = [[Add 'Trim' plugins to all tracks.  Move the fader value into the trim.]]
7 }
8
9 function action_params ()
10         return
11         {
12         }
13 end
14
15
16 function factory (params)
17         return function ()
18                 -- loop over all tracks
19                 for t in Session:get_tracks():iter() do
20                         
21                         fader_value = t:gain_control():get_value()
22                         v = math.log(fader_value, 10)
23                         trim_gain = 20*v
24                         fader_pos = 0
25                         local proc;
26                         local i = 0;
27                         
28                         repeat
29                                 -- find the fader proc
30                                 proc = t:nth_processor (i)
31                                 if (not proc:isnil() and proc:display_name () == "Fader") then
32                                         fader_pos = i
33                                 end
34                                 i = i + 1
35                         until proc:isnil()
36                         
37                         -- apply the trim
38                         trim = t:nth_processor (fader_pos+1)
39                         if (not trim:isnil() and trim:display_name () == "a-Amplifier") then
40                                 --existing trim found; sum the trim and the fader gain, and set the trim to that value
41                                 cur_gain = ARDOUR.LuaAPI.get_processor_param (trim, 0)
42                                 ARDOUR.LuaAPI.set_processor_param (trim, 0, trim_gain+cur_gain)
43                         else
44                                 --create a new Trim processor, and set its value to match the fader
45                                 local a = ARDOUR.LuaAPI.new_luaproc(Session, "a-Amplifier");
46                                 if (not a:isnil()) then
47                                         t:add_processor_by_index(a, fader_pos-1, nil, true)
48                                         ARDOUR.LuaAPI.set_processor_param (a, 0, trim_gain)
49                                         a = nil -- explicitly drop shared-ptr reference
50                                 end
51                         end
52
53                         --zero the fader gain
54                         t:gain_control():set_value(1, PBD.GroupControlDisposition.NoGroup)
55
56                 end --foreach track
57
58         end  --function
59
60 end --factory