]> git.sesse.net Git - kdenlive/blobdiff - src/clipitem.cpp
Show progress while loading project
[kdenlive] / src / clipitem.cpp
index c2cc136169d78842fb5af6646bfef19dd80c5905..b5791614e831521330c41372cb969fc936ae16dc 100644 (file)
@@ -61,7 +61,8 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, i
     setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1);
 
     // set speed independant info
-    if (m_speed <= 0 && m_speed > -1) m_speed = 1.0;
+    if (m_speed <= 0 && m_speed > -1)
+        m_speed = -1.0;
     m_speedIndependantInfo = m_info;
     m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * qAbs(m_speed)), m_fps);
     m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * qAbs(m_speed)), m_fps);
@@ -69,10 +70,11 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, i
     m_videoPix = KIcon("kdenlive-show-video").pixmap(QSize(16, 16));
     m_audioPix = KIcon("kdenlive-show-audio").pixmap(QSize(16, 16));
 
-    if (m_speed == 1.0) m_clipName = m_clip->name();
-    else {
+    if (m_speed == 1.0)
+        m_clipName = m_clip->name();
+    else
         m_clipName = m_clip->name() + " - " + QString::number(m_speed * 100, 'f', 0) + '%';
-    }
+
     m_producer = m_clip->getId();
     m_clipType = m_clip->clipType();
     //m_cropStart = info.cropStart;
@@ -1210,7 +1212,7 @@ void ClipItem::resizeEnd(int posx)
 }
 
 
-bool ClipItem::checkEffectsKeyframesPos(const int previous, const int current, bool fromStart, int renderWidth, int renderHeight)
+bool ClipItem::checkEffectsKeyframesPos(const int previous, const int current, bool fromStart)
 {
     bool effModified = false;
     for (int i = 0; i < m_effectList.count(); i++) {
@@ -1252,16 +1254,6 @@ bool ClipItem::checkEffectsKeyframesPos(const int previous, const int current, b
                     }
                     e.setAttribute("keyframes", newkfr);
                 }
-            } else if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) {
-                Mlt::Geometry geometry(e.attribute("value").toUtf8().data(), cropDuration().frames(fps()), renderWidth, renderHeight);
-
-                Mlt::GeometryItem item;
-                while (!geometry.next_key(&item, cropDuration().frames(fps()))) {
-                    geometry.remove(item.frame());
-                    modified = true;
-                }
-                e.setAttribute("value", geometry.serialise());
             }
         }
     }
@@ -1430,14 +1422,8 @@ EffectsParameterList ClipItem::addEffect(const QDomElement effect, bool /*animat
 
     // special case: the affine effect needs in / out points
     if (effectId == "pan_zoom") {
-        int start = cropStart().frames(m_fps);
-        int end = (cropStart() + cropDuration()).frames(m_fps);
-        if (start < 0) {
-            end -= start;
-            start = 0;
-        }
-        parameters.addParam("in", QString::number(start));
-        parameters.addParam("out", QString::number(end));
+        parameters.addParam("in", QString::number(cropStart().frames(m_fps)));
+        parameters.addParam("out", QString::number((cropStart() + cropDuration()).frames(m_fps)));
     }
 
     QDomNodeList params = effect.elementsByTagName("parameter");
@@ -1450,8 +1436,8 @@ EffectsParameterList ClipItem::addEffect(const QDomElement effect, bool /*animat
                 double factor = e.attribute("factor", "1").toDouble();
                 if (factor != 1) {
                     for (int j = 0; j < values.count(); j++) {
-                        QString pos = values.at(j).section(":", 0, 0);
-                        double val = values.at(j).section(":", 1, 1).toDouble() / factor;
+                        QString pos = values.at(j).section(':', 0, 0);
+                        double val = values.at(j).section(':', 1, 1).toDouble() / factor;
                         values[j] = pos + "=" + QString::number(val);
                     }
                 }
@@ -1594,7 +1580,7 @@ void ClipItem::setSpeed(const double speed, const int strobe)
 {
     m_speed = speed;
     if (m_speed <= 0 && m_speed > -1)
-        m_speed = 1.0;
+        m_speed = -1.0;
     m_strobe = strobe;
     if (m_speed == 1.0) m_clipName = baseClip()->name();
     else m_clipName = baseClip()->name() + " - " + QString::number(speed * 100, 'f', 0) + '%';
@@ -1785,5 +1771,87 @@ void ClipItem::doGetIntraThumbs(QPainter *painter, const QPointF startPos, int o
     }
 }
 
+QList <int> ClipItem::updatePanZoom(int width, int height, int cut)
+{
+    QList <int> effectPositions;
+    for (int i = 0; i < m_effectList.count(); i++) {
+        QDomElement effect = m_effectList.at(i);
+        QDomNodeList params = effect.elementsByTagName("parameter");
+        for (int j = 0; j < params.count(); j++) {
+            QDomElement e = params.item(j).toElement();
+            if (e.isNull())
+                continue;
+            if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) {
+                effectPositions << i;
+
+                int in = cropStart().frames(fps());
+                int out = in + cropDuration().frames(fps());
+                int dur = out - in - 1;
+
+                effect.setAttribute("in", in);
+                effect.setAttribute("out", out);
+
+                Mlt::Geometry geometry(e.attribute("value").toUtf8().data(), dur, width, height);
+                Mlt::GeometryItem item;
+                bool endFrameAdded = false;
+                if (cut == 0) {
+                    while (!geometry.next_key(&item, dur)) {
+                        if (!endFrameAdded) {
+                            // add keyframe at the end with interpolated value
+
+                            // but only once ;)
+                            endFrameAdded = true;
+
+                            Mlt::GeometryItem endItem;
+                            Mlt::GeometryItem interp;
+                            geometry.fetch(&interp, dur - 1);
+                            endItem.frame(dur - 1);
+                            endItem.x(interp.x());
+                            endItem.y(interp.y());
+                            endItem.w(interp.w());
+                            endItem.h(interp.h());
+                            endItem.mix(interp.mix());
+                            geometry.insert(&endItem);
+                        }
+                        geometry.remove(item.frame());
+                    }
+                } else {
+                    Mlt::Geometry origGeometry(e.attribute("value").toUtf8().data(), dur, width, height);
+                    // remove keyframes before cut point
+                    while (!geometry.prev_key(&item, cut - 1) && item.frame() < cut)
+                        geometry.remove(item.frame());
+
+                    // add a keyframe at new pos 0
+                    origGeometry.fetch(&item, cut);
+                    item.frame(0);
+                    geometry.insert(&item);
+
+                    // move exisiting keyframes by -cut
+                    while (!origGeometry.next_key(&item, cut)) {
+                        geometry.remove(item.frame());
+                        origGeometry.remove(item.frame());
+                        item.frame(item.frame() - cut);
+                        geometry.insert(&item);
+                    }
+                    
+                }
+
+                e.setAttribute("value", geometry.serialise());
+            }
+        }
+    }
+
+    return effectPositions;
+}
+
+Mlt::Producer *ClipItem::getProducer(int track, bool trackSpecific)
+{
+    if (isAudioOnly())
+        return m_clip->audioProducer(track);
+    else if (isVideoOnly())
+        return m_clip->videoProducer();
+    else
+        return m_clip->producer(trackSpecific ? track : -1);
+}
 
 #include "clipitem.moc"