diff --git a/app/common/timerange.cpp b/app/common/timerange.cpp index f25ebc398..6af6f9a35 100644 --- a/app/common/timerange.cpp +++ b/app/common/timerange.cpp @@ -48,6 +48,11 @@ bool TimeRange::operator==(const TimeRange &r) const return in() == r.in() && out() == r.out(); } +bool TimeRange::operator!=(const TimeRange &r) const +{ + return in() != r.in() || out() != r.out(); +} + bool TimeRange::OverlapsWith(const TimeRange &a, bool in_inclusive, bool out_inclusive) const { bool overlaps_in = (in_inclusive) ? (a.out() < in()) : (a.out() <= in()); diff --git a/app/common/timerange.h b/app/common/timerange.h index 93707b754..f4754fb9c 100644 --- a/app/common/timerange.h +++ b/app/common/timerange.h @@ -17,6 +17,7 @@ public: void set_range(const rational& in, const rational& out); bool operator==(const TimeRange& r) const; + bool operator!=(const TimeRange& r) const; bool OverlapsWith(const TimeRange& a, bool in_inclusive = true, bool out_inclusive = true) const; bool Contains(const TimeRange& a, bool in_inclusive = true, bool out_inclusive = true) const; diff --git a/app/project/item/footage/footage.cpp b/app/project/item/footage/footage.cpp index 6e8e7d3dc..0c9101173 100644 --- a/app/project/item/footage/footage.cpp +++ b/app/project/item/footage/footage.cpp @@ -80,6 +80,8 @@ void Footage::Load(QXmlStreamReader *reader, XMLNodeData &xml_node_data, const Q } else { qWarning() << "Invalid stream found in project file"; } + } else if (reader->name() == QStringLiteral("points")) { + TimelinePoints::Load(reader); } else { reader->skipCurrentElement(); } @@ -93,6 +95,8 @@ void Footage::Save(QXmlStreamWriter *writer) const writer->writeAttribute("name", name()); writer->writeAttribute("filename", filename()); + TimelinePoints::Save(writer); + foreach (StreamPtr stream, streams_) { stream->Save(writer); } diff --git a/app/project/item/sequence/sequence.cpp b/app/project/item/sequence/sequence.cpp index 60989af7b..d258269f0 100644 --- a/app/project/item/sequence/sequence.cpp +++ b/app/project/item/sequence/sequence.cpp @@ -97,6 +97,10 @@ void Sequence::Load(QXmlStreamReader *reader, XMLNodeData& xml_node_data, const } set_audio_params(AudioParams(rate, layout)); + } else if (reader->name() == QStringLiteral("points")) { + + TimelinePoints::Load(reader); + } else if (reader->name() == QStringLiteral("node") || reader->name() == QStringLiteral("viewer")) { Node* node; @@ -150,6 +154,9 @@ void Sequence::Save(QXmlStreamWriter *writer) const writer->writeEndElement(); // audio + // Write TimelinePoints + TimelinePoints::Save(writer); + foreach (Node* node, nodes()) { if (node != viewer_output_) { node->Save(writer); diff --git a/app/timeline/timelinemarker.cpp b/app/timeline/timelinemarker.cpp index 83a136c7b..085869d95 100644 --- a/app/timeline/timelinemarker.cpp +++ b/app/timeline/timelinemarker.cpp @@ -1,5 +1,7 @@ #include "timelinemarker.h" +#include "common/xmlutils.h" + TimelineMarker::TimelineMarker(const TimeRange &time, const QString &name, QObject *parent) : QObject(parent), time_(time), @@ -29,6 +31,24 @@ void TimelineMarker::set_name(const QString &name) emit NameChanged(name_); } +void TimelineMarkerList::Save(QXmlStreamWriter *writer) const +{ + writer->writeStartElement(QStringLiteral("markers")); + + foreach (TimelineMarker* marker, markers_) { + writer->writeStartElement(QStringLiteral("marker")); + + writer->writeAttribute(QStringLiteral("name"), marker->name()); + + writer->writeAttribute(QStringLiteral("in"), marker->time().in().toString()); + writer->writeAttribute(QStringLiteral("out"), marker->time().out().toString()); + + writer->writeEndElement(); // marker + } + + writer->writeEndElement(); // markers +} + TimelineMarkerList::~TimelineMarkerList() { qDeleteAll(markers_); @@ -59,3 +79,25 @@ const QList &TimelineMarkerList::list() const { return markers_; } + +void TimelineMarkerList::Load(QXmlStreamReader *reader) +{ + while (XMLReadNextStartElement(reader)) { + if (reader->name() == QStringLiteral("marker")) { + QString name; + TimeRange range; + + XMLAttributeLoop(reader, attr) { + if (attr.name() == QStringLiteral("name")) { + name = attr.value().toString(); + } else if (attr.name() == QStringLiteral("in")) { + range.set_in(rational::fromString(attr.value().toString())); + } else if (attr.name() == QStringLiteral("out")) { + range.set_out(rational::fromString(attr.value().toString())); + } + } + } + + reader->skipCurrentElement(); + } +} diff --git a/app/timeline/timelinemarker.h b/app/timeline/timelinemarker.h index 998f27585..943745f5b 100644 --- a/app/timeline/timelinemarker.h +++ b/app/timeline/timelinemarker.h @@ -2,6 +2,8 @@ #define TIMELINEMARKER_H #include +#include +#include #include "common/timerange.h" @@ -43,6 +45,9 @@ public: const QList &list() const; + void Load(QXmlStreamReader* reader); + void Save(QXmlStreamWriter* writer) const; + signals: void MarkerAdded(TimelineMarker* marker); diff --git a/app/timeline/timelinepoints.cpp b/app/timeline/timelinepoints.cpp index b3aae146c..525345053 100644 --- a/app/timeline/timelinepoints.cpp +++ b/app/timeline/timelinepoints.cpp @@ -1,5 +1,7 @@ #include "timelinepoints.h" +#include "common/xmlutils.h" + TimelineMarkerList *TimelinePoints::markers() { return &markers_; @@ -15,6 +17,30 @@ const TimelineWorkArea *TimelinePoints::workarea() const return &workarea_; } +void TimelinePoints::Load(QXmlStreamReader *reader) +{ + while (XMLReadNextStartElement(reader)) { + if (reader->name() == QStringLiteral("markers")) { + markers_.Load(reader); + } else if (reader->name() == QStringLiteral("workarea")) { + workarea_.Load(reader); + } else { + reader->skipCurrentElement(); + } + } +} + +void TimelinePoints::Save(QXmlStreamWriter *writer) const +{ + writer->writeStartElement(QStringLiteral("points")); + + workarea_.Save(writer); + + markers_.Save(writer); + + writer->writeEndElement(); // points +} + TimelineWorkArea *TimelinePoints::workarea() { return &workarea_; diff --git a/app/timeline/timelinepoints.h b/app/timeline/timelinepoints.h index ed2570f1c..119def69d 100644 --- a/app/timeline/timelinepoints.h +++ b/app/timeline/timelinepoints.h @@ -1,6 +1,9 @@ #ifndef TIMELINEPOINTS_H #define TIMELINEPOINTS_H +#include +#include + #include "timelinemarker.h" #include "timelineworkarea.h" @@ -15,6 +18,9 @@ public: TimelineWorkArea* workarea(); const TimelineWorkArea* workarea() const; + void Load(QXmlStreamReader* reader); + void Save(QXmlStreamWriter* writer) const; + private: TimelineMarkerList markers_; diff --git a/app/timeline/timelineworkarea.cpp b/app/timeline/timelineworkarea.cpp index 57b29364a..f2dc285bf 100644 --- a/app/timeline/timelineworkarea.cpp +++ b/app/timeline/timelineworkarea.cpp @@ -1,5 +1,7 @@ #include "timelineworkarea.h" +#include "common/xmlutils.h" + const rational TimelineWorkArea::kResetIn = 0; const rational TimelineWorkArea::kResetOut = RATIONAL_MAX; @@ -30,6 +32,41 @@ void TimelineWorkArea::set_range(const TimeRange &range) emit RangeChanged(workarea_range_); } +void TimelineWorkArea::Load(QXmlStreamReader *reader) +{ + rational range_in = workarea_range_.in(); + rational range_out = workarea_range_.out(); + + XMLAttributeLoop(reader, attr) { + if (attr.name() == QStringLiteral("enabled")) { + set_enabled(attr.value() != 0); + } else if (attr.name() == QStringLiteral("in")) { + range_in = rational::fromString(attr.value().toString()); + } else if (attr.name() == QStringLiteral("out")) { + range_out = rational::fromString(attr.value().toString()); + } + } + + TimeRange loaded_workarea(range_in, range_out); + + if (loaded_workarea != workarea_range_) { + set_range(loaded_workarea); + } + + reader->skipCurrentElement(); +} + +void TimelineWorkArea::Save(QXmlStreamWriter *writer) const +{ + writer->writeStartElement(QStringLiteral("workarea")); + + writer->writeAttribute(QStringLiteral("enabled"), QString::number(workarea_enabled_)); + writer->writeAttribute(QStringLiteral("in"), workarea_range_.in().toString()); + writer->writeAttribute(QStringLiteral("out"), workarea_range_.out().toString()); + + writer->writeEndElement(); // workarea +} + const rational &TimelineWorkArea::in() const { return workarea_range_.in(); diff --git a/app/timeline/timelineworkarea.h b/app/timeline/timelineworkarea.h index bad23bc82..7764a0c6f 100644 --- a/app/timeline/timelineworkarea.h +++ b/app/timeline/timelineworkarea.h @@ -2,6 +2,8 @@ #define TIMELINEWORKAREA_H #include +#include +#include #include "common/timerange.h" @@ -19,6 +21,9 @@ public: const TimeRange& range() const; void set_range(const TimeRange& range); + void Load(QXmlStreamReader* reader); + void Save(QXmlStreamWriter* writer) const; + static const rational kResetIn; static const rational kResetOut;