lots of changes including: ability to store and recall more than one mixer state, ability to work on selected tracks only, plus bugfixes and removal of redundant checks

This commit is contained in:
Nikolaus Gullotta 2018-03-29 10:21:09 -05:00
parent ca0e4f2e32
commit d0f7bec624

View file

@ -8,24 +8,25 @@ ardour {
function factory() return function()
local invalidate = {}
local path = ARDOUR.LuaAPI.build_filename(Session:path(), "export", "params.lua")
function new_plugin(name)
local plugin = nil
for x = 0, 6 do
plugin = ARDOUR.LuaAPI.new_plugin(Session, name, x, "")
if not(plugin:isnil()) then break end
end return plugin
if not(plugin:isnil()) then return plugin end
end
end
function group_by_id(id)
local group = nil
local id = tonumber(id)
for g in Session:route_groups():iter() do
local group_id = tonumber(g:to_stateful():id():to_s())
if group_id == id then group = g end
end return group
if group_id == id then return g end
end
end
function route_group_interrogate(t)
function route_groupid_interrogate(t)
local group = false
for g in Session:route_groups():iter() do
for r in g:route_list():iter() do
@ -34,31 +35,48 @@ function factory() return function()
end return group
end
local path = ARDOUR.LuaAPI.build_filename(Session:path(), "export", "params.lua")
function mark()
function route_group_interrogate(t)
for g in Session:route_groups():iter() do
for r in g:route_list():iter() do
if r:name() == t:name() then return g end
end
end
end
function empty_last_store() --empty current file from last run
local file = io.open(path, "w")
file:write("") --empty current file from last run
file:write("")
file:close()
end
local g_route_str, group_str = "", ""
function mark_selected_tracks()
empty_last_store()
local sel = Editor:get_selection ()
local groups_to_write = {}
local i = 0
for g in Session:route_groups():iter() do --@ToDo: Color, and other bools
for r in sel.tracks:routelist():iter() do
local group = route_group_interrogate(r)
if group then groups_to_write[#groups_to_write + 1] = group end
end
for k, g in pairs(groups_to_write) do
local g_route_str, group_str = "", ""
group_str = "instance = {group_id = " .. g:to_stateful():id():to_s() .. ", name = " .. "\"" .. g:name() .. "\"" .. ", routes = {"
for t in g:route_list():iter() do
g_route_str = g_route_str .."[".. i .."] = " .. t:to_stateful():id():to_s() .. ","
i = i + 1
end
group_str = group_str .. g_route_str .. "}}"
if not(group_str == "") then --sometimes there are no groups in the session
file = io.open(path, "a")
file:write(group_str, "\r\n")
file:close()
end
end
if not(group_str == "") then --sometimes there are no groups in the session
file = io.open(path, "a")
file:write(group_str, "\r\n")
file:close()
end
for r in Session:get_routes():iter() do
for r in sel.tracks:routelist():iter() do
if r:is_monitor () or r:is_auditioner () then goto nextroute end -- skip special routes
local order = ARDOUR.ProcessorList()
@ -86,7 +104,7 @@ function factory() return function()
on = on + 1
end
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_group_interrogate(r)) .. "}"
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)) .. "}"
file = io.open(path, "a")
file:write(route_str, "\r\n")
file:close()
@ -125,7 +143,94 @@ function factory() return function()
::nextroute::
end
end
local invalidate = {}
function mark_all_tracks()
empty_last_store()
local i = 0
for g in Session:route_groups():iter() do --@ToDo: Color, and other bools
local g_route_str, group_str = "", ""
group_str = "instance = {group_id = " .. g:to_stateful():id():to_s() .. ", name = " .. "\"" .. g:name() .. "\"" .. ", routes = {"
for t in g:route_list():iter() do
g_route_str = g_route_str .."[".. i .."] = " .. t:to_stateful():id():to_s() .. ","
i = i + 1
end
group_str = group_str .. g_route_str .. "}}"
if not(group_str == "") then --sometimes there are no groups in the session
file = io.open(path, "a")
file:write(group_str, "\r\n")
file:close()
end
end
for r in Session:get_routes():iter() do
if r:is_monitor () or r:is_auditioner () then goto nextroute end -- skip special routes
local order = ARDOUR.ProcessorList()
local x = 0
repeat
local proc = r:nth_processor(x)
if not proc:isnil() then
order:push_back(proc)
end
x = x + 1
until proc:isnil()
local route_str, proc_order_str, cache_str = "", "", ""
local rid = r:to_stateful():id():to_s()
local pan = r:pan_azimuth_control()
if pan:isnil() then pan = false else pan = pan:get_value() end --sometimes a route doesn't have pan, like the master.
local on = 0
for p in order:iter() do
local pid = p:to_stateful():id():to_s()
if not(string.find(p:display_name(), "latcomp")) then
proc_order_str = proc_order_str .. "[" .. on .. "] = " .. pid ..","
cache_str = cache_str .. "[" .. pid .. "] = " .. "\"" .. p:display_name() .. "\"" ..","
end
on = on + 1
end
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)) .. "}"
file = io.open(path, "a")
file:write(route_str, "\r\n")
file:close()
local i = 0
while true do
local params = {}
local proc_str, params_str = "", ""
local proc = r:nth_plugin (i)
if proc:isnil () then break end
local active = proc:active()
local id = proc:to_stateful():id():to_s()
local plug = proc:to_insert ():plugin (0)
local n = 0 -- count control-ports
for j = 0, plug:parameter_count () - 1 do -- iterate over all plugin parameters
if plug:parameter_is_control (j) then
local label = plug:parameter_label (j)
if plug:parameter_is_input (j) and label ~= "hidden" and label:sub (1,1) ~= "#" then
local _, _, pd = ARDOUR.LuaAPI.plugin_automation(proc, n)
local val = ARDOUR.LuaAPI.get_processor_param(proc, j, true)
--print(r:name(), "->", proc:display_name(), label, val)
params[n] = val
end
n = n + 1
end
end
i = i + 1
for k, v in pairs(params) do
params_str = params_str .. "[".. k .."] = " .. v .. ","
end
proc_str = "instance = {plugin_id = " .. id .. ", parameters = {" .. params_str .. "}, active = " .. tostring(active) .. "}"
file = io.open(path, "a")
file:write(proc_str, "\r\n")
file:close()
end
::nextroute::
end
end
function recall()
local file = io.open(path, "r")
assert(file, "File not found!")
@ -136,16 +241,16 @@ function factory() return function()
local f = load(l)
f ()
if instance["route_id"] ~= nil then route = true end
if instance["plugin_id"] ~= nil then plugin = true end
if instance["group_id"] ~= nil then group = true end
if instance["route_id"] then route = true end
if instance["plugin_id"] then plugin = true end
if instance["group_id"] then group = true end
if group then
local g_id = instance["group_id"]
local g_id = instance["group_id"]
local routes = instance["routes"]
local name = instance["name"]
local group = group_by_id(g_id)
if group == nil then group = Session:new_route_group(name) end
local name = instance["name"]
local group = group_by_id(g_id)
if not(group) then group = Session:new_route_group(name) end
for k, v in pairs(routes) do
local rt = Session:route_by_id(PBD.ID(v))
if not(rt:isnil()) then group:add(rt) end
@ -165,7 +270,7 @@ function factory() return function()
local rt = Session:route_by_id(r_id)
if rt:isnil() then goto nextline end
local cur_group_id = route_group_interrogate(rt)
local cur_group_id = route_groupid_interrogate(rt)
if not(group) and (cur_group_id) then
local g = group_by_id(cur_group_id)
if g then g:remove(rt) end
@ -199,7 +304,7 @@ function factory() return function()
local enable = {}
local params = instance["parameters"]
local p_id = instance["plugin_id"]
local act = instance["active"]
local act = instance["active"]
for k, v in pairs(invalidate) do --invalidate any deleted plugin's id
if p_id == k then
@ -229,16 +334,48 @@ function factory() return function()
end
local dialog_options = {
{ type = "label", colspan= 10, title = "" },
{ type = "radio", colspan= 10, key = "select", title = "", values ={ ["1. Mark"] = "mark", ["2. Recall"] = "recall" }, default = "1. Mark"},
{ type = "label", colspan= 10, title = "" },
{ type = "label", colspan = 5, title = "" },
{ type = "radio", col = 1, colspan = 7, key = "select", title = "", values ={ ["Store"] = "store", ["Recall"] = "recall" }, default = "Store"},
{ type = "label", colspan = 5, title = "" },
}
local store_options = {
{ type = "label", colspan = 5, title = "" },
{ type = "checkbox", col=1, colspan = 1, key = "selected", default = false, title = "Selected tracks only"},
{ type = "entry", col=2, colspan = 10, key = "filename", default = "params", title = "Store name" },
{ type = "label", colspan = 5, title = "" },
}
local recall_options = {
{ type = "label", colspan = 5, title = "" },
{ type = "file", col =1, colspan = 10, key = "file", title = "Select a File", path = ARDOUR.LuaAPI.build_filename(Session:path(), "export", "params.lua") },
{ type = "label", colspan = 5, title = "" },
}
local rv = LuaDialog.Dialog("Mixer Store:", dialog_options):run()
if rv then
local c = rv["select"]
if c == "mark" then mark() end
if c == "recall" then recall() end
local choice = rv["select"]
if choice == "store" then
local srv = LuaDialog.Dialog("Mixer Store:", store_options):run()
if srv then
empty_last_store() --ensures that params.lua will exist for the recall dialog
path = ARDOUR.LuaAPI.build_filename(Session:path(), "export", srv["filename"] .. ".lua")
if srv['selected'] then
mark_selected_tracks()
else
mark_all_tracks()
end
end
end
if choice == "recall" then
local rrv = LuaDialog.Dialog("Mixer Store:", recall_options):run()
if rrv then
if rrv['file'] ~= path then path = rrv['file'] end
recall()
end
end
end
end end