]> git.sesse.net Git - kdenlive/blobdiff - src/clipitem.cpp
Make the keyframe parameter which can be edited in timeline selectable
[kdenlive] / src / clipitem.cpp
index 39df20878d6c91fe8abe2427999786cd678dcc1e..e80e3fcd9a1d5c0fbc70f77ffbe34888b55a84c7 100644 (file)
@@ -61,17 +61,20 @@ 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;
     m_speedIndependantInfo = m_info;
-    m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * m_speed), m_fps);
-    m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * m_speed), m_fps);
+    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);
 
     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;
@@ -195,8 +198,10 @@ void ClipItem::setEffectList(const EffectsList effectList)
                     }
                 }
             }
-            if (fade > 0) m_startFade = fade;
-            else if (fade < 0) m_endFade = -fade;
+            if (fade > 0)
+                m_startFade = fade;
+            else if (fade < 0)
+                m_endFade = -fade;
         }
         setSelectedEffect(0);
     }
@@ -242,7 +247,7 @@ void ClipItem::initEffect(QDomElement effect, int diff)
             QString def = e.attribute("default");
             // Effect has a keyframe type parameter, we need to set the values
             if (e.attribute("keyframes").isEmpty()) {
-                e.setAttribute("keyframes", QString::number(cropStart().frames(m_fps)) + ':' + def + ';' + QString::number((cropStart() + cropDuration()).frames(m_fps) - 1) + ':' + def);
+                e.setAttribute("keyframes", QString::number(cropStart().frames(m_fps)) + ':' + def);
                 kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
                 //break;
             }
@@ -250,7 +255,7 @@ void ClipItem::initEffect(QDomElement effect, int diff)
     }
     if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
         if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
