From d4b6dc2efbf65bdbbea25ff6c8c2df785895f570 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Wed, 20 Jun 2012 09:22:44 +0200 Subject: [PATCH] Fix keyframes not correctly updated when resizing clip --- src/clipitem.cpp | 25 ++++++++++++++++++------- src/clipitem.h | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/clipitem.cpp b/src/clipitem.cpp index fa7afdae..7b95d695 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -1931,7 +1931,10 @@ QMap ClipItem::adjustEffectsToDuration(int width, int height, int frame = EffectsList::parameter(effect, "frame").toInt(); EffectsList::setParameter(effect, "frame", QString::number(frame - diff)); continue; - } + } else if (effect.attribute("id") == "pan_zoom") { + effect.setAttribute("in", cropStart().frames(m_fps)); + effect.setAttribute("out", (cropStart() + cropDuration()).frames(m_fps) - 1); + } QDomNodeList params = effect.elementsByTagName("parameter"); for (int j = 0; j < params.count(); j++) { @@ -1945,7 +1948,7 @@ QMap ClipItem::adjustEffectsToDuration(int width, int height, } else if (type == "simplekeyframe" || type == "keyframe") { if (!effects.contains(i)) effects[i] = effect.cloneNode().toElement(); - updateNormalKeyframes(param); + updateNormalKeyframes(param, oldInfo); #ifdef USE_QJSON } else if (type == "roto-spline") { if (!effects.contains(i)) @@ -1960,16 +1963,25 @@ QMap ClipItem::adjustEffectsToDuration(int width, int height, return effects; } -bool ClipItem::updateNormalKeyframes(QDomElement parameter) +bool ClipItem::updateNormalKeyframes(QDomElement parameter, ItemInfo oldInfo) { int in = cropStart().frames(m_fps); int out = (cropStart() + cropDuration()).frames(m_fps) - 1; + int oldin = oldInfo.cropStart.frames(m_fps); QLocale locale; + bool keyFrameUpdated = false; const QStringList data = parameter.attribute("keyframes").split(';', QString::SkipEmptyParts); QMap keyframes; - foreach (QString keyframe, data) - keyframes[keyframe.section(':', 0, 0).toInt()] = locale.toDouble(keyframe.section(':', 1, 1)); + foreach (QString keyframe, data) { + int keyframepos = keyframe.section(':', 0, 0).toInt(); + // if keyframe was at clip start, update it + if (keyframepos == oldin) { + keyframepos = in; + keyFrameUpdated = true; + } + keyframes[keyframepos] = locale.toDouble(keyframe.section(':', 1, 1)); + } QMap::iterator i = keyframes.end(); @@ -2021,7 +2033,7 @@ bool ClipItem::updateNormalKeyframes(QDomElement parameter) ++i; } - if (startFound || endFound) { + if (startFound || endFound || keyFrameUpdated) { QString newkfr; QMap::const_iterator k = keyframes.constBegin(); while (k != keyframes.constEnd()) { @@ -2037,7 +2049,6 @@ bool ClipItem::updateNormalKeyframes(QDomElement parameter) void ClipItem::updateGeometryKeyframes(QDomElement effect, int paramIndex, int width, int height, ItemInfo oldInfo) { - QDomElement param = effect.elementsByTagName("parameter").item(paramIndex).toElement(); int offset = oldInfo.cropStart.frames(m_fps); QString data = param.attribute("value"); diff --git a/src/clipitem.h b/src/clipitem.h index a2317f42..ef81fe83 100644 --- a/src/clipitem.h +++ b/src/clipitem.h @@ -172,7 +172,7 @@ public: void movedKeyframe(QDomElement effect, int oldpos, int newpos, double value); void updateKeyframes(QDomElement effect); void updateGeometryKeyframes(QDomElement effect, int paramIndex, int width, int height, ItemInfo oldInfo); - bool updateNormalKeyframes(QDomElement parameter); + bool updateNormalKeyframes(QDomElement parameter, ItemInfo oldInfo); /** @brief Adjusts effects after a clip duration change. */ QMap adjustEffectsToDuration(int width, int height, ItemInfo oldInfo); -- 2.39.5