From a2dbc4c8a5fcee4af6956ca6b4c314f79ea11394 Mon Sep 17 00:00:00 2001 From: Till Theato Date: Sat, 10 Sep 2011 23:41:52 +0000 Subject: [PATCH] Allow to offset effect parameters. Offset will be added to values coming from MLT after the attribute "factor" is applied. svn path=/trunk/kdenlive/; revision=5910 --- effects/README | 3 ++- src/clipitem.cpp | 15 ++++++++++----- src/customtrackview.cpp | 13 +++++++++---- src/renderer.cpp | 12 +++++++----- src/trackview.cpp | 30 ++++++++++++++++++------------ 5 files changed, 46 insertions(+), 27 deletions(-) diff --git a/effects/README b/effects/README index fb5dc3e7..4ee66466 100644 --- a/effects/README +++ b/effects/README @@ -57,7 +57,8 @@ The rest: - number - represented by a slider - additional parameter attributes: - - "factor": (optional) values coming from MLT will be multiplied with factor, values from the GUI divided by factor + - "factor": (optional) values coming from MLT will be multiplied with factor + - "offset": (optional) will be added to values coming from MLT after "factor" is applied - "min": smallest value possible (after multiplying with "factor") - "max": largest value possible (after multiplying with "factor") - "suffix": (optional) displayed unit of the values diff --git a/src/clipitem.cpp b/src/clipitem.cpp index f761acf6..e19af808 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -1403,10 +1403,11 @@ EffectsParameterList ClipItem::addEffect(const QDomElement effect, bool /*animat if (e.attribute("type") == "simplekeyframe") { QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts); double factor = locale.toDouble(e.attribute("factor", "1")); - if (factor != 1) { + double offset = e.attribute("offset", "0").toDouble(); + if (factor != 1 || offset != 0) { for (int j = 0; j < values.count(); j++) { QString pos = values.at(j).section(':', 0, 0); - double val = locale.toDouble(values.at(j).section(':', 1, 1)) / factor; + double val = (locale.toDouble(values.at(j).section(':', 1, 1)) - offset) / factor; values[j] = pos + "=" + locale.toString(val); } } @@ -1419,9 +1420,10 @@ EffectsParameterList ClipItem::addEffect(const QDomElement effect, bool /*animat parameters.addParam("max", e.attribute("max")); parameters.addParam("min", e.attribute("min")); parameters.addParam("factor", e.attribute("factor", "1")); + parameters.addParam("offset", e.attribute("offset", "0")); parameters.addParam("starttag", e.attribute("starttag", "start")); parameters.addParam("endtag", e.attribute("endtag", "end")); - } else if (e.attribute("factor", "1") == "1") { + } else if (e.attribute("factor", "1") == "1" && e.attribute("offset", "0") == "0") { parameters.addParam(e.attribute("name"), e.attribute("value")); // check if it is a fade effect @@ -1470,8 +1472,11 @@ EffectsParameterList ClipItem::addEffect(const QDomElement effect, bool /*animat double fact; if (e.attribute("factor").contains('%')) { fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor")); - } else fact = locale.toDouble(e.attribute("factor", "1")); - parameters.addParam(e.attribute("name"), locale.toString(locale.toDouble(e.attribute("value")) / fact)); + } else { + fact = locale.toDouble(e.attribute("factor", "1")); + } + double offset = e.attribute("offset", "0").toDouble(); + parameters.addParam(e.attribute("name"), locale.toString((locale.toDouble(e.attribute("value")) - offset) / fact)); } } } diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index bb92463b..078eddda 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -6586,9 +6586,10 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement &effect) QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts); double factor = e.attribute("factor", "1").toDouble(); + double offset = e.attribute("offset", "0").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; + double val = (values.at(j).section(':', 1, 1).toDouble() - offset) / factor; values[j] = pos + "=" + locale.toString(val); } // kDebug() << "/ / / /SENDING KEYFR:" << values; @@ -6603,6 +6604,7 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement &effect) parameters.addParam("max", e.attribute("max")); parameters.addParam("min", e.attribute("min")); parameters.addParam("factor", e.attribute("factor", "1")); + parameters.addParam("offset", e.attribute("offset", "0")); parameters.addParam("starttag", e.attribute("starttag", "start")); parameters.addParam("endtag", e.attribute("endtag", "end")); } else if (e.attribute("namedesc").contains(';')) { @@ -6619,12 +6621,15 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement &effect) } parameters.addParam("start", neu); } else { - if (e.attribute("factor", "1") != "1") { + if (e.attribute("factor", "1") != "1" || e.attribute("offset", "0") != "0") { double fact; if (e.attribute("factor").contains('%')) { fact = ProfilesDialog::getStringEval(m_document->mltProfile(), e.attribute("factor")); - } else fact = e.attribute("factor", "1").toDouble(); - parameters.addParam(e.attribute("name"), locale.toString(e.attribute("value").toDouble() / fact)); + } else { + fact = e.attribute("factor", "1").toDouble(); + } + double offset = e.attribute("offset", "0").toDouble(); + parameters.addParam(e.attribute("name"), locale.toString((e.attribute("value").toDouble() - offset) / fact)); } else { parameters.addParam(e.attribute("name"), e.attribute("value")); } diff --git a/src/renderer.cpp b/src/renderer.cpp index 1b8d0324..91251de4 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -2472,12 +2472,14 @@ bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int //double max = params.paramValue("max").toDouble(); double min = params.paramValue("min").toDouble(); double factor = params.paramValue("factor", "1").toDouble(); + double paramOffset = params.paramValue("offset", "0").toDouble(); params.removeParam("starttag"); params.removeParam("endtag"); params.removeParam("keyframes"); params.removeParam("min"); params.removeParam("max"); params.removeParam("factor"); + params.removeParam("offset"); int offset = 0; // Special case, only one keyframe, means we want a constant value if (keyFrames.count() == 1) { @@ -2491,7 +2493,7 @@ bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int } filter->set("in", x1); //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<set(starttag, m_locale.toString((min + y1) / factor).toUtf8().data()); + filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data()); service.attach(*filter); } } else for (int i = 0; i < keyFrames.size() - 1; ++i) { @@ -2511,8 +2513,8 @@ bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int filter->set("in", x1); filter->set("out", x2); //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<set(starttag, m_locale.toString((min + y1) / factor).toUtf8().data()); - filter->set(endtag, m_locale.toString((min + y2) / factor).toUtf8().data()); + filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data()); + filter->set(endtag, m_locale.toString(((min + y2) - paramOffset) / factor).toUtf8().data()); service.attach(*filter); offset = 1; } @@ -3599,8 +3601,8 @@ QMap Render::mltGetTransitionParamsFromXml(QDomElement xml) if (!e.attribute("value").isEmpty()) { map[name] = e.attribute("value"); } - if (e.attribute("type") != "addedgeometry" && !e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) { - map[name] = m_locale.toString(map.value(name).toDouble() / e.attribute("factor").toDouble()); + if (e.attribute("type") != "addedgeometry" && (e.attribute("factor", "1") != "1" || e.attribute("offset", "0") != "0")) { + map[name] = m_locale.toString((map.value(name).toDouble() - e.attribute("offset", "0").toDouble()) / e.attribute("factor", "1").toDouble()); //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . , } diff --git a/src/trackview.cpp b/src/trackview.cpp index 471706eb..01a9a4a6 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -360,13 +360,15 @@ void TrackView::parseDocument(QDomDocument doc) if (!e.isNull() && e.attribute("tag") == paramName) { if (e.attribute("type") == "double") { QString factor = e.attribute("factor", "1"); - if (factor != "1") { + double offset = e.attribute("offset", "0").toDouble(); + if (factor != "1" || offset != 0) { double fact; if (factor.contains('%')) { fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor); - } else fact = factor.toDouble(); - double val = paramValue.toDouble() * fact; - paramValue = QString::number(val); + } else { + fact = factor.toDouble(); + } + paramValue = QLocale().toString(offset + paramValue.toDouble() * fact); } } e.setAttribute("value", paramValue); @@ -792,6 +794,7 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo QString factor; QString starttag; QString endtag; + double offset = 0; QDomNodeList params = currenteffect.elementsByTagName("parameter"); for (int i = 0; i < params.count(); i++) { QDomElement e = params.item(i).toElement(); @@ -799,6 +802,7 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo starttag = e.attribute("starttag", "start"); endtag = e.attribute("endtag", "end"); factor = e.attribute("factor", "1"); + offset = e.attribute("offset", "0").toDouble(); break; } } @@ -808,17 +812,18 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo double startvalue = 0; double endvalue = 0; double fact; - if (factor.isEmpty()) fact = 1; - else if (factor.contains('%')) { + if (factor.contains('%')) { fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor); - } else fact = factor.toDouble(); + } else { + fact = factor.toDouble(); + } for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) { // parse effect parameters QDomElement effectparam = n3.toElement(); if (effectparam.attribute("name") == starttag) - startvalue = effectparam.text().toDouble() * fact; + startvalue = offset + effectparam.text().toDouble() * fact; if (effectparam.attribute("name") == endtag) - endvalue = effectparam.text().toDouble() * fact; + endvalue = offset + effectparam.text().toDouble() * fact; } // add first keyframe if (effectout <= effectin) { @@ -844,7 +849,7 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo continueParsing = false; break; } else if (subeffectparam.attribute("name") == endtag) { - endvalue = subeffectparam.text().toDouble() * fact; + endvalue = offset + subeffectparam.text().toDouble() * fact; break; } } @@ -892,18 +897,19 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo } else { fact = factor.toDouble(); } + double offset = e.attribute("offset", "0").toDouble(); if (type == "simplekeyframe") { QStringList kfrs = paramvalue.split(";"); for (int l = 0; l < kfrs.count(); l++) { QString fr = kfrs.at(l).section('=', 0, 0); double val = locale.toDouble(kfrs.at(l).section('=', 1, 1)); //kfrs[l] = fr + ":" + locale.toString((int)(val * fact)); - kfrs[l] = fr + ":" + QString::number((int) (val * fact)); + kfrs[l] = fr + ":" + QString::number((int) (offset + val * fact)); } e.setAttribute("keyframes", kfrs.join(";")); } else if (type == "double" || type == "constant") { bool ok; - e.setAttribute("value", locale.toDouble(paramvalue, &ok) * fact); + e.setAttribute("value", offset + locale.toDouble(paramvalue, &ok) * fact); if (!ok) e.setAttribute("value", paramvalue); } else { -- 2.39.2