-            int end = (cropDuration() + cropStart()).frames(m_fps);
+            int end = (cropDuration() + cropStart()).frames(m_fps) - 1;
             int start = end;
             if (effect.attribute("id") == "fadeout") {
                 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
@@ -308,9 +313,14 @@ void ClipItem::initEffect(QDomElement effect, int diff)
 bool ClipItem::checkKeyFrames()
 {
     bool clipEffectsModified = false;
-    for (int ix = 0; ix < m_effectList.count(); ix ++) {
-        QString kfr = keyframes(ix);
-        if (!kfr.isEmpty()) {
+    // go through all effects this clip has
+    for (int ix = 0; ix < m_effectList.count(); ++ix) {
+        QStringList keyframeParams = keyframes(ix);
+        QStringList newKeyFrameParams;
+        bool effModified = false;
+
+        // go through all params which have keyframes
+        foreach(const QString &kfr, keyframeParams) {
             const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
             QStringList newKeyFrames;
             bool cutKeyFrame = false;
@@ -319,6 +329,8 @@ bool ClipItem::checkKeyFrames()
             double lastValue = -1;
             int start = cropStart().frames(m_fps);
             int end = (cropStart() + cropDuration()).frames(m_fps);
+
+            // go through all keyframes for one param
             foreach(const QString &str, keyframes) {
                 int pos = str.section(':', 0, 0).toInt();
                 double val = str.section(':', 1, 1).toDouble();
@@ -354,27 +366,34 @@ bool ClipItem::checkKeyFrames()
                 lastPos = pos;
                 lastValue = val;
             }
-            if (modified) {
-                // update KeyFrames
-                setKeyframes(ix, newKeyFrames.join(";"));
-                clipEffectsModified = true;
-            }
+
+            newKeyFrameParams.append(newKeyFrames.join(";"));
+            if (modified)
+                effModified = true;
+        }
+
+        if (effModified) {
+            // update KeyFrames
+            setKeyframes(ix, newKeyFrameParams);
+            clipEffectsModified = true;
         }
     }
     return clipEffectsModified;
 }
 
-void ClipItem::setKeyframes(const int ix, const QString keyframes)
+void ClipItem::setKeyframes(const int ix, const QStringList keyframes)
 {
     QDomElement effect = getEffectAt(ix);
     if (effect.attribute("disable") == "1") return;
     QDomNodeList params = effect.elementsByTagName("parameter");
+    int keyframeParams = 0;
     for (int i = 0; i < params.count(); i++) {
         QDomElement e = params.item(i).toElement();
-        if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
-            e.setAttribute("keyframes", keyframes);
-            if (ix == m_selectedEffect) {
+        if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && e.attribute("intimeline") == "1") {
+            e.setAttribute("keyframes", keyframes.at(keyframeParams));
+            if (ix == m_selectedEffect && keyframeParams == 0) {
                 m_keyframes.clear();
+                m_visibleParam = i;
                 double max = e.attribute("max").toDouble();
                 double min = e.attribute("min").toDouble();
                 m_keyframeFactor = 100.0 / (max - min);
@@ -390,9 +409,8 @@ void ClipItem::setKeyframes(const int ix, const QString keyframes)
                 if (m_keyframes.find(m_editedKeyframe) == m_keyframes.end()) m_editedKeyframe = -1;
                 if (m_keyframes.find(m_editedKeyframe) == m_keyframes.end()) m_editedKeyframe = -1;
                 update();
-                return;
             }
-            break;
+            ++keyframeParams;
         }
     }
 }
@@ -407,8 +425,9 @@ void ClipItem::setSelectedEffect(const int ix)
         if (effect.attribute("disable") != "1")
             for (int i = 0; i < params.count(); i++) {
                 QDomElement e = params.item(i).toElement();
-                if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
+                if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe") && e.attribute("intimeline") == "1") {
                     m_keyframes.clear();
+                    m_visibleParam = i;
                     double max = e.attribute("max").toDouble();
                     double min = e.attribute("min").toDouble();
                     m_keyframeFactor = 100.0 / (max - min);
@@ -434,18 +453,16 @@ void ClipItem::setSelectedEffect(const int ix)
     }
 }
 
-QString ClipItem::keyframes(const int index)
+QStringList ClipItem::keyframes(const int index)
 {
-    QString result;
+    QStringList result;
     QDomElement effect = effectAt(index);
     QDomNodeList params = effect.elementsByTagName("parameter");
 
     for (int i = 0; i < params.count(); i++) {
         QDomElement e = params.item(i).toElement();
-        if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
-            result = e.attribute("keyframes");
-            break;
-        }
+        if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe"))
+            result.append(e.attribute("keyframes"));
     }
     return result;
 }
@@ -456,23 +473,19 @@ void ClipItem::updateKeyframeEffect()
     QDomElement effect = getEffectAt(m_selectedEffect);
     if (effect.attribute("disable") == "1") return;
     QDomNodeList params = effect.elementsByTagName("parameter");
-
-    for (int i = 0; i < params.count(); i++) {
-        QDomElement e = params.item(i).toElement();
-        if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
-            QString keyframes;
-            if (m_keyframes.count() > 0) {
-                QMap<int, int>::const_iterator i = m_keyframes.constBegin();
-                while (i != m_keyframes.constEnd()) {
-                    keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
-                    ++i;
-                }
+    QDomElement e = params.item(m_visibleParam).toElement();
+
+    if (!e.isNull()) {
+        QString keyframes;
+        if (m_keyframes.count() > 0) {
+            QMap<int, int>::const_iterator i = m_keyframes.constBegin();
+            while (i != m_keyframes.constEnd()) {
+                keyframes.append(QString::number(i.key()) + ':' + QString::number(i.value()) + ';');
+                ++i;
             }
-            // Effect has a keyframe type parameter, we need to set the values
-            //kDebug() << ":::::::::::::::   SETTING EFFECT KEYFRAMES: " << keyframes;
-            e.setAttribute("keyframes", keyframes);
-            break;
         }
+        // Effect has a keyframe type parameter, we need to set the values
+        e.setAttribute("keyframes", keyframes);
     }
 }
 
@@ -503,11 +516,10 @@ void ClipItem::refreshClip(bool checkDuration)
                 if (m_info.cropStart > m_maxDuration) {
                     m_info.cropStart = GenTime();
                     m_info.cropDuration = qMin(m_info.cropDuration, m_maxDuration);
-                    updateRectGeometry();
                 } else {
                     m_info.cropDuration = m_maxDuration;
-                    updateRectGeometry();
                 }
+                updateRectGeometry();
             }
         }
     }
@@ -645,12 +657,7 @@ DocClipBase *ClipItem::baseClip() const
 
 QDomElement ClipItem::xml() const
 {
-    QDomElement xml = m_clip->toXML();
-    if (m_speed != 1.0) xml.setAttribute("speed", m_speed);
-    if (m_strobe > 1) xml.setAttribute("strobe", m_strobe);
-    if (m_audioOnly) xml.setAttribute("audio_only", 1);
-    else if (m_videoOnly) xml.setAttribute("video_only", 1);
-    return xml;
+    return itemXml();
 }
 
 QDomElement ClipItem::itemXml() const
