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 new_plugin(name)
16 plugin = ARDOUR.LuaAPI.new_plugin(Session, name, x, "")
17 if not(plugin:isnil()) then return plugin end
21 function group_by_id(id)
22 local id = tonumber(id)
23 for g in Session:route_groups():iter() do
24 local group_id = tonumber(g:to_stateful():id():to_s())
25 if group_id == id then return g end
29 function route_groupid_interrogate(t)
31 for g in Session:route_groups():iter() do
32 for r in g:route_list():iter() do
33 if r:name() == t:name() then group = g:to_stateful():id():to_s() end
38 function route_group_interrogate(t)
39 for g in Session:route_groups():iter() do
40 for r in g:route_list():iter() do
41 if r:name() == t:name() then return g end
46 function empty_last_store() --empty current file from last run
47 local file = io.open(path, "w")
52 function mark_selected_tracks()
55 local sel = Editor:get_selection ()
56 local groups_to_write = {}
59 for r in sel.tracks:routelist():iter() do
60 local group = route_group_interrogate(r)
61 if group then groups_to_write[#groups_to_write + 1] = group end
64 for k, g in pairs(groups_to_write) do
65 local g_route_str, group_str = "", ""
66 group_str = "instance = {group_id = " .. g:to_stateful():id():to_s() .. ", name = " .. "\"" .. g:name() .. "\"" .. ", routes = {"
67 for t in g:route_list():iter() do
68 g_route_str = g_route_str .."[".. i .."] = " .. t:to_stateful():id():to_s() .. ","
71 group_str = group_str .. g_route_str .. "}}"
72 if not(group_str == "") then --sometimes there are no groups in the session
73 file = io.open(path, "a")
74 file:write(group_str, "\r\n")
79 for r in sel.tracks:routelist():iter() do
80 if r:is_monitor () or r:is_auditioner () then goto nextroute end -- skip special routes
82 local order = ARDOUR.ProcessorList()
85 local proc = r:nth_processor(x)
86 if not proc:isnil() then
92 local route_str, proc_order_str, cache_str = "", "", ""
93 local rid = r:to_stateful():id():to_s()
94 local pan = r:pan_azimuth_control()
95 if pan:isnil() then pan = false else pan = pan:get_value() end --sometimes a route doesn't have pan, like the master.
98 for p in order:iter() do
99 local pid = p:to_stateful():id():to_s()
100 if not(string.find(p:display_name(), "latcomp")) then
101 proc_order_str = proc_order_str .. "[" .. on .. "] = " .. pid ..","
102 cache_str = cache_str .. "[" .. pid .. "] = " .. "\"" .. p:display_name() .. "\"" ..","
107 route_str = "instance = {route_id = " .. rid .. ", 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)) .. "}"
108 file = io.open(path, "a")
109 file:write(route_str, "\r\n")
115 local proc_str, params_str = "", ""
116 local proc = r:nth_plugin (i)
117 if proc:isnil () then break end
118 local active = proc:active()
119 local id = proc:to_stateful():id():to_s()
120 local plug = proc:to_insert ():plugin (0)
121 local n = 0 -- count control-ports
122 for j = 0, plug:parameter_count () - 1 do -- iterate over all plugin parameters
123 if plug:parameter_is_control (j) then
124 local label = plug:parameter_label (j)
125 if plug:parameter_is_input (j) and label ~= "hidden" and label:sub (1,1) ~= "#" then
126 local _, _, pd = ARDOUR.LuaAPI.plugin_automation(proc, n)
127 local val = ARDOUR.LuaAPI.get_processor_param(proc, j, true)
128 --print(r:name(), "->", proc:display_name(), label, val)
135 for k, v in pairs(params) do
136 params_str = params_str .. "[".. k .."] = " .. v .. ","
138 proc_str = "instance = {plugin_id = " .. id .. ", parameters = {" .. params_str .. "}, active = " .. tostring(active) .. "}"
139 file = io.open(path, "a")
140 file:write(proc_str, "\r\n")
147 function mark_all_tracks()
151 for g in Session:route_groups():iter() do --@ToDo: Color, and other bools
152 local g_route_str, group_str = "", ""
153 group_str = "instance = {group_id = " .. g:to_stateful():id():to_s() .. ", name = " .. "\"" .. g:name() .. "\"" .. ", routes = {"
154 for t in g:route_list():iter() do
155 g_route_str = g_route_str .."[".. i .."] = " .. t:to_stateful():id():to_s() .. ","
158 group_str = group_str .. g_route_str .. "}}"
159 if not(group_str == "") then --sometimes there are no groups in the session
160 file = io.open(path, "a")
161 file:write(group_str, "\r\n")
166 for r in Session:get_routes():iter() do
167 if r:is_monitor () or r:is_auditioner () then goto nextroute end -- skip special routes
169 local order = ARDOUR.ProcessorList()
172 local proc = r:nth_processor(x)
173 if not proc:isnil() then
174 order:push_back(proc)
179 local route_str, proc_order_str, cache_str = "", "", ""
180 local rid = r:to_stateful():id():to_s()
181 local pan = r:pan_azimuth_control()
182 if pan:isnil() then pan = false else pan = pan:get_value() end --sometimes a route doesn't have pan, like the master.
185 for p in order:iter() do
186 local pid = p:to_stateful():id():to_s()
187 if not(string.find(p:display_name(), "latcomp")) then
188 proc_order_str = proc_order_str .. "[" .. on .. "] = " .. pid ..","
189 cache_str = cache_str .. "[" .. pid .. "] = " .. "\"" .. p:display_name() .. "\"" ..","
194 route_str = "instance = {route_id = " .. rid .. ", 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)) .. "}"
195 file = io.open(path, "a")
196 file:write(route_str, "\r\n")
202 local proc_str, params_str = "", ""
203 local proc = r:nth_plugin (i)
204 if proc:isnil () then break end
205 local active = proc:active()
206 local id = proc:to_stateful():id():to_s()
207 local plug = proc:to_insert ():plugin (0)
208 local n = 0 -- count control-ports
209 for j = 0, plug:parameter_count () - 1 do -- iterate over all plugin parameters
210 if plug:parameter_is_control (j) then
211 local label = plug:parameter_label (j)
212 if plug:parameter_is_input (j) and label ~= "hidden" and label:sub (1,1) ~= "#" then
213 local _, _, pd = ARDOUR.LuaAPI.plugin_automation(proc, n)
214 local val = ARDOUR.LuaAPI.get_processor_param(proc, j, true)
215 --print(r:name(), "->", proc:display_name(), label, val)
222 for k, v in pairs(params) do
223 params_str = params_str .. "[".. k .."] = " .. v .. ","
225 proc_str = "instance = {plugin_id = " .. id .. ", parameters = {" .. params_str .. "}, active = " .. tostring(active) .. "}"
226 file = io.open(path, "a")
227 file:write(proc_str, "\r\n")
235 local file = io.open(path, "r")
236 assert(file, "File not found!")
237 for l in file:lines() do
240 local plugin, route, group = false, false, false
244 if instance["route_id"] then route = true end
245 if instance["plugin_id"] then plugin = true end
246 if instance["group_id"] then group = true end
249 local g_id = instance["group_id"]
250 local routes = instance["routes"]
251 local name = instance["name"]
252 local group = group_by_id(g_id)
253 if not(group) then group = Session:new_route_group(name) end
254 for k, v in pairs(routes) do
255 local rt = Session:route_by_id(PBD.ID(v))
256 if not(rt:isnil()) then group:add(rt) end
262 local old_order = ARDOUR.ProcessorList()
263 local r_id = PBD.ID(instance["route_id"])
264 local muted, soloed = instance["muted"], instance["soloed"]
265 local order = instance["order"]
266 local cache = instance["cache"]
267 local group = instance["group"]
268 local gc, tc, pc = instance["gain_control"], instance["trim_control"], instance["pan_control"]
270 local rt = Session:route_by_id(r_id)
271 if rt:isnil() then goto nextline end
273 local cur_group_id = route_groupid_interrogate(rt)
274 if not(group) and (cur_group_id) then
275 local g = group_by_id(cur_group_id)
276 if g then g:remove(rt) end
279 for k, v in pairs(order) do
280 local proc = Session:processor_by_id(PBD.ID(v))
282 for id, name in pairs(cache) do
284 proc = new_plugin(name)
285 if not(proc:isnil()) then
286 rt:add_processor_by_index(proc, 0, nil, true)
287 invalidate[v] = proc:to_stateful():id():to_s()
292 if not(proc:isnil()) then old_order:push_back(proc) end
295 if muted then rt:mute_control():set_value(1, 1) else rt:mute_control():set_value(0, 1) end
296 if soloed then rt:solo_control():set_value(1, 1) else rt:solo_control():set_value(0, 1) end
297 rt:gain_control():set_value(gc, 1)
298 rt:trim_control():set_value(tc, 1)
299 if pc ~= false then rt:pan_azimuth_control():set_value(pc, 1) end
300 rt:reorder_processors(old_order, nil)
305 local params = instance["parameters"]
306 local p_id = instance["plugin_id"]
307 local act = instance["active"]
309 for k, v in pairs(invalidate) do --invalidate any deleted plugin's id
315 local proc = Session:processor_by_id(PBD.ID(p_id))
316 if proc:isnil() then goto nextline end
317 local plug = proc:to_insert():plugin(0)
319 for k, v in pairs(params) do
320 local label = plug:parameter_label(k)
321 if string.find(label, "Assign") or string.find(label, "Enable") then --@ToDo: Check Plugin type == LADSPA or VST?
322 enable[k] = v --queue any assignments/enables for after the initial parameter recalling to duck the 'in-on-change' feature
324 ARDOUR.LuaAPI.set_processor_param(proc, k, v)
327 for k, v in pairs(enable) do
328 ARDOUR.LuaAPI.set_processor_param(proc, k, v)
330 if act then proc:activate() else proc:deactivate() end
336 local dialog_options = {
337 { type = "label", colspan = 5, title = "" },
338 { type = "radio", col = 1, colspan = 7, key = "select", title = "", values ={ ["Store"] = "store", ["Recall"] = "recall" }, default = "Store"},
339 { type = "label", colspan = 5, title = "" },
342 local store_options = {
343 { type = "label", colspan = 5, title = "" },
344 { type = "checkbox", col=1, colspan = 1, key = "selected", default = false, title = "Selected tracks only"},
345 { type = "entry", col=2, colspan = 10, key = "filename", default = "params", title = "Store name" },
346 { type = "label", colspan = 5, title = "" },
349 local recall_options = {
350 { type = "label", colspan = 5, title = "" },
351 { type = "file", col =1, colspan = 10, key = "file", title = "Select a File", path = ARDOUR.LuaAPI.build_filename(Session:path(), "export", "params.lua") },
352 { type = "label", colspan = 5, title = "" },
355 local rv = LuaDialog.Dialog("Mixer Store:", dialog_options):run()
358 local choice = rv["select"]
359 if choice == "store" then
360 local srv = LuaDialog.Dialog("Mixer Store:", store_options):run()
362 empty_last_store() --ensures that params.lua will exist for the recall dialog
363 path = ARDOUR.LuaAPI.build_filename(Session:path(), "export", srv["filename"] .. ".lua")
364 if srv['selected'] then
365 mark_selected_tracks()
372 if choice == "recall" then
373 local rrv = LuaDialog.Dialog("Mixer Store:", recall_options):run()
375 if rrv['file'] ~= path then path = rrv['file'] end