diff base/EventSeries.h @ 1653:eaad70939848 single-point

Add nearest-event-matching search
author Chris Cannam
date Tue, 19 Mar 2019 14:24:05 +0000
parents 513192aa9b03
children 26aa42fd60e9
line wrap: on
line diff
--- a/base/EventSeries.h	Tue Mar 19 13:05:56 2019 +0000
+++ b/base/EventSeries.h	Tue Mar 19 14:24:05 2019 +0000
@@ -161,6 +161,23 @@
      */
     bool getEventFollowing(const Event &e, Event &following) const;
 
+    enum Direction {
+        Forward,
+        Backward
+    };
+
+    /**
+     * Return the first event for which the given predicate returns
+     * true, searching events with start frames increasingly far from
+     * the given frame in the given direction. If the direction is
+     * Forward then the search includes events starting at the given
+     * frame, otherwise it does not.
+     */
+    bool getNearestEventMatching(sv_frame_t startSearchAt,
+                                 std::function<bool(const Event &)> predicate,
+                                 Direction direction,
+                                 Event &found) const;
+    
     /**
      * Return the event at the given numerical index in the series,
      * where 0 = the first event and count()-1 = the last.
@@ -173,7 +190,7 @@
      * return count().
      */
     int getIndexForEvent(const Event &e) const;
-    
+
     /**
      * Emit to XML as a dataset element.
      */