made timerangelist a encapsulation rather than a derivation
Locks off functionality that really shouldn't be used.
This commit is contained in:
+47
-14
@@ -176,42 +176,42 @@ void TimeRange::normalize()
|
||||
length_ = out_ - in_;
|
||||
}
|
||||
|
||||
void TimeRangeList::InsertTimeRange(TimeRange range_to_add)
|
||||
void TimeRangeList::insert(TimeRange range_to_add)
|
||||
{
|
||||
// See if list contains this range
|
||||
if (ContainsTimeRange(range_to_add)) {
|
||||
if (contains(range_to_add)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Does not contain range, so we'll almost certainly be adding it in some way
|
||||
for (int i=0;i<size();i++) {
|
||||
const TimeRange& compare = at(i);
|
||||
const TimeRange& compare = array_.at(i);
|
||||
|
||||
if (compare.OverlapsWith(range_to_add)) {
|
||||
range_to_add = TimeRange::Combine(range_to_add, compare);
|
||||
removeAt(i);
|
||||
array_.removeAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
append(range_to_add);
|
||||
array_.append(range_to_add);
|
||||
}
|
||||
|
||||
void TimeRangeList::RemoveTimeRange(const TimeRange &remove)
|
||||
void TimeRangeList::remove(const TimeRange &remove)
|
||||
{
|
||||
int sz = this->size();
|
||||
|
||||
for (int i=0;i<sz;i++) {
|
||||
TimeRange& compare = (*this)[i];
|
||||
TimeRange& compare = array_[i];
|
||||
|
||||
if (remove.Contains(compare)) {
|
||||
// This element is entirely encompassed in this range, remove it
|
||||
this->removeAt(i);
|
||||
array_.removeAt(i);
|
||||
i--;
|
||||
sz--;
|
||||
} else if (compare.Contains(remove, false, false)) {
|
||||
// The remove range is within this element, only choice is to split the element into two
|
||||
this->append(TimeRange(remove.out(), compare.out()));
|
||||
array_.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
|
||||
@@ -223,10 +223,10 @@ void TimeRangeList::RemoveTimeRange(const TimeRange &remove)
|
||||
}
|
||||
}
|
||||
|
||||
bool TimeRangeList::ContainsTimeRange(const TimeRange &range, bool in_inclusive, bool out_inclusive) const
|
||||
bool TimeRangeList::contains(const TimeRange &range, bool in_inclusive, bool out_inclusive) const
|
||||
{
|
||||
for (int i=0;i<size();i++) {
|
||||
if (at(i).Contains(range, in_inclusive, out_inclusive)) {
|
||||
if (array_.at(i).Contains(range, in_inclusive, out_inclusive)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -234,12 +234,45 @@ bool TimeRangeList::ContainsTimeRange(const TimeRange &range, bool in_inclusive,
|
||||
return false;
|
||||
}
|
||||
|
||||
void TimeRangeList::shift(const rational &diff)
|
||||
{
|
||||
for (int i=0; i<array_.size(); i++) {
|
||||
array_[i] += diff;
|
||||
}
|
||||
}
|
||||
|
||||
void TimeRangeList::trim_in(const rational &diff)
|
||||
{
|
||||
// Re-do list since we want to handle overlaps
|
||||
TimeRangeList temp = *this;
|
||||
|
||||
clear();
|
||||
|
||||
foreach (TimeRange r, temp) {
|
||||
r.set_in(r.in() + diff);
|
||||
insert(r);
|
||||
}
|
||||
}
|
||||
|
||||
void TimeRangeList::trim_out(const rational &diff)
|
||||
{
|
||||
// Re-do list since we want to handle overlaps
|
||||
TimeRangeList temp = *this;
|
||||
|
||||
clear();
|
||||
|
||||
foreach (TimeRange r, temp) {
|
||||
r.set_out(r.out() + diff);
|
||||
insert(r);
|
||||
}
|
||||
}
|
||||
|
||||
TimeRangeList TimeRangeList::Intersects(const TimeRange &range) const
|
||||
{
|
||||
TimeRangeList intersect_list;
|
||||
|
||||
for (int i=0;i<size();i++) {
|
||||
const TimeRange& compare = at(i);
|
||||
const TimeRange& compare = array_.at(i);
|
||||
|
||||
if (compare.out() <= range.in() || compare.in() >= range.out()) {
|
||||
// No intersect
|
||||
@@ -249,7 +282,7 @@ TimeRangeList TimeRangeList::Intersects(const TimeRange &range) const
|
||||
TimeRange cropped(qMax(range.in(), compare.in()),
|
||||
qMin(range.out(), compare.out()));
|
||||
|
||||
intersect_list.append(cropped);
|
||||
intersect_list.insert(cropped);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,7 +294,7 @@ void TimeRangeList::PrintTimeList()
|
||||
qDebug() << "TimeRangeList now contains:";
|
||||
|
||||
for (int i=0;i<size();i++) {
|
||||
qDebug() << " " << at(i);
|
||||
qDebug() << " " << array_.at(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+50
-5
@@ -67,26 +67,71 @@ private:
|
||||
|
||||
};
|
||||
|
||||
class TimeRangeList : public QList<TimeRange> {
|
||||
class TimeRangeList {
|
||||
public:
|
||||
TimeRangeList() = default;
|
||||
|
||||
TimeRangeList(std::initializer_list<TimeRange> r) :
|
||||
QList<TimeRange>(r)
|
||||
array_(r)
|
||||
{
|
||||
}
|
||||
|
||||
void InsertTimeRange(TimeRange range_to_add);
|
||||
void insert(TimeRange range_to_add);
|
||||
|
||||
void RemoveTimeRange(const TimeRange& remove);
|
||||
void remove(const TimeRange& remove);
|
||||
|
||||
bool ContainsTimeRange(const TimeRange& range, bool in_inclusive = true, bool out_inclusive = true) const;
|
||||
bool contains(const TimeRange& range, bool in_inclusive = true, bool out_inclusive = true) const;
|
||||
|
||||
bool isEmpty() const
|
||||
{
|
||||
return array_.isEmpty();
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
array_.clear();
|
||||
}
|
||||
|
||||
int size() const
|
||||
{
|
||||
return array_.size();
|
||||
}
|
||||
|
||||
void shift(const rational& diff);
|
||||
|
||||
void trim_in(const rational& diff);
|
||||
|
||||
void trim_out(const rational& diff);
|
||||
|
||||
TimeRangeList Intersects(const TimeRange& range) const;
|
||||
|
||||
using const_iterator = QVector<TimeRange>::const_iterator;
|
||||
|
||||
const_iterator begin() const
|
||||
{
|
||||
return array_.constBegin();
|
||||
}
|
||||
|
||||
const_iterator end() const
|
||||
{
|
||||
return array_.constEnd();
|
||||
}
|
||||
|
||||
const TimeRange& first() const
|
||||
{
|
||||
return array_.first();
|
||||
}
|
||||
|
||||
const TimeRange& last() const
|
||||
{
|
||||
return array_.last();
|
||||
}
|
||||
|
||||
private:
|
||||
void PrintTimeList();
|
||||
|
||||
QVector<TimeRange> array_;
|
||||
|
||||
};
|
||||
|
||||
uint qHash(const TimeRange& r, uint seed);
|
||||
|
||||
@@ -127,7 +127,7 @@ void AudioPlaybackCache::WritePCM(const TimeRange &range, SampleBufferPtr sample
|
||||
|
||||
seg_file.close();
|
||||
|
||||
ranges_we_validated.InsertTimeRange(TimeRange(this_write_in_point, this_write_out_point));
|
||||
ranges_we_validated.insert(TimeRange(this_write_in_point, this_write_out_point));
|
||||
} else {
|
||||
qWarning() << "Failed to write PCM data to" << seg_file.fileName();
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ void FrameHashCache::ValidateFramesWithHash(const QByteArray &hash)
|
||||
if (iterator.value() == hash) {
|
||||
TimeRange frame_range(iterator.key(), iterator.key() + timebase_);
|
||||
|
||||
if (invalidated_ranges.ContainsTimeRange(frame_range)) {
|
||||
if (invalidated_ranges.contains(frame_range)) {
|
||||
Validate(frame_range);
|
||||
}
|
||||
}
|
||||
@@ -167,7 +167,7 @@ QVector<rational> FrameHashCache::GetFrameListFromTimeRange(TimeRangeList range_
|
||||
}
|
||||
|
||||
times.append(snapped);
|
||||
range_list.RemoveTimeRange(TimeRange(snapped, next));
|
||||
range_list.remove(TimeRange(snapped, next));
|
||||
}
|
||||
|
||||
return times;
|
||||
@@ -362,7 +362,7 @@ void FrameHashCache::HashDeleted(const QString& s, const QByteArray &hash)
|
||||
QMap<rational, QByteArray>::const_iterator i;
|
||||
for (i=time_hash_map_.constBegin(); i!=time_hash_map_.constEnd(); i++) {
|
||||
if (i.value() == hash) {
|
||||
ranges_to_invalidate.InsertTimeRange(TimeRange(i.key(), i.key() + timebase_));
|
||||
ranges_to_invalidate.insert(TimeRange(i.key(), i.key() + timebase_));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ void PlaybackCache::Invalidate(const TimeRange &r)
|
||||
{
|
||||
Q_ASSERT(r.in() != r.out());
|
||||
|
||||
invalidated_.InsertTimeRange(r);
|
||||
invalidated_.insert(r);
|
||||
|
||||
RemoveRangeFromJobs(r);
|
||||
qint64 job_time = QDateTime::currentMSecsSinceEpoch();
|
||||
@@ -69,11 +69,11 @@ void PlaybackCache::SetLength(const rational &r)
|
||||
jobs_.clear();
|
||||
} else if (r > length_) {
|
||||
// If new length is greater, simply extend the invalidated range for now
|
||||
invalidated_.InsertTimeRange(range_diff);
|
||||
invalidated_.insert(range_diff);
|
||||
jobs_.append({range_diff, QDateTime::currentMSecsSinceEpoch()});
|
||||
} else {
|
||||
// If new length is smaller, removed hashes
|
||||
invalidated_.RemoveTimeRange(range_diff);
|
||||
invalidated_.remove(range_diff);
|
||||
RemoveRangeFromJobs(range_diff);
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ void PlaybackCache::Shift(const rational &from, const rational &to)
|
||||
|
||||
void PlaybackCache::Validate(const TimeRange &r)
|
||||
{
|
||||
invalidated_.RemoveTimeRange(r);
|
||||
invalidated_.remove(r);
|
||||
|
||||
emit Validated(r);
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ void PreviewAutoCacher::VideoInvalidated(const TimeRange &range)
|
||||
if (ignore_next_mouse_button_ || !(qApp->mouseButtons() & Qt::LeftButton)) {
|
||||
ignore_next_mouse_button_ = false;
|
||||
|
||||
invalidated_video_.InsertTimeRange(range);
|
||||
invalidated_video_.insert(range);
|
||||
|
||||
TryRender();
|
||||
}
|
||||
@@ -147,7 +147,7 @@ void PreviewAutoCacher::AudioInvalidated(const TimeRange &range)
|
||||
ClearQueue(false);
|
||||
|
||||
// Start jobs to re-render the audio at this range, split into 2 second chunks
|
||||
invalidated_audio_.InsertTimeRange(range);
|
||||
invalidated_audio_.insert(range);
|
||||
|
||||
TryRender();
|
||||
}
|
||||
|
||||
@@ -88,11 +88,11 @@ bool ExportTask::Run()
|
||||
TimeRangeList video_range, audio_range;
|
||||
|
||||
if (params_.video_enabled()) {
|
||||
video_range.append(range);
|
||||
video_range = {range};
|
||||
}
|
||||
|
||||
if (params_.audio_enabled()) {
|
||||
audio_range.append(range);
|
||||
audio_range = {range};
|
||||
audio_data_.SetLength(range.length());
|
||||
}
|
||||
|
||||
|
||||
@@ -531,7 +531,7 @@ void TimelineWidget::DeleteSelected(bool ripple)
|
||||
TimeRangeList range_list;
|
||||
|
||||
foreach (Block* b, blocks_to_delete) {
|
||||
range_list.InsertTimeRange(TimeRange(b->in(), b->out()));
|
||||
range_list.insert(TimeRange(b->in(), b->out()));
|
||||
}
|
||||
|
||||
new TimelineRippleDeleteGapsAtRegionsCommand(GetConnectedNode(), range_list, command);
|
||||
@@ -1512,7 +1512,7 @@ void TimelineWidget::EndRubberBandSelect()
|
||||
|
||||
void TimelineWidget::AddSelection(const TimeRange &time, const TrackReference &track)
|
||||
{
|
||||
selections_[track].InsertTimeRange(time);
|
||||
selections_[track].insert(time);
|
||||
|
||||
UpdateViewports(track.type());
|
||||
}
|
||||
@@ -1524,7 +1524,7 @@ void TimelineWidget::AddSelection(TimelineViewBlockItem *item)
|
||||
|
||||
void TimelineWidget::RemoveSelection(const TimeRange &time, const TrackReference &track)
|
||||
{
|
||||
selections_[track].RemoveTimeRange(time);
|
||||
selections_[track].remove(time);
|
||||
|
||||
UpdateViewports(track.type());
|
||||
}
|
||||
|
||||
@@ -25,9 +25,7 @@ OLIVE_NAMESPACE_ENTER
|
||||
void TimelineWidgetSelections::ShiftTime(const rational &diff)
|
||||
{
|
||||
for (auto it=this->begin(); it!=this->end(); it++) {
|
||||
for (auto it2=it.value().begin(); it2!=it.value().end(); it2++) {
|
||||
(*it2) += diff;
|
||||
}
|
||||
it.value().shift(diff);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,18 +57,14 @@ void TimelineWidgetSelections::ShiftTracks(Timeline::TrackType type, int diff)
|
||||
void TimelineWidgetSelections::TrimIn(const rational &diff)
|
||||
{
|
||||
for (auto it=this->begin(); it!=this->end(); it++) {
|
||||
for (auto it2=it.value().begin(); it2!=it.value().end(); it2++) {
|
||||
(*it2).set_in((*it2).in() + diff);
|
||||
}
|
||||
it.value().trim_in(diff);
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidgetSelections::TrimOut(const rational &diff)
|
||||
{
|
||||
for (auto it=this->begin(); it!=this->end(); it++) {
|
||||
for (auto it2=it.value().begin(); it2!=it.value().end(); it2++) {
|
||||
(*it2).set_out((*it2).out() + diff);
|
||||
}
|
||||
it.value().trim_out(diff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user