whitespace editing and comments + add ability to substitute routes at will
[ardour.git] / scripts / reset_mixer.lua
1 ardour {\r
2         ["type"] = "EditorAction",\r
3         name = "Reset Mixer",\r
4         author = "Ben Loftis, Nikolaus Gullotta",\r
5         description = [[Resets key Mixer settings after user-prompt (warning: this cannot be undone)]]\r
6 }\r
7 \r
8 function factory() return function()\r
9 \r
10         local dlg = {\r
11                 { type = "label", align ="left", colspan="3", title = "Select the items to reset:" },\r
12                 { type = "checkbox", key = "fader", default = true,  title = "Fader" },\r
13                 { type = "checkbox", key = "mute",  default = true,  title = "Mute" },\r
14                 { type = "checkbox", key = "trim",  default = true,  title = "Trim + Phase" },\r
15                 { type = "checkbox", key = "plug",  default = true,  title = "Plug-ins" },\r
16                 { type = "checkbox", key = "dest",  default = false, title = "Remove plug-ins instead of bypassing?" },\r
17                 { type = "label", colspan="3", title = "" },\r
18                 { type = "label", colspan="3", title = "Note that this is a script which can be user-edited to match your needs." },\r
19                 { type = "label", colspan="3", title = "" },\r
20         }\r
21 \r
22         local pref = LuaDialog.Dialog("Reset Mixer", dlg):run()\r
23         if not(pref) then goto end_script end\r
24     assert(pref, 'Dialog box was cancelled or is ' .. type(pref))\r
25 \r
26         Session:cancel_all_solo()\r
27         -- loop over all tracks\r
28         for t in Session:get_routes():iter() do\r
29                 if not t:is_monitor() and not t:is_auditioner() then\r
30                         --zero the fader and input trim\r
31                         if pref["fader"] then t:gain_control():set_value(1, 1) end\r
32                         if pref["trim"]  then\r
33                                 t:trim_control():set_value(1, 1)\r
34                                 t:phase_control():set_value(0, 1)\r
35                         end\r
36                         if pref["mute"]  then t:mute_control():set_value(0, 1) end\r
37                         if not(t:pan_azimuth_control():isnil()) then\r
38                                 if pref["pan"] then\r
39                                         t:pan_azimuth_control():set_value(0.5, 1)\r
40                                 end\r
41                         end\r
42 \r
43                         i = 0\r
44                         local proc = t:nth_processor (i)\r
45                         local queue = {}\r
46 \r
47                         local protected = {\r
48                         "recorder", "latcomp-", "player",\r
49                         "Polarity", "Trim", "Fader",\r
50                         "meter-", "main outs", "Monitor",\r
51                         }\r
52 \r
53                         repeat\r
54                                 local name = proc:display_name()\r
55                                 --check if processor is foreign to us\r
56                                 protected_proc = false\r
57                                 for _, v in pairs(protected) do\r
58                                         if string.find(name, v) then\r
59                                                 --processor is not foreign to us\r
60                                                 protected_proc = true\r
61                                         end\r
62                                 end\r
63 \r
64                                 if not(protected_proc) and proc:display_to_user() then\r
65                                         print(name)\r
66                                         queue[#queue + 1] = proc\r
67                                 end\r
68 \r
69                                 i = i + 1\r
70                                 proc = t:nth_processor(i)\r
71                         until proc:isnil()\r
72 \r
73                         for p = 1, #queue do\r
74                                 if pref['plug'] then\r
75                                         if not(pref["dest"]) then\r
76                                                 queue[p]:deactivate()\r
77                                         else\r
78                                                 t:remove_processor(queue[p], nil, true)\r
79                                         end\r
80                                 end\r
81                         end\r
82                 end\r
83         end\r
84         ::end_script::\r
85         collectgarbage()\r
86 end end\r