Mercurial > hg > svcore
changeset 1636:05e3ea2237f5 single-point
Add getEventsWithin
author | Chris Cannam |
---|---|
date | Wed, 13 Mar 2019 10:01:14 +0000 |
parents | e8e51f3ca120 |
children | e8099be64726 |
files | base/EventSeries.cpp |
diffstat | 1 files changed, 27 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/base/EventSeries.cpp Wed Mar 13 10:01:02 2019 +0000 +++ b/base/EventSeries.cpp Wed Mar 13 10:01:14 2019 +0000 @@ -230,6 +230,33 @@ } EventVector +EventSeries::getEventsWithin(sv_frame_t frame, + sv_frame_t duration) const +{ + EventVector span; + + const sv_frame_t start = frame; + const sv_frame_t end = frame + duration; + + // because we don't need to "look back" at events that started + // earlier than the start of the given range, we can do this + // entirely from m_events + + auto pitr = lower_bound(m_events.begin(), m_events.end(), + Event(start)); + while (pitr != m_events.end() && pitr->getFrame() < end) { + if (!pitr->hasDuration()) { + span.push_back(*pitr); + } else if (pitr->getFrame() + pitr->getDuration() <= end) { + span.push_back(*pitr); + } + ++pitr; + } + + return span; +} + +EventVector EventSeries::getEventsCovering(sv_frame_t frame) const { EventVector cover;