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 return exists(path.."/")
37 function get_processor_by_name(track, name)
39 local proc = track:nth_processor(i)
41 if(proc:display_name() == name) then
46 proc = track:nth_processor(i)
50 function new_plugin(name)
52 local plugin = ARDOUR.LuaAPI.new_plugin(Session, name, x, "")
53 if not(plugin:isnil()) then return plugin end
57 function group_by_id(id)
58 local id = tonumber(id)
59 for g in Session:route_groups():iter() do
60 local group_id = tonumber(g:to_stateful():id():to_s())
61 if group_id == id then return g end
65 function group_by_name(name)
66 for g in Session:route_groups():iter() do
67 if g:name() == name then return g end
71 function route_groupid_interrogate(t)
73 for g in Session:route_groups():iter() do
74 for r in g:route_list():iter() do
75 if r:name() == t:name() then group = g:to_stateful():id():to_s() end
80 function route_group_interrogate(t)
81 for g in Session:route_groups():iter() do
82 for r in g:route_list():iter() do
83 if r:name() == t:name() then return g end
88 function recall(debug, path, dry_run)
89 local file = io.open(path, "r")
90 assert(file, "File not found!")
91 local bypass_routes = {}
94 for l in file:lines() do
97 local exec_line = dry_run["dothis-"..i]
98 local skip_line = false
99 if not(exec_line == nil) and not(exec_line) then
103 local plugin, route, group = false, false, false
107 print(i, string.sub(l, 0, 29), f)
112 if instance["route_id"] then route = true end
113 if instance["plugin_id"] then plugin = true end
114 if instance["group_id"] then group = true end
117 if skip_line then goto nextline end
119 local g_id = instance["group_id"]
120 local routes = instance["routes"]
121 local name = instance["name"]
122 local group = group_by_id(g_id)
124 local group = Session:new_route_group(name)
125 for _, v in pairs(routes) do
126 local rt = Session:route_by_id(PBD.ID(v))
127 if rt:isnil() then rt = Session:route_by_name(name) end
128 if not(rt:isnil()) then group:add(rt) end
134 local substitution = tonumber(dry_run["destination-"..i])
135 if skip_line or (substitution == 0) then
136 bypass_routes[#bypass_routes + 1] = instance["route_id"]
140 local old_order = ARDOUR.ProcessorList()
141 local route_id = instance["route_id"]
142 local r_id = PBD.ID(instance["route_id"])
143 local muted, soloed = instance["muted"], instance["soloed"]
144 local order = instance["order"]
145 local cache = instance["cache"]
146 local group = instance["group"]
147 local group_name = instance["group_name"]
148 local name = instance["route_name"]
149 local gc, tc, pc = instance["gain_control"], instance["trim_control"], instance["pan_control"]
151 if not(substitution == instance["route_id"]) then
152 print('SUBSTITUTION FOR: ', name, substitution, Session:route_by_id(PBD.ID(substitution)):name())
153 --bypass_routes[#bypass_routes + 1] = route_id
155 r_id = PBD.ID(substitution)
158 local rt = Session:route_by_id(r_id)
159 if rt:isnil() then rt = Session:route_by_name(name) end
160 if rt:isnil() then goto nextline end
162 local cur_group_id = route_groupid_interrogate(rt)
163 if not(group) and (cur_group_id) then
164 local g = group_by_id(cur_group_id)
165 if g then g:remove(rt) end
168 local rt_group = group_by_name(group_name)
169 if rt_group then rt_group:add(rt) end
171 well_known = {'PRE', 'Trim', 'EQ', 'Comp', 'Fader', 'POST'}
173 for k, v in pairs(order) do
174 local proc = Session:processor_by_id(PBD.ID(1))
175 if not(was_subbed) then
176 proc = Session:processor_by_id(PBD.ID(v))
179 for id, name in pairs(cache) do
181 proc = new_plugin(name)
182 for _, control in pairs(well_known) do
183 if name == control then
184 proc = get_processor_by_name(rt, control)
185 invalidate[v] = proc:to_stateful():id():to_s()
189 if not(proc) then goto nextproc end
190 if not(proc:isnil()) then
191 rt:add_processor_by_index(proc, 0, nil, true)
192 invalidate[v] = proc:to_stateful():id():to_s()
198 if proc and not(proc:isnil()) then old_order:push_back(proc) end
200 rt:reorder_processors(old_order, nil)
201 if muted then rt:mute_control():set_value(1, 1) else rt:mute_control():set_value(0, 1) end
202 if soloed then rt:solo_control():set_value(1, 1) else rt:solo_control():set_value(0, 1) end
203 rt:gain_control():set_value(gc, 1)
204 rt:trim_control():set_value(tc, 1)
205 if pc ~= false then rt:pan_azimuth_control():set_value(pc, 1) end
209 if skip_line then goto nextline end
211 --if the plugin is owned by a route
212 --we decided not to use, skip it
213 for _, v in pairs(bypass_routes) do
214 if instance["owned_by_route_id"] == v then
220 local params = instance["parameters"]
221 local p_id = instance["plugin_id"]
222 local act = instance["active"]
224 for k, v in pairs(invalidate) do --invalidate any deleted plugin's id
230 local proc = Session:processor_by_id(PBD.ID(p_id))
231 if proc:isnil() then goto nextline end
232 local plug = proc:to_insert():plugin(0)
234 for k, v in pairs(params) do
235 local label = plug:parameter_label(k)
236 if string.find(label, "Assign") or string.find(label, "Enable") then --@ToDo: Check Plugin type == LADSPA or VST?
237 enable[k] = v --queue any assignments/enables for after the initial parameter recalling to duck the 'in-on-change' feature
239 ARDOUR.LuaAPI.set_processor_param(proc, k, v)
242 for k, v in pairs(enable) do
243 ARDOUR.LuaAPI.set_processor_param(proc, k, v)
245 if act then proc:activate() else proc:deactivate() end
254 function dry_run(debug, path)
255 --returns a dialog-able table of
256 --everything we do (logically)
257 --in the recall function
258 local route_values = {['----'] = "0"}
259 for r in Session:get_routes():iter() do
260 route_values[r:name()] = r:to_stateful():id():to_s()
265 {type = "label", align="left", key="col-0-title", col=0, colspan=1, title = 'Source'},
266 {type = "label", align="left", key="col-2-title", col=1, colspan=1, title = 'Destination:'},
267 --{type = "label", align="left", key="col-0-title", col=1, colspan=1, title = 'Actions:'},
268 --{type = "label", align="left", key="col-2-title", col=3, colspan=1, title = 'Do this?'},
270 local file = io.open(path, "r")
271 assert(file, "File not found!")
273 for l in file:lines() do
274 local do_plugin, do_route, do_group = false, false, false
278 print(i, string.sub(l, 0, 29), f)
283 if instance["route_id"] then do_route = true end
284 if instance["plugin_id"] then do_plugin = true end
285 if instance["group_id"] then do_group = true end
288 local group_id = instance["group_id"]
289 local group_name = instance["name"]
290 local dlg_title, action_title = "", ""
292 local group_ptr = group_by_id(group_id)
294 if not(group_ptr) then
295 new_group = Session:new_route_group(group_name)
296 dlg_title = string.format("(Group) %s.", group_name, new_group:name())
297 --action_title = "will create and use settings"
299 dlg_title = string.format("(Group) %s.", group_ptr:name())
300 --action_title = "will use group settings"
302 table.insert(dry_table, {
303 type = "label", align = "left", key = "group-"..i , col = 0, colspan = 1, title = dlg_title
308 local route_id = instance["route_id"]
309 local route_name = instance["route_name"]
312 local route_ptr = Session:route_by_id(PBD.ID(route_id))
314 if route_ptr:isnil() then
315 route_ptr = Session:route_by_name(route_name)
316 if not(route_ptr:isnil()) then
317 dlg_title = string.format("(Strip) %s", route_ptr:name())
318 --action_title = "will use route settings"
320 dlg_title = string.format("Strip) %s", route_name)
321 --action_title = "will be ignored"
324 dlg_title = string.format("(Strip) %s", route_ptr:name())
325 --action_title = "will use route settings"
327 if route_ptr:isnil() then name = route_name else name = route_ptr:name() end
328 table.insert(dry_table, {
329 type = "label", align = "left", key = "route-"..i , col = 0, colspan = 1, title = dlg_title
331 table.insert(dry_table, {
332 type = "dropdown", align = "left", key = "destination-"..i, col = 1, colspan = 1, title = "", values = route_values, default = name or "----"
340 local global_vs_local_dlg = {
341 { type = "label", col=0, colspan=20, align="left", title = "" },
343 type = "radio", col=0, colspan=20, align="left", key = "recall-dir", title = "", values =
345 ['Pick from Global Settings'] = 1, ['Pick from Local Settings'] = 2
347 default = 'Pick from Local Settings'
349 { type = "label", col=0, colspan=20, align="left", title = ""},
352 local recall_options = {
353 { type = "label", col=0, colspan=10, align="left", title = "" },
354 { type = "file", col=0, colspan=10, align="left", key = "file", title = "Select a Settings File:", path = ARDOUR.LuaAPI.build_filename(Session:path(), "export", "params.lua") },
355 { type = "label", col=0, colspan=10, align="left", title = "" },
358 local gvld = LuaDialog.Dialog("Recall Mixer Settings:", global_vs_local_dlg):run()
363 if gvld['recall-dir'] == 1 then
364 local global_ok = isdir(global_path)
365 local global_default_path = ARDOUR.LuaAPI.build_filename(global_path, 'factory_default.lua')
366 print(global_default_path)
368 recall_options[2]['path'] = global_default_path
369 local rv = LuaDialog.Dialog("Recall Mixer Settings:", recall_options):run()
370 if not(rv) then return end
371 local dry_return = LuaDialog.Dialog("Mixer Store:", dry_run(false, rv['file'])):run()
373 recall(false, rv['file'], dry_return)
378 LuaDialog.Message ("Recall Mixer Settings:",
379 global_path .. [[does not exist!
380 Please run Store Mixer Settings first.]],
381 LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run()
385 if gvld['recall-dir'] == 2 then
386 local local_ok = isdir(local_path)
387 local local_default_path = ARDOUR.LuaAPI.build_filename(local_path, 'stub')
388 print(local_default_path)
390 recall_options[2]['path'] = local_path
391 local rv = LuaDialog.Dialog("Recall Mixer Settings:", recall_options):run()
392 if not(rv) then return end
393 local dry_return = LuaDialog.Dialog("Mixer Store:", dry_run(false, rv['file'])):run()
395 recall(false, rv['file'], dry_return)
400 LuaDialog.Message ("Recall Mixer Settings:",
401 local_path .. [[does not exist!
402 Please run Store Mixer Settings first.]],
403 LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run()