1 ardour { ["type"] = "Snippet", name = "Vamp Audio Transcription Example" }
3 function factory () return function ()
5 -- simple progress information print()ing
10 local progress = 100 * pos / progress_total;
11 if progress - progress_last > 5 then
12 progress_last = progress;
13 print ("Progress: ", progress)
18 -- get Editor selection
19 -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Editor
20 -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Selection
21 local sel = Editor:get_selection ()
22 local sr = Session:nominal_frame_rate ()
24 -- Instantiate a Vamp Plugin
25 -- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:LuaAPI:Vamp
26 local vamp = ARDOUR.LuaAPI.Vamp ("libardourvampplugins:qm-transcription", sr)
28 -- for each selected region
29 -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:RegionSelection
30 for r in sel.regions:regionlist ():iter () do
31 -- "r" is-a http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Region
34 progress_total = r:to_readable ():readable_length ()
37 vamp:analyze (r:to_readable (), 0, nil --[[cb--]])
38 print ("-- Post Processing: ", r:name ())
40 -- post-processing takes longer than actually parsing the data :(
41 local f = vamp:plugin ():getRemainingFeatures ()
43 local fl = f:table ()[0]
44 print (" Time (sample) | Len | Midi-Note");
45 if fl then for f in fl:iter () do
46 assert (f.hasTimestamp and f.hasDuration);
47 local ft = Vamp.RealTime.realTime2Frame (f.timestamp, sr)
48 local fd = Vamp.RealTime.realTime2Frame (f.duration, sr)
49 local fn = f.values:at (0) -- midi note number
50 print (string.format (" %14d %7d %d", ft, fd, fn))
53 -- reset the plugin (prepare for next iteration)