]> git.sesse.net Git - kdenlive/blobdiff - src/trackview.cpp
Work on firewire capture: dv should work, you now get a captured file dialog when...
[kdenlive] / src / trackview.cpp
index 9f0a8b73ab3ded87f247acaf7228522a2273de59..ec26ff6359b8b94bdcec97664fd933b8e9af411b 100644 (file)
@@ -18,8 +18,6 @@
  ***************************************************************************/
 
 
-#include <QMouseEvent>
-#include <QStylePainter>
 #include <QScrollBar>
 
 #include <KDebug>
@@ -37,7 +35,7 @@
 #include "customtrackview.h"
 
 TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
-        : QWidget(parent), m_doc(doc), m_scale(1.0), m_projectTracks(0), m_currentZoom(4) {
+        : QWidget(parent), m_doc(doc), m_scale(1.0), m_projectTracks(0) {
 
     view = new Ui::TimeLine_UI();
     view->setupUi(this);
@@ -76,19 +74,16 @@ TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
     connect(m_trackview->verticalScrollBar(), SIGNAL(valueChanged(int)), view->headers_area->verticalScrollBar(), SLOT(setValue(int)));
     connect(m_trackview, SIGNAL(trackHeightChanged()), this, SLOT(slotRebuildTrackHeaders()));
 
-    parseDocument(doc->toXml());
+    parseDocument(m_doc->toXml());
 
     connect(m_trackview, SIGNAL(cursorMoved(int, int)), m_ruler, SLOT(slotCursorMoved(int, int)));
     connect(m_trackview->horizontalScrollBar(), SIGNAL(valueChanged(int)), m_ruler, SLOT(slotMoveRuler(int)));
     connect(m_trackview, SIGNAL(mousePosition(int)), this, SIGNAL(mousePosition(int)));
     connect(m_trackview, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotClipItemSelected(ClipItem*)));
     connect(m_trackview, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotTransitionItemSelected(Transition*)));
-    slotChangeZoom(m_currentZoom);
+    slotChangeZoom(m_doc->zoom());
 }
 
