]> git.sesse.net Git - kdenlive/blobdiff - src/trackview.cpp
Refactor representation of 2pass in profiles.
[kdenlive] / src / trackview.cpp
index 5333eb0e325bc04aaede201fa2d73e99815d09a4..b5b2b9efd173d318e5b0a7bb4b14cbc7941663ec 100644 (file)
 #include <QInputDialog>
 
 TrackView::TrackView(KdenliveDoc *doc, bool *ok, QWidget *parent) :
-        QWidget(parent),
-        m_scale(1.0),
-        m_projectTracks(0),
-        m_doc(doc),
-        m_verticalZoom(1)
+    QWidget(parent),
+    m_scale(1.0),
+    m_projectTracks(0),
+    m_doc(doc),
+    m_verticalZoom(1)
 {
 
     setupUi(this);
@@ -197,8 +197,9 @@ void TrackView::parseDocument(QDomDocument doc)
     }*/
 
     // parse project tracks
-    QDomElement tractor = doc.elementsByTagName("tractor").item(0).toElement();
-    QDomNodeList tracks = doc.elementsByTagName("track");
+    QDomElement mlt = doc.firstChildElement("mlt");
+    QDomElement tractor = mlt.firstChildElement("tractor");
+    QDomNodeList tracks = tractor.elementsByTagName("track");
     QDomNodeList playlists = doc.elementsByTagName("playlist");
     int duration = 300;
     m_projectTracks = tracks.count();
@@ -232,7 +233,7 @@ void TrackView::parseDocument(QDomDocument doc)
         if (e.hasAttribute("in") == false && e.hasAttribute("out") == false) continue;
         int in = e.attribute("in").toInt();
         int out = e.attribute("out").toInt();
-        if (in > out || in == out) {
+        if (in >= out) {
             // invalid producer, remove it
             QString id = e.attribute("id");
             m_invalidProducers.append(id);
@@ -285,7 +286,7 @@ void TrackView::parseDocument(QDomDocument doc)
     }
 
     // parse transitions
-    QDomNodeList transitions = doc.elementsByTagName("transition");
+    QDomNodeList transitions = tractor.elementsByTagName("transition");
 
     //kDebug() << "//////////// TIMELINE FOUND: " << projectTransitions << " transitions";
     for (int i = 0; i < transitions.count(); i++) {
@@ -412,7 +413,7 @@ void TrackView::parseDocument(QDomDocument doc)
                 kDebug() << "///// REMOVED INVALID TRANSITION: " << e.attribute("id");
                 tractor.removeChild(transitions.item(i));
                 i--;
-            } else {
+            } else if (m_trackview->canBePastedTo(transitionInfo, TRANSITIONWIDGET)) {
                 Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base, isAutomatic);
                 if (forceTrack) tr->setForcedTrack(true, a_track);
                 m_scene->addItem(tr);
@@ -420,11 +421,19 @@ void TrackView::parseDocument(QDomDocument doc)
                     tr->setItemLocked(true);
                 }
             }
+            else {
+                m_documentErrors.append(i18n("Removed overlapping transition: (%1, %2, %3)", e.attribute("id"), mlt_service, transitionId) + '\n');
+                tractor.removeChild(transitions.item(i));
+                i--;
+            }
         }
     }
 
+
+    QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
+
     // Add guides
-    QDomNodeList guides = doc.elementsByTagName("guide");
+    QDomNodeList guides = infoXml.elementsByTagName("guide");
     for (int i = 0; i < guides.count(); i++) {
         e = guides.item(i).toElement();
         const QString comment = e.attribute("comment");
@@ -433,19 +442,17 @@ void TrackView::parseDocument(QDomDocument doc)
     }
 
     // Rebuild groups
-    QDomNodeList groups = doc.elementsByTagName("group");
+    QDomNodeList groups = infoXml.elementsByTagName("group");
     m_trackview->loadGroups(groups);
     m_trackview->setDuration(duration);
     kDebug() << "///////////  TOTAL PROJECT DURATION: " << duration;
 
     // Remove Kdenlive extra info from xml doc before sending it to MLT
-    QDomElement mlt = doc.firstChildElement("mlt");
-    QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
     mlt.removeChild(infoXml);
 
     slotRebuildTrackHeaders();
     if (!m_documentErrors.isNull()) KMessageBox::sorry(this, m_documentErrors);
