Update Lua VAMP scripts to show a progress dialog

This commit is contained in:
Robin Gareus 2019-09-02 05:19:27 +02:00
parent 6edb649b53
commit a1f9beb355
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
4 changed files with 56 additions and 19 deletions

View file

@ -2,19 +2,6 @@ ardour { ["type"] = "Snippet", name = "Vamp Audio Transcription Example" }
function factory () return function ()
-- simple progress information print()ing
--[[
local progress_total;
local progress_last;
function cb (_f, pos)
local progress = 100 * pos / progress_total;
if progress - progress_last > 5 then
progress_last = progress;
print ("Progress: ", progress)
end
end
--]]
-- get Editor selection
-- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Editor
-- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Selection
@ -25,16 +12,33 @@ function factory () return function ()
-- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:LuaAPI:Vamp
local vamp = ARDOUR.LuaAPI.Vamp ("libardourvampplugins:qm-transcription", sr)
-- prepare progress dialog
local progress_total = 0;
local progress_part = 0
local pdialog = LuaDialog.LuaProgressWindow ("Audio to MIDI", true)
function cb (_, pos)
return pdialog:progress ((pos + progress_part) / progress_total, "Analyzing")
end
-- calculate max progress
for r in sel.regions:regionlist ():iter () do
progress_total = progress_total + r:to_readable ():readable_length ()
end
-- for each selected region
-- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:RegionSelection
for r in sel.regions:regionlist ():iter () do
-- "r" is-a http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Region
--[[
progress_total = r:to_readable ():readable_length ()
progress_last = 0
--]]
vamp:analyze (r:to_readable (), 0, nil --[[cb--]])
vamp:analyze (r:to_readable (), 0, cb)
if pdialog:canceled () then
goto out
end
progress_part = progress_part + r:to_readable ():readable_length ()
pdialog:progress (progress_part / progress_total, "Post Processing")
print ("-- Post Processing: ", r:name ())
-- post-processing takes longer than actually parsing the data :(
@ -54,4 +58,11 @@ function factory () return function ()
vamp:reset ()
end
::out::
-- hide modal progress dialog and destroy it
pdialog:done ();
pdialog = nil
vamp = nil;
collectgarbage ()
end end