1 ardour { ["type"] = "EditorAction", name = "Vamp Audio to MIDI" }
3 function factory () return function ()
4 local sel = Editor:get_selection ()
5 local sr = Session:nominal_frame_rate ()
6 local tm = Session:tempo_map ()
7 local vamp = ARDOUR.LuaAPI.Vamp ("libardourvampplugins:qm-transcription", sr)
11 for r in sel.regions:regionlist ():iter () do
12 if r:to_midiregion():isnil() then
15 mr = r:to_midiregion()
18 -- analyze audio from selected audio region to selected midi region
21 vamp:analyze (ar:to_readable (), 0, nil)
22 local fl = vamp:plugin ():getRemainingFeatures ():at (0)
23 if fl and fl:size() > 0 then
24 local mm = mr:midi_source(0):model()
25 local midi_command = mm:new_note_diff_command ("Audio2Midi")
26 for f in fl:iter () do
27 local ft = Vamp.RealTime.realTime2Frame (f.timestamp, sr)
28 local fd = Vamp.RealTime.realTime2Frame (f.duration, sr)
29 local fn = f.values:at (0)
31 local bs = tm:exact_beat_at_frame (ft, 0)
32 local be = tm:exact_beat_at_frame (ft + fd, 0)
34 local pos = Evoral.Beats (bs)
35 local len = Evoral.Beats (be - bs)
37 local note = ARDOUR.LuaAPI.new_noteptr (1, pos, len, fn, 0x7f)
38 midi_command:add (note)
41 mm:apply_command (Session, midi_command)