-    if (infoXml.hasAttribute("upgraded")) {
+    if (infoXml.hasAttribute("upgraded") || infoXml.hasAttribute("modified")) {
         // Our document was upgraded, create a backup copy just in case
         QString baseFile = m_doc->url().path().section(".kdenlive", 0, 0);
         int ct = 0;
@@ -454,8 +461,13 @@ void TrackView::parseDocument(QDomDocument doc)
             ct++;
             backupFile = baseFile + "_backup" + QString::number(ct) + ".kdenlive";
         }
+        QString message;
+        if (infoXml.hasAttribute("upgraded"))
+            message = i18n("Your project file was upgraded to the latest Kdenlive document version.\nTo make sure you don't lose data, a backup copy called %1 was created.", backupFile);
+        else
+            message = i18n("Your project file was modified by Kdenlive.\nTo make sure you don't lose data, a backup copy called %1 was created.", backupFile);
         if (KIO::NetAccess::file_copy(m_doc->url(), KUrl(backupFile), this))
-            KMessageBox::information(this, i18n("Your project file was upgraded to the latest Kdenlive document version.\nTo make sure you don't lose data, a backup copy called %1 was created.", backupFile));
+            KMessageBox::information(this, message);
         else
             KMessageBox::information(this, i18n("Your project file was upgraded to the latest Kdenlive document version, but it was not possible to create a backup copy.", backupFile));
     }
@@ -608,7 +620,8 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
                 speed = idString.section(':', 2, 2).toDouble();
                 strobe = idString.section(':', 3, 3).toInt();
                 if (strobe == 0) strobe = 1;
-            } else id = id.section('_', 0, 0);
+            }
+            id = id.section('_', 0, 0);
             DocClipBase *clip = m_doc->clipManager()->getClipById(id);
             if (clip == NULL) {
                 // The clip in playlist was not listed in the kdenlive producers,
@@ -630,6 +643,7 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
                     producerXml.setAttribute("id", id);
                     clip = new DocClipBase(m_doc->clipManager(), doc.documentElement(), id);
                     xml.insertBefore(producerXml, QDomNode());
+                    nodeindex++;
                     m_doc->clipManager()->addClip(clip);
 
                     m_documentErrors.append(i18n("Broken clip producer %1", id) + '\n');
@@ -677,15 +691,16 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
 
 void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNode, ClipItem *clip, int trackIndex)
 {
+    int effectNb = 0;
     for (int ix = 0; ix < effects.count(); ix++) {
         bool disableeffect = false;
         QDomElement effect = effects.at(ix).toElement();
         if (effect.tagName() != "filter") continue;
-
+        effectNb++;
         // add effect to clip
         QString effecttag;
         QString effectid;
-        QString effectindex = QString::number(ix + 1);
+        QString effectindex = QString::number(effectNb);
         QString ladspaEffectFile;
         // Get effect tag & index
         for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
@@ -715,8 +730,12 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo
         //kDebug() << "+ + CLIP EFF FND: " << effecttag << ", " << effectid << ", " << effectindex;
         // get effect standard tags
         QDomElement clipeffect = MainWindow::customEffects.getEffectByTag(QString(), effectid);
-        if (clipeffect.isNull()) clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag, effectid);
-        if (clipeffect.isNull()) clipeffect = MainWindow::audioEffects.getEffectByTag(effecttag, effectid);
+        if (clipeffect.isNull()) {
+            clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag, effectid);
+        }
+        if (clipeffect.isNull()) {
+            clipeffect = MainWindow::audioEffects.getEffectByTag(effecttag, effectid);
+        }
         if (clipeffect.isNull()) {
             kDebug() << "///  WARNING, EFFECT: " << effecttag << ": " << effectid << " not found, removing it from project";
             m_documentErrors.append(i18n("Effect %1:%2 not found in MLT, it was removed from this project\n", effecttag, effectid));
@@ -763,7 +782,7 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo
                 }
                 // add first keyframe
                 if (effectout <= effectin) {
-                    // there is only one keyframe
+                    // there is only one keyframe
                     keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';');
                 } else keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';');
                 QDomNode lastParsedEffect;
