2 ["type"] = "EditorAction",
3 name = "Recall Mixer Settings",
4 author = "Mixbus Team",
7 Recalls mixer settings outined by files
8 created by Store Mixer Settings.
10 Allows for some room to change Source
16 function factory () return function ()
18 local user_cfg = ARDOUR.user_config_directory(-1)
19 local local_path = ARDOUR.LuaAPI.build_filename(Session:path(), 'mixer_settings')
20 local global_path = ARDOUR.LuaAPI.build_filename(user_cfg, 'mixer_settings')
25 local ok, err, code = os.rename(file, file)
27 if code == 13 then -- Permission denied, but it exists
34 if not pcall(function() local first_check = Session:get_mixbus(0) end) then
37 local second_check = Session:get_mixbus(11)
38 if second_check:isnil() then
47 return exists(path.."/")
50 function get_processor_by_name(track, name)
52 local proc = track:nth_processor(i)
54 if(proc:display_name() == name) then
59 proc = track:nth_processor(i)
63 function new_plugin(name)
65 local plugin = ARDOUR.LuaAPI.new_plugin(Session, name, x, "")
66 if not(plugin:isnil()) then return plugin end
70 function group_by_id(id)
71 local id = tonumber(id)
72 for g in Session:route_groups():iter() do
73 local group_id = tonumber(g:to_stateful():id():to_s())
74 if group_id == id then return g end
78 function group_by_name(name)
79 for g in Session:route_groups():iter() do
80 if g:name() == name then return g end
84 function route_groupid_interrogate(t)
86 for g in Session:route_groups():iter() do
87 for r in g:route_list():iter() do
88 if r:name() == t:name() then group = g:to_stateful():id():to_s() end
93 function route_group_interrogate(t)
94 for g in Session:route_groups():iter() do
95 for r in g:route_list():iter() do
96 if r:name() == t:name() then return g end
101 function recall(debug, path, dry_run)
102 local file = io.open(path, "r")
103 assert(file, "File not found!")
104 local bypass_routes = {}
107 for l in file:lines() do
110 local exec_line = dry_run["dothis-"..i]
111 local skip_line = false
112 if not(exec_line == nil) and not(exec_line) then
116 local plugin, route, group = false, false, false
120 print(i, string.sub(l, 0, 29), f)
125 if instance["route_id"] then route = true end
126 if instance["plugin_id"] then plugin = true end
127 if instance["group_id"] then group = true end
130 if skip_line then goto nextline end
132 local g_id = instance["group_id"]
133 local routes = instance["routes"]
134 local name = instance["name"]
135 local group = group_by_id(g_id)
137 local group = Session:new_route_group(name)
138 for _, v in pairs(routes) do
139 local rt = Session:route_by_id(PBD.ID(v))
140 if rt:isnil() then rt = Session:route_by_name(name) end
141 if not(rt:isnil()) then group:add(rt) end
147 local substitution = tonumber(dry_run["destination-"..i])
148 if skip_line or (substitution == 0) then
149 bypass_routes[#bypass_routes + 1] = instance["route_id"]
153 local old_order = ARDOUR.ProcessorList()
154 local route_id = instance["route_id"]
155 local r_id = PBD.ID(instance["route_id"])
156 local muted, soloed = instance["muted"], instance["soloed"]
157 local order = instance["order"]
158 local cache = instance["cache"]
159 local group = instance["group"]
160 local group_name = instance["group_name"]
161 local name = instance["route_name"]
162 local gc, tc, pc = instance["gain_control"], instance["trim_control"], instance["pan_control"]
164 if not(substitution == instance["route_id"]) then
165 print('SUBSTITUTION FOR: ', name, substitution, Session:route_by_id(PBD.ID(substitution)):name())
166 --bypass_routes[#bypass_routes + 1] = route_id
168 r_id = PBD.ID(substitution)
171 local rt = Session:route_by_id(r_id)
172 if rt:isnil() then rt = Session:route_by_name(name) end
173 if rt:isnil() then goto nextline end
175 local cur_group_id = route_groupid_interrogate(rt)
176 if not(group) and (cur_group_id) then
177 local g = group_by_id(cur_group_id)
178 if g then g:remove(rt) end
181 local rt_group = group_by_name(group_name)
182 if rt_group then rt_group:add(rt) end
184 well_known = {'PRE', 'Trim', 'EQ', 'Comp', 'Fader', 'POST'}
186 for k, v in pairs(order) do
187 local proc = Session:processor_by_id(PBD.ID(1))
188 if not(was_subbed) then
189 proc = Session:processor_by_id(PBD.ID(v))
192 for id, name in pairs(cache) do
194 proc = new_plugin(name)
195 for _, control in pairs(well_known) do
196 if name == control then
197 proc = get_processor_by_name(rt, control)
198 invalidate[v] = proc:to_stateful():id():to_s()
202 if not(proc) then goto nextproc end
203 if not(proc:isnil()) then
204 rt:add_processor_by_index(proc, 0, nil, true)
205 invalidate[v] = proc:to_stateful():id():to_s()
211 if proc and not(proc:isnil()) then old_order:push_back(proc) end
213 rt:reorder_processors(old_order, nil)
214 if muted then rt:mute_control():set_value(1, 1) else rt:mute_control():set_value(0, 1) end
215 if soloed then rt:solo_control():set_value(1, 1) else rt:solo_control():set_value(0, 1) end
216 rt:gain_control():set_value(gc, 1)
217 rt:trim_control():set_value(tc, 1)
218 if pc ~= false then rt:pan_azimuth_control():set_value(pc, 1) end
222 if skip_line then goto nextline end
224 --if the plugin is owned by a route
225 --we decided not to use, skip it
226 for _, v in pairs(bypass_routes) do
227 if instance["owned_by_route_id"] == v then
233 local params = instance["parameters"]
234 local p_id = instance["plugin_id"]
235 local act = instance["active"]
237 for k, v in pairs(invalidate) do --invalidate any deleted plugin's id
243 local proc = Session:processor_by_id(PBD.ID(p_id))
244 if proc:isnil() then goto nextline end
245 local plug = proc:to_insert():plugin(0)
247 for k, v in pairs(params) do
248 local label = plug:parameter_label(k)
249 if string.find(label, "Assign") or string.find(label, "Enable") then --@ToDo: Check Plugin type == LADSPA or VST?
250 enable[k] = v --queue any assignments/enables for after the initial parameter recalling to duck the 'in-on-change' feature
252 ARDOUR.LuaAPI.set_processor_param(proc, k, v)
255 for k, v in pairs(enable) do
256 ARDOUR.LuaAPI.set_processor_param(proc, k, v)
258 if act then proc:activate() else proc:deactivate() end
267 function dry_run(debug, path)
268 --returns a dialog-able table of
269 --everything we do (logically)
270 --in the recall function
271 local route_values = {['----'] = "0"}
272 for r in Session:get_routes():iter() do
273 route_values[r:name()] = r:to_stateful():id():to_s()
278 {type = "label", align="left", key="col-0-title", col=0, colspan=1, title = 'Source'},
279 {type = "label", align="left", key="col-2-title", col=1, colspan=1, title = 'Destination:'},
280 --{type = "label", align="left", key="col-0-title", col=1, colspan=1, title = 'Actions:'},
281 --{type = "label", align="left", key="col-2-title", col=3, colspan=1, title = 'Do this?'},
283 local file = io.open(path, "r")
284 assert(file, "File not found!")
286 for l in file:lines() do
287 local do_plugin, do_route, do_group = false, false, false
291 print(i, string.sub(l, 0, 29), f)
296 if instance["route_id"] then do_route = true end
297 if instance["plugin_id"] then do_plugin = true end
298 if instance["group_id"] then do_group = true end
301 local group_id = instance["group_id"]
302 local group_name = instance["name"]
303 local dlg_title, action_title = "", ""
305 local group_ptr = group_by_id(group_id)
307 if not(group_ptr) then
308 new_group = Session:new_route_group(group_name)
309 dlg_title = string.format("(Group) %s.", group_name, new_group:name())
310 --action_title = "will create and use settings"
312 dlg_title = string.format("(Group) %s.", group_ptr:name())
313 --action_title = "will use group settings"
315 table.insert(dry_table, {
316 type = "label", align = "left", key = "group-"..i , col = 0, colspan = 1, title = dlg_title
321 local route_id = instance["route_id"]
322 local route_name = instance["route_name"]
325 local route_ptr = Session:route_by_id(PBD.ID(route_id))
327 if route_ptr:isnil() then
328 route_ptr = Session:route_by_name(route_name)
329 if not(route_ptr:isnil()) then
330 dlg_title = string.format("(Strip) %s", route_ptr:name())
331 --action_title = "will use route settings"
333 dlg_title = string.format("Strip) %s", route_name)
334 --action_title = "will be ignored"
337 dlg_title = string.format("(Strip) %s", route_ptr:name())
338 --action_title = "will use route settings"
340 if route_ptr:isnil() then name = route_name else name = route_ptr:name() end
341 table.insert(dry_table, {
342 type = "label", align = "left", key = "route-"..i , col = 0, colspan = 1, title = dlg_title
344 table.insert(dry_table, {
345 type = "dropdown", align = "left", key = "destination-"..i, col = 1, colspan = 1, title = "", values = route_values, default = name or "----"
353 local global_vs_local_dlg = {
354 { type = "label", col=0, colspan=20, align="left", title = "" },
356 type = "radio", col=0, colspan=20, align="left", key = "recall-dir", title = "", values =
358 ['Pick from Global Settings'] = 1, ['Pick from Local Settings'] = 2
360 default = 'Pick from Local Settings'
362 { type = "label", col=0, colspan=20, align="left", title = ""},
365 local recall_options = {
366 { type = "label", col=0, colspan=10, align="left", title = "" },
367 { type = "file", col=0, colspan=15, align="left", key = "file", title = "Select a Settings File:", path = ARDOUR.LuaAPI.build_filename(Session:path(), "export", "params.lua") },
368 { type = "label", col=0, colspan=10, align="left", title = "" },
371 local gvld = LuaDialog.Dialog("Recall Mixer Settings:", global_vs_local_dlg):run()
376 if gvld['recall-dir'] == 1 then
377 local global_ok = isdir(global_path)
378 local global_default_path = ARDOUR.LuaAPI.build_filename(global_path, string.format("FactoryDefault-%s.lua", whoami()))
379 print(global_default_path)
381 recall_options[2]['path'] = global_default_path
382 local rv = LuaDialog.Dialog("Recall Mixer Settings:", recall_options):run()
383 if not(rv) then return end
384 local dry_return = LuaDialog.Dialog("Mixer Store:", dry_run(false, rv['file'])):run()
386 recall(false, rv['file'], dry_return)
391 LuaDialog.Message ("Recall Mixer Settings:",
392 global_path .. [[does not exist!
393 Please run Store Mixer Settings first.]],
394 LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run()
398 if gvld['recall-dir'] == 2 then
399 local local_ok = isdir(local_path)
400 local local_default_path = ARDOUR.LuaAPI.build_filename(local_path, 'stub')
401 print(local_default_path)
403 recall_options[2]['path'] = local_path
404 local rv = LuaDialog.Dialog("Recall Mixer Settings:", recall_options):run()
405 if not(rv) then return end
406 local dry_return = LuaDialog.Dialog("Mixer Store:", dry_run(false, rv['file'])):run()
408 recall(false, rv['file'], dry_return)
413 LuaDialog.Message ("Recall Mixer Settings:",
414 local_path .. [[does not exist!
415 Please run Store Mixer Settings first.]],
416 LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run()