changeset 1635:e8e51f3ca120 single-point

Add getEventsWithin
author Chris Cannam
date Wed, 13 Mar 2019 10:01:02 +0000
parents 687a2453cc15
children 05e3ea2237f5
files base/EventSeries.h base/test/TestEventSeries.h
diffstat 2 files changed, 41 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/base/EventSeries.h	Wed Mar 13 10:00:49 2019 +0000
+++ b/base/EventSeries.h	Wed Mar 13 10:01:02 2019 +0000
@@ -61,15 +61,15 @@
     int count() const;
 
     /**
-     * Retrieve all events any part of which falls within the span in
+     * Retrieve all events any part of which falls within the range in
      * frames defined by the given frame f and duration d.
      *
-     * - An event without duration is within the span if its own frame
-     * is greater than or equal to f and less than f + d.
+     * - An event without duration is spanned by the range if its own
+     * frame is greater than or equal to f and less than f + d.
      * 
-     * - An event with duration is within the span if its start frame
-     * is less than f + d and its start frame plus its duration is
-     * greater than f.
+     * - An event with duration is spanned by the range if its start
+     * frame is less than f + d and its start frame plus its duration
+     * is greater than f.
      * 
      * Note: Passing a duration of zero is seldom useful here; you
      * probably want getEventsCovering instead. getEventsSpanning(f,
@@ -81,6 +81,20 @@
                                   sv_frame_t duration) const;
 
     /**
+     * Retrieve all events falling wholly within the range in frames
+     * defined by the given frame f and duration d.
+     *
+     * - An event without duration is within the range if its own
+     * frame is greater than or equal to f and less than f + d.
+     * 
+     * - An event with duration is within the range if its start frame
+     * is greater than or equal to f and its start frame plus its
+     * duration is less than or equal to f + d.
+     */
+    EventVector getEventsWithin(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
@@ -88,7 +102,7 @@
      * than it.
      */
     EventVector getEventsCovering(sv_frame_t frame) const;
-
+    
     /**
      * If e is in the series and is not the first event in it, set
      * preceding to the event immediate preceding it according to the
--- a/base/test/TestEventSeries.h	Wed Mar 13 10:00:49 2019 +0000
+++ b/base/test/TestEventSeries.h	Wed Mar 13 10:01:02 2019 +0000
@@ -427,6 +427,26 @@
         QCOMPARE(s.getEventsSpanning(6, 2), EventVector({ a, b, c, cc, d, dd }));
     }
 
+    void eventPatternWithin() {
+
+        EventSeries s;
+        Event a(0, 1.0f, 18, QString("a"));
+        Event b(3, 2.0f, 6, QString("b"));
+        Event c(5, 3.0f, 2, QString("c"));
+        Event cc(5, 3.1f, 2, QString("cc"));
+        Event d(6, 4.0f, 10, QString("d"));
+        Event dd(6, 4.5f, 10, QString("dd"));
+        Event e(14, 5.0f, 3, QString("e"));
+        s.add(b);
+        s.add(c);
+        s.add(d);
+        s.add(a);
+        s.add(cc);
+        s.add(dd);
+        s.add(e);
+        QCOMPARE(s.getEventsWithin(2, 7), EventVector({ b, c, cc }));
+    }
+
     void eventPatternAddRemove() {
 
         // This is mostly here to exercise the innards of EventSeries