summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-10-07 16:33:50 +0200
committerRobin Gareus <robin@gareus.org>2016-10-07 16:33:50 +0200
commitd6453cf534e65028987aed96d86aede5b7e9382b (patch)
tree69362dc57b6b79037c539f9a8bc257d34fc2eae8 /scripts
parent39653830dcba9b7d69c6e830d99677cf8acc36dd (diff)
add BBT offsets to Audio->MIDI script
Diffstat (limited to 'scripts')
-rw-r--r--scripts/_vamp_audio_to_midi.lua21
1 files changed, 10 insertions, 11 deletions
diff --git a/scripts/_vamp_audio_to_midi.lua b/scripts/_vamp_audio_to_midi.lua
index be9742ff59..e74aac59eb 100644
--- a/scripts/_vamp_audio_to_midi.lua
+++ b/scripts/_vamp_audio_to_midi.lua
@@ -1,13 +1,12 @@
-ardour { ["type"] = "EditorAction", name = "Vamp Audio to MIDI" }
+ardour { ["type"] = "EditorAction", name = "Vamp Audio to MIDI",
+description = "analyze audio from selected audio region to selected midi region" }
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)
-
- local ar = nil
- local mr = nil
+ local ar, mr
for r in sel.regions:regionlist ():iter () do
if r:to_midiregion():isnil() then
ar = r
@@ -15,8 +14,11 @@ function factory () return function ()
mr = r:to_midiregion()
end
end
- -- analyze audio from selected audio region to selected midi region
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)
vamp:analyze (ar:to_readable (), 0, nil)
local fl = vamp:plugin ():getRemainingFeatures ():at (0)
@@ -27,16 +29,13 @@ 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 bs = tm:exact_beat_at_frame (ft, 0)
- local be = tm:exact_beat_at_frame (ft + fd, 0)
-
- local pos = Evoral.Beats (bs)
+ local pos = Evoral.Beats (bs - m_off)
local len = Evoral.Beats (be - bs)
-
local note = ARDOUR.LuaAPI.new_noteptr (1, pos, len, fn + 1, 0x7f)
midi_command:add (note)
-
end
mm:apply_command (Session, midi_command)
end