diff --git a/libs/ardour/ardour/midi_source.h b/libs/ardour/ardour/midi_source.h index 6a55398ca9..7f2ddfbc22 100644 --- a/libs/ardour/ardour/midi_source.h +++ b/libs/ardour/ardour/midi_source.h @@ -79,7 +79,9 @@ class LIBARDOUR_API MidiSource : virtual public Source, public boost::enable_sha framecnt_t cnt, MidiStateTracker* tracker, MidiChannelFilter* filter, - const std::set& filtered) const; + const std::set& filtered, + double beat, + double start_beat) const; /** Write data from a MidiRingBuffer to this source. * @param source Source to read from. diff --git a/libs/ardour/midi_region.cc b/libs/ardour/midi_region.cc index e64a343e68..6dd7fc61ae 100644 --- a/libs/ardour/midi_region.cc +++ b/libs/ardour/midi_region.cc @@ -331,7 +331,9 @@ MidiRegion::_read_at (const SourceList& /*srcs*/, to_read, // read duration in frames tracker, filter, - _filtered_parameters + _filtered_parameters, + beat(), + _start_beats.val().to_double() ) != to_read) { return 0; /* "read nothing" */ } diff --git a/libs/ardour/midi_source.cc b/libs/ardour/midi_source.cc index b8afba6b3f..70364b6841 100644 --- a/libs/ardour/midi_source.cc +++ b/libs/ardour/midi_source.cc @@ -44,6 +44,7 @@ #include "ardour/midi_source.h" #include "ardour/midi_state_tracker.h" #include "ardour/session.h" +#include "ardour/tempo.h" #include "ardour/session_directory.h" #include "ardour/source_factory.h" @@ -192,9 +193,11 @@ MidiSource::midi_read (const Lock& lm, framecnt_t cnt, MidiStateTracker* tracker, MidiChannelFilter* filter, - const std::set& filtered) const + const std::set& filtered, + double beat, + double start_beat) const { - BeatsFramesConverter converter(_session.tempo_map(), source_start); + //BeatsFramesConverter converter(_session.tempo_map(), source_start); DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("MidiSource::midi_read() %5 sstart %1 start %2 cnt %3 tracker %4\n", @@ -247,12 +250,14 @@ MidiSource::midi_read (const Lock& lm, * some way (maybe keep an iterator per playlist). */ for (i = _model->begin(); i != _model->end(); ++i) { - const framecnt_t time_frames = converter.to(i->time()); - if (time_frames >= start) { + if (i->time().to_double() + (beat - start_beat) >= beat) { break; } } _model_iter_valid = true; + if (!linear_read) { + _model->active_notes().clear(); + } #endif } @@ -260,21 +265,21 @@ MidiSource::midi_read (const Lock& lm, // Copy events in [start, start + cnt) into dst for (; i != _model->end(); ++i) { - const framecnt_t time_frames = converter.to(i->time()); - if (time_frames < start + cnt) { + const framecnt_t time_frames = _session.tempo_map().frame_at_beat (i->time().to_double() + (beat - start_beat)); + + if (time_frames < start + cnt + source_start) { if (filter && filter->filter(i->buffer(), i->size())) { DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("%1: filter event @ %2 type %3 size %4\n", - _name, time_frames + source_start, i->event_type(), i->size())); + _name, time_frames, i->event_type(), i->size())); continue; } - // Offset by source start to convert event time to session time - dst.write (time_frames + source_start, i->event_type(), i->size(), i->buffer()); + dst.write (time_frames, i->event_type(), i->size(), i->buffer()); DEBUG_TRACE (DEBUG::MidiSourceIO, string_compose ("%1: add event @ %2 type %3 size %4\n", - _name, time_frames + source_start, i->event_type(), i->size())); + _name, time_frames, i->event_type(), i->size())); if (tracker) { tracker->track (*i);