2 ["type"] = "EditorAction",
4 author = "Ardour Lua Taskforce",
5 description = [[Stores the current Mixer state as a file that can be recalled arbitrarily. Supports: processor settings, gain, trim, pan and processor ordering.]]
8 function factory() return function()
10 function new_plugin(name)
13 plugin = ARDOUR.LuaAPI.new_plugin(Session, name, x, "")
14 if not(plugin:isnil()) then break end
18 local path = ARDOUR.LuaAPI.build_filename(Session:path(), "export", "params.lua")
20 local file = io.open(path, "w")
21 file:write("") --empty current file from last run
23 for r in Session:get_routes():iter() do
24 if r:is_monitor () or r:is_auditioner () then goto nextroute end -- skip special routes
26 local order = ARDOUR.ProcessorList()
29 local proc = r:nth_processor(x)
30 if not proc:isnil() then
36 local route_str, proc_order_str, cache_str = "", "", ""
37 local rid = r:to_stateful():id():to_s()
38 local pan = r:pan_azimuth_control()
39 if pan:isnil() then pan = false else pan = pan:get_value() end --sometimes a route doesn't have pan, like the master.
42 for p in order:iter() do
43 local pid = p:to_stateful():id():to_s()
44 proc_order_str = proc_order_str .. "[" .. on .. "] = " .. pid ..","
45 cache_str = cache_str .. "[" .. pid .. "] = " .. "\"" .. p:display_name() .. "\"" ..","
49 route_str = "instance = {route_id = " .. rid .. ", gain_control = " .. r:gain_control():get_value() .. ", trim_control = " .. r:trim_control():get_value() .. ", pan_control = " .. tostring(pan) .. ", order = {" .. proc_order_str .."}, cache = {" .. cache_str .. "}" .. "}"
50 file = io.open(path, "a")
51 file:write(route_str, "\r\n")
57 local proc_str, params_str = "", ""
58 local proc = r:nth_plugin (i)
59 if proc:isnil () then break end
60 local active = proc:active()
61 local id = proc:to_stateful():id():to_s()
62 local plug = proc:to_insert ():plugin (0)
63 local n = 0 -- count control-ports
64 for j = 0, plug:parameter_count () - 1 do -- iterate over all plugin parameters
65 if plug:parameter_is_control (j) then
66 local label = plug:parameter_label (j)
67 if plug:parameter_is_input (j) and label ~= "hidden" and label:sub (1,1) ~= "#" then
68 local _, _, pd = ARDOUR.LuaAPI.plugin_automation(proc, n)
69 local val = ARDOUR.LuaAPI.get_processor_param(proc, j, true)
76 for k, v in pairs(params) do
77 params_str = params_str .. "[".. k .."] = " .. v .. ","
79 proc_str = "instance = {plugin_id = " .. id .. ", parameters = {" .. params_str .. "}, active = " .. tostring(active) .. "}"
80 file = io.open(path, "a")
81 file:write(proc_str, "\r\n")
89 local file = io.open(path, "r")
90 assert(file, "File not found!")
91 for l in file:lines() do
94 local plugin, route = false, false
98 if instance["route_id"] ~= nil then route = true end
99 if instance["plugin_id"] ~= nil then plugin = true end
102 local old_order = ARDOUR.ProcessorList()
103 local rid = PBD.ID(instance["route_id"])
104 local order = instance["order"]
105 local cache = instance["cache"]
106 local gc, tc, pc = instance["gain_control"], instance["trim_control"], instance["pan_control"]
108 local rt = Session:route_by_id(rid)
109 if rt:isnil() then goto nextline end
111 for k, v in pairs(order) do
112 local proc = Session:processor_by_id(PBD.ID(v))
114 for id, name in pairs(cache) do
116 proc = new_plugin(name)
117 invalidate[v] = proc:to_stateful():id():to_s()
121 if not(proc:isnil()) then old_order:push_back(proc) end
124 rt:gain_control():set_value(gc, 1)
125 rt:trim_control():set_value(tc, 1)
126 if pc ~= false then rt:pan_azimuth_control():set_value(pc, 1) end
127 rt:reorder_processors(old_order, nil)
132 local params = instance["parameters"]
133 local p_id = instance["plugin_id"]
134 local act = instance["active"]
136 for k, v in pairs(invalidate) do --invalidate any deleted plugin's id
142 local proc = Session:processor_by_id(PBD.ID(p_id))
143 if proc:isnil() then goto nextline end
144 local plug = proc:to_insert():plugin(0)
146 for k, v in pairs(params) do
147 local label = plug:parameter_label(k)
148 if string.find(label, "Assign") or string.find(label, "Enable") then --@ToDo: Check Plugin type == LADSPA or VST?
149 enable[k] = v --queue any assignments/enables for after the initial parameter recalling to duck the 'in-on-change' feature
151 ARDOUR.LuaAPI.set_processor_param(proc, k, v)
154 for k, v in pairs(enable) do
155 ARDOUR.LuaAPI.set_processor_param(proc, k, v)
157 if act then proc:activate() else proc:deactivate() end
163 local dialog_options = {
164 { type = "label", colspan= 10, title = "" },
165 { type = "radio", colspan= 10, key = "select", title = "", values ={ ["1. Mark"] = "mark", ["2. Recall"] = "recall" }, default = "1. Mark"},
166 { type = "label", colspan= 10, title = "" },
169 local rv = LuaDialog.Dialog("Mixer Store:", dialog_options):run()
170 assert(rv, 'Dialog box was canceled or is ' .. type(rv))
171 local c = rv["select"]
172 if c == "mark" then mark() end
173 if c == "recall" then recall() end