Also use xjadeo 64bit windows version
[ardour.git] / scripts / _vamp_note_example.lua
1 ardour { ["type"] = "Snippet", name = "Vamp Audio Transcription Example" }
2
3 function factory () return function ()
4
5         -- simple progress information print()ing
6         --[[
7         local progress_total;
8         local progress_last;
9         function cb (_f, pos)
10                 local progress = 100 * pos / progress_total;
11                 if progress - progress_last > 5 then
12                         progress_last = progress;
13                         print ("Progress: ", progress)
14                 end
15         end
16         --]]
17
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_sample_rate ()
23
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)
27
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
32
33                 --[[
34                 progress_total = r:to_readable ():readable_length ()
35                 progress_last = 0
36                 --]]
37                 vamp:analyze (r:to_readable (), 0, nil --[[cb--]])
38                 print ("-- Post Processing: ", r:name ())
39
40                 -- post-processing takes longer than actually parsing the data :(
41                 local f = vamp:plugin ():getRemainingFeatures ()
42
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))
51                 end end
52
53                 -- reset the plugin (prepare for next iteration)
54                 vamp:reset ()
55         end
56
57 end end