]> git.sesse.net Git - kdenlive/blobdiff - src/trackview.cpp
Patch from Ray Lehtiniemi (3):
[kdenlive] / src / trackview.cpp
index 57b48fa37bd328ed5a6a79bf310f3c0fccc6a6d3..490d56c5a431ff3b719393f678c92b5828e0cc4c 100644 (file)
@@ -120,7 +120,7 @@ void TrackView::setDuration(int dur) {
 }
 
 void TrackView::parseDocument(QDomDocument doc) {
-    int cursorPos = 0;
+    //int cursorPos = 0;
     m_documentErrors.clear();
     // kDebug() << "//// DOCUMENT: " << doc.toString();
     /*QDomNode props = doc.elementsByTagName("properties").item(0);
@@ -139,7 +139,23 @@ void TrackView::parseDocument(QDomDocument doc) {
     QDomElement p;
 
     int pos = m_projectTracks - 1;
-
+    m_invalidProducers.clear();
+    QDomNodeList producers = doc.elementsByTagName("producer");
+    for (int i = 0; i < producers.count(); i++) {
+        // CHeck for invalid producers
+        QDomNode n = producers.item(i);
+        e = n.toElement();
+        int in = e.attribute("in").toInt();
+        int out = e.attribute("out").toInt();
+        if (in > out || in == out) {
+            // invalid producer, remove it
+            QString id = e.attribute("id");
+            m_invalidProducers.append(id);
+            m_documentErrors.append(i18n("Invalid clip producer %1\n", id));
+            doc.documentElement().removeChild(producers.at(i));
+            i--;
+        }
+    }
 
     for (int i = 0; i < m_projectTracks; i++) {
         e = tracks.item(i).toElement();
@@ -217,8 +233,7 @@ void TrackView::parseDocument(QDomDocument doc) {
             QString transitionId;
             if (mlt_service == "composite") {
                 // When adding composite transition, check if it is a wipe transition
-                if (mlt_geometry == "0%,0%:100%x100%") transitionId = "alphatransparency";
-                else if (mlt_geometry.count(';') == 1) {
+                if (mlt_geometry.count(';') == 1) {
                     mlt_geometry.remove(QChar('%'), Qt::CaseInsensitive);
                     mlt_geometry.replace(QChar('x'), QChar(','), Qt::CaseInsensitive);
                     QString start = mlt_geometry.section(';', 0, 0);
@@ -301,6 +316,10 @@ void TrackView::parseDocument(QDomDocument doc) {
         m_trackview->addGuide(pos, comment);
     }
 
+    // Rebuild groups
+    QDomNodeList groups = doc.elementsByTagName("group");
+    m_trackview->loadGroups(groups);
+
     m_trackview->setDuration(duration);
     kDebug() << "///////////  TOTAL PROJECT DURATION: " << duration;
     slotRebuildTrackHeaders();
@@ -336,14 +355,6 @@ int TrackView::fitZoom() const {
     return i;
 }
 
-const double TrackView::zoomFactor() const {
-    return m_scale;
-}
-
-const int TrackView::mapLocalToValue(int x) const {
-    return (int)(x * zoomFactor());
-}
-
 KdenliveDoc *TrackView::document() {
     return m_doc;
 }
@@ -354,7 +365,7 @@ void TrackView::refresh() {
 
 void TrackView::slotRebuildTrackHeaders() {
     QList <TrackInfo> list = m_doc->tracksList();
-    QList<HeaderTrack *> widgets = this->findChildren<HeaderTrack *>();
+    QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
     for (int i = 0; i < widgets.count(); i++)
         delete widgets.at(i);
     int max = list.count();
@@ -374,10 +385,11 @@ void TrackView::slotRebuildTrackHeaders() {
 
 
 int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked) {
-    int trackTop = KdenliveSettings::trackheight() * ix;
     // parse track
     int position = 0;
-    for (QDomNode n = xml.firstChild(); !n.isNull(); n = n.nextSibling()) {
+    QDomNodeList children = xml.childNodes();
+    for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
+        QDomNode n = children.item(nodeindex);
         QDomElement elem = n.toElement();
         if (elem.tagName() == "blank") {
             position += elem.attribute("length").toInt();
@@ -387,8 +399,10 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked) {
             // Found a clip
             int in = elem.attribute("in").toInt();
             int out = elem.attribute("out").toInt();
-            if (in > out || in == out) {
+            if (in > out || in == out || m_invalidProducers.contains(elem.attribute("producer"))) {
                 m_documentErrors.append(i18n("Invalid clip removed from track %1 at %2\n", ix, position));
+                xml.removeChild(children.at(nodeindex));
+                nodeindex--;
                 continue;
             }
             QString idString = elem.attribute("producer");
@@ -407,6 +421,8 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked) {
                 clipinfo.track = ix;
                 //kDebug() << "// INSERTING CLIP: " << in << "x" << out << ", track: " << ix << ", ID: " << id << ", SCALE: " << m_scale << ", FPS: " << m_doc->fps();
                 ClipItem *item = new ClipItem(clip, clipinfo, m_doc->fps(), speed, false);
+                if (idString.endsWith("_video")) item->setVideoOnly(true);
+                else if (idString.endsWith("_audio")) item->setAudioOnly(true);
                 m_scene->addItem(item);
                 if (locked) item->setItemLocked(true);
                 clip->addReference();
@@ -617,7 +633,7 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked) {
 }
 
 DocClipBase *TrackView::getMissingProducer(const QString id) const {
-    QDomElement missingXml = QDomElement();
+    QDomElement missingXml;
     QDomDocument doc = m_doc->toXml();
     QString docRoot = doc.documentElement().attribute("root");
     if (!docRoot.endsWith('/')) docRoot.append('/');
@@ -668,7 +684,7 @@ const QString & TrackView::editMode() const {
 }
 
 void TrackView::slotChangeTrackLock(int ix, bool lock) {
-    QList<HeaderTrack *> widgets = this->findChildren<HeaderTrack *>();
+    QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
     widgets.at(ix)->setLock(lock);
 }