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="right", key="col-1-title", col=0, colspan=1, title = 'Source:'},
279 {type = "label", align="left", key="col-2-title", col=1, colspan=1, title = 'Destination:'},
281 local file = io.open(path, "r")
282 assert(file, "File not found!")
284 for l in file:lines() do
285 local do_plugin, do_route, do_group = false, false, false
289 print(i, string.sub(l, 0, 29), f)
294 if instance["route_id"] then do_route = true end
295 if instance["plugin_id"] then do_plugin = true end
296 if instance["group_id"] then do_group = true end
299 local group_id = instance["group_id"]
300 local group_name = instance["name"]
301 local dlg_title, action_title = "", ""
303 local group_ptr = group_by_id(group_id)
305 if not(group_ptr) then
306 new_group = Session:new_route_group(group_name)
307 dlg_title = string.format("(Group) %s.", group_name, new_group:name())
308 --action_title = "will create and use settings"
310 dlg_title = string.format("(Group) %s.", group_ptr:name())
311 --action_title = "will use group settings"
313 table.insert(dry_table, {
314 type = "label", align="right", key = "type-"..i , col = 0, colspan = 1, title = ""
316 table.insert(dry_table, {
317 type = "label", align="right", key = "group-"..i , col = 1, colspan = 1, title = dlg_title
322 local route_id = instance["route_id"]
323 local route_name = instance["route_name"]
326 local route_ptr = Session:route_by_id(PBD.ID(route_id))
328 if route_ptr:isnil() then
329 route_ptr = Session:route_by_name(route_name)
330 if not(route_ptr:isnil()) then
331 dlg_title = string.format("%s", route_ptr:name())
332 --action_title = "will use route settings"
334 dlg_title = string.format("%s", route_name)
335 --action_title = "will be ignored"
338 dlg_title = string.format("%s", route_ptr:name())
339 --action_title = "will use route settings"
341 if route_ptr:isnil() then name = route_name else name = route_ptr:name() end
343 table.insert(dry_table, {
344 type = "label", align="right", key = "route-"..i , col = 1, colspan = 1, title = dlg_title
346 table.insert(dry_table, {
347 type = "dropdown", align="left", key = "destination-"..i, col = 2, colspan = 1, title = "", values = route_values, default = name or "----"
355 local global_vs_local_dlg = {
356 { type = "label", col=0, colspan=20, align="left", title = "" },
358 type = "radio", col=0, colspan=20, align="left", key = "recall-dir", title = "", values =
360 ['Pick from Global Settings'] = 1, ['Pick from Local Settings'] = 2
362 default = 'Pick from Local Settings'
364 { type = "label", col=0, colspan=20, align="left", title = ""},
367 local recall_options = {
368 { type = "label", col=0, colspan=10, align="left", title = "" },
369 { 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") },
370 { type = "label", col=0, colspan=10, align="left", title = "" },
373 local gvld = LuaDialog.Dialog("Recall Mixer Settings:", global_vs_local_dlg):run()
378 if gvld['recall-dir'] == 1 then
379 local global_ok = isdir(global_path)
380 local global_default_path = ARDOUR.LuaAPI.build_filename(global_path, string.format("FactoryDefault-%s.lua", whoami()))
381 print(global_default_path)
383 recall_options[2]['path'] = global_default_path
384 local rv = LuaDialog.Dialog("Recall Mixer Settings:", recall_options):run()
385 if not(rv) then return end
386 local dry_return = LuaDialog.Dialog("Mixer Store:", dry_run(false, rv['file'])):run()
388 recall(false, rv['file'], dry_return)
393 LuaDialog.Message ("Recall Mixer Settings:",
394 global_path .. ' does not exist!\nPlease run Store Mixer Settings first.',
395 LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run()
399 if gvld['recall-dir'] == 2 then
400 local local_ok = isdir(local_path)
401 local local_default_path = ARDOUR.LuaAPI.build_filename(local_path, 'stub')
402 print(local_default_path)
404 recall_options[2]['path'] = local_path
405 local rv = LuaDialog.Dialog("Recall Mixer Settings:", recall_options):run()
406 if not(rv) then return end
407 local dry_return = LuaDialog.Dialog("Mixer Store:", dry_run(false, rv['file'])):run()
409 recall(false, rv['file'], dry_return)
414 LuaDialog.Message ("Recall Mixer Settings:",
415 local_path .. 'does not exist!\nPlease run Store Mixer Settings first.',
416 LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run()