diff base/EventSeries.cpp @ 1640:e7f557789f99 single-point

Add and test getEndFrame (and getStartFrame)
author Chris Cannam
date Wed, 13 Mar 2019 11:54:13 +0000
parents b57a75aa5ae3
children d591836e47ef
line wrap: on
line diff
--- a/base/EventSeries.cpp	Wed Mar 13 10:55:24 2019 +0000
+++ b/base/EventSeries.cpp	Wed Mar 13 11:54:13 2019 +0000
@@ -40,6 +40,10 @@
     }
     m_events.insert(pitr, p);
 
+    if (!p.hasDuration() && p.getFrame() > m_finalDurationlessEventFrame) {
+        m_finalDurationlessEventFrame = p.getFrame();
+    }
+    
     if (p.hasDuration() && isUnique) {
 
         const sv_frame_t frame = p.getFrame();
@@ -92,6 +96,17 @@
 
     m_events.erase(pitr);
 
+    if (!p.hasDuration() && isUnique &&
+        p.getFrame() == m_finalDurationlessEventFrame) {
+        m_finalDurationlessEventFrame = 0;
+        for (auto ritr = m_events.rbegin(); ritr != m_events.rend(); ++ritr) {
+            if (!ritr->hasDuration()) {
+                m_finalDurationlessEventFrame = ritr->getFrame();
+                break;
+            }
+        }
+    }
+    
     if (p.hasDuration() && isUnique) {
             
         const sv_frame_t frame = p.getFrame();
@@ -181,6 +196,33 @@
 {
     m_events.clear();
     m_seams.clear();
+    m_finalDurationlessEventFrame = 0;
+}
+
+sv_frame_t
+EventSeries::getStartFrame() const
+{
+    if (m_events.empty()) return 0;
+    return m_events.begin()->getFrame();
+}
+
+sv_frame_t
+EventSeries::getEndFrame() const
+{
+    sv_frame_t latest = 0;
+
+    if (m_events.empty()) return latest;
+    
+    latest = m_finalDurationlessEventFrame;
+
+    if (m_seams.empty()) return latest;
+    
+    sv_frame_t lastSeam = m_seams.rbegin()->first;
+    if (lastSeam > latest) {
+        latest = lastSeam;
+    }
+
+    return latest;
 }
 
 EventVector
@@ -362,6 +404,13 @@
     return m_events[index];
 }
 
+int
+EventSeries::getIndexForEvent(const Event &e) const
+{
+    auto pitr = lower_bound(m_events.begin(), m_events.end(), e);
+    return distance(m_events.begin(), pitr);
+}
+
 void
 EventSeries::toXml(QTextStream &out,
                    QString indent,