]> git.sesse.net Git - kdenlive/blobdiff - src/documentvalidator.cpp
Check document for invalid (overlapping) transitions
[kdenlive] / src / documentvalidator.cpp
index e6e0be7edaab395330d09b06003bc9b6c87986d9..e6f7317fb79c8fef05e5d6a01cebb18cf4184dff 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <QFile>
 #include <QColor>
+#include <QBitmap>
+
 
 DocumentValidator::DocumentValidator(QDomDocument doc):
         m_doc(doc),
@@ -143,9 +145,44 @@ bool DocumentValidator::validate(const double currentVersion)
                 }
             }
         }
+        
+        // Make sure transitions do not overlap
+        QDomNodeList transitions = m_doc.elementsByTagName("transition");
+        QPolygon scenelist;
+        QStringList overlappingTransitions;
+        for (int i = 0; i < transitions.count(); i++) {
+            QDomElement t = transitions.at(i).toElement();
+            QDomNodeList props = t.elementsByTagName("property");
+            bool testTransition = true;
+            int track = -1;
+            for (int k = 0; k < props.count(); k++) {
+                QDomElement p = props.at(k).toElement();
+                QString name = p.attribute("name");
+                if (name == "mlt_service" && p.firstChild().nodeValue() == "mix") testTransition = false;
+                else if (name == "b_track") track = p.firstChild().nodeValue().toInt();
+            }
+            if (testTransition) {
+                QRect r(t.attribute("in").toInt(), 3 * track, t.attribute("out").toInt() - t.attribute("in").toInt(), 1);
+                QPolygon p(r);
+                if (scenelist.intersected(p).isEmpty()) {
+                    scenelist = scenelist.united(p);
+                }
+                else {
+                    // Transition is overlapping, should be removed
+                    overlappingTransitions << t.attribute("id");
+                    tractor.removeChild(t);
+                    i--;
+                }
+            }
+        }
+        if (!overlappingTransitions.isEmpty()) {
+            KMessageBox::informationList(kapp->activeWindow(), i18n("The following transitions were corrupted (overlapping)\n and removed from project."), overlappingTransitions, i18n("Invalid Transitions"));
+            m_modified = true;
+        }
 
         // TODO: check the tracks references
         // TODO: check internal mix transitions
+        
     }
 
     return true;
@@ -811,6 +848,30 @@ bool DocumentValidator::upgrade(double version, const double currentVersion)
             }
         }
     }
+    if (version <= 0.85) {
+        // update the LADSPA effects to use the new ladspa.id format instead of external xml file
+        QDomNodeList effectNodes = m_doc.elementsByTagName("filter");
+        for (int i = 0; i < effectNodes.count(); ++i) {
+            QDomElement effect = effectNodes.at(i).toElement();
+            if (EffectsList::property(effect, "mlt_service") == "ladspa") {
+                // Needs to be converted
+                QStringList info = getInfoFromEffectName(EffectsList::property(effect, "kdenlive_id"));
+                if (info.isEmpty()) continue;
+                // info contains the correct ladspa.id from kdenlive effect name, and a list of parameter's old and new names
+                EffectsList::setProperty(effect, "kdenlive_id", info.at(0));
+                EffectsList::setProperty(effect, "tag", info.at(0));
+                EffectsList::setProperty(effect, "mlt_service", info.at(0));
+                EffectsList::removeProperty(effect, "src");
+                for (int j = 1; j < info.size(); j++) {
+                    QString value = EffectsList::property(effect, info.at(j).section('=', 0, 0));
+                    if (!value.isEmpty()) {
+                        // update parameter name
+                        EffectsList::renameProperty(effect, info.at(j).section('=', 0, 0), info.at(j).section('=', 1, 1));
+                    }
+                }
+            }
+        }
+    }
 
 
     // The document has been converted: mark it as modified
@@ -819,6 +880,84 @@ bool DocumentValidator::upgrade(double version, const double currentVersion)
     return true;
 }
 
+QStringList DocumentValidator::getInfoFromEffectName(const QString oldName)
+{
+    QStringList info;
+    // Returns a list to convert old Kdenlive ladspa effects
+    if (oldName == "pitch_shift") {
+        info << "ladspa.1433";
+        info << "pitch=0";
+    }
+    else if (oldName == "vinyl") {
+        info << "ladspa.1905";
+        info << "year=0";
+        info << "rpm=1";
+        info << "warping=2";
+        info << "crackle=3";
+        info << "wear=4";
+    }
+    else if (oldName == "room_reverb") {
+        info << "ladspa.1216";
+        info << "room=0";
+        info << "delay=1";
+        info << "damp=2";
+    }
+    else if (oldName == "reverb") {
+        info << "ladspa.1423";
+        info << "room=0";
+        info << "damp=1";
+    }
+    else if (oldName == "rate_scale") {
+        info << "ladspa.1417";
+        info << "rate=0";
+    }
+    else if (oldName == "pitch_scale") {
+        info << "ladspa.1193";
+        info << "coef=0";
+    }
+    else if (oldName == "phaser") {
+        info << "ladspa.1217";
+        info << "rate=0";
+        info << "depth=1";
+        info << "feedback=2";
+        info << "spread=3";
+    }
+    else if (oldName == "limiter") {
+        info << "ladspa.1913";
+        info << "gain=0";
+        info << "limit=1";
+        info << "release=2";
+    }
+    else if (oldName == "equalizer_15") {
+        info << "ladspa.1197";
+        info << "1=0";
+        info << "2=1";
+        info << "3=2";
+        info << "4=3";
+        info << "5=4";
+        info << "6=5";
+        info << "7=6";
+        info << "8=7";
+        info << "9=8";
+        info << "10=9";
+        info << "11=10";
+        info << "12=11";
+        info << "13=12";
+        info << "14=13";
+        info << "15=14";
+    }
+    else if (oldName == "equalizer") {
+        info << "ladspa.1901";
+        info << "logain=0";
+        info << "midgain=1";
+        info << "higain=2";
+    }
+    else if (oldName == "declipper") {
+        info << "ladspa.1195";
+    }
+    return info;
+}
+
 QString DocumentValidator::colorToString(const QColor& c)
 {
     QString ret = "%1,%2,%3,%4";