2016-10-07 10:33:50 -04:00
|
|
|
ardour { ["type"] = "EditorAction", name = "Vamp Audio to MIDI",
|
|
|
|
description = "analyze audio from selected audio region to selected midi region" }
|
2016-10-06 21:45:59 -04:00
|
|
|
|
|
|
|
function factory () return function ()
|
|
|
|
local sel = Editor:get_selection ()
|
|
|
|
local sr = Session:nominal_frame_rate ()
|
|
|
|
local tm = Session:tempo_map ()
|
|
|
|
local vamp = ARDOUR.LuaAPI.Vamp ("libardourvampplugins:qm-transcription", sr)
|
2016-10-07 10:33:50 -04:00
|
|
|
local ar, mr
|
2016-10-06 21:45:59 -04:00
|
|
|
for r in sel.regions:regionlist ():iter () do
|
|
|
|
if r:to_midiregion():isnil() then
|
|
|
|
ar = r
|
|
|
|
else
|
|
|
|
mr = r:to_midiregion()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
assert (ar and mr)
|
2016-10-07 10:33:50 -04:00
|
|
|
assert (mr:position () >= mr:start ())
|
|
|
|
|
|
|
|
local a_off = ar:position ()
|
|
|
|
local m_off = tm:exact_beat_at_frame (mr:position () - mr:start (), 0)
|
2016-10-06 21:45:59 -04:00
|
|
|
|
|
|
|
vamp:analyze (ar:to_readable (), 0, nil)
|
|
|
|
local fl = vamp:plugin ():getRemainingFeatures ():at (0)
|
|
|
|
if fl and fl:size() > 0 then
|
|
|
|
local mm = mr:midi_source(0):model()
|
|
|
|
local midi_command = mm:new_note_diff_command ("Audio2Midi")
|
|
|
|
for f in fl:iter () do
|
2016-10-07 08:42:11 -04:00
|
|
|
local ft = Vamp.RealTime.realTime2Frame (f.timestamp, sr)
|
|
|
|
local fd = Vamp.RealTime.realTime2Frame (f.duration, sr)
|
2016-10-06 21:45:59 -04:00
|
|
|
local fn = f.values:at (0)
|
2016-10-07 10:33:50 -04:00
|
|
|
local bs = tm:exact_beat_at_frame (a_off + ft, 0)
|
|
|
|
local be = tm:exact_beat_at_frame (a_off + ft + fd, 0)
|
2016-10-06 21:45:59 -04:00
|
|
|
|
2016-10-07 10:33:50 -04:00
|
|
|
local pos = Evoral.Beats (bs - m_off)
|
2016-10-06 21:45:59 -04:00
|
|
|
local len = Evoral.Beats (be - bs)
|
2016-10-07 08:54:54 -04:00
|
|
|
local note = ARDOUR.LuaAPI.new_noteptr (1, pos, len, fn + 1, 0x7f)
|
2016-10-06 21:45:59 -04:00
|
|
|
midi_command:add (note)
|
|
|
|
end
|
|
|
|
mm:apply_command (Session, midi_command)
|
|
|
|
end
|
|
|
|
end end
|