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, type)
64 local plugin = ARDOUR.LuaAPI.new_plugin(Session, name, type, "")
65 if not(plugin:isnil()) then return plugin end
68 function group_by_id(id)
69 local id = tonumber(id)
70 for g in Session:route_groups():iter() do
71 local group_id = tonumber(g:to_stateful():id():to_s())
72 if group_id == id then return g end
76 function group_by_name(name)
77 for g in Session:route_groups():iter() do
78 if g:name() == name then return g end
82 function route_groupid_interrogate(t)
84 for g in Session:route_groups():iter() do
85 for r in g:route_list():iter() do
86 if r:name() == t:name() then group = g:to_stateful():id():to_s() end
91 function route_group_interrogate(t)
92 for g in Session:route_groups():iter() do
93 for r in g:route_list():iter() do
94 if r:name() == t:name() then return g end
99 function recall(debug, path, dry_run)
100 local file = io.open(path, "r")
101 assert(file, "File not found!")
102 local bypass_routes = {}
105 for l in file:lines() do
108 local create_groups = dry_run["create_groups"]
109 local skip_line = false
111 local plugin, route, group = false, false, false
115 --print('create_groups ' .. tostring(create_groups))
116 print(i, string.sub(l, 0, 29), f)
121 if instance["route_id"] then route = true end
122 if instance["plugin_id"] then plugin = true end
123 if instance["group_id"] then group = true end
126 local g_id = instance["group_id"]
127 local routes = instance["routes"]
128 local name = instance["name"]
129 local group = group_by_id(g_id)
131 if create_groups then
132 local group = Session:new_route_group(name)
133 for _, v in pairs(routes) do
134 local rt = Session:route_by_id(PBD.ID(v))
135 if rt:isnil() then rt = Session:route_by_name(name) end
136 if not(rt:isnil()) then group:add(rt) end
143 local substitution = tonumber(dry_run["destination-"..i])
144 if substitution == 0 then
145 bypass_routes[#bypass_routes + 1] = instance["route_id"]
149 local old_order = ARDOUR.ProcessorList()
150 local route_id = instance["route_id"]
151 local r_id = PBD.ID(instance["route_id"])
152 local muted, soloed = instance["muted"], instance["soloed"]
153 local order = instance["order"]
154 local cache = instance["cache"]
155 local group = instance["group"]
156 local group_name = instance["group_name"]
157 local name = instance["route_name"]
158 local gc, tc, pc = instance["gain_control"], instance["trim_control"], instance["pan_control"]
160 if not(substitution == instance["route_id"]) then
161 print('SUBSTITUTION FOR: ', name, substitution, Session:route_by_id(PBD.ID(substitution)):name())
162 --bypass_routes[#bypass_routes + 1] = route_id
164 r_id = PBD.ID(substitution)
167 local rt = Session:route_by_id(r_id)
168 if rt:isnil() then rt = Session:route_by_name(name) end
169 if rt:isnil() then goto nextline end
171 local cur_group_id = route_groupid_interrogate(rt)
172 if not(group) and (cur_group_id) then
173 local g = group_by_id(cur_group_id)
174 if g then g:remove(rt) end
177 local rt_group = group_by_name(group_name)
178 if rt_group then rt_group:add(rt) end
180 well_known = {'PRE', 'Trim', 'EQ', 'Comp', 'Fader', 'POST'}
181 protected_instrument = false
182 for k, v in pairs(order) do
183 local proc = Session:processor_by_id(PBD.ID(1))
184 if not(was_subbed) then
185 proc = Session:processor_by_id(PBD.ID(v))
188 for id, sub_tbl in pairs(cache) do
189 local name = sub_tbl[1]
190 local type = sub_tbl[2]
192 proc = new_plugin(name, type)
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
210 if not(old_order:empty()) and not(protected_instrument) then
211 if not(rt:to_track():to_midi_track():isnil()) then
212 if not(rt:the_instrument():isnil()) then
213 protected_instrument = true
214 old_order:push_back(rt:the_instrument())
219 rt:reorder_processors(old_order, nil)
220 if muted then rt:mute_control():set_value(1, 1) else rt:mute_control():set_value(0, 1) end
221 if soloed then rt:solo_control():set_value(1, 1) else rt:solo_control():set_value(0, 1) end
222 rt:gain_control():set_value(gc, 1)
223 rt:trim_control():set_value(tc, 1)
224 if pc ~= false and not(rt:is_master()) then rt:pan_azimuth_control():set_value(pc, 1) end
228 --if the plugin is owned by a route
229 --we decided not to use, skip it
230 for _, v in pairs(bypass_routes) do
231 if instance["owned_by_route_id"] == v then
237 local params = instance["parameters"]
238 local p_id = instance["plugin_id"]
239 local act = instance["active"]
241 for k, v in pairs(invalidate) do --invalidate any deleted plugin's id
247 local proc = Session:processor_by_id(PBD.ID(p_id))
248 if proc:isnil() then goto nextline end
249 local plug = proc:to_insert():plugin(0)
251 for k, v in pairs(params) do
252 local label = plug:parameter_label(k)
253 if string.find(label, "Assign") or string.find(label, "Enable") then --@ToDo: Check Plugin type == LADSPA or VST?
254 enable[k] = v --queue any assignments/enables for after the initial parameter recalling to duck the 'in-on-change' feature
256 print(string.format("%s (Port: %s) -> %s", label, k, v))
257 ARDOUR.LuaAPI.set_processor_param(proc, k, v)
260 for k, v in pairs(enable) do
261 ARDOUR.LuaAPI.set_processor_param(proc, k, v)
263 if act then proc:activate() else proc:deactivate() end
272 function dry_run(debug, path)
273 --returns a dialog-able table of
274 --everything we do (logically)
275 --in the recall function
276 local route_values = {['----'] = "0"}
277 for r in Session:get_routes():iter() do
278 route_values[r:name()] = r:to_stateful():id():to_s()
283 {type = "label", align="right", key="col-1-title", col=0, colspan=1, title = 'Source:'},
284 {type = "label", align="left", key="col-2-title", col=1, colspan=1, title = 'Destination:'},
286 local file = io.open(path, "r")
287 assert(file, "File not found!")
289 for l in file:lines() do
290 local do_plugin, do_route, do_group = false, false, false
294 print(i, string.sub(l, 0, 29), f)
299 if instance["route_id"] then do_route = true end
300 if instance["plugin_id"] then do_plugin = true end
301 if instance["group_id"] then do_group = true end
304 local group_id = instance["group_id"]
305 local group_name = instance["name"]
306 local dlg_title, action_title = "", ""
308 local group_ptr = group_by_id(group_id)
310 if not(group_ptr) then
311 dlg_title = string.format("(Group) %s.", group_name)
312 --action_title = "will create and use settings"
314 dlg_title = string.format("(Group) %s.", group_ptr:name())
315 --action_title = "will use group settings"
317 table.insert(dry_table, {
318 order=pad, type = "label", align="right", key = "group-"..i , col = 0, colspan = 1, title = dlg_title
324 local route_id = instance["route_id"]
325 local route_name = instance["route_name"]
328 local route_ptr = Session:route_by_id(PBD.ID(route_id))
330 if route_ptr:isnil() then
331 route_ptr = Session:route_by_name(route_name)
332 if not(route_ptr:isnil()) then
333 dlg_title = string.format("%s", route_ptr:name())
334 --action_title = "will use route settings"
336 dlg_title = string.format("%s", route_name)
337 --action_title = "will be ignored"
340 dlg_title = string.format("%s", route_ptr:name())
341 --action_title = "will use route settings"
343 if route_ptr:isnil() then name = route_name else name = route_ptr:name() end
345 table.insert(dry_table, {
346 order=instance['pi_order']+pad, type = "label", align="right", key = "route-"..i , col = 0, colspan = 1, title = dlg_title
348 table.insert(dry_table, {
349 type = "dropdown", align="left", key = "destination-"..i, col = 1, colspan = 1, title = "", values = route_values, default = name or "----"
354 table.insert(dry_table, {
355 type = "checkbox", col=0, colspan=2, align="left", key = "create_groups", default = true, title = "Create Groups if necessary?"
360 local global_vs_local_dlg = {
361 { type = "label", col=0, colspan=20, align="left", title = "" },
363 type = "radio", col=0, colspan=20, align="left", key = "recall-dir", title = "", values =
365 ['Pick from Global Settings'] = 1, ['Pick from Local Settings'] = 2
367 default = 'Pick from Local Settings'
369 { type = "label", col=0, colspan=20, align="left", title = ""},
372 local recall_options = {
373 { type = "label", col=0, colspan=10, align="left", title = "" },
374 { 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") },
375 { type = "label", col=0, colspan=10, align="left", title = "" },
378 local gvld = LuaDialog.Dialog("Recall Mixer Settings:", global_vs_local_dlg):run()
383 if gvld['recall-dir'] == 1 then
384 local global_ok = isdir(global_path)
385 local global_default_path = ARDOUR.LuaAPI.build_filename(global_path, string.format("FactoryDefault-%s.lua", whoami()))
386 print(global_default_path)
388 recall_options[2]['path'] = global_default_path
389 local rv = LuaDialog.Dialog("Recall Mixer Settings:", recall_options):run()
390 if not(rv) then return end
391 local dry_return = LuaDialog.Dialog("Recall Mixer Settings:", dry_run(false, rv['file'])):run()
393 recall(false, rv['file'], dry_return)
398 LuaDialog.Message ("Recall Mixer Settings:",
399 global_path .. ' does not exist!\nPlease run Store Mixer Settings first.',
400 LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run()
404 if gvld['recall-dir'] == 2 then
405 local local_ok = isdir(local_path)
406 local local_default_path = ARDOUR.LuaAPI.build_filename(local_path, 'asdf')
407 print(local_default_path)
409 recall_options[2]['path'] = local_default_path
410 local rv = LuaDialog.Dialog("Recall Mixer Settings:", recall_options):run()
411 if not(rv) then return end
412 local dry_return = LuaDialog.Dialog("Recall Mixer Settings:", dry_run(false, rv['file'])):run()
414 recall(true, rv['file'], dry_return)
419 LuaDialog.Message ("Recall Mixer Settings:",
420 local_path .. 'does not exist!\nPlease run Store Mixer Settings first.',
421 LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run()