2 ["type"] = "EditorAction",
4 author = "Ardour Lua Taskforce",
5 description = [[Stores the current Mixer state as a file that can be read and recalled arbitrarily.
6 Supports: processor settings, grouping, mute, solo, gain, trim, pan and processor ordering, plus re-adding certain deleted plugins.]]
9 function factory() return function()
12 local path = ARDOUR.LuaAPI.build_filename(Session:path(), "export", "params.lua")
14 function get_processor_by_name(track, name)
16 local proc = track:nth_processor(i)
18 if ( proc:display_name() == name ) then
23 proc = track:nth_processor(i)
27 function new_plugin(name)
29 plugin = ARDOUR.LuaAPI.new_plugin(Session, name, x, "")
30 if not(plugin:isnil()) then return plugin end
34 function group_by_id(id)
35 local id = tonumber(id)
36 for g in Session:route_groups():iter() do
37 local group_id = tonumber(g:to_stateful():id():to_s())
38 if group_id == id then return g end
42 function route_groupid_interrogate(t)
44 for g in Session:route_groups():iter() do
45 for r in g:route_list():iter() do
46 if r:name() == t:name() then group = g:to_stateful():id():to_s() end
51 function route_group_interrogate(t)
52 for g in Session:route_groups():iter() do
53 for r in g:route_list():iter() do
54 if r:name() == t:name() then return g end
59 function empty_last_store() --empty current file from last run
60 local file = io.open(path, "w")
65 function mark_selected_tracks()
68 local sel = Editor:get_selection ()
69 local groups_to_write = {}
72 for r in sel.tracks:routelist():iter() do
73 local group = route_group_interrogate(r)
74 if group then groups_to_write[#groups_to_write + 1] = group end
77 for k, g in pairs(groups_to_write) do
78 local g_route_str, group_str = "", ""
79 group_str = "instance = {group_id = " .. g:to_stateful():id():to_s() .. ", name = " .. "\"" .. g:name() .. "\"" .. ", routes = {"
80 for t in g:route_list():iter() do
81 g_route_str = g_route_str .."[".. i .."] = " .. t:to_stateful():id():to_s() .. ","
84 group_str = group_str .. g_route_str .. "}}"
85 if not(group_str == "") then --sometimes there are no groups in the session
86 file = io.open(path, "a")
87 file:write(group_str, "\r\n")
92 for r in sel.tracks:routelist():iter() do
93 if r:is_monitor () or r:is_auditioner () then goto nextroute end -- skip special routes
95 local order = ARDOUR.ProcessorList()
98 local proc = r:nth_processor(x)
99 if not proc:isnil() then
100 order:push_back(proc)
105 local route_str, proc_order_str, cache_str = "", "", ""
106 local rid = r:to_stateful():id():to_s()
107 local pan = r:pan_azimuth_control()
108 if pan:isnil() then pan = false else pan = pan:get_value() end --sometimes a route doesn't have pan, like the master.
111 for p in order:iter() do
112 local pid = p:to_stateful():id():to_s()
113 if not(string.find(p:display_name(), "latcomp")) then
114 proc_order_str = proc_order_str .. "[" .. on .. "] = " .. pid ..","
115 cache_str = cache_str .. "[" .. pid .. "] = " .. "\"" .. p:display_name() .. "\"" ..","
120 route_str = "instance = {route_id = " .. rid .. ", route_name = " .. r:name() .. ", gain_control = " .. r:gain_control():get_value() .. ", trim_control = " .. r:trim_control():get_value() .. ", pan_control = " .. tostring(pan) .. ", muted = " .. tostring(r:muted()) .. ", soloed = " .. tostring(r:soloed()) .. ", order = {" .. proc_order_str .."}, cache = {" .. cache_str .. "}, group = " .. tostring(route_groupid_interrogate(r)) .. "}"
121 file = io.open(path, "a")
122 file:write(route_str, "\r\n")
128 local proc_str, params_str = "", ""
129 local proc = r:nth_plugin (i)
130 if proc:isnil () then break end
131 local active = proc:active()
132 local id = proc:to_stateful():id():to_s()
133 local plug = proc:to_insert ():plugin (0)
134 local n = 0 -- count control-ports
135 for j = 0, plug:parameter_count () - 1 do -- iterate over all plugin parameters
136 if plug:parameter_is_control (j) then
137 local label = plug:parameter_label (j)
138 if plug:parameter_is_input (j) and label ~= "hidden" and label:sub (1,1) ~= "#" then
139 local _, _, pd = ARDOUR.LuaAPI.plugin_automation(proc, n)
140 local val = ARDOUR.LuaAPI.get_processor_param(proc, j, true)
141 --print(r:name(), "->", proc:display_name(), label, val)
148 for k, v in pairs(params) do
149 params_str = params_str .. "[".. k .."] = " .. v .. ","
151 proc_str = "instance = {plugin_id = " .. id .. ", parameters = {" .. params_str .. "}, active = " .. tostring(active) .. "}"
152 file = io.open(path, "a")
153 file:write(proc_str, "\r\n")
160 function mark_all_tracks()
164 for g in Session:route_groups():iter() do --@ToDo: Color, and other bools
165 local g_route_str, group_str = "", ""
166 group_str = "instance = {group_id = " .. g:to_stateful():id():to_s() .. ", name = " .. "\"" .. g:name() .. "\"" .. ", routes = {"
167 for t in g:route_list():iter() do
168 g_route_str = g_route_str .."[".. i .."] = " .. t:to_stateful():id():to_s() .. ","
171 group_str = group_str .. g_route_str .. "}}"
172 if not(group_str == "") then --sometimes there are no groups in the session
173 file = io.open(path, "a")
174 file:write(group_str, "\r\n")
179 for r in Session:get_routes():iter() do
180 if r:is_monitor () or r:is_auditioner () then goto nextroute end -- skip special routes
182 local order = ARDOUR.ProcessorList()
185 local proc = r:nth_processor(x)
186 if not proc:isnil() then
187 order:push_back(proc)
192 local route_str, proc_order_str, cache_str = "", "", ""
193 local rid = r:to_stateful():id():to_s()
194 local pan = r:pan_azimuth_control()
195 if pan:isnil() then pan = false else pan = pan:get_value() end --sometimes a route doesn't have pan, like the master.
198 for p in order:iter() do
199 local pid = p:to_stateful():id():to_s()
200 if not(string.find(p:display_name(), "latcomp")) then
201 proc_order_str = proc_order_str .. "[" .. on .. "] = " .. pid ..","
202 cache_str = cache_str .. "[" .. pid .. "] = " .. "\"" .. p:display_name() .. "\"" ..","
207 route_str = "instance = {route_id = " .. rid .. ", route_name = '" .. r:name() .. "', gain_control = " .. r:gain_control():get_value() .. ", trim_control = " .. r:trim_control():get_value() .. ", pan_control = " .. tostring(pan) .. ", muted = " .. tostring(r:muted()) .. ", soloed = " .. tostring(r:soloed()) .. ", order = {" .. proc_order_str .."}, cache = {" .. cache_str .. "}, group = " .. tostring(route_groupid_interrogate(r)) .. "}"
208 file = io.open(path, "a")
209 file:write(route_str, "\r\n")
215 local proc_str, params_str = "", ""
216 local proc = r:nth_plugin (i)
217 if proc:isnil () then break end
218 local active = proc:active()
219 local id = proc:to_stateful():id():to_s()
220 local plug = proc:to_insert ():plugin (0)
221 local n = 0 -- count control-ports
222 for j = 0, plug:parameter_count () - 1 do -- iterate over all plugin parameters
223 if plug:parameter_is_control (j) then
224 local label = plug:parameter_label (j)
225 if plug:parameter_is_input (j) and label ~= "hidden" and label:sub (1,1) ~= "#" then
226 local _, _, pd = ARDOUR.LuaAPI.plugin_automation(proc, n)
227 local val = ARDOUR.LuaAPI.get_processor_param(proc, j, true)
228 --print(r:name(), "->", proc:display_name(), label, val)
235 for k, v in pairs(params) do
236 params_str = params_str .. "[".. k .."] = " .. v .. ","
238 proc_str = "instance = {plugin_id = " .. id .. ", parameters = {" .. params_str .. "}, active = " .. tostring(active) .. "}"
239 file = io.open(path, "a")
240 file:write(proc_str, "\r\n")
248 local file = io.open(path, "r")
249 assert(file, "File not found!")
250 for l in file:lines() do
253 local plugin, route, group = false, false, false
257 if instance["route_id"] then route = true end
258 if instance["plugin_id"] then plugin = true end
259 if instance["group_id"] then group = true end
262 local g_id = instance["group_id"]
263 local routes = instance["routes"]
264 local name = instance["name"]
265 local group = group_by_id(g_id)
266 if not(group) then group = Session:new_route_group(name) end
267 for k, v in pairs(routes) do
268 local rt = Session:route_by_id(PBD.ID(v))
269 if not(rt:isnil()) then group:add(rt) end
275 local old_order = ARDOUR.ProcessorList()
276 local r_id = PBD.ID(instance["route_id"])
277 local muted, soloed = instance["muted"], instance["soloed"]
278 local order = instance["order"]
279 local cache = instance["cache"]
280 local group = instance["group"]
281 local name = instance["route_name"]
282 local gc, tc, pc = instance["gain_control"], instance["trim_control"], instance["pan_control"]
284 local rt = Session:route_by_id(r_id)
285 if rt:isnil() then rt = Session:route_by_name(name) end
286 if rt:isnil() then goto nextline end
288 local cur_group_id = route_groupid_interrogate(rt)
289 if not(group) and (cur_group_id) then
290 local g = group_by_id(cur_group_id)
291 if g then g:remove(rt) end
294 well_known = {'PRE', 'Trim', 'EQ', 'Comp', 'Fader', 'POST'}
296 for k, v in pairs(order) do
297 local proc = Session:processor_by_id(PBD.ID(v))
299 for id, name in pairs(cache) do
301 proc = new_plugin(name)
302 for _, control in pairs(well_known) do
303 if name == control then
304 proc = get_processor_by_name(rt, control)
305 invalidate[v] = proc:to_stateful():id():to_s()
309 if not(proc) then goto nextproc end
310 if not(proc:isnil()) then
311 rt:add_processor_by_index(proc, 0, nil, true)
312 invalidate[v] = proc:to_stateful():id():to_s()
318 if proc and not(proc:isnil()) then old_order:push_back(proc) end
321 if muted then rt:mute_control():set_value(1, 1) else rt:mute_control():set_value(0, 1) end
322 if soloed then rt:solo_control():set_value(1, 1) else rt:solo_control():set_value(0, 1) end
323 rt:gain_control():set_value(gc, 1)
324 rt:trim_control():set_value(tc, 1)
325 if pc ~= false then rt:pan_azimuth_control():set_value(pc, 1) end
326 rt:reorder_processors(old_order, nil)
331 local params = instance["parameters"]
332 local p_id = instance["plugin_id"]
333 local act = instance["active"]
335 for k, v in pairs(invalidate) do --invalidate any deleted plugin's id
341 local proc = Session:processor_by_id(PBD.ID(p_id))
342 if proc:isnil() then goto nextline end
343 local plug = proc:to_insert():plugin(0)
345 for k, v in pairs(params) do
346 local label = plug:parameter_label(k)
347 if string.find(label, "Assign") or string.find(label, "Enable") then --@ToDo: Check Plugin type == LADSPA or VST?
348 enable[k] = v --queue any assignments/enables for after the initial parameter recalling to duck the 'in-on-change' feature
350 ARDOUR.LuaAPI.set_processor_param(proc, k, v)
353 for k, v in pairs(enable) do
354 ARDOUR.LuaAPI.set_processor_param(proc, k, v)
356 if act then proc:activate() else proc:deactivate() end
362 local dialog_options = {
363 { type = "label", colspan = 5, title = "" },
364 { type = "radio", col = 1, colspan = 7, key = "select", title = "", values ={ ["Store"] = "store", ["Recall"] = "recall" }, default = "Store"},
365 { type = "label", colspan = 5, title = "" },
368 local store_options = {
369 { type = "label", colspan = 5, title = "" },
370 { type = "checkbox", col=1, colspan = 1, key = "selected", default = false, title = "Selected tracks only"},
371 { type = "entry", col=2, colspan = 10, key = "filename", default = "params", title = "Store name" },
372 { type = "label", colspan = 5, title = "" },
375 local recall_options = {
376 { type = "label", colspan = 5, title = "" },
377 { type = "file", col =1, colspan = 10, key = "file", title = "Select a File", path = ARDOUR.LuaAPI.build_filename(Session:path(), "export", "params.lua") },
378 { type = "label", colspan = 5, title = "" },
381 local rv = LuaDialog.Dialog("Mixer Store:", dialog_options):run()
384 local choice = rv["select"]
385 if choice == "store" then
386 local srv = LuaDialog.Dialog("Mixer Store:", store_options):run()
388 empty_last_store() --ensures that params.lua will exist for the recall dialog
389 path = ARDOUR.LuaAPI.build_filename(Session:path(), "export", srv["filename"] .. ".lua")
390 if srv['selected'] then
391 mark_selected_tracks()
398 if choice == "recall" then
399 local rrv = LuaDialog.Dialog("Mixer Store:", recall_options):run()
401 if rrv['file'] ~= path then path = rrv['file'] end