@@ -825,27 +844,33 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo
                 for (int k = 0; k < clipeffectparams.count(); k++) {
                     e = clipeffectparams.item(k).toElement();
                     if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) {
-                        if (e.attribute("factor", "1") != "1") {
-                            QString factor = e.attribute("factor", "1");
-                            double fact;
-                            if (factor.startsWith('%')) {
-                                fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
-                            } else fact = factor.toDouble();
-                            if (e.attribute("type") == "simplekeyframe") {
-                                QStringList kfrs = paramvalue.split(";");
-                                for (int l = 0; l < kfrs.count(); l++) {
-                                    QString fr = kfrs.at(l).section("=", 0, 0);
-                                    double val = kfrs.at(l).section("=", 1, 1).toDouble();
-                                    kfrs[l] = fr + ":" + QString::number((int)(val * fact));
-                                }
-                                e.setAttribute("keyframes", kfrs.join(";"));
-                            } else e.setAttribute("value", paramvalue.toDouble() * fact);
-                        } else e.setAttribute("value", paramvalue);
+                        QString factor = e.attribute("factor", "1");
+                        double fact;
+                        if (factor.startsWith('%')) {
+                            fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
+                        } else {
+                            fact = factor.toDouble();
+                        }
+                        if (e.attribute("type") == "simplekeyframe") {
+                            QStringList kfrs = paramvalue.split(";");
+                            for (int l = 0; l < kfrs.count(); l++) {
+                                QString fr = kfrs.at(l).section('=', 0, 0);
+                                double val = kfrs.at(l).section('=', 1, 1).toDouble();
+                                kfrs[l] = fr + ":" + QString::number((int)(val * fact));
+                            }
+                            e.setAttribute("keyframes", kfrs.join(";"));
+                        } else {
+                            bool ok;
+                            e.setAttribute("value", paramvalue.toDouble(&ok) * fact);
+                            if (!ok)
+                                e.setAttribute("value", paramvalue);
+                        }
                         break;
                     }
                 }
             }
-            if (effecttag == "ladspa") {
+            // Old LADSPA filter, deprecated
+            /*if (effecttag == "ladspa") {
                 //QString ladspaEffectFile = EffectsList::parameter(effect, "src", "property");
 
                 if (!QFile::exists(ladspaEffectFile)) {
@@ -853,13 +878,13 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo
                     initEffects::ladspaEffectFile(ladspaEffectFile, currenteffect.attribute("ladspaid").toInt(), m_trackview->getLadspaParams(currenteffect));
                 }
                 currenteffect.setAttribute("src", ladspaEffectFile);
-            }
+            }*/
+            
             if (disableeffect) currenteffect.setAttribute("disable", "1");
-            if (clip) clip->addEffect(currenteffect, false);
-            else {
-                kDebug() << "<< TRACK: " << trackIndex << ", adding effect";;
+            if (clip)
+                clip->addEffect(currenteffect, false);
+            else
                 m_doc->addTrackEffect(trackIndex, currenteffect);
-            }
         }
     }
 }
@@ -873,9 +898,15 @@ DocClipBase *TrackView::getMissingProducer(const QString id) const
     if (!docRoot.endsWith('/')) docRoot.append('/');
     QDomNodeList prods = doc.elementsByTagName("producer");
     int maxprod = prods.count();
+    bool slowmotionClip = false;
     for (int i = 0; i < maxprod; i++) {
         QDomNode m = prods.at(i);
         QString prodId = m.toElement().attribute("id");
+        if (prodId.startsWith("slowmotion")) {
+            slowmotionClip = true;
+            prodId = prodId.section(':', 1, 1);
+        }
+        prodId = prodId.section('_', 0, 0);
         if (prodId == id) {
             missingXml =  m.toElement();
             break;
@@ -892,6 +923,7 @@ DocClipBase *TrackView::getMissingProducer(const QString id) const
             break;
         }
     }
+    if (slowmotionClip) resource = resource.section('?', 0, 0);
     // prepend MLT XML document root if no path in clip resource and not a color clip
     if (!resource.startsWith('/') && !resource.startsWith("0x")) resource.prepend(docRoot);
     DocClipBase *missingClip = NULL;
@@ -992,11 +1024,26 @@ void TrackView::slotShowTrackEffects(int ix)
 void TrackView::slotUpdateTrackEffectState(int ix)
 {
     QList<HeaderTrack *> widgets = findChildren<HeaderTrack *>();
-    if (ix >= widgets.count()) {
+    if (ix < 0 || ix >= widgets.count()) {
         kDebug() << "ERROR, Trying to access a non existant track: " << ix;
         return;
     }
     widgets.at(m_doc->tracksCount() - ix - 1)->updateEffectLabel(m_doc->trackInfoAt(ix).effectsList.effectNames());
 }
 
+void TrackView::slotSaveTimelinePreview(const QString path)
+{
+    QImage img(width(), height(), QImage::Format_ARGB32_Premultiplied);
+    img.fill(palette().base().color().rgb());
+    QPainter painter(&img);
+    render(&painter);
+    painter.end();
+    img = img.scaledToWidth(600, Qt::SmoothTransformation);
+    img.save(path);
+}
+
+
 #include "trackview.moc"
+
+
+