From: Till Theato Date: Tue, 6 Sep 2011 21:15:48 +0000 (+0000) Subject: Update mechanism for effects. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=2612143ef0a28634d7ed05286cf2c0e2179ea06d;p=kdenlive Update mechanism for effects. A js file can contain an update function modifing a filter to work with the installed version of frei0r. Additionally updated frei0r_levels.xml to also work with version 0.2 of the filter and added an update file. TODO: test, document add update files for more filters. svn path=/trunk/kdenlive/; revision=5858 --- diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index 0a95eb79..0c7cd3ef 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -106,3 +106,5 @@ audiopan.xml rotoscoping.xml DESTINATION ${DATA_INSTALL_DIR}/kdenlive/effects) + +add_subdirectory(update) diff --git a/effects/frei0r_balanc0r.xml b/effects/frei0r_balanc0r.xml index 54f8b42f..37b45976 100644 --- a/effects/frei0r_balanc0r.xml +++ b/effects/frei0r_balanc0r.xml @@ -11,7 +11,7 @@ Green Tint - + White Balance Adjust the white balance / color temperature Dan Dennedy diff --git a/effects/frei0r_levels.xml b/effects/frei0r_levels.xml index 2c80efc8..bb4c14bd 100644 --- a/effects/frei0r_levels.xml +++ b/effects/frei0r_levels.xml @@ -1,8 +1,10 @@ - + + Levels Adjust levels Maksim Golovkin + Red,Green,Blue,Luma Channel @@ -29,4 +31,37 @@ Top Left,Top Right,Bottom Left,Bottom Right Histogram position - + + + Levels + Adjust levels + Maksim Golovkin + + + Red,Green,Blue,Luma + Channel + + + Input black level + + + Input white level + + + Gamma + + + Black output + + + White output + + + Show histogram + + + Top Left,Top Right,Bottom Left,Bottom Right + Histogram position + + + diff --git a/effects/update/CMakeLists.txt b/effects/update/CMakeLists.txt new file mode 100644 index 00000000..67af8114 --- /dev/null +++ b/effects/update/CMakeLists.txt @@ -0,0 +1,4 @@ +INSTALL(FILES + +frei0r_levels.js +DESTINATION ${DATA_INSTALL_DIR}/kdenlive/effects/update) diff --git a/effects/update/frei0r_levels.js b/effects/update/frei0r_levels.js new file mode 100644 index 00000000..279ae2fa --- /dev/null +++ b/effects/update/frei0r_levels.js @@ -0,0 +1,23 @@ + +function update(serviceVersion, effectVersion, effectString) { + var locale = new QLocale(); + var doc = new QDomDocument(); + doc.setContent(effectString); + for (var node = doc.documentElement().firstChild(); !node.isNull(); node = node.nextSibling()) { + var effectparam = node.toElement(); + if (effectparam.attribute("name") == "Channel" || effectparam.attribute("name") == "Histogram position") { + if (serviceVersion < effectVersion) { + // downgrade + if (effectVersion > 0.1) { + effectparam.firstChild().toText().setData(locale.toString(effectparam.text() * 10)); + } + } else { + // upgrade + if (effectVersion < 0.2) { + effectparam.firstChild().toText().setData(locale.toString(effectparam.text() / 10.)); + } + } + } + } + return doc.toString(); +} diff --git a/src/documentvalidator.cpp b/src/documentvalidator.cpp index d13fd99e..ce1c83ab 100644 --- a/src/documentvalidator.cpp +++ b/src/documentvalidator.cpp @@ -21,15 +21,20 @@ #include "documentvalidator.h" #include "definitions.h" #include "initeffects.h" +#include "mainwindow.h" #include #include #include #include +#include +#include #include #include #include +#include +#include #include @@ -178,6 +183,8 @@ bool DocumentValidator::validate(const double currentVersion) } + updateEffects(); + return true; } @@ -1021,3 +1028,75 @@ bool DocumentValidator::isModified() const { return m_modified; } + +void DocumentValidator::updateEffects() +{ + // WARNING: order by findDirs will determine which js file to use (in case multiple for the same filter exist) + QMap paths; + QMap scripts; + QStringList directories = KGlobal::dirs()->findDirs("appdata", "effects/update"); + foreach (const QString &directoryName, directories) { + QDir directory(directoryName); + QStringList fileList = directory.entryList(QStringList() << "*.js", QDir::Files); + foreach (const QString &fileName, fileList) { + QString identifier = fileName; + identifier.chop(3); + identifier.replace('_', '.'); + paths.insert(identifier, KUrl(directoryName + fileName)); + } + } + + QDomNodeList effects = m_doc.elementsByTagName("filter"); + + for(int i = 0; i < effects.count(); ++i) { + QDomElement effect = effects.at(i).toElement(); + QString effectId = EffectsList::property(effect, "kdenlive_id"); + QString effectTag = EffectsList::property(effect, "tag"); + QString effectVersionStr = EffectsList::property(effect, "version"); + double effectVersion = effectVersionStr.isNull() ? -1 : effectVersionStr.toDouble(); + + QDomElement effectDescr = MainWindow::customEffects.getEffectByTag(QString(), effectId); + if (effectDescr.isNull()) { + effectDescr = MainWindow::videoEffects.getEffectByTag(effectTag, effectId); + } + if (effectDescr.isNull()) { + effectDescr = MainWindow::audioEffects.getEffectByTag(effectTag, effectId); + } + if (!effectDescr.isNull()) { + double serviceVersion = -1; + QDomElement serviceVersionElem = effectDescr.firstChildElement("version"); + if (!serviceVersionElem.isNull()) { + serviceVersion = serviceVersionElem.text().toDouble(); + } + if (serviceVersion != effectVersion && paths.contains(effectId)) { + if (!scripts.contains(effectId)) { + QFile scriptFile(paths.value(effectId).path()); + if (!scriptFile.open(QIODevice::ReadOnly)) { + continue; + } + QScriptProgram scriptProgram(scriptFile.readAll()); + scriptFile.close(); + scripts.insert(effectId, scriptProgram); + } + + QDomDocument scriptDoc; + scriptDoc.appendChild(scriptDoc.importNode(effect, true)); + + QScriptEngine scriptEngine; + scriptEngine.importExtension("qt.core"); + scriptEngine.importExtension("qt.xml"); + scriptEngine.evaluate(scripts.value(effectId)); + QString effectString = scriptEngine.globalObject().property("update").call(QScriptValue(), QScriptValueList() << serviceVersion << effectVersion << scriptDoc.toString()).toString(); + + if (!effectString.isEmpty()) { + scriptDoc.setContent(effectString); + QDomNode updatedEffect = effect.ownerDocument().importNode(scriptDoc.documentElement(), true); + effect.parentNode().replaceChild(updatedEffect, effect); + // TODO: set version to avoid dependency on latest MLT + m_modified = true; + } + } + } + } +} + diff --git a/src/documentvalidator.h b/src/documentvalidator.h index a4427b7f..dd15c1e3 100644 --- a/src/documentvalidator.h +++ b/src/documentvalidator.h @@ -39,6 +39,7 @@ private: bool upgrade(double version, const double currentVersion); QStringList getInfoFromEffectName(const QString oldName); QString colorToString(const QColor& c); + void updateEffects(); }; #endif