diff options
author | Robin Gareus <robin@gareus.org> | 2019-09-02 05:19:27 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2019-09-02 05:19:27 +0200 |
commit | a1f9beb3552409872b4c6cf855a7922acc5dfa02 (patch) | |
tree | 2cefa905434e364b32798db34e997b54fa95ea0c /scripts/_vamp_note_example.lua | |
parent | 6edb649b533bcb5be173d600429e932daf00f743 (diff) |
Update Lua VAMP scripts to show a progress dialog
Diffstat (limited to 'scripts/_vamp_note_example.lua')
-rw-r--r-- | scripts/_vamp_note_example.lua | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/scripts/_vamp_note_example.lua b/scripts/_vamp_note_example.lua index dd2cc46870..5f0c27b94d 100644 --- a/scripts/_vamp_note_example.lua +++ b/scripts/_vamp_note_example.lua @@ -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 |