summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-10-07 03:45:59 +0200
committerRobin Gareus <robin@gareus.org>2016-10-07 03:45:59 +0200
commit5e63206216605c73b453293e6e4b79f46373e751 (patch)
tree3d9b853ad3403ecec434f4416da370266f04144f /scripts
parent86bfe4eff63abd24073d7c2b291eb3667b3eab91 (diff)
prototype polyphonic audio to midi script
Diffstat (limited to 'scripts')
-rw-r--r--scripts/_vamp_audio_to_midi.lua43
1 files changed, 43 insertions, 0 deletions
diff --git a/scripts/_vamp_audio_to_midi.lua b/scripts/_vamp_audio_to_midi.lua
new file mode 100644
index 0000000000..59a6a967a0
--- /dev/null
+++ b/scripts/_vamp_audio_to_midi.lua
@@ -0,0 +1,43 @@
+ardour { ["type"] = "EditorAction", name = "Vamp Audio to MIDI" }
+
+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
+ for r in sel.regions:regionlist ():iter () do
+ if r:to_midiregion():isnil() then
+ ar = r
+ else
+ mr = r:to_midiregion()
+ end
+ end
+ -- analyze audio from selected audio region to selected midi region
+ assert (ar and mr)
+
+ 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
+ local ft = Vamp.RealTime.realTime2Frame (f.timestamp, sr / 2)
+ local fd = Vamp.RealTime.realTime2Frame (f.duration, sr / 2)
+ local fn = f.values:at (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 len = Evoral.Beats (be - bs)
+
+ local note = ARDOUR.LuaAPI.new_noteptr (1, pos, len, fn, 0x7f)
+ midi_command:add (note)
+
+ end
+ mm:apply_command (Session, midi_command)
+ end
+end end