summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2019-09-02 05:19:27 +0200
committerRobin Gareus <robin@gareus.org>2019-09-02 05:19:27 +0200
commita1f9beb3552409872b4c6cf855a7922acc5dfa02 (patch)
tree2cefa905434e364b32798db34e997b54fa95ea0c /scripts
parent6edb649b533bcb5be173d600429e932daf00f743 (diff)
Update Lua VAMP scripts to show a progress dialog
Diffstat (limited to 'scripts')
-rw-r--r--scripts/_vamp_note_example.lua47
-rw-r--r--scripts/_vamp_onset_example.lua1
-rw-r--r--scripts/_vamp_tempomap_example.lua1
-rw-r--r--scripts/vamp_audio_to_midi.lua26
4 files changed, 56 insertions, 19 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
diff --git a/scripts/_vamp_onset_example.lua b/scripts/_vamp_onset_example.lua
index 28b4091daa..adcdc16982 100644
--- a/scripts/_vamp_onset_example.lua
+++ b/scripts/_vamp_onset_example.lua
@@ -43,6 +43,7 @@ function factory () return function ()
end
end
end
+ return false -- continue, !cancel
end
-- Configure Vamp plugin
diff --git a/scripts/_vamp_tempomap_example.lua b/scripts/_vamp_tempomap_example.lua
index 44b8771858..1c216c06f3 100644
--- a/scripts/_vamp_tempomap_example.lua
+++ b/scripts/_vamp_tempomap_example.lua
@@ -54,6 +54,7 @@ function factory () return function ()
end
end
end
+ return false -- continue, !cancel
end
vamp:plugin ():setParameter ("Beats Per Bar", 4); -- TODO ask
diff --git a/scripts/vamp_audio_to_midi.lua b/scripts/vamp_audio_to_midi.lua
index 7806dda7c6..8fdbd36d56 100644
--- a/scripts/vamp_audio_to_midi.lua
+++ b/scripts/vamp_audio_to_midi.lua
@@ -22,6 +22,8 @@ function factory () return function ()
local audio_regions = {}
local start_time = Session:current_end_sample ()
local end_time = Session:current_start_sample ()
+ local max_pos = 0
+ local cur_pos = 0
for r in sel.regions:regionlist ():iter () do
if r:to_midiregion():isnil() then
local st = r:position()
@@ -34,6 +36,7 @@ function factory () return function ()
end_time = et
end
table.insert(audio_regions, r)
+ max_pos = max_pos + r:to_readable ():readable_length ()
else
midi_region = r:to_midiregion()
end
@@ -42,11 +45,24 @@ function factory () return function ()
midi_region:set_initial_position(start_time)
midi_region:set_length(end_time - start_time, 0)
+ local pdialog = LuaDialog.LuaProgressWindow ("Audio to MIDI", true)
+ function progress (_, pos)
+ return pdialog:progress ((cur_pos + pos) / max_pos, "Analyzing")
+ end
+
for i,ar in pairs(audio_regions) do
local a_off = ar:position ()
local b_off = midi_region:quarter_note () - midi_region:start_beats ()
- vamp:analyze (ar:to_readable (), 0, nil)
+ vamp:analyze (ar:to_readable (), 0, progress)
+
+ if pdialog:canceled () then
+ goto out
+ end
+
+ cur_pos = cur_pos + ar:to_readable ():readable_length ()
+ pdialog:progress (cur_pos / max_pos, "Generating MIDI")
+
local fl = vamp:plugin ():getRemainingFeatures ():at (0)
if fl and fl:size() > 0 then
local mm = midi_region:midi_source(0):model()
@@ -66,7 +82,15 @@ function factory () return function ()
end
mm:apply_command (Session, midi_command)
end
+ -- reset the plugin (prepare for next iteration)
+ vamp:reset ()
end
+
+ ::out::
+ pdialog:done ();
+ pdialog = nil
+ vamp = nil;
+ collectgarbage ()
end end
function icon (params) return function (ctx, width, height, fg)