changeset 1866:b4b11af915f4

If duration < 0, swap start time and duration rather than throwing an exception - this is too deep to be throwing an exception here, we end up with bugs like #1989 (Crash when trying to import CSV file with certain unexpected data in it) - and the meaning of negative duration is not actually ambiguous
author Chris Cannam
date Thu, 11 Jun 2020 14:07:56 +0100
parents 14bf9bf5ac28
children 2654bf447a84
files base/Event.h
diffstat 1 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/base/Event.h	Fri May 29 17:37:41 2020 +0100
+++ b/base/Event.h	Thu Jun 11 14:07:56 2020 +0100
@@ -84,7 +84,10 @@
         m_haveDuration(true), m_haveReferenceFrame(false),
         m_value(value), m_level(0.f), m_frame(frame),
         m_duration(duration), m_referenceFrame(0), m_label(label) {
-        if (m_duration < 0) throw std::logic_error("duration must be >= 0");
+        if (m_duration < 0) {
+            m_frame += m_duration;
+            m_duration = -m_duration;
+        }
     }
         
     Event(sv_frame_t frame, float value, sv_frame_t duration,
@@ -93,7 +96,10 @@
         m_haveDuration(true), m_haveReferenceFrame(false),
         m_value(value), m_level(level), m_frame(frame),
         m_duration(duration), m_referenceFrame(0), m_label(label) {
-        if (m_duration < 0) throw std::logic_error("duration must be >= 0");
+        if (m_duration < 0) {
+            m_frame += m_duration;
+            m_duration = -m_duration;
+        }
     }
 
     Event(const Event &event) =default;
@@ -135,7 +141,10 @@
         Event p(*this);
         p.m_duration = duration;
         p.m_haveDuration = true;
-        if (duration < 0) throw std::logic_error("duration must be >= 0");
+        if (p.m_duration < 0) {
+            p.m_frame += p.m_duration;
+            p.m_duration = -p.m_duration;
+        }
         return p;
     }
     Event withoutDuration() const {