From d64646a2caa582a65303fb8c44489122f27f9dec Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Mon, 5 Dec 2016 09:48:25 -0600 Subject: fader-to-trim lua script by Phillip Smith --- scripts/faders_to_trims.lua | 60 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 scripts/faders_to_trims.lua diff --git a/scripts/faders_to_trims.lua b/scripts/faders_to_trims.lua new file mode 100644 index 0000000000..2d0ed44cae --- /dev/null +++ b/scripts/faders_to_trims.lua @@ -0,0 +1,60 @@ +ardour { + ["type"] = "EditorAction", + name = "Faders to Trims", + license = "MIT", + author = "PSmith", + description = [[Add 'Trim' plugins to all tracks. Move the fader value into the trim.]] +} + +function action_params () + return + { + } +end + + +function factory (params) + return function () + -- loop over all tracks + for t in Session:get_tracks():iter() do + + fader_value = t:gain_control():get_value() + v = math.log(fader_value, 10) + trim_gain = 20*v + fader_pos = 0 + local proc; + local i = 0; + + repeat + -- find the fader proc + proc = t:nth_processor (i) + if (not proc:isnil() and proc:display_name () == "Fader") then + fader_pos = i + end + i = i + 1 + until proc:isnil() + + -- apply the trim + trim = t:nth_processor (fader_pos+1) + if (not trim:isnil() and trim:display_name () == "a-Amplifier") then + --existing trim found; sum the trim and the fader gain, and set the trim to that value + cur_gain = ARDOUR.LuaAPI.get_processor_param (trim, 0) + ARDOUR.LuaAPI.set_processor_param (trim, 0, trim_gain+cur_gain) + else + --create a new Trim processor, and set its value to match the fader + local a = ARDOUR.LuaAPI.new_luaproc(Session, "a-Amplifier"); + if (not a:isnil()) then + t:add_processor_by_index(a, fader_pos-1, nil, true) + ARDOUR.LuaAPI.set_processor_param (a, 0, trim_gain) + a = nil -- explicitly drop shared-ptr reference + end + end + + --zero the fader gain + t:gain_control():set_value(1, PBD.GroupControlDisposition.NoGroup) + + end --foreach track + + end --function + +end --factory -- cgit v1.2.3