]> git.sesse.net Git - kdenlive/commitdiff
When opening a project file, restore effects
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 11 May 2008 09:11:03 +0000 (09:11 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 11 May 2008 09:11:03 +0000 (09:11 +0000)
svn path=/branches/KDE4/; revision=2178

src/clipitem.cpp
src/clipitem.h
src/effectslist.cpp
src/effectslist.h
src/trackview.cpp

index 1b512cb3e1b13d1dab4959fc6dd48b1d22c34cc2..c94329886b3b14042e825876246580c88698acfd 100644 (file)
@@ -565,8 +565,11 @@ void ClipItem::setEffectAt(int ix, QDomElement effect) {
     update(boundingRect());
 }
 
-QMap <QString, QString> ClipItem::addEffect(QDomElement effect) {
+QMap <QString, QString> ClipItem::addEffect(QDomElement effect, bool animate) {
     QMap <QString, QString> effectParams;
+    /*QDomDocument doc;
+    doc.appendChild(doc.importNode(effect, true));
+    kDebug() << "///////  CLIP ADD EFFECT: "<< doc.toString();*/
     m_effectList.append(effect);
     effectParams["tag"] = effect.attribute("tag");
     effectParams["kdenlive_ix"] = effect.attribute("kdenlive_ix");
@@ -582,7 +585,7 @@ QMap <QString, QString> ClipItem::addEffect(QDomElement effect) {
             effectParams[e.attribute("name")] =  QString::number(effectParams[e.attribute("name")].toDouble() / e.attribute("factor").toDouble());
         }
     }
-    flashClip();
+    if (animate) flashClip();
     update(boundingRect());
     return effectParams;
 }
index 992a8f8158ccab414dd5df5c69c9441c06f59e85..64dde38a6107e4c798371e7c7dd40808c704419f 100644 (file)
@@ -58,7 +58,7 @@ public:
     /** Give a string list of the clip's effect names */
     QStringList effectNames();
     /** Add an effect to the clip and return the parameters that will be passed to Mlt */
-    QMap <QString, QString> addEffect(QDomElement effect);
+    QMap <QString, QString> addEffect(QDomElement effect, bool animate = true);
     /** Get the effect parameters that will be passed to Mlt */
     QMap <QString, QString> getEffectArgs(QDomElement effect);
     /** Delete effect with id index */
index f17de756e8eeb6aee784a09e68b430dab85aa4ca..9e0bad5cb489675fd4cb93a5b44e2d5de3d77f8e 100644 (file)
@@ -45,7 +45,7 @@ QMap <QString, QString> EffectsList::effect(const QString & name) {
     return filter;
 }
 
-QDomElement EffectsList::getEffectByName(const QString & name) {
+QDomElement EffectsList::getEffectByName(const QString & name) const {
     QString effectName;
     for (int i = 0; i < this->size(); ++i) {
         QDomElement effect =  this->at(i);
@@ -64,6 +64,23 @@ QDomElement EffectsList::getEffectByName(const QString & name) {
     return QDomElement();
 }
 
+QDomElement EffectsList::getEffectByTag(const QString & tag) const {
+    QString effectName;
+    for (int i = 0; i < this->size(); ++i) {
+        QDomElement effect =  this->at(i);
+        if (effect.attribute("tag") == tag) {
+            QDomNodeList params = effect.elementsByTagName("parameter");
+            for (int i = 0; i < params.count(); i++) {
+                QDomElement e = params.item(i).toElement();
+                e.setAttribute("value", e.attribute("default"));
+            }
+            return effect;
+        }
+    }
+
+    return QDomElement();
+}
+
 QStringList EffectsList::effectNames() {
     QStringList list;
     for (int i = 0; i < this->size(); ++i) {
index 3a16b835d5a094d25555094a5641376138f17146..a51bf521732e9fbd26cce5f8d6440e4d3c781ea0 100644 (file)
@@ -33,7 +33,8 @@ public:
     EffectsList();
     ~EffectsList();
     /** Returns an XML version of this Effect.*/
-    QDomElement getEffectByName(const QString & name);
+    QDomElement getEffectByName(const QString & name) const;
+    QDomElement getEffectByTag(const QString & tag) const;
     QStringList effectNames();
     QString getInfo(QString effectName);
     QMap <QString, QString> effect(const QString & name);
index 9c6ba89a276cb2b7f89b7d1b4404673e712bcbaa..cd02fd7213cfc8bcc62c1e5fbd56d770f56b39c9 100644 (file)
@@ -32,6 +32,7 @@
 #include "clipmanager.h"
 #include "customruler.h"
 #include "kdenlivedoc.h"
+#include "mainwindow.h"
 #include "customtrackview.h"
 
 TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
@@ -218,6 +219,7 @@ void TrackView::slotRebuildTrackHeaders() {
 
 int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool videotrack) {
     TrackInfo info;
+
     if (videotrack) {
         info.type = VIDEOTRACK;
         info.isMute = false;
@@ -233,12 +235,12 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool videotrack) {
     int trackTop = KdenliveSettings::trackheight() * ix;
     // parse track
     int position = 0;
-
     for (QDomNode n = xml.firstChild(); !n.isNull(); n = n.nextSibling()) {
         QDomElement elem = n.toElement();
         if (elem.tagName() == "blank") {
             position += elem.attribute("length").toInt();
         } else if (elem.tagName() == "entry") {
+           // Found a clip
             int in = elem.attribute("in").toInt();
             int id = elem.attribute("producer").toInt();
             DocClipBase *clip = m_doc->clipManager()->getClipById(id);
@@ -253,6 +255,52 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool videotrack) {
                 ClipItem *item = new ClipItem(clip, clipinfo, m_scale, m_doc->fps());
                 m_scene->addItem(item);
                 position += out;
+
+               // parse clip effects
+               for (QDomNode n2 = elem.firstChild(); !n2.isNull(); n2 = n2.nextSibling()) {
+                   QDomElement effect = n2.toElement();
+                   if (effect.tagName() == "filter") {
+                       // add effect to clip
+                       QString effecttag;
+                       QString effectindex;
+                       // Get effect tag & index
+                       for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
+                           // parse effect parameters
+                           QDomElement effectparam = n3.toElement();
+                           if (effectparam.attribute("name") == "tag") {
+                               effecttag = effectparam.text();
+                           }
+                           if (effectparam.attribute("name") == "kdenlive_ix") {
+                               effectindex = effectparam.text();
+                           }
+                       }
+
+                       // get effect standard tags
+                       QDomElement clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag);
+                       clipeffect.setAttribute("kdenlive_ix",effectindex);
+                       QDomNodeList clipeffectparams = clipeffect.childNodes();
+
+                       // adjust effect parameters
+                       for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
+                           // parse effect parameters
+                           QDomElement effectparam = n3.toElement();
+                           QString paramname = effectparam.attribute("name");
+                           QString paramvalue = effectparam.text();
+
+                           // try to find this parameter in the effect xml
+                           QDomElement e;
+                           for (int k = 0; k < clipeffectparams.count(); k++) {
+                               e = clipeffectparams.item(k).toElement();
+                               if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) {
+                                   e.setAttribute("value", paramvalue);
+                                   break;
+                               }
+                           }
+                       }
+                       item->addEffect(clipeffect, false);
+                   }
+               }
+
             } else kWarning() << "CANNOT INSERT CLIP " << id;
             //m_clipList.append(clip);
         }