From 2d8c605cc94648a968d26005f080efeaad20004e Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Mon, 5 Oct 2020 16:50:38 +1100 Subject: [PATCH] timerangelist: fixed bug where ranges might sometimes overlap --- app/common/timerange.cpp | 30 ++++++++++++++---------------- app/common/timerange.h | 2 +- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/app/common/timerange.cpp b/app/common/timerange.cpp index 6656facbe..d8b2a5b6b 100644 --- a/app/common/timerange.cpp +++ b/app/common/timerange.cpp @@ -160,20 +160,25 @@ void TimeRange::normalize() length_ = out_ - in_; } -void TimeRangeList::InsertTimeRange(const TimeRange &range) +void TimeRangeList::InsertTimeRange(TimeRange range_to_add) { + // See if list contains this range + if (ContainsTimeRange(range_to_add)) { + return; + } + + // Does not contain range, so we'll almost certainly be adding it in some way for (int i=0;iremoveAt(i); - i--; - sz--; - - InsertTimeRange(before); - InsertTimeRange(after); + this->append(TimeRange(remove.out(), compare.out())); + compare.set_out(remove.in()); } else if (compare.in() < remove.in() && compare.out() > remove.in()) { // This element's out point overlaps the range's in, we'll trim it compare.set_out(remove.in()); diff --git a/app/common/timerange.h b/app/common/timerange.h index 22b8317fb..de5785b5f 100644 --- a/app/common/timerange.h +++ b/app/common/timerange.h @@ -74,7 +74,7 @@ public: { } - void InsertTimeRange(const TimeRange& range); + void InsertTimeRange(TimeRange range_to_add); void RemoveTimeRange(const TimeRange& remove);