]> git.sesse.net Git - kdenlive/commitdiff
When cutting a clip with keyframe effect, ensure that both parts of the clip get...
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 29 Oct 2008 23:51:55 +0000 (23:51 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 29 Oct 2008 23:51:55 +0000 (23:51 +0000)
http://www.kdenlive.org:80/mantis/view.php?id=227

svn path=/branches/KDE4/; revision=2598

src/abstractclipitem.cpp
src/abstractclipitem.h
src/clipitem.cpp
src/clipitem.h
src/customtrackview.cpp

index b1b7d6613dd782ffba530a8e51dbad3f904cbd68..87419b8f8b7c5100e9a9ffd3848d54c9a2ee4ffc 100644 (file)
@@ -97,7 +97,7 @@ void AbstractClipItem::resizeStart(int posx) {
     }
 }
 
-void AbstractClipItem::resizeEnd(int posx) {
+void AbstractClipItem::resizeEnd(int posx, bool updateKeyFrames) {
     GenTime durationDiff = GenTime(posx, m_fps) - endPos();
     if (durationDiff == GenTime()) return;
     //kDebug() << "-- RESCALE: CROP=" << m_cropStart << ", DIFF = " << durationDiff;
index f23dea01843e1ff5839a5230bbf8bff59bcee841..7b7d60e8e2430210938e9a768d817433581eaf76 100644 (file)
@@ -48,7 +48,7 @@ public:
     virtual int track() const ;
     virtual GenTime cropStart() const ;
     virtual void resizeStart(int posx);
-    virtual void resizeEnd(int posx);
+    virtual void resizeEnd(int posx, bool updateKeyFrames = true);
     virtual GenTime duration() const;
     virtual double fps() const;
     virtual GenTime maxDuration() const;
index e6a89cea0abc8d81addd2f0de6362a7ae824ac12..217467411ca2313502be670e70bd279f2b85b667 100644 (file)
@@ -150,6 +150,64 @@ void ClipItem::initEffect(QDomElement effect) {
     }
 }
 
+bool ClipItem::checkKeyFrames() {
+    bool clipEffectsModified = false;
+    for (int ix = 0; ix < m_effectList.count(); ix ++) {
+        QString kfr = keyframes(ix);
+        if (!kfr.isEmpty()) {
+            const QStringList keyframes = kfr.split(";", QString::SkipEmptyParts);
+            QStringList newKeyFrames;
+            bool cutKeyFrame = false;
+            bool modified = false;
+            int lastPos = -1;
+            double lastValue = -1;
+            int start = m_cropStart.frames(m_fps);
+            int end = (m_cropStart + m_cropDuration).frames(m_fps);
+            foreach(const QString str, keyframes) {
+                int pos = str.section(":", 0, 0).toInt();
+                double val = str.section(":", 1, 1).toDouble();
+                if (pos - start < 0) {
+                    // a keyframe is defined before the start of the clip
+                    cutKeyFrame = true;
+                } else if (cutKeyFrame) {
+                    // create new keyframe at clip start, calculate interpolated value
+                    if (pos > start) {
+                        int diff = pos - lastPos;
+                        double ratio = (double)(start - lastPos) / diff;
+                        double newValue = lastValue + (val - lastValue) * ratio;
+                        newKeyFrames.append(QString::number(start) + ":" + QString::number(newValue));
+                        modified = true;
+                    }
+                    cutKeyFrame = false;
+                }
+                if (!cutKeyFrame) {
+                    if (pos > end) {
+                        // create new keyframe at clip end, calculate interpolated value
+                        int diff = pos - lastPos;
+                        if (diff != 0) {
+                            double ratio = (double)(end - lastPos) / diff;
+                            double newValue = lastValue + (val - lastValue) * ratio;
+                            newKeyFrames.append(QString::number(end) + ":" + QString::number(newValue));
+                            modified = true;
+                        }
+                        break;
+                    } else {
+                        newKeyFrames.append(QString::number(pos) + ":" + QString::number(val));
+                    }
+                }
+                lastPos = pos;
+                lastValue = val;
+            }
+            if (modified) {
+                // update KeyFrames
+                setKeyframes(ix, newKeyFrames.join(";"));
+                clipEffectsModified = true;
+            }
+        }
+    }
+    return clipEffectsModified;
+}
+
 void ClipItem::setKeyframes(const int ix, const QString keyframes) {
     QDomElement effect = effectAt(ix);
     if (effect.attribute("disabled") == "1") return;
@@ -654,8 +712,7 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos) {
     double maximumOffset;
     if (scale > 3) maximumOffset = 25 / scale;
     else maximumOffset = 6 / scale;
-    QMatrix matrix;
-    matrix.scale(scale, 0);
+
     //kDebug()<<"// Item rect: "<<rect.x()<<". pos. "<<pos.x()<<", scale: "<<scale<<", ratio: "<<qAbs((int)(pos.x() - rect.x())) / scale;
 
     if (qAbs((int)(pos.x() - (rect.x() + m_startFade))) < maximumOffset  && qAbs((int)(pos.y() - rect.y())) < 6) {
@@ -875,13 +932,13 @@ void ClipItem::resizeStart(int posx) {
     }
 }
 
-void ClipItem::resizeEnd(int posx) {
+void ClipItem::resizeEnd(int posx, bool updateKeyFrames) {
     const int max = (startPos() - cropStart() + maxDuration()).frames(m_fps) + 1;
     if (posx > max) posx = max;
     if (posx == endPos().frames(m_fps)) return;
     const int previous = (cropStart() + duration()).frames(m_fps);
     AbstractClipItem::resizeEnd(posx);
-    checkEffectsKeyframesPos(previous, (cropStart() + duration()).frames(m_fps), false);
+    if (updateKeyFrames) checkEffectsKeyframesPos(previous, (cropStart() + duration()).frames(m_fps), false);
     if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
         /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
         endThumbTimer->start(100);
@@ -899,9 +956,11 @@ void ClipItem::checkEffectsKeyframesPos(const int previous, const int current, b
                 // parse keyframes and adjust values
                 const QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
                 QMap <int, double> kfr;
+                int pos;
+                double val;
                 foreach(const QString str, keyframes) {
-                    int pos = str.section(":", 0, 0).toInt();
-                    double val = str.section(":", 1, 1).toDouble();
+                    pos = str.section(":", 0, 0).toInt();
+                    val = str.section(":", 1, 1).toDouble();
                     if (pos == previous) kfr[current] = val;
                     else {
                         if (fromStart && pos >= current) kfr[pos] = val;
index f66004ea08d2d549d6df7b185177d1674cf08a42..8a3d4a2c72e719ff116e54a736cfecd98c920ade 100644 (file)
@@ -47,7 +47,7 @@ public:
                        QWidget *);
     virtual int type() const;
     void resizeStart(int posx);
-    void resizeEnd(int posx);
+    void resizeEnd(int posx, bool updateKeyFrames = true);
     OPERATIONTYPE operationMode(QPointF pos);
     const QString &clipProducer() const;
     int clipType() const;
@@ -97,6 +97,7 @@ public:
     double speed() const;
     GenTime maxDuration() const;
     int hasEffect(const QString &tag, const QString &id) const;
+    bool checkKeyFrames();
 
 protected:
     //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
index cc73c8a6415d1db84bf457ae2d274bd7814fbf13..a354d5242a99fae59a429c7c9200714f295ba612 100644 (file)
@@ -961,8 +961,10 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut) {
         newPos.track = info.track;
         ClipItem *dup = item->clone(newPos);
         kDebug() << "// REsizing item to: " << cutPos;
-        item->resizeEnd(cutPos);
+        item->resizeEnd(cutPos, false);
         scene()->addItem(dup);
+        if (item->checkKeyFrames()) slotRefreshEffects(item);
+        if (dup->checkKeyFrames()) slotRefreshEffects(dup);
         item->baseClip()->addReference();
         m_document->updateClip(item->baseClip()->getId());
         kDebug() << "/////////  CUTTING CLIP RESULT: (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), DUP: (" << dup->startPos().frames(25) << "-" << dup->endPos().frames(25) << ")" << ", CUT: " << cutTime.frames(25);
@@ -1055,7 +1057,7 @@ void CustomTrackView::addTransition(ItemInfo transitionInfo, int endTrack, QDomE
     Transition *tr = new Transition(transitionInfo, endTrack, m_document->fps(), params);
     scene()->addItem(tr);
 
-    //kDebug() << "---- ADDING transition " << e.attribute("tag") << ", on tracks " << m_scene->m_tracksList.count() - e.attribute("transition_track").toInt() << " / " << getPreviousVideoTrack(e.attribute("transition_track").toInt());
+    //kDebug() << "---- ADDING transition " << params.attribute("value");
     m_document->renderer()->mltAddTransition(tr->transitionTag(), endTrack, m_scene->m_tracksList.count() - transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, tr->toXML());
     m_document->setModified(true);
 }