Update reset_mixer script to use new well-known controls
authorNikolaus Gullotta <nik@harrisonconsoles.com>
Thu, 9 Jan 2020 19:54:23 +0000 (13:54 -0600)
committerNikolaus Gullotta <nik@harrisonconsoles.com>
Thu, 9 Jan 2020 19:54:43 +0000 (13:54 -0600)
scripts/reset_mixer.lua

index 56c2d75605a7951e72e9d4264df6d07f581d09ee..d3b3717d4d8bb0569345531c63ebd127f1ea1a9b 100644 (file)
 ardour {\r
-       ["type"] = "EditorAction",\r
-       name = "Reset Mixer",\r
-       author = "Ben Loftis, Nikolaus Gullotta, Maxime Lecoq",\r
+       ["type"]    = "EditorAction",\r
+       name        = "Reset Mixer",\r
+       license     = "MIT",\r
+       author      = "Ben Loftis, Nikolaus Gullotta, Maxime Lecoq",\r
        description = [[Resets key Mixer settings after user-prompt (warning: this cannot be undone)]]\r
 }\r
 \r
 function factory() return function()\r
-       \r
-       local sp_radio_buttons = { Unreset="unreset", Bypass="bypass", Remove="remove" }\r
-\r
+       local sp_radio_buttons = {Bypass="bypass", Remove="remove", Nothing=false}\r
        local dlg = {\r
-               { type = "label", align ="left", colspan="3", title = "Please select below the items you want to reset:" },\r
-               { type = "label", align ="left", colspan="3", title = "(Warning: this cannot be undone!)\n" },\r
-\r
-               { type = "label", align ="left", colspan="3", title = "Levels:" },\r
-               { type = "checkbox", key = "fader", default = false,  title = "Fader" },\r
-               { type = "checkbox", key = "mute",  default = false,  title = "Mute" },\r
-               { type = "checkbox", key = "solo",  default = false,  title = "Solo" },\r
-               { type = "checkbox", key = "trim",  default = false,  title = "Trim + Phase" },\r
-\r
-               { type = "label", align ="left", colspan="3", title = "\nPan:" },\r
-               { type = "checkbox", key = "pan",  default = false,  title = "Pan" },\r
-               { type = "checkbox", key = "panwidth", default = false,  title = "Pan width" },\r
-\r
-               { type = "label", align ="left", colspan="3", title = "\nSignal processors:" },\r
-               { type = "radio", key = "sends", title = "Sends", values=sp_radio_buttons, default="Unreset" },\r
-               { type = "radio", key = "inserts", title = "Inserts", values=sp_radio_buttons, default="Unreset" },\r
-               { type = "radio", key = "plug-ins", title = "Plug-ins", values=sp_radio_buttons, default="Unreset" },\r
-\r
-               { type = "label", align ="left", colspan="3", title = "\nAutomation (switch to manual mode):" },\r
-               { type = "checkbox", key = "autogain", default = false,  title = "Gain" },\r
-               { type = "checkbox", key = "autopan", default = false,  title = "Pan" },\r
-               { type = "checkbox", key = "autopanwidth", default = false,  title = "Pan width" },\r
-\r
-               { type = "label", align ="left", colspan="3", title = "" },\r
-       }\r
+               {type="label", align="left", colspan="3", title="Please select below the items you want to reset:" },\r
+               {type="label", align="left", colspan="3", title="(Warning: this cannot be undone!)\n" },\r
 \r
-       local pref = LuaDialog.Dialog("Reset Mixer", dlg):run()\r
-       \r
-       if not(pref) then goto pass_script end\r
-    assert(pref, 'Dialog box was cancelled or is ' .. type(pref))\r
-       \r
-       -- Manage signal processors state or removal according\r
-       -- to the user prompt settings and log trace.\r
-       function handle_processor(effect_type_name, track, proc)\r
-               local action_name = pref[effect_type_name]\r
-               local proc_name = proc:display_name()\r
-               local track_name = track:name()\r
-               local proc_handled = false\r
+               {type="heading", align ="center", colspan="3", title = "Common Controls:" },\r
+               {type="checkbox", key="fader", default=true, title="Fader"      },\r
+               {type="checkbox", key="mute",  default=true, title="Mute"       },\r
+               {type="checkbox", key="solo",  default=true, title="Solo"       },\r
+               {type="checkbox", key="trim",  default=true, title="Trim"       },\r
+               {type="checkbox", key="pan",   default=true, title="Pan (All)"  },\r
+               {type="checkbox", key="phase", default=true, title="Phase"      },\r
+               {type="checkbox", key="sends", default=true, title="Sends"      },\r
+               {type="checkbox", key="eq",    default=true, title="EQ"         },\r
+               {type="checkbox", key="comp",  default=true, title="Compressor" },\r
+               \r
+               {type="heading", align="center", colspan="3", title="Processors:" },\r
+               {type="radio", key="plugins", title="Plug-ins",      values=sp_radio_buttons, default="Bypass" },\r
+               {type="radio", key="io",      title="Sends/Inserts", values=sp_radio_buttons, default="Bypass" },\r
+\r
+               {type="hseparator", title=""},\r
                \r
