1 ardour { ["type"] = "Snippet", name = "Vamp Plugin Example" }
3 function factory () return function ()
5 -- get a list of all available plugins
6 -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:LuaAPI:Vamp
7 -- returns a http://manual.ardour.org/lua-scripting/class_reference/#C:StringVector
8 local plugins = ARDOUR.LuaAPI.Vamp.list_plugins ();
9 for id in plugins:iter () do
13 local sel = Editor:get_selection ()
15 -- load the Vamp Plugin with Id "libardourvampplugins:dBTP"
16 -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:LuaAPI:Vamp
17 local vamp = ARDOUR.LuaAPI.Vamp("libardourvampplugins:dBTP", Session:nominal_sample_rate())
18 print (vamp:plugin():getName())
20 -- for each selected region
21 for r in sel.regions:regionlist ():iter () do
22 print ("Region:", r:name ())
24 -- run the plugin, analyze the first channel of the audio-region
25 vamp:analyze (r:to_readable (), 0, nil)
27 -- get analysis results
28 local f = vamp:plugin ():getRemainingFeatures ()
30 -- f is-a Vamp::Plugin::FeatureSet aka std::map<int, Vamp::Plugin::FeatureList>
31 -- http://manual.ardour.org/lua-scripting/class_reference/#Vamp:Plugin:FeatureSet
32 for id, featlist in f:iter () do
36 -- get the first FeatureList
37 local featurelist = f:table()[0]
38 -- Vamp::Plugin::FeatureList is a typedef for std::vector<Feature>
39 for feat in featurelist:iter () do
40 print ("-", feat.label)
43 -- get the first feature..
44 -- http://manual.ardour.org/lua-scripting/class_reference/#Vamp:Plugin:Feature
45 local feature = featurelist:at(0)
46 -- ..and the values of the feature, which is-a std::vector<float>
47 local values = feature.values
48 -- iterate over the std::vector<float>
49 for val in values:iter () do
53 -- access the first element of Vamp::Plugin::Feature's "values" vector
54 -- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatVector
55 local value = values:at(0)
56 -- in case of libardourvampplugins:dBTP that's the true-peak (signal value)
57 local dbtp = 20 * math.log (value) / math.log(10) -- convert it to dB
58 print (string.format ("Region '%s': %.2f dBTP", r:name (), dbtp))
60 -- reset the plugin for the next iteration