From 6dc909696f6b1642b3e498075fe3da1753315260 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 8 Oct 2020 03:38:03 +0200 Subject: [PATCH] Allow src/dst MIDI buffer offsets This is needed for ARDOUR::PluginInsert::automate_and_run when processing is split on events. --- libs/ardour/midi_buffer.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/ardour/midi_buffer.cc b/libs/ardour/midi_buffer.cc index 14a5b33b60..a27a5f7fc1 100644 --- a/libs/ardour/midi_buffer.cc +++ b/libs/ardour/midi_buffer.cc @@ -98,7 +98,7 @@ MidiBuffer::copy(MidiBuffer const * const copy) void -MidiBuffer::read_from (const Buffer& src, samplecnt_t nframes, sampleoffset_t dst_offset, sampleoffset_t /* src_offset*/) +MidiBuffer::read_from (const Buffer& src, samplecnt_t nframes, sampleoffset_t dst_offset, sampleoffset_t src_offset) { assert (src.type() == DataType::MIDI); assert (&src != this); @@ -106,7 +106,6 @@ MidiBuffer::read_from (const Buffer& src, samplecnt_t nframes, sampleoffset_t ds const MidiBuffer& msrc = (const MidiBuffer&) src; assert (_capacity >= msrc.size()); - assert (dst_offset == 0); /* there is no known scenario in Nov 2019 where this should be false */ clear (); assert (_size == 0); @@ -114,10 +113,14 @@ MidiBuffer::read_from (const Buffer& src, samplecnt_t nframes, sampleoffset_t ds for (MidiBuffer::const_iterator i = msrc.begin(); i != msrc.end(); ++i) { const Evoral::Event ev(*i, false); - if (ev.time() >= 0 && ev.time() < nframes) { - push_back (ev.time(), ev.event_type (), ev.size(), ev.buffer()); + if (ev.time() >= src_offset && ev.time() < nframes + src_offset) { + push_back (ev.time() + dst_offset - src_offset, ev.event_type (), ev.size(), ev.buffer()); } else { - cerr << "\t!!!! MIDI event @ " << ev.time() << " skipped, not within range 0 .. " << nframes << endl; + cerr << "\t!!!! MIDI event @ " << ev.time() + << " skipped, not within range. nframes: " << nframes + << " src_offset: " << src_offset + << " dst_offset: " << dst_offset + << "\n"; PBD::stacktrace (cerr, 30); } }