@@ -739,6 +746,12 @@ void ClipItem::paint(QPainter *painter,
             QLineF l2(mapped.left() + m_startPix.width(), mapped.top(), mapped.left() + m_startPix.width(), mapped.bottom());
             painter->drawLine(l2);
         }
+        if (painter->matrix().m11() == FRAME_SIZE) {
+            int offset = (m_info.startPos - m_info.cropStart).frames(m_fps);
+            int left = qMax((int) m_info.startPos.frames(m_fps) + 1, (int) mapToScene(exposed.left(), 0).x());
+            int right = qMin((int)(m_info.startPos + m_info.cropDuration).frames(m_fps) - 1, (int) mapToScene(exposed.right(), 0).x());
+            doGetIntraThumbs(painter, mapped.topLeft(), m_info.cropStart.frames(m_fps), left - offset, right - offset);
+        }
         painter->setPen(Qt::black);
     }
 
@@ -771,6 +784,7 @@ void ClipItem::paint(QPainter *painter,
         const int mappedEndPixel =  painter->matrix().map(QPointF(endpixel + cropLeft, 0)).x() - clipStart;
         cropLeft = cropLeft * scale;
 
+
         if (channels >= 1) {
             emit prepareAudioThumb(scale, mappedStartPixel, mappedEndPixel, channels);
         }
@@ -838,7 +852,7 @@ void ClipItem::paint(QPainter *painter,
         pen.setStyle(Qt::DotLine);
 
         for (; it != markers.end(); ++it) {
-            pos = GenTime((int)((*it).time().frames(m_fps) / m_speed + 0.5), m_fps) - cropStart();
+            pos = GenTime((int)((*it).time().frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
             if (pos > GenTime()) {
                 if (pos > cropDuration()) break;
                 QLineF l(rect().x() + pos.frames(m_fps), rect().y(), rect().x() + pos.frames(m_fps), rect().bottom());
@@ -969,8 +983,7 @@ QList <GenTime> ClipItem::snapMarkers() const
     GenTime pos;
 
     for (int i = 0; i < markers.size(); i++) {
-
-        pos = GenTime((int)(markers.at(i).frames(m_fps) / m_speed + 0.5), m_fps) - cropStart();
+        pos = GenTime((int)(markers.at(i).frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
         if (pos > GenTime()) {
             if (pos > cropDuration()) break;
             else snaps.append(pos + startPos());
@@ -986,7 +999,7 @@ QList <CommentedTime> ClipItem::commentedSnapMarkers() const
     GenTime pos;
 
     for (int i = 0; i < markers.size(); i++) {
-        pos = GenTime((int)(markers.at(i).time().frames(m_fps) / m_speed + 0.5), m_fps) - cropStart();
+        pos = GenTime((int)(markers.at(i).time().frames(m_fps) / qAbs(m_speed) + 0.5), m_fps) - cropStart();
         if (pos > GenTime()) {
             if (pos > cropDuration()) break;
             else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment()));
@@ -1150,13 +1163,13 @@ void ClipItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
 }
 */
 
-void ClipItem::resizeStart(int posx, bool)
+void ClipItem::resizeStart(int posx, bool /*size*/)
 {
     bool sizeLimit = false;
     if (clipType() != IMAGE && clipType() != COLOR && clipType() != TEXT) {
-       const int min = (startPos() - cropStart()).frames(m_fps);
-       if (posx < min) posx = min;
-       sizeLimit = true;
+        const int min = (startPos() - cropStart()).frames(m_fps);
+        if (posx < min) posx = min;
+        sizeLimit = true;
     }
 
     if (posx == startPos().frames(m_fps)) return;
@@ -1165,8 +1178,8 @@ void ClipItem::resizeStart(int posx, bool)
 
     // set speed independant info
     m_speedIndependantInfo = m_info;
-    m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * m_speed), m_fps);
-    m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * m_speed), m_fps);
+    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);
 
     if ((int) cropStart().frames(m_fps) != previous) {
         if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
@@ -1186,8 +1199,8 @@ void ClipItem::resizeEnd(int posx)
 
     // set speed independant info
     m_speedIndependantInfo = m_info;
-    m_speedIndependantInfo.cropStart = GenTime((int)(m_info.cropStart.frames(m_fps) * m_speed), m_fps);
-    m_speedIndependantInfo.cropDuration = GenTime((int)(m_info.cropDuration.frames(m_fps) * m_speed), m_fps);
+    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);
 
     if ((int) cropDuration().frames(m_fps) != previous) {
         if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
@@ -1199,12 +1212,13 @@ void ClipItem::resizeEnd(int posx)
 
 bool ClipItem::checkEffectsKeyframesPos(const int previous, const int current, bool fromStart)
 {
-    bool modified = false;
+    bool effModified = false;
     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(i).toElement();
+            bool modified = false;
+            QDomElement e = params.item(j).toElement();
             if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
                 // parse keyframes and adjust values
                 const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
@@ -1215,16 +1229,19 @@ bool ClipItem::checkEffectsKeyframesPos(const int previous, const int current, b
                     pos = str.section(':', 0, 0).toInt();
                     val = str.section(':', 1, 1).toDouble();
                     if (pos == previous) {
+                        // first or last keyframe
                         kfr[current] = val;
                         modified = true;
                     } else {
                         if ((fromStart && pos >= current) || (!fromStart && pos <= current)) {
+                            // only keyframes in range
                             kfr[pos] = val;
                             modified = true;
                         }
                     }
                 }
                 if (modified) {
+                    effModified = true;
                     QString newkfr;
                     QMap<int, double>::const_iterator k = kfr.constBegin();
                     while (k != kfr.constEnd()) {
@@ -1232,13 +1249,12 @@ bool ClipItem::checkEffectsKeyframesPos(const int previous, const int current, b
                         ++k;
                     }
                     e.setAttribute("keyframes", newkfr);
-                    break;
                 }
             }
         }
     }
-    if (modified && m_selectedEffect >= 0) setSelectedEffect(m_selectedEffect);
-    return modified;
+    if (effModified && m_selectedEffect >= 0) setSelectedEffect(m_selectedEffect);
+    return effModified;
 }
 
 //virtual
@@ -1396,11 +1412,16 @@ EffectsParameterList ClipItem::addEffect(const QDomElement effect, bool /*animat
     if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
     if (effect.hasAttribute("disable")) parameters.addParam("disable", effect.attribute("disable"));
 
-
     QString effectId = effect.attribute("id");
     if (effectId.isEmpty()) effectId = effect.attribute("tag");
     parameters.addParam("id", effectId);
 
+    // special case: the affine effect needs in / out points
+    if (effectId == "pan_zoom") {
+        parameters.addParam("in", QString::number(cropStart().frames(m_fps)));
+        parameters.addParam("out", QString::number((cropStart() + cropDuration()).frames(m_fps)));
+    }
+
     QDomNodeList params = effect.elementsByTagName("parameter");
     int fade = 0;
     for (int i = 0; i < params.count(); i++) {
@@ -1411,8 +1432,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);
                     }
                 }
@@ -1500,70 +1521,6 @@ EffectsParameterList ClipItem::addEffect(const QDomElement effect, bool /*animat
     return parameters;
 }
 
-EffectsParameterList ClipItem::getEffectArgs(const QDomElement effect)
-{
-    EffectsParameterList parameters;
-    parameters.addParam("tag", effect.attribute("tag"));
-    parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
-    parameters.addParam("id", effect.attribute("id"));
-    if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
-    if (effect.hasAttribute("disable")) parameters.addParam("disable", effect.attribute("disable"));
-
-    QDomNodeList params = effect.elementsByTagName("parameter");
-    for (int i = 0; i < params.count(); i++) {
-        QDomElement e = params.item(i).toElement();
-        //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
-        if (e.attribute("type") == "simplekeyframe") {
-
-            QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
-            double factor = e.attribute("factor", "1").toDouble();
-            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;
-                values[j] = pos + "=" + QString::number(val);
-            }
-            // kDebug() << "/ / / /SENDING KEYFR:" << values;
-            parameters.addParam(e.attribute("name"), values.join(";"));
-            /*parameters.addParam(e.attribute("name"), e.attribute("keyframes").replace(":", "="));
-            parameters.addParam("max", e.attribute("max"));
-            parameters.addParam("min", e.attribute("min"));
-            parameters.addParam("factor", e.attribute("factor", "1"));*/
-        } else if (e.attribute("type") == "keyframe") {
-            kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE";
-            parameters.addParam("keyframes", e.attribute("keyframes"));
-            parameters.addParam("max", e.attribute("max"));
-            parameters.addParam("min", e.attribute("min"));
-            parameters.addParam("factor", e.attribute("factor", "1"));
-            parameters.addParam("starttag", e.attribute("starttag", "start"));
-            parameters.addParam("endtag", e.attribute("endtag", "end"));
-        } else if (e.attribute("namedesc").contains(';')) {
-            QString format = e.attribute("format");
-            QStringList separators = format.split("%d", QString::SkipEmptyParts);
-            QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
-            QString neu;
-            QTextStream txtNeu(&neu);
-            if (values.size() > 0)
-                txtNeu << (int)values[0].toDouble();
-            for (int i = 0; i < separators.size() && i + 1 < values.size(); i++) {
-                txtNeu << separators[i];
-                txtNeu << (int)(values[i+1].toDouble());
-            }
-            parameters.addParam("start", neu);
-        } else {
-            if (e.attribute("factor", "1") != "1") {
-                double fact;
-                if (e.attribute("factor").startsWith('%')) {
-                    fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor"));
-                } else fact = e.attribute("factor", "1").toDouble();
-                parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / fact));
-            } else {
-                parameters.addParam(e.attribute("name"), e.attribute("value"));
-            }
-        }
-    }
-    return parameters;
-}
-
 void ClipItem::deleteEffect(QString index)
 {
     bool needRepaint = false;
@@ -1618,17 +1575,19 @@ int ClipItem::strobe() const
 void ClipItem::setSpeed(const double speed, const int strobe)
 {
     m_speed = speed;
+    if (m_speed <= 0 && m_speed > -1)
+        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) + '%';
-    m_info.cropStart = GenTime((int)(m_speedIndependantInfo.cropStart.frames(m_fps) / m_speed + 0.5), m_fps);
-    m_info.cropDuration = GenTime((int)(m_speedIndependantInfo.cropDuration.frames(m_fps) / m_speed + 0.5), m_fps);
+    m_info.cropStart = GenTime((int)(m_speedIndependantInfo.cropStart.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
+    m_info.cropDuration = GenTime((int)(m_speedIndependantInfo.cropDuration.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
     //update();
 }
 
 GenTime ClipItem::maxDuration() const
 {
-    return GenTime((int)(m_maxDuration.frames(m_fps) / m_speed + 0.5), m_fps);
+    return GenTime((int)(m_maxDuration.frames(m_fps) / qAbs(m_speed) + 0.5), m_fps);
 }
 
 GenTime ClipItem::speedIndependantCropStart() const
@@ -1720,24 +1679,33 @@ void ClipItem::insertKeyframe(QDomElement effect, int pos, int val)
     QDomNodeList params = effect.elementsByTagName("parameter");
     for (int i = 0; i < params.count(); i++) {
         QDomElement e = params.item(i).toElement();
-        QString kfr = e.attribute("keyframes");
-        const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
-        QStringList newkfr;
-        bool added = false;
-        foreach(const QString &str, keyframes) {
-            int kpos = str.section(':', 0, 0).toInt();
-            double newval = str.section(':', 1, 1).toDouble();
-            if (kpos < pos) {
-                newkfr.append(str);
-            } else if (!added) {
-                if (i == 0) newkfr.append(QString::number(pos) + ":" + QString::number(val));
-                else newkfr.append(QString::number(pos) + ":" + QString::number(newval));
-                if (kpos > pos) newkfr.append(str);
-                added = true;
-            } else newkfr.append(str);
+        if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
+            QString kfr = e.attribute("keyframes");
+            const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
+            QStringList newkfr;
+            bool added = false;
+            foreach(const QString &str, keyframes) {
+                int kpos = str.section(':', 0, 0).toInt();
+                double newval = str.section(':', 1, 1).toDouble();
+                if (kpos < pos) {
+                    newkfr.append(str);
+                } else if (!added) {
+                    if (i == m_visibleParam)
+                        newkfr.append(QString::number(pos) + ":" + QString::number(val));
+                    else
+                        newkfr.append(QString::number(pos) + ":" + QString::number(newval));
+                    if (kpos > pos) newkfr.append(str);
+                    added = true;
+                } else newkfr.append(str);
+            }
+            if (!added) {
+                if (i == m_visibleParam)
+                    newkfr.append(QString::number(pos) + ":" + QString::number(val));
+                else
+                    newkfr.append(QString::number(pos) + ":" + e.attribute("default"));
+            }
+            e.setAttribute("keyframes", newkfr.join(";"));
         }
-        if (!added) newkfr.append(QString::number(pos) + ":" + QString::number(val));
-        e.setAttribute("keyframes", newkfr.join(";"));
     }
 }
 
@@ -1750,20 +1718,24 @@ void ClipItem::movedKeyframe(QDomElement effect, int oldpos, int newpos, double
     int end = (cropStart() + cropDuration()).frames(m_fps) - 1;
     for (int i = 0; i < params.count(); i++) {
         QDomElement e = params.item(i).toElement();
-        QString kfr = e.attribute("keyframes");
-        const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
-        QStringList newkfr;
-        foreach(const QString &str, keyframes) {
-            if (str.section(':', 0, 0).toInt() != oldpos) {
-                newkfr.append(str);
-            } else if (newpos != -1) {
-                newpos = qMax(newpos, start);
-                newpos = qMin(newpos, end);
-                if (i == 0) newkfr.append(QString::number(newpos) + ":" + QString::number(value));
-                else newkfr.append(QString::number(newpos) + ":" + str.section(':', 1, 1));
+        if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
+            QString kfr = e.attribute("keyframes");
+            const QStringList keyframes = kfr.split(';', QString::SkipEmptyParts);
+            QStringList newkfr;
+            foreach(const QString &str, keyframes) {
+                if (str.section(':', 0, 0).toInt() != oldpos) {
+                    newkfr.append(str);
+                } else if (newpos != -1) {
+                    newpos = qMax(newpos, start);
+                    newpos = qMin(newpos, end);
+                    if (i == m_visibleParam)
+                        newkfr.append(QString::number(newpos) + ":" + QString::number(value));
+                    else
+                        newkfr.append(QString::number(newpos) + ":" + str.section(':', 1, 1));
+                }
             }
+            e.setAttribute("keyframes", newkfr.join(";"));
         }
-        e.setAttribute("keyframes", newkfr.join(";"));
     }
 
     updateKeyframes(effect);
@@ -1775,7 +1747,11 @@ void ClipItem::updateKeyframes(QDomElement effect)
     m_keyframes.clear();
     // parse keyframes
     QDomNodeList params = effect.elementsByTagName("parameter");
-    QDomElement e = params.item(0).toElement();
+    QDomElement e = params.item(m_visibleParam).toElement();
+    if (e.attribute("intimeline") != "1") {
+        setSelectedEffect(m_selectedEffect);
+        return;
+    }
     const QStringList keyframes = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
     foreach(const QString &str, keyframes) {
         int pos = str.section(':', 0, 0).toInt();
@@ -1784,4 +1760,111 @@ void ClipItem::updateKeyframes(QDomElement effect)
     }
     if (!m_keyframes.contains(m_selectedKeyframe)) m_selectedKeyframe = -1;
 }
+
+void ClipItem::doGetIntraThumbs(QPainter *painter, const QPointF startPos, int offset, int start, int end)
+{
+    if (!m_clip->thumbProducer() || clipType() == COLOR) return;
+    if (scene() && scene()->views().isEmpty()) return;
+    CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
+    if (view == NULL) return;
+    const int theight = KdenliveSettings::trackheight();
+    const int twidth = FRAME_SIZE;
+
+    if (clipType() == IMAGE || clipType() == TEXT) {
+        for (int i = start; i <= end; i++)
+            painter->drawPixmap(startPos + QPointF(twidth *(i - offset), 0), m_startPix);
+    }
+    QPixmap p;
+    for (int i = start; i <= end; i++) {
+        if (!view->pixmapCache->find(m_clip->fileURL().path() + "%" + QString::number(i), p)) {
+            p = m_clip->thumbProducer()->extractImage(i, twidth, theight);
+            view->pixmapCache->insert(m_clip->fileURL().path() + "%" + QString::number(i), p);
+        }
+        painter->drawPixmap(startPos + QPointF(twidth *(i - offset), 0), p);
+    }
+}
+
+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"