cleanup effects handling, move stuff to mlteffectscontroller

parent 78616e7b
......@@ -1512,7 +1512,7 @@ void Bin::addEffect(const QString &id, const QDomElement &effect)
}
else currentItem = m_rootFolder->clip(id);
if (!currentItem) return;
currentItem->addEffect(effect);
currentItem->addEffect(m_monitor->profileInfo(), effect);
m_monitor->refreshMonitor();
}
......
......@@ -566,9 +566,9 @@ void ProjectClip::addMarkers(QList <CommentedTime> &markers)
emit refreshClipDisplay();
}
void ProjectClip::addEffect(const QDomElement &effect)
void ProjectClip::addEffect(const ProfileInfo pInfo, const QDomElement &effect)
{
m_controller->addEffect(effect);
m_controller->addEffect(pInfo, effect);
bin()->editMasterEffect(m_controller);
}
......@@ -186,7 +186,7 @@ public:
bool deleteClipMarkers(QUndoCommand *groupCommand);
void addMarkers(QList <CommentedTime> &markers);
/** @brief Add an effect to bin clip. */
void addEffect(const QDomElement &effect);
void addEffect(const ProfileInfo pInfo, const QDomElement &effect);
public slots:
//TODO
......
......@@ -66,73 +66,6 @@ bool MltVideoProfile::operator!=(const MltVideoProfile &other) const {
return !(*this == other);
}
EffectInfo::EffectInfo() {isCollapsed = false; groupIndex = -1; groupIsCollapsed = false;}
QString EffectInfo::toString() const {
QStringList data;
// effect collapsed state: 0 = effect not collapsed, 1 = effect collapsed,
// 2 = group collapsed - effect not, 3 = group and effect collapsed
int collapsedState = (int) isCollapsed;
if (groupIsCollapsed) collapsedState += 2;
data << QString::number(collapsedState) << QString::number(groupIndex) << groupName;
return data.join(QLatin1String("/"));
}
void EffectInfo::fromString(QString value) {
if (value.isEmpty()) return;
QStringList data = value.split(QLatin1String("/"));
isCollapsed = data.at(0).toInt() == 1 || data.at(0).toInt() == 3;
groupIsCollapsed = data.at(0).toInt() >= 2;
if (data.count() > 1) groupIndex = data.at(1).toInt();
if (data.count() > 2) groupName = data.at(2);
}
EffectParameter::EffectParameter(const QString &name, const QString &value): m_name(name), m_value(value) {}
QString EffectParameter::name() const {
return m_name;
}
QString EffectParameter::value() const {
return m_value;
}
void EffectParameter::setValue(const QString &value) {
m_value = value;
}
EffectsParameterList::EffectsParameterList(): QList < EffectParameter >() {}
bool EffectsParameterList::hasParam(const QString &name) const {
for (int i = 0; i < size(); ++i)
if (at(i).name() == name) return true;
return false;
}
QString EffectsParameterList::paramValue(const QString &name, const QString &defaultValue) const {
for (int i = 0; i < size(); ++i) {
if (at(i).name() == name) return at(i).value();
}
return defaultValue;
}
void EffectsParameterList::addParam(const QString &name, const QString &value) {
if (name.isEmpty()) return;
append(EffectParameter(name, value));
}
void EffectsParameterList::removeParam(const QString &name) {
for (int i = 0; i < size(); ++i)
if (at(i).name() == name) {
removeAt(i);
break;
}
}
CommentedTime::CommentedTime(): t(GenTime(0)), type(0) {}
......
......@@ -162,7 +162,14 @@ public:
isMute(0),
isBlind(0),
isLocked(0),
duration(0) {}
duration(0),
effectsList() {}
};
struct ProfileInfo {
QSize profileSize;
double profileFps;
};
struct requestClipInfo {
......@@ -232,50 +239,7 @@ public:
bool operator!=(const MltVideoProfile &other) const;
};
/**)
* @class EffectInfo
* @brief A class holding some meta info for effects widgets, like state (collapsed or not, ...)
* @author Jean-Baptiste Mardelle
*/
class EffectInfo
{
public:
EffectInfo();
bool isCollapsed;
bool groupIsCollapsed;
int groupIndex;
QString groupName;
QString toString() const;
void fromString(QString value);
};
class EffectParameter
{
public:
EffectParameter(const QString &name, const QString &value);
QString name() const;
QString value() const;
void setValue(const QString &value);
private:
QString m_name;
QString m_value;
};
/** Use our own list for effect parameters so that they are not sorted in any ways, because
some effects like sox need a precise order
*/
class EffectsParameterList: public QList < EffectParameter >
{
public:
EffectsParameterList();
bool hasParam(const QString &name) const;
QString paramValue(const QString &name, const QString &defaultValue = QString()) const;
void addParam(const QString &name, const QString &value);
void removeParam(const QString &name);
};
class CommentedTime
{
......
......@@ -912,11 +912,19 @@ MltVideoProfile KdenliveDoc::mltProfile() const
return m_profile;
}
Mlt::Profile *KdenliveDoc::profile()
ProfileInfo KdenliveDoc::getProfileInfo() const
{
return pCore->binController()->profile();
ProfileInfo info;
info.profileSize = getRenderSize();
info.profileFps = fps();
return info;
}
/*Mlt::Profile *KdenliveDoc::profile()
{
return pCore->binController()->profile();
}*/
bool KdenliveDoc::setProfilePath(QString path)
{
if (path.isEmpty())
......@@ -1515,7 +1523,7 @@ void KdenliveDoc::addTrackEffect(int ix, QDomElement effect)
// Check if this effect has a variable parameter
if (e.attribute("default").contains('%')) {
double evaluatedValue = EffectsController::getStringEval(profile(), e.attribute("default"));
double evaluatedValue = EffectsController::getStringEval(getProfileInfo(), e.attribute("default"));
e.setAttribute("default", evaluatedValue);
if (e.hasAttribute("value") && e.attribute("value").startsWith('%')) {
e.setAttribute("value", evaluatedValue);
......@@ -1703,14 +1711,13 @@ QStringList KdenliveDoc::getExpandedFolders()
return result;
}
const QSize KdenliveDoc::getRenderSize()
const QSize KdenliveDoc::getRenderSize() const
{
QSize size;
if (m_render) {
size.setWidth(m_render->frameRenderWidth());
size.setHeight(m_render->renderHeight());
}
qDebug()<<"/ / /PROXY SIZE: "<<size;
return size;
}
// static
......
......@@ -40,6 +40,7 @@
#include "timecode.h"
#include "definitions.h"
#include "timeline/guide.h"
#include "mltcontroller/effectscontroller.h"
class Render;
class ClipManager;
......@@ -104,7 +105,8 @@ public:
void setThumbsProgress(const QString &message, int progress);
const QString &profilePath() const;
MltVideoProfile mltProfile() const;
Mlt::Profile *profile();
ProfileInfo getProfileInfo() const;
//Mlt::Profile *profile();
const QString description() const;
void setUrl(const QUrl &url);
......@@ -179,8 +181,8 @@ public:
/** @brief Set the document metadata (author, copyright, ...) */
void setMetadata(const QMap <QString, QString>& meta);
void slotUpdateClipProperties(const QString &id, QMap <QString, QString> properties, bool refreshPropertiesPanel);
/** @brief Get frame size of the renderer */
const QSize getRenderSize();
/** @brief Get frame size of the renderer (profile)*/
const QSize getRenderSize() const;
/** @brief Add url to the file watcher so that we monitor changes */
void watchFile(const QUrl &url);
......
......@@ -20,17 +20,14 @@
* @brief List for effects objects.
* @author Jason Wood
*
* This is a list of DocClipBase objects, to be used instead of
* QList<DocClipBase> to enable sorting lists correctly. It also contains the
* ability to set a "master clip", which can be used by a number of operations
* where there is the need of one clip to act as a reference for what happens to
* all clips.
*/
*/
#ifndef EFFECTSLIST_H
#define EFFECTSLIST_H
#include <QDomDocument>
#include <QSize>
namespace Kdenlive {
enum EFFECTTYPE { simpleEffect, groupEffect };
......@@ -41,7 +38,6 @@ class EffectsList: public QDomDocument
public:
explicit EffectsList(bool indexRequired = false);
~EffectsList();
/** @brief Returns the XML element of an effect.
* @param name name of the effect to be returned */
QDomElement getEffectByName(const QString & name) const;
......
......@@ -24,7 +24,7 @@
#include "parametercontainer.h"
#include "abstractcollapsiblewidget.h"
#include "timecode.h"
#include "mltcontroller/effectscontroller.h"
#include <QDomElement>
......
......@@ -49,7 +49,8 @@ EffectStackView2::EffectStackView2(QWidget *parent) :
m_draggedGroup(NULL),
m_groupIndex(0),
m_monitorSceneWanted(false),
m_status(EMPTY)
m_status(EMPTY),
m_trackInfo()
{
m_effectMetaInfo.monitor = NULL;
m_effects = QList <CollapsibleEffect*>();
......@@ -660,7 +661,7 @@ void EffectStackView2::slotUpdateEffectParams(const QDomElement &old, const QDom
slotSetCurrentEffect(ix);
}
else if (m_status == MASTER_CLIP) {
m_masterclipref->updateEffect(old, e, ix);
m_masterclipref->updateEffect(m_effectMetaInfo.monitor->profileInfo(), old, e, ix);
m_effectMetaInfo.monitor->refreshMonitor();
}
QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
......@@ -779,7 +780,7 @@ void EffectStackView2::slotResetEffect(int ix)
}
emit updateEffect(NULL, m_trackindex, old, dom, ix,false);
} else if (m_status == TIMELINE_CLIP) {
m_clipref->initEffect(m_effectMetaInfo.monitor->profile(), dom);
m_clipref->initEffect(m_effectMetaInfo.monitor->profileInfo(), dom);
for (int i = 0; i < m_effects.count(); ++i) {
if (m_effects.at(i)->effectIndex() == ix) {
m_effects.at(i)->updateWidget(m_clipref->info(), dom, &m_effectMetaInfo);
......
......@@ -220,7 +220,7 @@ private slots:
signals:
void removeEffect(ClipItem*, int, const QDomElement&);
/** Parameters for an effect changed, update the filter in playlist */
/** Parameters for an effect changed, update the filter in timeline */
void updateEffect(ClipItem*, int, const QDomElement&, const QDomElement &, int,bool);
/** An effect in stack was moved, we need to regenerate
all effects for this clip in the playlist */
......
......@@ -151,11 +151,11 @@ ParameterContainer::ParameterContainer(const QDomElement &effect, const ItemInfo
double min;
double max;
if (pa.attribute("min").contains('%'))
min = EffectsController::getStringEval(m_metaInfo->monitor->profile(), pa.attribute("min"), m_metaInfo->frameSize);
min = EffectsController::getStringEval(m_metaInfo->monitor->profileInfo(), pa.attribute("min"), m_metaInfo->frameSize);
else
min = pa.attribute("min").toDouble();
if (pa.attribute("max").contains('%'))
max = EffectsController::getStringEval(m_metaInfo->monitor->profile(), pa.attribute("max"), m_metaInfo->frameSize);
max = EffectsController::getStringEval(m_metaInfo->monitor->profileInfo(), pa.attribute("max"), m_metaInfo->frameSize);
else
max = pa.attribute("max").toDouble();
......@@ -855,7 +855,7 @@ void ParameterContainer::slotStartFilterJobAction()
// Replace with current geometry
EffectsParameterList parameters;
QDomNodeList params = m_effect.elementsByTagName("parameter");
EffectsController::adjustEffectParameters(parameters, params, m_metaInfo->monitor->profile());
EffectsController::adjustEffectParameters(parameters, params, m_metaInfo->monitor->profileInfo());
QString paramData;
for (int j = 0; j < parameters.count(); ++j) {
filterParams.insert(parameters.at(j).name(), parameters.at(j).value());
......
......@@ -69,7 +69,7 @@ ClipController::ClipController(BinController *bincontroller) : QObject()
, m_effectFreeIndex(1)
{
m_masterProducer = NULL;
m_effectList = EffectsList(true);
m_effectList = EffectsList();
}
ClipController::~ClipController()
......@@ -570,7 +570,7 @@ Mlt::Properties &ClipController::properties()
return *m_properties;
}
void ClipController::addEffect(QDomElement effect)
void ClipController::addEffect(const ProfileInfo pInfo, QDomElement effect)
{
QDomDocument doc = effect.ownerDocument();
Mlt::Service service = m_masterProducer->parent();
......@@ -579,8 +579,8 @@ void ClipController::addEffect(QDomElement effect)
ItemInfo info;
info.cropStart = GenTime();
info.cropDuration = getPlaytime();
EffectsController::initEffect(m_masterProducer->profile(), info, m_effectList, property("proxy"), effect);
EffectsParameterList params = EffectsController::getEffectArgs(m_masterProducer->profile(), effect);
EffectsController::initEffect(info, pInfo, m_effectList, property("proxy"), effect);
EffectsParameterList params = EffectsController::getEffectArgs(pInfo, effect);
Render::addFilterToService(m_masterProducer->parent(), params, getPlaytime().frames(m_binController->fps()));
m_effectList.append(effect);
m_binController->updateTrackProducer(clipId());
......@@ -620,9 +620,9 @@ void ClipController::changeEffectState(const QList <int> indexes, bool disable)
//slotRefreshTracks();
}
void ClipController::updateEffect(const QDomElement &old, const QDomElement &e, int ix)
void ClipController::updateEffect(const ProfileInfo pInfo, const QDomElement &old, const QDomElement &e, int ix)
{
EffectsParameterList params = EffectsController::getEffectArgs(m_masterProducer->profile(), e);
EffectsParameterList params = EffectsController::getEffectArgs(pInfo, e);
Mlt::Service service = m_masterProducer->parent();
for (int i = 0; i < service.filter_count(); ++i) {
Mlt::Filter *effect = service.filter(i);
......
......@@ -160,11 +160,11 @@ public:
QPoint zone() const;
bool hasLimitedDuration() const;
Mlt::Properties &properties();
void addEffect(QDomElement effect);
void addEffect(const ProfileInfo pInfo, QDomElement effect);
EffectsList effectList();
/** @brief Enable/disable an effect. */
void changeEffectState(const QList <int> indexes, bool disable);
void updateEffect(const QDomElement &old, const QDomElement &e, int ix);
void updateEffect(const ProfileInfo pInfo, const QDomElement &old, const QDomElement &e, int ix);
bool hasEffects() const;
private:
......
......@@ -29,9 +29,72 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QScriptEngine>
#include <KLocalizedString>
EffectInfo::EffectInfo() {isCollapsed = false; groupIndex = -1; groupIsCollapsed = false;}
QString EffectInfo::toString() const {
QStringList data;
// effect collapsed state: 0 = effect not collapsed, 1 = effect collapsed,
// 2 = group collapsed - effect not, 3 = group and effect collapsed
int collapsedState = (int) isCollapsed;
if (groupIsCollapsed) collapsedState += 2;
data << QString::number(collapsedState) << QString::number(groupIndex) << groupName;
return data.join(QLatin1String("/"));
}
void EffectInfo::fromString(QString value) {
if (value.isEmpty()) return;
QStringList data = value.split(QLatin1String("/"));
isCollapsed = data.at(0).toInt() == 1 || data.at(0).toInt() == 3;
groupIsCollapsed = data.at(0).toInt() >= 2;
if (data.count() > 1) groupIndex = data.at(1).toInt();
if (data.count() > 2) groupName = data.at(2);
}
EffectParameter::EffectParameter(const QString &name, const QString &value): m_name(name), m_value(value) {}
QString EffectParameter::name() const {
return m_name;
}
QString EffectParameter::value() const {
return m_value;
}
void EffectParameter::setValue(const QString &value) {
m_value = value;
}
EffectsParameterList::EffectsParameterList(): QList < EffectParameter >() {}
bool EffectsParameterList::hasParam(const QString &name) const {
for (int i = 0; i < size(); ++i)
if (at(i).name() == name) return true;
return false;
}
QString EffectsParameterList::paramValue(const QString &name, const QString &defaultValue) const {
for (int i = 0; i < size(); ++i) {
if (at(i).name() == name) return at(i).value();
}
return defaultValue;
}
void EffectsParameterList::addParam(const QString &name, const QString &value) {
if (name.isEmpty()) return;
append(EffectParameter(name, value));
}
void EffectsParameterList::removeParam(const QString &name) {
for (int i = 0; i < size(); ++i)
if (at(i).name() == name) {
removeAt(i);
break;
}
}
EffectsParameterList EffectsController::getEffectArgs(Mlt::Profile *profile, const QDomElement &effect)
EffectsParameterList EffectsController::getEffectArgs(const ProfileInfo info, const QDomElement &effect)
{
EffectsParameterList parameters;
QLocale locale;
......@@ -54,17 +117,17 @@ EffectsParameterList EffectsController::getEffectArgs(Mlt::Profile *profile, con
parameters.addParam(QString("filter%1.tag").arg(subeffectix), subeffect.attribute("tag"));
parameters.addParam(QString("filter%1.kdenlive_info").arg(subeffectix), subeffect.attribute("kdenlive_info"));
QDomNodeList subparams = subeffect.elementsByTagName("parameter");
adjustEffectParameters(parameters, subparams, profile, QString("filter%1.").arg(subeffectix));
adjustEffectParameters(parameters, subparams, info, QString("filter%1.").arg(subeffectix));
}
}
QDomNodeList params = effect.elementsByTagName("parameter");
adjustEffectParameters(parameters, params, profile);
adjustEffectParameters(parameters, params, info);
return parameters;
}
void EffectsController::adjustEffectParameters(EffectsParameterList &parameters, QDomNodeList params, Mlt::Profile *profile, const QString &prefix)
void EffectsController::adjustEffectParameters(EffectsParameterList &parameters, QDomNodeList params, const ProfileInfo info, const QString &prefix)
{
QLocale locale;
locale.setNumberOptions(QLocale::OmitGroupSeparator);
......@@ -116,7 +179,7 @@ void EffectsController::adjustEffectParameters(EffectsParameterList &parameters,
if (e.attribute("factor", "1") != "1" || e.attribute("offset", "0") != "0") {
double fact;
if (e.attribute("factor").contains('%')) {
fact = getStringEval(profile, e.attribute("factor"));
fact = getStringEval(info, e.attribute("factor"));
} else {
fact = e.attribute("factor", "1").toDouble();
}
......@@ -130,17 +193,17 @@ void EffectsController::adjustEffectParameters(EffectsParameterList &parameters,
}
double EffectsController::getStringEval(Mlt::Profile *profile, QString eval, const QPoint& frameSize)
double EffectsController::getStringEval(const ProfileInfo info, QString eval, const QPoint& frameSize)
{
QScriptEngine sEngine;
sEngine.globalObject().setProperty("maxWidth", profile->width() > frameSize.x() ? profile->width() : frameSize.x());
sEngine.globalObject().setProperty("maxHeight", profile->height() > frameSize.y() ? profile->height() : frameSize.y());
sEngine.globalObject().setProperty("width", profile->width());
sEngine.globalObject().setProperty("height", profile->height());
sEngine.globalObject().setProperty("maxWidth", info.profileSize.width() > frameSize.x() ? info.profileSize.width() : frameSize.x());
sEngine.globalObject().setProperty("maxHeight", info.profileSize.height() > frameSize.y() ? info.profileSize.height() : frameSize.y());
sEngine.globalObject().setProperty("width", info.profileSize.width());
sEngine.globalObject().setProperty("height", info.profileSize.height());
return sEngine.evaluate(eval.remove('%')).toNumber();
}
void EffectsController::initEffect(Mlt::Profile *profile, ItemInfo info, EffectsList list, const QString proxy, QDomElement effect, int diff, int offset)
void EffectsController::initEffect(ItemInfo info, ProfileInfo pInfo, EffectsList list, const QString proxy, QDomElement effect, int diff, int offset)
{
// the kdenlive_ix int is used to identify an effect in mlt's playlist, should
// not be changed
......@@ -148,7 +211,7 @@ void EffectsController::initEffect(Mlt::Profile *profile, ItemInfo info, Effects
if (effect.attribute("id") == "freeze" && diff > 0) {
EffectsList::setParameter(effect, "frame", QString::number(diff));
}
double fps = profile->fps();
double fps = pInfo.profileFps;
// Init parameter value & keyframes if required
QDomNodeList params = effect.elementsByTagName("parameter");
for (int i = 0; i < params.count(); ++i) {
......@@ -159,7 +222,7 @@ void EffectsController::initEffect(Mlt::Profile *profile, ItemInfo info, Effects
// Check if this effect has a variable parameter
if (e.attribute("default").contains('%')) {
double evaluatedValue = EffectsController::getStringEval(profile, e.attribute("default"));
double evaluatedValue = EffectsController::getStringEval(pInfo, e.attribute("default"));
e.setAttribute("default", evaluatedValue);
if (e.hasAttribute("value") && e.attribute("value").startsWith('%')) {
e.setAttribute("value", evaluatedValue);
......@@ -263,7 +326,7 @@ const QString EffectsController::adjustKeyframes(const QString &keyframes, int o
return result.join(";");
}
EffectsParameterList EffectsController::addEffect(Mlt::Profile *profile, QDomElement effect)
EffectsParameterList EffectsController::addEffect(const ProfileInfo info, QDomElement effect)
{
bool needRepaint = false;
QLocale locale;
......@@ -327,7 +390,7 @@ EffectsParameterList EffectsController::addEffect(Mlt::Profile *profile, QDomEle
} else {
double fact;
if (e.attribute("factor").contains('%')) {
fact = EffectsController::getStringEval(profile, e.attribute("factor"));
fact = EffectsController::getStringEval(info, e.attribute("factor"));
} else {
fact = locale.toDouble(e.attribute("factor", "1"));
}
......
......@@ -30,9 +30,60 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QUrl>
namespace Mlt {
class Profile;
}
/**)
* @class EffectInfo
* @brief A class holding some meta info for effects widgets, like state (collapsed or not, ...)
* @author Jean-Baptiste Mardelle
*/
class EffectInfo
{
public:
EffectInfo();
bool isCollapsed;
bool groupIsCollapsed;
int groupIndex;
QString groupName;
QString toString() const;
void fromString(QString value);
};
/**)
* @class EffectParameter