1 ardour { ["type"] = "Snippet", name = "Vamp Plugin Example" }
3 function factory () return function ()
4 local sel = Editor:get_selection ()
6 local vamp = ARDOUR.LuaAPI.Vamp("libardourvampplugins:dBTP", Session:nominal_frame_rate())
7 print (vamp:plugin():getName())
9 -- for each selected region
10 for r in sel.regions:regionlist ():iter () do
11 print ("Region:", r:name ())
13 -- run the plugin, analyze the first channel of the audio-region
14 vamp:analyze (r:to_readable (), 0, nil)
16 -- get analysis results
17 local f = vamp:plugin ():getRemainingFeatures ()
19 -- f is-a Vamp::Plugin::FeatureSet aka std::map<int, Vamp::Plugin::FeatureList>
20 for id, featlist in f:iter () do
24 -- get the first FeatureList
25 local featurelist = f:table()[0]
26 -- Vamp::Plugin::FeatureList is a typedef for std::vector<Feature>
27 for feat in featurelist:iter () do
28 print ("-", feat.label)
31 -- get the first feature..
32 local feature = featurelist:at(0)
33 -- ..and the values of the feature, which is-a std::vector<float>
34 local values = feature.values
35 -- iterate over the std::vector<float>
36 for val in values:iter () do
40 -- access the first element of Vamp::Plugin::Feature's "values" vector
41 local value = values:at(0)
42 -- in case of libardourvampplugins:dBTP that's the true-peak
43 local dbtp = 20 * math.log (value) / math.log(10)
44 print (string.format ("Region '%s': %.2f dBTP", r:name (), dbtp))