From: Till Theato Date: Sat, 19 Jun 2010 06:53:37 +0000 (+0000) Subject: Fix handling of effects with multiple keyframable parameters during cut: X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=574472e8c2d42cc2828750920c9171ef7cc9c992;p=kdenlive Fix handling of effects with multiple keyframable parameters during cut: http://kdenlive.org/mantis/view.php?id=1658 svn path=/trunk/kdenlive/; revision=4526 --- diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 5e1a7503..1d428a57 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -309,9 +309,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; @@ -320,6 +325,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(); @@ -355,26 +362,32 @@ 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) { + e.setAttribute("keyframes", keyframes.at(keyframeParams)); + if (ix == m_selectedEffect && keyframeParams == 0) { m_keyframes.clear(); double max = e.attribute("max").toDouble(); double min = e.attribute("min").toDouble(); @@ -391,9 +404,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; } } } @@ -435,18 +447,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; } diff --git a/src/clipitem.h b/src/clipitem.h index 6ef64c16..27fc24d0 100644 --- a/src/clipitem.h +++ b/src/clipitem.h @@ -124,8 +124,16 @@ public: QDomElement selectedEffect(); int selectedEffectIndex() const; void initEffect(QDomElement effect, int diff = 0); - QString keyframes(const int index); - void setKeyframes(const int ix, const QString keyframes); + + /** @brief Gets all keyframes. + * @param index Number of the effect + * @return a list of strings of keyframes (one string per param) */ + QStringList keyframes(const int index); + + /** @brief Sets params with keyframes and updates the visible keyframes. + * @param ix Number of the effect + * @param keyframes a list of strings of keyframes (one string per param), which should be used */ + void setKeyframes(const int ix, const QStringList keyframes); void setEffectList(const EffectsList effectList); void setSpeed(const double speed, int strobe); double speed() const; @@ -135,6 +143,9 @@ public: GenTime speedIndependantCropDuration() const; const ItemInfo speedIndependantInfo() const; int hasEffect(const QString &tag, const QString &id) const; + + /** @brief Makes sure all keyframes are in the clip's cropped duration. + * @return Whether or not changes were made */ bool checkKeyFrames(); QPixmap startThumb() const; QPixmap endThumb() const; diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 181d24d6..de7e724e 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -1387,11 +1387,11 @@ void CustomTrackView::editItemDuration() void CustomTrackView::editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes) { - ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), track); + /*ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), track); if (clip) { clip->setKeyframes(index, keyframes); updateEffect(m_document->tracksCount() - clip->track(), clip->startPos(), clip->effectAt(index), index, false); - } else emit displayMessage(i18n("Cannot find clip with keyframe"), ErrorMessage); + } else emit displayMessage(i18n("Cannot find clip with keyframe"), ErrorMessage);*/ } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index be1fafa5..1dbdef51 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3432,7 +3432,8 @@ void MainWindow::slotChangePalette(QAction *action, const QString &themename) ((QWidget*)subchild)->setPalette(plt); } } - if (m_activeTimeline) m_activeTimeline->projectView()->updatePalette(); + if (m_activeTimeline) + m_activeTimeline->projectView()->updatePalette(); }