Only show user-presets in favorite sidebar
[ardour.git] / scripts / reset_mixer.lua
1 ardour {\r
2         ["type"] = "EditorAction",\r
3         name = "Reset Mixer",\r
4         author = "Ben Loftis, Nikolaus Gullotta, Maxime Lecoq",\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 sp_radio_buttons = { Unreset="unreset", Bypass="bypass", Remove="remove" }\r
11 \r
12         local dlg = {\r
13                 { type = "label", align ="left", colspan="3", title = "Please select below the items you want to reset:" },\r
14                 { type = "label", align ="left", colspan="3", title = "(Warning: this cannot be undone!)\n" },\r
15 \r
16                 { type = "label", align ="left", colspan="3", title = "Levels:" },\r
17                 { type = "checkbox", key = "fader", default = false,  title = "Fader" },\r
18                 { type = "checkbox", key = "mute",  default = false,  title = "Mute" },\r
19                 { type = "checkbox", key = "solo",  default = false,  title = "Solo" },\r
20                 { type = "checkbox", key = "trim",  default = false,  title = "Trim + Phase" },\r
21 \r
22                 { type = "label", align ="left", colspan="3", title = "\nPan:" },\r
23                 { type = "checkbox", key = "pan",  default = false,  title = "Pan" },\r
24                 { type = "checkbox", key = "panwidth", default = false,  title = "Pan width" },\r
25 \r
26                 { type = "label", align ="left", colspan="3", title = "\nSignal processors:" },\r
27                 { type = "radio", key = "sends", title = "Sends", values=sp_radio_buttons, default="Unreset" },\r
28                 { type = "radio", key = "inserts", title = "Inserts", values=sp_radio_buttons, default="Unreset" },\r
29                 { type = "radio", key = "plug-ins", title = "Plug-ins", values=sp_radio_buttons, default="Unreset" },\r
30 \r
31                 { type = "label", align ="left", colspan="3", title = "\nAutomation (switch to manual mode):" },\r
32                 { type = "checkbox", key = "autogain", default = false,  title = "Gain" },\r
33                 { type = "checkbox", key = "autopan", default = false,  title = "Pan" },\r
34                 { type = "checkbox", key = "autopanwidth", default = false,  title = "Pan width" },\r
35 \r
36                 { type = "label", align ="left", colspan="3", title = "" },\r
37         }\r
38 \r
39         local pref = LuaDialog.Dialog("Reset Mixer", dlg):run()\r
40         \r
41         if not(pref) then goto pass_script end\r
42     assert(pref, 'Dialog box was cancelled or is ' .. type(pref))\r
43         \r
44         -- Manage signal processors state or removal according\r
45         -- to the user prompt settings and log trace.\r
46         function handle_processor(effect_type_name, track, proc)\r
47                 local action_name = pref[effect_type_name]\r
48                 local proc_name = proc:display_name()\r
49                 local track_name = track:name()\r
50                 local proc_handled = false\r
51                 \r
52                 if(action_name == "bypass") then\r
53                         if(proc:active()) then \r
54                                 proc:deactivate()\r
55                                 proc_handled = true\r
56                         end\r
57                 elseif(action_name == "remove") then\r
58                         track:remove_processor(proc, nil, true)\r
59                         proc_handled = true\r
60                 end\r
61                 \r
62                 if(proc_handled) then print(action_name, effect_type_name, proc_name, "on track", track_name) end\r
63         end\r
64         \r
65         -- solo\r
66         -- (could be handled in track loop but it's simplier to do it on the session)\r
67         if pref["solo"] then Session:cancel_all_solo() end\r
68         \r
69         -- loop over all tracks\r
70         for t in Session:get_routes():iter() do\r
71                 \r
72                 if not t:is_monitor() and not t:is_auditioner() then\r
73                         \r
74                         -- automation first\r
75                         if pref["autogain"] then t:gain_control():set_automation_state(ARDOUR.AutoState.Off) end\r
76                         if pref["autopan"] then t:pan_azimuth_control():set_automation_state(ARDOUR.AutoState.Off) end\r
77                         if pref["autopanwidth"] then \r
78                                 local pwc = t:pan_width_control()\r
79                                 if(not pwc:isnil()) then -- careful stereo track\r
80                                         pwc:set_automation_state(ARDOUR.AutoState.Off)\r
81                                 end\r
82                         end\r
83                         \r
84                         -- levels\r
85                         if pref["fader"] then t:gain_control():set_value(1, 1) end\r
86                         if pref["trim"]  then\r
87                                 t:trim_control():set_value(1, 1)\r
88                                 t:phase_control():set_value(0, 1)\r
89                         end\r
90                         if pref["mute"] then t:mute_control():set_value(0, 1) end\r
91                         \r
92                         -- pan\r
93                         if not(t:pan_azimuth_control():isnil()) then\r
94                                 if pref["pan"] then t:pan_azimuth_control():set_value(0.5, 1) end\r
95                         end\r
96                         if not(t:pan_width_control():isnil()) then\r
97                                 if pref["panwidth"] then t:pan_width_control():set_value(1, 1) end\r
98                         end\r
99 \r
100                         -- signal processors management\r
101                         i = 0\r
102                         local proc = t:nth_processor (i)\r
103                         \r
104                         -- collect user procs\r
105                         repeat -- loop over the track procs\r
106 \r
107                                 -- send\r
108                                 if not(proc:to_ioprocessor():isnil()) then\r
109                                         --check if processor is a send or insert\r
110                                         if proc:to_ioprocessor():display_to_user() then\r
111                                                 handle_processor("sends", t, proc)\r
112                                         end\r
113                                 end\r
114 \r
115                                 -- insert\r
116                                 if not(proc:to_insert():isnil()) then\r
117                                         --check if processor is foreign to us\r
118                                         if not(proc:to_insert():display_to_user()) then\r
119                                                 handle_processor("inserts", t, proc)\r
120                                         end\r
121                                 end\r
122                                 \r
123                                 -- regular user plug-in\r
124                                 if not(proc:to_plugininsert():isnil()) then\r
125                                         handle_processor("plug-ins", t, proc)\r
126                                 end\r
127 \r
128                                 -- prepare the next proc to be inspected\r
129                                 i = i + 1\r
130                                 proc = t:nth_processor(i)\r
131                                 \r
132                         until proc:isnil() -- end repeat track procs\r
133                         \r
134                 end -- if monitor or auditioner\r
135                 \r
136         end -- loop over all tracks\r
137         ::pass_script::\r
138         collectgarbage()\r
139 end end