-int TrackView::currentZoom() const {
-    return m_currentZoom;
-}
 
 int TrackView::duration() const {
     return m_trackview->duration();
@@ -196,7 +191,7 @@ void TrackView::parseDocument(QDomDocument doc) {
         if (transitionAdd) {
             // Transition should be added to the scene
             ItemInfo transitionInfo;
-            QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service);
+            QDomElement base = MainWindow::transitions.getEffectByTag(mlt_service, QString());
 
             for (int k = 0; k < transitionparams.count(); k++) {
                 p = transitionparams.item(k).toElement();
@@ -209,8 +204,8 @@ void TrackView::parseDocument(QDomDocument doc) {
                             QDomElement e = params.item(i).toElement();
                             if (!e.isNull() && e.attribute("tag") == paramName) {
                                 if (e.attribute("type") == "double") {
-                                    QString factor = e.attribute("factor");
-                                    if (!factor.isEmpty()) {
+                                    QString factor = e.attribute("factor", "1");
+                                    if (factor != "1") {
                                         double val = paramValue.toDouble() * factor.toDouble();
                                         paramValue = QString::number(val);
                                     }
@@ -235,6 +230,14 @@ void TrackView::parseDocument(QDomDocument doc) {
         }
     }
 
+    // Add guides
+    QDomNodeList guides = doc.elementsByTagName("guide");
+    for (int i = 0; i < guides.count(); i++) {
+        e = guides.item(i).toElement();
+        const QString comment = e.attribute("comment");
+        const GenTime pos = GenTime(e.attribute("time").toDouble());
+        m_trackview->addGuide(pos, comment);
+    }
 
     m_trackview->setDuration(duration);
     kDebug() << "///////////  TOTAL PROJECT DURATION: " << duration;
@@ -256,10 +259,9 @@ void TrackView::moveCursorPos(int pos) {
 }
 
 void TrackView::slotChangeZoom(int factor) {
-
+    m_doc->setZoom(factor);
     m_ruler->setPixelPerMark(factor);
     m_scale = (double) FRAME_SIZE / m_ruler->comboScale[factor]; // m_ruler->comboScale[m_currentZoom] /
-    m_currentZoom = factor;
     m_trackview->setScale(m_scale);
 }
 
@@ -336,19 +338,23 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool videotrack) {
 
                 ItemInfo clipinfo;
                 clipinfo.startPos = GenTime(position, m_doc->fps());
-                clipinfo.endPos = clipinfo.startPos + GenTime(out - in, m_doc->fps());
+                clipinfo.endPos = clipinfo.startPos + GenTime(out - in + 1, m_doc->fps());
+                clipinfo.cropStart = GenTime(in, m_doc->fps());
                 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, GenTime(in, m_doc->fps()), m_scale, m_doc->fps());
+                ClipItem *item = new ClipItem(clip, clipinfo, m_scale, m_doc->fps());
                 m_scene->addItem(item);
-                position += (out - in);
+                clip->addReference();
+                position += (out - in + 1);
 
                 // parse clip effects
                 for (QDomNode n2 = elem.firstChild(); !n2.isNull(); n2 = n2.nextSibling()) {
                     QDomElement effect = n2.toElement();
                     if (effect.tagName() == "filter") {
+                        kDebug() << " * * * * * * * * * * ** CLIP EFF FND  * * * * * * * * * * *";
                         // add effect to clip
                         QString effecttag;
+                        QString effectid;
                         QString effectindex;
                         // Get effect tag & index
                         for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
@@ -356,17 +362,86 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool videotrack) {
                             QDomElement effectparam = n3.toElement();
                             if (effectparam.attribute("name") == "tag") {
                                 effecttag = effectparam.text();
-                            }
-                            if (effectparam.attribute("name") == "kdenlive_ix") {
+                            } else if (effectparam.attribute("name") == "kdenlive_id") {
+                                effectid = effectparam.text();
+                            } else if (effectparam.attribute("name") == "kdenlive_ix") {
                                 effectindex = effectparam.text();
                             }
                         }
 
                         // get effect standard tags
-                        QDomElement clipeffect = MainWindow::videoEffects.getEffectByTag(effecttag);
+                        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);
+
                         clipeffect.setAttribute("kdenlive_ix", effectindex);
                         QDomNodeList clipeffectparams = clipeffect.childNodes();
 
+                        if (MainWindow::videoEffects.hasKeyFrames(clipeffect)) {
+                            kDebug() << " * * * * * * * * * * ** CLIP EFF WITH KFR FND  * * * * * * * * * * *";
+                            // effect is key-framable, read all effects to retrieve keyframes
+                            double factor;
+                            QString starttag;
+                            QString endtag;
+                            QDomNodeList params = clipeffect.elementsByTagName("parameter");
+                            for (int i = 0; i < params.count(); i++) {
+                                QDomElement e = params.item(i).toElement();
+                                if (e.attribute("type") == "keyframe") {
+                                    starttag = e.attribute("starttag", "start");
+                                    endtag = e.attribute("endtag", "end");
+                                    factor = e.attribute("factor", "1").toDouble();
+                                    break;
+                                }
+                            }
+                            QString keyframes;
+                            int effectin = effect.attribute("in").toInt();
+                            int effectout = effect.attribute("out").toInt();
+                            double startvalue;
+                            double endvalue;
+                            for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
+                                // parse effect parameters
+                                QDomElement effectparam = n3.toElement();
+                                if (effectparam.attribute("name") == starttag)
+                                    startvalue = effectparam.text().toDouble() * factor;
+                                if (effectparam.attribute("name") == endtag)
+                                    endvalue = effectparam.text().toDouble() * factor;
+                            }
+                            // add first keyframe
+                            keyframes.append(QString::number(in + effectin) + ":" + QString::number(startvalue) + ";" + QString::number(in + effectout) + ":" + QString::number(endvalue) + ";");
+                            QDomNode lastParsedEffect;
+                            n2 = n2.nextSibling();
+                            bool continueParsing = true;
+                            for (; !n2.isNull() && continueParsing; n2 = n2.nextSibling()) {
+                                // parse all effects
+                                QDomElement kfreffect = n2.toElement();
+                                int effectout = kfreffect.attribute("out").toInt();
+
+                                for (QDomNode n4 = kfreffect.firstChild(); !n4.isNull(); n4 = n4.nextSibling()) {
+                                    // parse effect parameters
+                                    QDomElement subeffectparam = n4.toElement();
+                                    if (subeffectparam.attribute("name") == "kdenlive_ix" && subeffectparam.text() != effectindex) {
+                                        //We are not in the same effect, stop parsing
+                                        lastParsedEffect = n2.previousSibling();
+                                        continueParsing = false;
+                                        break;
+                                    } else if (subeffectparam.attribute("name") == endtag) {
+                                        endvalue = subeffectparam.text().toDouble() * factor;
+                                        break;
+                                    }
+                                }
+                                if (continueParsing) keyframes.append(QString::number(in + effectout) + ":" + QString::number(endvalue) + ";");
+                            }
+
+                            params = clipeffect.elementsByTagName("parameter");
+                            for (int i = 0; i < params.count(); i++) {
+                                QDomElement e = params.item(i).toElement();
+                                if (e.attribute("type") == "keyframe") e.setAttribute("keyframes", keyframes);
+                            }
+                            if (!continueParsing) {
+                                n2 = lastParsedEffect;
+                            }
+                        }
+
                         // adjust effect parameters
                         for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
                             // parse effect parameters
@@ -385,6 +460,7 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool videotrack) {
                             }
                         }
                         item->addEffect(clipeffect, false);
+                        item->effectsCounter();
                     }
                 }
 
@@ -417,4 +493,6 @@ const QString & TrackView::editMode() const {
     return m_editMode;
 }
 
+
+
 #include "trackview.moc"