-               if(action_name == "bypass") then\r
-                       if(proc:active()) then \r
-                               proc:deactivate()\r
-                               proc_handled = true\r
+               {type="heading", align="center", colspan="3", title="Misc." },\r
+               {type="checkbox", key="auto",    colspan="3", title = "Automation (switch to manual mode)" },\r
+               {type="checkbox", key="groups",  colspan="3", title = "Groups"                             },\r
+       }\r
+\r
+       function reset(ctrl, disp, auto)\r
+               local disp = disp or PBD.GroupControlDisposition.NoGroup\r
+\r
+               if not(ctrl:isnil()) then\r
+                       local pd = ctrl:desc()\r
+                       ctrl:set_value(pd.normal, disp)\r
+\r
+                       if auto then\r
+                               ctrl:set_automation_state(auto)\r
                        end\r
-               elseif(action_name == "remove") then\r
-                       track:remove_processor(proc, nil, true)\r
-                       proc_handled = true\r
                end\r
-               \r
-               if(proc_handled) then print(action_name, effect_type_name, proc_name, "on track", track_name) end\r
        end\r
-       \r
-       -- solo\r
-       -- (could be handled in track loop but it's simplier to do it on the session)\r
-       if pref["solo"] then Session:cancel_all_solo() end\r
-       \r
-       -- loop over all tracks\r
-       for t in Session:get_routes():iter() do\r
+\r
+       function reset_eq_controls(route, disp, auto)\r
+               if route:isnil() then\r
+                       return\r
+               end\r
                \r
-               if not t:is_monitor() and not t:is_auditioner() then\r
-                       \r
-                       -- automation first\r
-                       if pref["autogain"] then t:gain_control():set_automation_state(ARDOUR.AutoState.Off) end\r
-                       if pref["autopan"] then t:pan_azimuth_control():set_automation_state(ARDOUR.AutoState.Off) end\r
-                       if pref["autopanwidth"] then \r
-                               local pwc = t:pan_width_control()\r
-                               if(not pwc:isnil()) then -- careful stereo track\r
-                                       pwc:set_automation_state(ARDOUR.AutoState.Off)\r
-                               end\r
-                       end\r
-                       \r
-                       -- levels\r
-                       if pref["fader"] then t:gain_control():set_value(1, 1) end\r
-                       if pref["trim"]  then\r
-                               t:trim_control():set_value(1, 1)\r
-                               t:phase_control():set_value(0, 1)\r
-                       end\r
-                       if pref["mute"] then t:mute_control():set_value(0, 1) end\r
-                       \r
-                       -- pan\r
-                       if not(t:pan_azimuth_control():isnil()) then\r
-                               if pref["pan"] then t:pan_azimuth_control():set_value(0.5, 1) end\r
+               local disp = disp or PBD.GroupControlDisposition.NoGroup\r
+\r
+               reset(route:eq_enable_controllable(), disp, auto)\r
+\r
+               local i = 0\r
+               repeat\r
+                       for _,ctrl in pairs({\r
+                               route:eq_freq_controllable(i),\r
+                               route:eq_gain_controllable(i),\r
+                               route:eq_q_controllable(i),\r
+                       }) do\r
+                               reset(ctrl, disp, auto)\r
                        end\r
-                       if not(t:pan_width_control():isnil()) then\r
-                               if pref["panwidth"] then t:pan_width_control():set_value(1, 1) end\r
+                       i = i + 1\r
+               until route:eq_freq_controllable(i):isnil()\r
+       end\r
+\r
+       function reset_comp_controls(route, disp, auto)\r
+               if route:isnil() then\r
+                       return\r
+               end\r
+\r
+               local disp = disp or PBD.GroupControlDisposition.NoGroup\r
+\r
+               for _,ctrl in pairs({\r
+                       route:comp_enable_controllable(),\r
+                       route:comp_makeup_controllable(),\r
+                       route:comp_mode_controllable(),\r
+                       route:comp_speed_controllable(),\r
+                       route:comp_threshold_controllable(),\r
+               }) do\r
+                       reset(ctrl, disp, auto)\r
+               end\r
+       end\r
+\r
+       function reset_send_controls(route, disp, auto)\r
+               if route:isnil() then\r
+                       return\r
+               end\r
+\r
+               local disp = disp or PBD.GroupControlDisposition.NoGroup\r
+\r
+               local i = 0\r
+               repeat\r
+                       for _,ctrl in pairs({\r
+                               route:send_level_controllable(i),\r
+                               route:send_enable_controllable(i),\r
+                               route:send_pan_azimuth_controllable(i),\r
+                               route:send_pan_azimuth_enable_controllable(i),\r
+                       }) do\r
+                               reset(ctrl, disp, auto)\r
                        end\r
+                       i = i + 1\r
+               until route:send_enable_controllable(i):isnil()\r
+       end\r
+\r
+       function reset_plugins(route, prefs)\r
+               if route:isnil() then\r
+                       return\r
+               end\r
 \r
-                       -- signal processors management\r
-                       i = 0\r
-                       local proc = t:nth_processor (i)\r
-                       \r
-                       -- collect user procs\r
-                       repeat -- loop over the track procs\r
-\r
-                               -- send\r
-                               if not(proc:to_ioprocessor():isnil()) then\r
-                                       --check if processor is a send or insert\r
-                                       if proc:to_ioprocessor():display_to_user() then\r
-                                               handle_processor("sends", t, proc)\r
+               local i = 0\r
+               repeat \r
+                       local proc = route:nth_processor(i)\r
+                       if not(proc:isnil()) then\r
+                               \r
+                               if prefs["plugins"] then\r
+                                       local insert = proc:to_insert()\r
+                                       if not(insert:isnil()) then\r
+                                               if insert:is_channelstrip() or not(insert:display_to_user()) then\r
+                                                       ARDOUR.LuaAPI.reset_processor_to_default(insert)\r
+                                               else\r
+                                                       if prefs["plugins"] == "remove" then\r
+                                                               route:remove_processor(proc, nil, true)\r
+                                                       else\r
+                                                               insert:deactivate()\r
+                                                       end\r
+                                               end\r
                                        end\r
                                end\r
 \r
-                               -- insert\r
-                               if not(proc:to_insert():isnil()) then\r
-                                       --check if processor is foreign to us\r
-                                       if not(proc:to_insert():display_to_user()) then\r
-                                               handle_processor("inserts", t, proc)\r
+                               if prefs["io"] then\r
+                                       local io_proc = proc:to_ioprocessor()\r
+                                       if not(io_proc:isnil()) then\r
+                                               if prefs["io"] == "remove" then\r
+                                                       route:remove_processor(proc, nil, true)\r
+                                               else\r
+                                                       io_proc:deactivate()\r
+                                               end\r
                                        end\r
                                end\r
-                               \r
-                               -- regular user plug-in\r
-                               if not(proc:to_plugininsert():isnil()) then\r
-                                       handle_processor("plug-ins", t, proc)\r
-                               end\r
+                       end\r
+                       i = i + 1\r
+               until proc:isnil()\r
+       end\r
 \r
-                               -- prepare the next proc to be inspected\r
-                               i = i + 1\r
-                               proc = t:nth_processor(i)\r
-                               \r
-                       until proc:isnil() -- end repeat track procs\r
-                       \r
-               end -- if monitor or auditioner\r
+       local pref = LuaDialog.Dialog("Reset Mixer", dlg):run()\r
+       \r
+       if not(pref) then goto pass_script end\r
+    assert(pref, "Dialog box was cancelled or is nil")\r
+\r
+       for route in Session:get_routes():iter() do\r
+               local disp = PBD.GroupControlDisposition.NoGroup\r
+               local auto = nil\r
+               \r
+               if pref["auto"] then\r
+                       auto = ARDOUR.AutoState.Off\r
+               end\r
                \r
-       end -- loop over all tracks\r
+               if pref["eq"]    then reset_eq_controls(route, disp, auto) end\r
+               if pref["comp"]  then reset_comp_controls(route, disp, auto) end\r
+               if pref["sends"] then reset_send_controls(route, disp, auto) end\r
+               reset_plugins(route, pref)\r
+\r
+               if pref["fader"] then\r
+                       reset(route:gain_control(), disp, auto)\r
+               end\r
+               \r
+               if pref["phase"] then\r
+                       reset(route:phase_control(), disp, auto)\r
+               end\r
+\r
+               if pref["trim"] then\r
+                       reset(route:trim_control(), disp, auto)\r
+               end\r
+\r
+               if pref["mute"] then\r
+                       reset(route:mute_control(), disp, auto)\r
+               end\r
+\r
+               if pref["solo"] then\r
+                       reset(route:solo_control(), disp, auto)\r
+               end\r
+\r
+               if pref["pan"] then\r
+                       reset(route:pan_azimuth_control(), disp, auto)\r
+                       reset(route:pan_elevation_control(), disp, auto)\r
+                       reset(route:pan_frontback_control(), disp, auto)\r
+                       reset(route:pan_lfe_control(), disp, auto)\r
+                       reset(route:pan_width_control(), disp, auto)\r
+               end\r
+       end\r
+\r
+       if pref["groups"] then\r
+               for group in Session:route_groups():iter() do\r
+                       Session:remove_route_group(group)\r
+               end\r
+       end\r
        ::pass_script::\r
        collectgarbage()\r
 end end
\ No newline at end of file