lots of changes including: ability to store and recall more than one mixer state...
authorNikolaus Gullotta <nikolaus.gullotta@gmail.com>
Thu, 29 Mar 2018 15:21:09 +0000 (10:21 -0500)
committerNikolaus Gullotta <nikolaus.gullotta@gmail.com>
Mon, 2 Apr 2018 15:11:22 +0000 (10:11 -0500)
scripts/_store_recall_mixer.lua

index 3107cdbc165a731138e85f549287f5e585c66e10..85e6acbeaeec3cf4ed793a0dd64d48e6d95b5b49 100644 (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,28 +35,132 @@ 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
+
+       function mark_selected_tracks()
+               empty_last_store()
 
-               local g_route_str, group_str = "", ""
+               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
+               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()
+                       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(group_str, "\r\n")
+                       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 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
@@ -86,7 +191,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 +230,7 @@ function factory() return function()
                        ::nextroute::
                end
        end
-       local invalidate = {}
+
        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