changeset 1656:e4084bc60fe8 single-point

Test & fixes for getEventsStartingAt
author Chris Cannam
date Wed, 20 Mar 2019 14:58:56 +0000
parents 0cfb882155a6
children 31b46a5647db
files base/EventSeries.h base/test/TestEventSeries.h data/model/NoteModel.h data/model/RegionModel.h data/model/SparseTimeValueModel.h
diffstat 5 files changed, 52 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/base/EventSeries.h	Wed Mar 20 11:14:36 2019 +0000
+++ b/base/EventSeries.h	Wed Mar 20 14:58:56 2019 +0000
@@ -93,6 +93,15 @@
                                   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
+     * equal to it and its end frame (start + duration) is greater
+     * than it.
+     */
+    EventVector getEventsCovering(sv_frame_t frame) const;
+
+    /**
      * Retrieve all events falling wholly within the range in frames
      * defined by the given frame f and duration d.
      *
@@ -113,25 +122,19 @@
 
     /**
      * 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.
+     * by the given frame f and duration d. An event (regardless of
+     * whether it has duration or not) starts within the range if its
+     * start frame is greater than or equal to f and less than f + d.
      */
     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
-     * equal to it and its end frame (start + duration) is greater
-     * than it.
+     * Retrieve all events starting at exactly the given frame.
      */
-    EventVector getEventsCovering(sv_frame_t frame) const;
+    EventVector getEventsStartingAt(sv_frame_t frame) const {
+        return getEventsStartingWithin(frame, 1);
+    }
 
     /**
      * Retrieve all events, in their natural order.
--- a/base/test/TestEventSeries.h	Wed Mar 20 11:14:36 2019 +0000
+++ b/base/test/TestEventSeries.h	Wed Mar 20 14:58:56 2019 +0000
@@ -519,6 +519,27 @@
                  EventVector({ b, c, cc, d, dd }));
     }
 
+    void eventPatternStartingAt() {
+
+        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.getEventsStartingAt(2), EventVector());
+        QCOMPARE(s.getEventsStartingAt(5), EventVector({ c, cc }));
+    }
+
     void eventPatternEndFrame() {
 
         EventSeries s;
--- a/data/model/NoteModel.h	Wed Mar 20 11:14:36 2019 +0000
+++ b/data/model/NoteModel.h	Wed Mar 20 14:58:56 2019 +0000
@@ -161,14 +161,17 @@
     EventVector getEventsSpanning(sv_frame_t f, sv_frame_t duration) const {
         return m_events.getEventsSpanning(f, duration);
     }
+    EventVector getEventsCovering(sv_frame_t f) const {
+        return m_events.getEventsCovering(f);
+    }
     EventVector getEventsWithin(sv_frame_t f, sv_frame_t duration) const {
         return m_events.getEventsWithin(f, duration);
     }
     EventVector getEventsStartingWithin(sv_frame_t f, sv_frame_t duration) const {
         return m_events.getEventsStartingWithin(f, duration);
     }
-    EventVector getEventsCovering(sv_frame_t f) const {
-        return m_events.getEventsCovering(f);
+    EventVector getEventsStartingAt(sv_frame_t f) const {
+        return m_events.getEventsStartingAt(f);
     }
 
     /**
--- a/data/model/RegionModel.h	Wed Mar 20 11:14:36 2019 +0000
+++ b/data/model/RegionModel.h	Wed Mar 20 14:58:56 2019 +0000
@@ -138,14 +138,17 @@
     EventVector getEventsSpanning(sv_frame_t f, sv_frame_t duration) const {
         return m_events.getEventsSpanning(f, duration);
     }
+    EventVector getEventsCovering(sv_frame_t f) const {
+        return m_events.getEventsCovering(f);
+    }
     EventVector getEventsWithin(sv_frame_t f, sv_frame_t duration) const {
         return m_events.getEventsWithin(f, duration);
     }
     EventVector getEventsStartingWithin(sv_frame_t f, sv_frame_t duration) const {
         return m_events.getEventsStartingWithin(f, duration);
     }
-    EventVector getEventsCovering(sv_frame_t f) const {
-        return m_events.getEventsCovering(f);
+    EventVector getEventsStartingAt(sv_frame_t f) const {
+        return m_events.getEventsStartingAt(f);
     }
 
     /**
--- a/data/model/SparseTimeValueModel.h	Wed Mar 20 11:14:36 2019 +0000
+++ b/data/model/SparseTimeValueModel.h	Wed Mar 20 14:58:56 2019 +0000
@@ -143,6 +143,9 @@
     EventVector getEventsSpanning(sv_frame_t f, sv_frame_t duration) const {
         return m_events.getEventsSpanning(f, duration);
     }
+    EventVector getEventsCovering(sv_frame_t f) const {
+        return m_events.getEventsCovering(f);
+    }
     EventVector getEventsWithin(sv_frame_t f, sv_frame_t duration,
                                 int overspill = 0) const {
         return m_events.getEventsWithin(f, duration, overspill);
@@ -150,8 +153,8 @@
     EventVector getEventsStartingWithin(sv_frame_t f, sv_frame_t duration) const {
         return m_events.getEventsStartingWithin(f, duration);
     }
-    EventVector getEventsCovering(sv_frame_t f) const {
-        return m_events.getEventsCovering(f);
+    EventVector getEventsStartingAt(sv_frame_t f) const {
+        return m_events.getEventsStartingAt(f);
     }
     bool getNearestEventMatching(sv_frame_t startSearchAt,
                                  std::function<bool(Event)> predicate,