2 ["type"] = "EditorAction",
3 name = "Store Mixer Settings",
4 author = "Mixbus Team",
7 Stores the current Mixer state as a file
8 that can be read and recalled arbitrarily
9 by it's companion script, Recall Mixer Settings.
11 Supports: processor settings, grouping,
12 mute, solo, gain, trim, pan and processor ordering,
13 plus re-adding certain deleted plugins.
18 function factory () return function ()
20 local user_cfg = ARDOUR.user_config_directory(-1)
21 local local_path = ARDOUR.LuaAPI.build_filename(Session:path(), 'mixer_settings')
22 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 setup_paths()
38 local global_ok, local_ok = false, false
40 if not(isdir(global_path)) then
41 global_ok, _, _ = os.execute('mkdir '.. global_path)
42 if global_ok == 0 then
43 local default_file = ARDOUR.LuaAPI.build_filename(global_path, 'factory_default.lua')
44 local file = io.open(default_file, "w")
52 if not(isdir(local_path)) then
53 local_ok, _, _ = os.execute('mkdir '.. local_path)
55 local stub_file = ARDOUR.LuaAPI.build_filename(local_path, 'stub')
56 local file = io.open(stub_file, "w")
64 return global_ok, local_ok
67 function get_processor_by_name(track, name)
69 local proc = track:nth_processor(i)
71 if(proc:display_name() == name) then
76 proc = track:nth_processor(i)
80 function new_plugin(name)
82 local plugin = ARDOUR.LuaAPI.new_plugin(Session, name, x, "")
83 if not(plugin:isnil()) then return plugin end
87 function group_by_id(id)
88 local id = tonumber(id)
89 for g in Session:route_groups():iter() do
90 local group_id = tonumber(g:to_stateful():id():to_s())
91 if group_id == id then return g end
95 function group_by_name(name)
96 for g in Session:route_groups():iter() do
97 if g:name() == name then return g end
101 function route_groupid_interrogate(t)
103 for g in Session:route_groups():iter() do
104 for r in g:route_list():iter() do
105 if r:name() == t:name() then group = g:to_stateful():id():to_s() end
110 function route_group_interrogate(t)
111 for g in Session:route_groups():iter() do
112 for r in g:route_list():iter() do
113 if r:name() == t:name() then return g end
118 function empty_last_store(path) --empty current file from last run
119 local file = io.open(path, "w")
124 function mark_tracks(selected, path)
126 empty_last_store(path)
128 local route_string = [[instance = {
142 local group_string = [[instance = {
148 local processor_string = [[instance = {
151 owned_by_route_name = '%s',
152 owned_by_route_id = %d,
157 local group_route_string = " [%d] = %s,"
158 local proc_order_string = " [%d] = %d,"
159 local proc_cache_string = " [%d] = '%s',"
160 local params_string = " [%d] = %f,"
162 --ensure easy-to-read formatting doesn't make it through
163 local route_string = string.gsub(route_string, "[\n\t]", "")
164 local group_string = string.gsub(group_string, "[\n\t]", "")
165 local processor_string = string.gsub(processor_string, "[\n\t]", "")
167 local sel = Editor:get_selection ()
168 local groups_to_write = {}
171 local tracks = Session:get_routes()
173 if selected then tracks = sel.tracks:routelist() end
175 for r in tracks:iter() do
176 local group = route_group_interrogate(r)
178 local already_there = false
179 for _, v in pairs(groups_to_write) do
184 if not(already_there) then
185 groups_to_write[#groups_to_write + 1] = group
190 for _, g in pairs(groups_to_write) do
192 for t in g:route_list():iter() do
193 tmp_str = tmp_str .. string.format(group_route_string, i, t:to_stateful():id():to_s())
196 local group_str = string.format(
198 g:to_stateful():id():to_s(),
203 file = io.open(path, "a")
204 file:write(group_str, "\r\n")
208 for r in tracks:iter() do
209 if r:is_monitor () or r:is_auditioner () then goto nextroute end -- skip special routes
211 local order = ARDOUR.ProcessorList()
214 local proc = r:nth_processor(x)
215 if not proc:isnil() then
216 order:push_back(proc)
221 local route_group = route_group_interrogate(r)
222 if route_group then route_group = route_group:name() else route_group = "" end
223 local rid = r:to_stateful():id():to_s()
224 local pan = r:pan_azimuth_control()
225 if pan:isnil() then pan = false else pan = pan:get_value() end --sometimes a route doesn't have pan, like the master.
228 local tmp_order_str, tmp_cache_str = "", ""
229 for p in order:iter() do
230 local pid = p:to_stateful():id():to_s()
231 if not(string.find(p:display_name(), "latcomp")) then
232 tmp_order_str = tmp_order_str .. string.format(proc_order_string, order_nmbr, pid)
233 tmp_cache_str = tmp_cache_str .. string.format(proc_cache_string, pid, p:display_name())
235 order_nmbr = order_nmbr + 1
238 local route_str = string.format(
242 r:gain_control():get_value(),
243 r:trim_control():get_value(),
249 route_groupid_interrogate(r),
253 file = io.open(path, "a")
254 file:write(route_str, "\n")
260 local proc = r:nth_plugin (i)
261 if proc:isnil () then break end
262 local active = proc:active()
263 local id = proc:to_stateful():id():to_s()
264 local plug = proc:to_insert ():plugin (0)
265 local n = 0 -- count control-ports
266 for j = 0, plug:parameter_count () - 1 do -- iterate over all plugin parameters
267 if plug:parameter_is_control (j) then
268 local label = plug:parameter_label (j)
269 if plug:parameter_is_input (j) and label ~= "hidden" and label:sub (1,1) ~= "#" then
270 local _, _, pd = ARDOUR.LuaAPI.plugin_automation(proc, n)
271 local val = ARDOUR.LuaAPI.get_processor_param(proc, j, true)
272 --print(r:name(), "->", proc:display_name(), label, val)
280 local tmp_params_str = ""
281 for k, v in pairs(params) do
282 tmp_params_str = tmp_params_str .. string.format(params_string, k, v)
285 local proc_str = string.format(
290 r:to_stateful():id():to_s(),
294 file = io.open(path, "a")
295 file:write(proc_str, "\n")
302 local store_options = {
303 { type = "label", col=0, colspan=1, align="left", title = "Settings name:" },
304 { type = "entry", col=1, colspan=1, align="right" , key = "filename", default = Session:name(), title=""},
305 { type = "label", col=0, colspan=1, align="left", title = "Selected Tracks Only:" },
306 { type = "checkbox", col=1, colspan=1, align="right", key = "selected", default = false, title = ""},
307 { type = "hseparator", title="", col=0, colspan = 3},
308 { type = "label", col=0, colspan=1, align="left", title = "Store Settings:" },
310 type = "radio", col=1, colspan=3, align="right", key = "store-dir", title = "", values =
312 ['Global (accessible from any session)'] = 1, ['Locally (this session only)'] = 2
314 default = 'Locally (this session only)'
316 --{ type = "label", col=0, colspan=2, align="left", title = ''},
317 --{ type = "label", col=0, colspan=2, align="left", title = "Global Path: " .. global_path},
318 --{ type = "label", col=0, colspan=2, align="left", title = "Local Path: " .. local_path},
321 local global_ok, local_ok = setup_paths()
323 if global_ok and local_ok then
324 local rv = LuaDialog.Dialog("Store Mixer Settings:", store_options):run()
326 if not(rv) then return end
328 local filename = rv['filename']
329 if rv['store-dir'] == 1 then
330 local store_path = ARDOUR.LuaAPI.build_filename(global_path, filename .. '.lua')
331 local selected = rv['selected']
332 mark_tracks(selected, store_path)
335 if rv['store-dir'] == 2 then
336 local store_path = ARDOUR.LuaAPI.build_filename(local_path, filename .. '.lua')
338 local selected = rv['selected']
339 mark_tracks(selected, store_path)