changeset 1638:b57a75aa5ae3 single-point

Add getEventsStartingWithin
author Chris Cannam
date Wed, 13 Mar 2019 10:55:02 +0000
parents e8099be64726
children 7482da1cd920
files base/EventSeries.cpp base/EventSeries.h
diffstat 2 files changed, 36 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/base/EventSeries.cpp	Wed Mar 13 10:54:42 2019 +0000
+++ b/base/EventSeries.cpp	Wed Mar 13 10:55:02 2019 +0000
@@ -257,6 +257,29 @@
 }
 
 EventVector
+EventSeries::getEventsStartingWithin(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) {
+        span.push_back(*pitr);
+        ++pitr;
+    }
+            
+    return span;
+}
+
+EventVector
 EventSeries::getEventsCovering(sv_frame_t frame) const
 {
     EventVector cover;
--- a/base/EventSeries.h	Wed Mar 13 10:54:42 2019 +0000
+++ b/base/EventSeries.h	Wed Mar 13 10:55:02 2019 +0000
@@ -95,6 +95,19 @@
                                 sv_frame_t duration) const;
 
     /**
+     * Retrieve all events starting within the range in frames defined
+     * by the given frame f and duration d.
+     *
+     * - An event without duration starts within the range if its own
+     * frame is greater than or equal to f and less than f + d.
+     * 
+     * - An event with duration starts within the range if its start
+     * frame is greater than or equal to f.
+     */
+    EventVector getEventsStartingWithin(sv_frame_t frame,
+                                        sv_frame_t duration) const;
+
+    /**
      * Retrieve all events that cover the given frame. An event without
      * duration covers a frame if its own frame is equal to it. An event
      * with duration covers a frame if its start frame is less than or