1 ardour { ["type"] = "Snippet", name = "Vamp TempoMap Test" }
3 function factory () return function ()
5 -- get Editor selection
6 -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Editor
7 -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:Selection
8 local sel = Editor:get_selection ()
10 -- Instantiate the QM BarBeat Tracker
11 -- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:LuaAPI:Vamp
12 -- http://vamp-plugins.org/plugin-doc/qm-vamp-plugins.html#qm-barbeattracker
13 local vamp = ARDOUR.LuaAPI.Vamp("libardourvampplugins:qm-barbeattracker", Session:nominal_sample_rate())
15 -- prepare table to hold results
19 -- for each selected region
20 -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:RegionSelection
21 for r in sel.regions:regionlist ():iter () do
22 -- "r" is-a http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Region
24 -- prepare lua table to hold results for the given region (by name)
28 -- callback to handle Vamp-Plugin analysis results
29 function callback (feats)
30 -- "feats" is-a http://manual.ardour.org/lua-scripting/class_reference/#Vamp:Plugin:FeatureSet
32 -- get the first output. here: Beats, estimated beat locations & beat-number
33 local fl = feats:table()[0]
34 -- "fl" is-a http://manual.ardour.org/lua-scripting/class_reference/#Vamp:Plugin:FeatureList
35 -- which may be empty or not nil
37 -- iterate over returned features
38 for f in fl:iter () do
39 -- "f" is-a http://manual.ardour.org/lua-scripting/class_reference/#Vamp:Plugin:Feature
40 if f.hasTimestamp then
41 local fn = Vamp.RealTime.realTime2Frame (f.timestamp, 48000)
42 table.insert (beats[r:name ()], {pos = fn, beat = f.label})
47 -- get the 2nd output. here: estimated bar locations
48 local fl = feats:table()[1]
50 for f in fl:iter () do
51 if f.hasTimestamp then
52 local fn = Vamp.RealTime.realTime2Frame (f.timestamp, 48000)
53 table.insert (bars[r:name ()], fn)
59 vamp:plugin ():setParameter ("Beats Per Bar", 4); -- TODO ask
61 -- run the plugin, analyze the first channel of the audio-region
62 vamp:analyze (r:to_readable (), 0, callback)
63 -- get remaining features (end of analyis)
64 callback (vamp:plugin ():getRemainingFeatures ())
65 -- reset the plugin (prepare for next iteration)
69 -- print results (for now)
70 -- TODO: calculate and set tempo-map
71 for n,o in pairs(bars) do
72 print ("Bar analysis for region:", n)
73 for _,t in ipairs(o) do
77 for n,o in pairs(beats) do
78 print ("Beat analysis for region:", n)
79 for _,t in ipairs(o) do
80 print ("-", t['pos'], t['beat'])