]> git.sesse.net Git - kdenlive/commitdiff
Allow to offset effect parameters.
authorTill Theato <root@ttill.de>
Sat, 10 Sep 2011 23:41:52 +0000 (23:41 +0000)
committerTill Theato <root@ttill.de>
Sat, 10 Sep 2011 23:41:52 +0000 (23:41 +0000)
Offset will be added to values coming from MLT after the attribute "factor" is applied.

svn path=/trunk/kdenlive/; revision=5910

effects/README
src/clipitem.cpp
src/customtrackview.cpp
src/renderer.cpp
src/trackview.cpp

index fb5dc3e724d3fb72d489e5ebf165482462e442f1..4ee6646694cab05f7b986a68bb18efe15a6eb90e 100644 (file)
@@ -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
index f761acf6f0803c73a4f8d60a5eade977e679033f..e19af808e98995c6aa737c38485548489ead58e6 100644 (file)
@@ -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));
             }
         }
     }
index bb92463b9631b51ca2afedf05c5377d74821bb74..078edddad9e5f869ee19f58b572f928f7beb16c5 100644 (file)
@@ -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"));
             }
index 1b8d03247e0a166f2bd15a8f008aaa052812c81a..91251de4d9db1754a687e30d81b5d383e6b9f06c 100644 (file)
@@ -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<<" / "<<max<<", "<<y1<<", factor: "<<factor;
-                filter->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<<" / "<<max<<", "<<y1<<", factor: "<<factor;
-                    filter->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<QString, QString> 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 . ,
         }
 
index 471706eb505385c1043489299e25392f6fc278c9..01a9a4a671aee8793b37cd9060038109c5c95955 100644 (file)
@@ -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 {