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 create_groups = dry_run["create_groups"]
111 local skip_line = false
113 local plugin, route, group = false, false, false
117 --print('create_groups ' .. tostring(create_groups))
118 print(i, string.sub(l, 0, 29), f)
123 if instance["route_id"] then route = true end
124 if instance["plugin_id"] then plugin = true end
125 if instance["group_id"] then group = true end
128 local g_id = instance["group_id"]
129 local routes = instance["routes"]
130 local name = instance["name"]
131 local group = group_by_id(g_id)
133 if create_groups then
134 local group = Session:new_route_group(name)
135 for _, v in pairs(routes) do
136 local rt = Session:route_by_id(PBD.ID(v))
137 if rt:isnil() then rt = Session:route_by_name(name) end
138 if not(rt:isnil()) then group:add(rt) end
145 local substitution = tonumber(dry_run["destination-"..i])
146 if substitution == 0 then
147 bypass_routes[#bypass_routes + 1] = instance["route_id"]
151 local old_order = ARDOUR.ProcessorList()
152 local route_id = instance["route_id"]
153 local r_id = PBD.ID(instance["route_id"])
154 local muted, soloed = instance["muted"], instance["soloed"]
155 local order = instance["order"]
156 local cache = instance["cache"]
157 local group = instance["group"]
158 local group_name = instance["group_name"]
159 local name = instance["route_name"]
160 local gc, tc, pc = instance["gain_control"], instance["trim_control"], instance["pan_control"]
162 if not(substitution == instance["route_id"]) then
163 print('SUBSTITUTION FOR: ', name, substitution, Session:route_by_id(PBD.ID(substitution)):name())
164 --bypass_routes[#bypass_routes + 1] = route_id
166 r_id = PBD.ID(substitution)
169 local rt = Session:route_by_id(r_id)
170 if rt:isnil() then rt = Session:route_by_name(name) end
171 if rt:isnil() then goto nextline end
173 local cur_group_id = route_groupid_interrogate(rt)
174 if not(group) and (cur_group_id) then
175 local g = group_by_id(cur_group_id)
176 if g then g:remove(rt) end
179 local rt_group = group_by_name(group_name)
180 if rt_group then rt_group:add(rt) end
182 well_known = {'PRE', 'Trim', 'EQ', 'Comp', 'Fader', 'POST'}
184 for k, v in pairs(order) do
185 local proc = Session:processor_by_id(PBD.ID(1))
186 if not(was_subbed) then
187 proc = Session:processor_by_id(PBD.ID(v))
190 for id, name in pairs(cache) do
192 proc = new_plugin(name)
193 for _, control in pairs(well_known) do
194 if name == control then
195 proc = get_processor_by_name(rt, control)
196 invalidate[v] = proc:to_stateful():id():to_s()
200 if not(proc) then goto nextproc end
201 if not(proc:isnil()) then
202 rt:add_processor_by_index(proc, 0, nil, true)
203 invalidate[v] = proc:to_stateful():id():to_s()
209 if proc and not(proc:isnil()) then old_order:push_back(proc) end
211 rt:reorder_processors(old_order, nil)
212 if muted then rt:mute_control():set_value(1, 1) else rt:mute_control():set_value(0, 1) end
213 if soloed then rt:solo_control():set_value(1, 1) else rt:solo_control():set_value(0, 1) end
214 rt:gain_control():set_value(gc, 1)
215 rt:trim_control():set_value(tc, 1)
216 if pc ~= false then rt:pan_azimuth_control():set_value(pc, 1) end
220 --if the plugin is owned by a route
221 --we decided not to use, skip it
222 for _, v in pairs(bypass_routes) do
223 if instance["owned_by_route_id"] == v then
229 local params = instance["parameters"]
230 local p_id = instance["plugin_id"]
231 local act = instance["active"]
233 for k, v in pairs(invalidate) do --invalidate any deleted plugin's id
239 local proc = Session:processor_by_id(PBD.ID(p_id))
240 if proc:isnil() then goto nextline end
241 local plug = proc:to_insert():plugin(0)
243 for k, v in pairs(params) do
244 local label = plug:parameter_label(k)
245 if string.find(label, "Assign") or string.find(label, "Enable") then --@ToDo: Check Plugin type == LADSPA or VST?
246 enable[k] = v --queue any assignments/enables for after the initial parameter recalling to duck the 'in-on-change' feature
248 ARDOUR.LuaAPI.set_processor_param(proc, k, v)
251 for k, v in pairs(enable) do
252 ARDOUR.LuaAPI.set_processor_param(proc, k, v)
254 if act then proc:activate() else proc:deactivate() end
263 function dry_run(debug, path)
264 --returns a dialog-able table of
265 --everything we do (logically)
266 --in the recall function
267 local route_values = {['----'] = "0"}
268 for r in Session:get_routes():iter() do
269 route_values[r:name()] = r:to_stateful():id():to_s()
274 {type = "label", align="right", key="col-1-title", col=0, colspan=1, title = 'Source:'},
275 {type = "label", align="left", key="col-2-title", col=1, colspan=1, title = 'Destination:'},
277 local file = io.open(path, "r")
278 assert(file, "File not found!")
280 for l in file:lines() do
281 local do_plugin, do_route, do_group = false, false, false
285 print(i, string.sub(l, 0, 29), f)
290 if instance["route_id"] then do_route = true end
291 if instance["plugin_id"] then do_plugin = true end
292 if instance["group_id"] then do_group = true end
295 local group_id = instance["group_id"]
296 local group_name = instance["name"]
297 local dlg_title, action_title = "", ""
299 local group_ptr = group_by_id(group_id)
301 if not(group_ptr) then
302 dlg_title = string.format("(Group) %s.", group_name)
303 --action_title = "will create and use settings"
305 dlg_title = string.format("(Group) %s.", group_ptr:name())
306 --action_title = "will use group settings"
308 table.insert(dry_table, {
309 order=pad, type = "label", align="right", key = "group-"..i , col = 0, colspan = 1, title = dlg_title
315 local route_id = instance["route_id"]
316 local route_name = instance["route_name"]
319 local route_ptr = Session:route_by_id(PBD.ID(route_id))
321 if route_ptr:isnil() then
322 route_ptr = Session:route_by_name(route_name)
323 if not(route_ptr:isnil()) then
324 dlg_title = string.format("%s", route_ptr:name())
325 --action_title = "will use route settings"
327 dlg_title = string.format("%s", route_name)
328 --action_title = "will be ignored"
331 dlg_title = string.format("%s", route_ptr:name())
332 --action_title = "will use route settings"
334 if route_ptr:isnil() then name = route_name else name = route_ptr:name() end
336 table.insert(dry_table, {
337 order=instance['pi_order']+pad, type = "label", align="right", key = "route-"..i , col = 0, colspan = 1, title = dlg_title
339 table.insert(dry_table, {
340 type = "dropdown", align="left", key = "destination-"..i, col = 1, colspan = 1, title = "", values = route_values, default = name or "----"
345 table.insert(dry_table, {
346 type = "checkbox", col=0, colspan=2, align="left", key = "create_groups", default = true, title = "Create Groups if necessary?"
351 local global_vs_local_dlg = {
352 { type = "label", col=0, colspan=20, align="left", title = "" },
354 type = "radio", col=0, colspan=20, align="left", key = "recall-dir", title = "", values =
356 ['Pick from Global Settings'] = 1, ['Pick from Local Settings'] = 2
358 default = 'Pick from Local Settings'
360 { type = "label", col=0, colspan=20, align="left", title = ""},
363 local recall_options = {
364 { type = "label", col=0, colspan=10, align="left", title = "" },
365 { 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") },
366 { type = "label", col=0, colspan=10, align="left", title = "" },
369 local gvld = LuaDialog.Dialog("Recall Mixer Settings:", global_vs_local_dlg):run()
374 if gvld['recall-dir'] == 1 then
375 local global_ok = isdir(global_path)
376 local global_default_path = ARDOUR.LuaAPI.build_filename(global_path, string.format("FactoryDefault-%s.lua", whoami()))
377 print(global_default_path)
379 recall_options[2]['path'] = global_default_path
380 local rv = LuaDialog.Dialog("Recall Mixer Settings:", recall_options):run()
381 if not(rv) then return end
382 local dry_return = LuaDialog.Dialog("Recall Mixer Settings:", dry_run(false, rv['file'])):run()
384 recall(false, rv['file'], dry_return)
389 LuaDialog.Message ("Recall Mixer Settings:",
390 global_path .. ' does not exist!\nPlease run Store Mixer Settings first.',
391 LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run()
395 if gvld['recall-dir'] == 2 then
396 local local_ok = isdir(local_path)
397 local local_default_path = ARDOUR.LuaAPI.build_filename(local_path, 'asdf')
398 print(local_default_path)
400 recall_options[2]['path'] = local_default_path
401 local rv = LuaDialog.Dialog("Recall Mixer Settings:", recall_options):run()
402 if not(rv) then return end
403 local dry_return = LuaDialog.Dialog("Recall Mixer Settings:", dry_run(false, rv['file'])):run()
405 recall(true, rv['file'], dry_return)
410 LuaDialog.Message ("Recall Mixer Settings:",
411 local_path .. 'does not exist!\nPlease run Store Mixer Settings first.',
412 LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run()