From 631c8afc668f8b57af21ca85332ac8f012a3f59e Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 9 Oct 2016 16:42:47 +0200 Subject: Audio->MIDI script: properly handle MIDI-region start-offset --- scripts/_vamp_audio_to_midi.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/_vamp_audio_to_midi.lua b/scripts/_vamp_audio_to_midi.lua index e74aac59eb..cf9b82c851 100644 --- a/scripts/_vamp_audio_to_midi.lua +++ b/scripts/_vamp_audio_to_midi.lua @@ -15,10 +15,9 @@ function factory () return function () end end assert (ar and mr) - assert (mr:position () >= mr:start ()) local a_off = ar:position () - local m_off = tm:exact_beat_at_frame (mr:position () - mr:start (), 0) + local b_off = 4.0 * mr:pulse () - mr:start_beats ():to_double () vamp:analyze (ar:to_readable (), 0, nil) local fl = vamp:plugin ():getRemainingFeatures ():at (0) @@ -29,10 +28,11 @@ function factory () return function () local ft = Vamp.RealTime.realTime2Frame (f.timestamp, sr) local fd = Vamp.RealTime.realTime2Frame (f.duration, sr) local fn = f.values:at (0) - local bs = tm:exact_beat_at_frame (a_off + ft, 0) - local be = tm:exact_beat_at_frame (a_off + ft + fd, 0) - local pos = Evoral.Beats (bs - m_off) + local bs = tm:exact_qn_at_frame (a_off + ft, 0) + local be = tm:exact_qn_at_frame (a_off + ft + fd, 0) + + local pos = Evoral.Beats (bs - b_off) local len = Evoral.Beats (be - bs) local note = ARDOUR.LuaAPI.new_noteptr (1, pos, len, fn + 1, 0x7f) midi_command:add (note) -- cgit v1.2.3