From 1bb5954abb1179a8cd75a3dbffec0911f297357e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sat, 14 Nov 2009 02:19:31 +0000 Subject: [PATCH] First draft for keyframes in frei0r effects svn path=/trunk/kdenlive/; revision=4121 --- src/clipitem.cpp | 48 ++++++++++++++++++++++++++++++++++------- src/effectslist.cpp | 11 ++++++++++ src/effectslist.h | 1 + src/effectstackedit.cpp | 2 +- src/trackview.cpp | 13 +++++++++-- 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 6835d419..d9d113fd 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -183,7 +183,7 @@ void ClipItem::initEffect(QDomElement effect, int diff) } } - if (!e.isNull() && e.attribute("type") == "keyframe") { + if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) { QString def = e.attribute("default"); // Effect has a keyframe type parameter, we need to set the values if (e.attribute("keyframes").isEmpty()) { @@ -316,7 +316,7 @@ void ClipItem::setKeyframes(const int ix, const QString keyframes) 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") { + if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) { e.setAttribute("keyframes", keyframes); if (ix == m_selectedEffect) { m_keyframes.clear(); @@ -349,7 +349,7 @@ void ClipItem::setSelectedEffect(const int ix) if (effect.attribute("disabled") != "1") for (int i = 0; i < params.count(); i++) { QDomElement e = params.item(i).toElement(); - if (!e.isNull() && e.attribute("type") == "keyframe") { + if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) { m_keyframes.clear(); double max = e.attribute("max").toDouble(); double min = e.attribute("min").toDouble(); @@ -381,7 +381,7 @@ QString ClipItem::keyframes(const int index) for (int i = 0; i < params.count(); i++) { QDomElement e = params.item(i).toElement(); - if (!e.isNull() && e.attribute("type") == "keyframe") { + if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) { result = e.attribute("keyframes"); break; } @@ -398,7 +398,7 @@ void ClipItem::updateKeyframeEffect() for (int i = 0; i < params.count(); i++) { QDomElement e = params.item(i).toElement(); - if (!e.isNull() && e.attribute("type") == "keyframe") { + if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) { QString keyframes; if (m_keyframes.count() > 1) { QMap::const_iterator i = m_keyframes.constBegin(); @@ -1111,7 +1111,7 @@ bool ClipItem::checkEffectsKeyframesPos(const int previous, const int current, b QDomNodeList params = effect.elementsByTagName("parameter"); for (int j = 0; j < params.count(); j++) { QDomElement e = params.item(i).toElement(); - if (e.attribute("type") == "keyframe") { + 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); QMap kfr; @@ -1308,7 +1308,22 @@ EffectsParameterList ClipItem::addEffect(const QDomElement effect, bool /*animat for (int i = 0; i < params.count(); i++) { QDomElement e = params.item(i).toElement(); if (!e.isNull()) { - if (e.attribute("type") == "keyframe") { + if (e.attribute("type") == "simplekeyframe") { + QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts); + 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; + values[j] = pos + "=" + QString::number(val); + } + } + parameters.addParam(e.attribute("name"), values.join(";")); + /*parameters.addParam("max", e.attribute("max")); + parameters.addParam("min", e.attribute("min")); + parameters.addParam("factor", );*/ + } + else if (e.attribute("type") == "keyframe") { parameters.addParam("keyframes", e.attribute("keyframes")); parameters.addParam("max", e.attribute("max")); parameters.addParam("min", e.attribute("min")); @@ -1403,7 +1418,24 @@ EffectsParameterList ClipItem::getEffectArgs(const QDomElement effect) 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") == "keyframe") { + if (e.attribute("type") == "simplekeyframe") { + kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE"; + QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts); + 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; + values[j] = pos + "=" + QString::number(val); + } + } + 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")); diff --git a/src/effectslist.cpp b/src/effectslist.cpp index 490f2f39..1b400ae6 100644 --- a/src/effectslist.cpp +++ b/src/effectslist.cpp @@ -150,6 +150,17 @@ bool EffectsList::hasKeyFrames(QDomElement effect) return false; } +// static +bool EffectsList::hasSimpleKeyFrames(QDomElement effect) +{ + QDomNodeList params = effect.elementsByTagName("parameter"); + for (int i = 0; i < params.count(); i++) { + QDomElement e = params.item(i).toElement(); + if (e.attribute("type") == "simplekeyframe") return true; + } + return false; +} + void EffectsList::clone(const EffectsList original) { setContent(original.toString()); diff --git a/src/effectslist.h b/src/effectslist.h index a9de689c..220174f0 100644 --- a/src/effectslist.h +++ b/src/effectslist.h @@ -51,6 +51,7 @@ public: void insert(int ix, QDomElement effect); void replace(int ix, QDomElement effect); static bool hasKeyFrames(QDomElement effect); + static bool hasSimpleKeyFrames(QDomElement effect); static void setParameter(QDomElement effect, const QString &name, const QString &value); static QString parameter(QDomElement effect, const QString &name); static void setProperty(QDomElement effect, const QString &name, const QString &value); diff --git a/src/effectstackedit.cpp b/src/effectstackedit.cpp index b57747e0..add62549 100644 --- a/src/effectstackedit.cpp +++ b/src/effectstackedit.cpp @@ -231,7 +231,7 @@ void EffectStackEdit::transferParamDesc(const QDomElement d, int in, int out) m_valueItems[paramName+"geometry"] = geo; connect(geo, SIGNAL(parameterChanged()), this, SLOT(collectAllParameters())); connect(geo, SIGNAL(seekToPos(int)), this, SLOT(slotSeekToPos(int))); - } else if (type == "keyframe") { + } else if (type == "keyframe" || type == "simplekeyframe") { // keyframe editor widget kDebug() << "min: " << m_in << ", MAX: " << m_out; KeyframeEdit *geo = new KeyframeEdit(pa, m_out - m_in - 1, pa.attribute("min").toInt(), pa.attribute("max").toInt(), m_timecode); diff --git a/src/trackview.cpp b/src/trackview.cpp index 70573a5d..16e0da31 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -689,7 +689,7 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked) QDomElement currenteffect = clipeffect.cloneNode().toElement(); currenteffect.setAttribute("kdenlive_ix", effectindex); QDomNodeList clipeffectparams = currenteffect.childNodes(); - + if (MainWindow::videoEffects.hasKeyFrames(currenteffect)) { //kDebug() << " * * * * * * * * * * ** CLIP EFF WITH KFR FND * * * * * * * * * * *"; // effect is key-framable, read all effects to retrieve keyframes @@ -792,7 +792,16 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked) if (factor.startsWith('%')) { fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor); } else fact = factor.toDouble(); - e.setAttribute("value", paramvalue.toDouble() * fact); + if (e.attribute("type") == "simplekeyframe") { + QStringList kfrs = paramvalue.split(";"); + for (int l = 0; l < kfrs.count(); l++) { + QString fr = kfrs.at(l).section("=", 0, 0); + double val = kfrs.at(l).section("=", 1, 1).toDouble(); + kfrs[l] = fr + ":" + QString::number((int) (val * fact)); + } + e.setAttribute("keyframes", kfrs.join(";")); + } + else e.setAttribute("value", paramvalue.toDouble() * fact); } else e.setAttribute("value", paramvalue); break; } -- 2.39.5