From 70f72800c1ecc318133dc324c342fabea3700618 Mon Sep 17 00:00:00 2001 From: Nikolaus Gullotta Date: Fri, 31 Jan 2020 09:16:57 -0600 Subject: [PATCH] Fix plugin removal in Reset Mixer script Removing processors while iterating over the route invalidates the loop. Instead, queue the plugins for later handling --- scripts/reset_mixer.lua | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/scripts/reset_mixer.lua b/scripts/reset_mixer.lua index ddfaa7936c..5cc69d4774 100644 --- a/scripts/reset_mixer.lua +++ b/scripts/reset_mixer.lua @@ -114,38 +114,48 @@ function factory() return function() end local i = 0 + local queue = {} repeat + -- Plugins are queued to not invalidate this loop local proc = route:nth_processor(i) if not(proc:isnil()) then - if prefs["plugins"] then local insert = proc:to_insert() if not(insert:isnil()) then if insert:is_channelstrip() or not(insert:display_to_user()) then ARDOUR.LuaAPI.reset_processor_to_default(insert) else - if prefs["plugins"] == "remove" then - route:remove_processor(proc, nil, true) - else - insert:deactivate() - end + queue[#queue + 1] = proc end end end - if prefs["io"] then local io_proc = proc:to_ioprocessor() if not(io_proc:isnil()) then - if prefs["io"] == "remove" then - route:remove_processor(proc, nil, true) - else - io_proc:deactivate() - end + queue[#queue + 1] = proc end end end i = i + 1 until proc:isnil() + + -- Deal with queue now + for _, proc in pairs(queue) do + if not(proc:to_insert():isnil()) then + if prefs["plugins"] == "remove" then + route:remove_processor(proc, nil, true) + elseif prefs["plugins"] == "bypass" then + proc:deactivate() + end + end + if not(proc:to_ioprocessor():isnil()) then + if prefs["io"] == "remove" then + route:remove_processor(proc, nil, true) + elseif prefs["io"] == "bypass" then + proc:deactivate() + end + end + end end local pref = LuaDialog.Dialog("Reset Mixer", dlg):run()