Commit 0b7ab8dd authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix fade effects not correctly saved or pasted.

Related to #1286
parent 4e62bfb3
......@@ -880,6 +880,13 @@ QVector<QPair<QString, QVariant>> AssetParameterModel::getAllParameters() const
for (const auto &param : m_params) {
if (!param.first.isEmpty()) {
QModelIndex ix = index(m_rows.indexOf(param.first), 0);
if (m_params.at(param.first).type == ParamType::MultiSwitch) {
// Multiswitch param value is not updated on change, fo fetch real value now
QVariant multiVal = data(ix, AssetParameterModel::ValueRole).toString();
res.push_back(QPair<QString, QVariant>(param.first, multiVal));
continue;
}
res.push_back(QPair<QString, QVariant>(param.first, param.second.value));
}
}
......@@ -1317,3 +1324,12 @@ Mlt::Properties *AssetParameterModel::getAsset()
{
return m_asset.get();
}
const QVariant AssetParameterModel::getParamFromName(const QString &paramName)
{
QModelIndex ix = index(m_rows.indexOf(paramName), 0);
if (ix.isValid()) {
return data(ix, ValueRole);
}
return QVariant();
}
......@@ -149,6 +149,8 @@ public:
/** @brief Return all the parameters as pairs (parameter name, parameter value) */
QVector<QPair<QString, QVariant>> getAllParameters() const;
/** @brief Get a parameter value from its name */
const QVariant getParamFromName(const QString &paramName);
/** @brief Returns a json definition of the effect with all param values */
QJsonDocument toJson(bool includeFixed = true) const;
/** @brief Returns the interpolated value at the given position with all param values as json*/
......
......@@ -915,7 +915,7 @@ void Core::updateItemKeyframes(ObjectId id)
void Core::updateItemModel(ObjectId id, const QString &service)
{
if (m_guiConstructed && id.first == ObjectType::TimelineClip && !m_mainWindow->getCurrentTimeline()->loading && service.startsWith(QLatin1String("fade"))) {
bool startFade = service == QLatin1String("fadein") || service == QLatin1String("fade_from_black");
bool startFade = service.startsWith(QLatin1String("fadein")) || service.startsWith(QLatin1String("fade_from_"));
m_mainWindow->getCurrentTimeline()->controller()->updateClip(id.second, {startFade ? TimelineModel::FadeInRole : TimelineModel::FadeOutRole});
}
}
......
......@@ -1839,7 +1839,7 @@ bool DocumentValidator::upgrade(double version, const double currentVersion)
QDomElement t = effects.at(i).toElement();
QString kdenliveId = Xml::getXmlProperty(t, QStringLiteral("kdenlive_id"));
if (kdenliveId.startsWith(QLatin1String("fade_"))) {
bool fadeIn = kdenliveId == QLatin1String("fade_from_black");
bool fadeIn = kdenliveId.startsWith(QLatin1String("fade_from_"));
bool isAlpha = Xml::getXmlProperty(t, QStringLiteral("alpha")).toInt() == -1;
// Clear unused properties
Xml::removeXmlProperty(t, QStringLiteral("start"));
......
......@@ -358,7 +358,7 @@ bool EffectStackModel::fromXml(const QDomElement &effectsXml, Fun &undo, Fun &re
connect(effect.get(), &AssetParameterModel::modelChanged, this, &EffectStackModel::modelChanged);
connect(effect.get(), &AssetParameterModel::replugEffect, this, &EffectStackModel::replugEffect, Qt::DirectConnection);
connect(effect.get(), &AssetParameterModel::showEffectZone, this, &EffectStackModel::updateEffectZones);
if (effectId == QLatin1String("fadein") || effectId == QLatin1String("fade_from_black")) {
if (effectId.startsWith(QLatin1String("fadein")) || effectId.startsWith(QLatin1String("fade_from_"))) {
m_fadeIns.insert(effect->getId());
int duration = effect->filter().get_length() - 1;
effect->filter().set("in", currentIn);
......@@ -371,7 +371,7 @@ bool EffectStackModel::fromXml(const QDomElement &effectsXml, Fun &undo, Fun &re
effect->filter().set("alpha", "0=0;-1=1");
}
}
} else if (effectId == QLatin1String("fadeout") || effectId == QLatin1String("fade_to_black")) {
} else if (effectId.startsWith(QLatin1String("fadeout")) || effectId.startsWith(QLatin1String("fade_to_"))) {
m_fadeOuts.insert(effect->getId());
int duration = effect->filter().get_length() - 1;
int filterOut = pCore->getItemIn(m_ownerId) + pCore->getItemDuration(m_ownerId) - 1;
......@@ -440,14 +440,14 @@ bool EffectStackModel::copyEffect(const std::shared_ptr<AbstractEffectItem> &sou
connect(effect.get(), &AssetParameterModel::replugEffect, this, &EffectStackModel::replugEffect, Qt::DirectConnection);
connect(effect.get(), &AssetParameterModel::showEffectZone, this, &EffectStackModel::updateEffectZones);
QVector<int> roles = {TimelineModel::EffectNamesRole};
if (effectId == QLatin1String("fadein") || effectId == QLatin1String("fade_from_black")) {
if (effectId.startsWith(QLatin1String("fadein")) || effectId.startsWith(QLatin1String("fade_from_"))) {
m_fadeIns.insert(effect->getId());
int duration = effect->filter().get_length() - 1;
int in = pCore->getItemIn(m_ownerId);
effect->filter().set("in", in);
effect->filter().set("out", in + duration);
roles << TimelineModel::FadeInRole;
} else if (effectId == QLatin1String("fadeout") || effectId == QLatin1String("fade_to_black")) {
} else if (effectId.startsWith(QLatin1String("fadeout")) || effectId.startsWith(QLatin1String("fade_to_"))) {
m_fadeOuts.insert(effect->getId());
int duration = effect->filter().get_length() - 1;
int out = pCore->getItemIn(m_ownerId) + pCore->getItemDuration(m_ownerId) - 1;
......@@ -512,13 +512,13 @@ bool EffectStackModel::appendEffect(const QString &effectId, bool makeCurrent)
if (res) {
int inFades = 0;
int outFades = 0;
if (effectId == QLatin1String("fadein") || effectId == QLatin1String("fade_from_black")) {
if (effectId.startsWith(QLatin1String("fadein")) || effectId.startsWith(QLatin1String("fade_from_"))) {
int duration = effect->filter().get_length() - 1;
int in = pCore->getItemIn(m_ownerId);
effect->filter().set("in", in);
effect->filter().set("out", in + duration);
inFades++;
} else if (effectId == QLatin1String("fadeout") || effectId == QLatin1String("fade_to_black")) {
} else if (effectId.startsWith(QLatin1String("fadeout")) || effectId.startsWith(QLatin1String("fade_to_"))) {
/*int duration = effect->filter().get_length() - 1;
int out = pCore->getItemIn(m_ownerId) + pCore->getItemDuration(m_ownerId) - 1;
effect->filter().set("in", out - duration);
......@@ -885,9 +885,9 @@ void EffectStackModel::registerItem(const std::shared_ptr<TreeItem> &item)
}
effectItem->setEffectStackEnabled(m_effectStackEnabled);
const QString &effectId = effectItem->getAssetId();
if (effectId == QLatin1String("fadein") || effectId == QLatin1String("fade_from_black")) {
if (effectId.startsWith(QLatin1String("fadein")) || effectId.startsWith(QLatin1String("fade_from_"))) {
m_fadeIns.insert(effectItem->getId());
} else if (effectId == QLatin1String("fadeout") || effectId == QLatin1String("fade_to_black")) {
} else if (effectId.startsWith(QLatin1String("fadeout")) || effectId.startsWith(QLatin1String("fade_to_"))) {
m_fadeOuts.insert(effectItem->getId());
}
ix = getIndexFromItem(effectItem);
......@@ -1041,7 +1041,7 @@ void EffectStackModel::importEffects(const std::weak_ptr<Mlt::Service> &service,
Fun redo = addItem_lambda(effect, rootItem->getId());
effect->prepareKeyframes();
if (redo()) {
if (effectId == QLatin1String("fadein") || effectId == QLatin1String("fade_from_black")) {
if (effectId.startsWith(QLatin1String("fadein")) || effectId.startsWith(QLatin1String("fade_from_"))) {
m_fadeIns.insert(effect->getId());
int clipIn = ptr->get_int("in");
if (effect->filter().get_int("in") != clipIn) {
......@@ -1050,7 +1050,7 @@ void EffectStackModel::importEffects(const std::weak_ptr<Mlt::Service> &service,
effect->filter().set("in", clipIn);
effect->filter().set("out", clipIn + filterLength);
}
} else if (effectId == QLatin1String("fadeout") || effectId == QLatin1String("fade_to_black")) {
} else if (effectId.startsWith(QLatin1String("fadeout")) || effectId.startsWith(QLatin1String("fade_to_"))) {
m_fadeOuts.insert(effect->getId());
int clipOut = ptr->get_int("out");
if (effect->filter().get_int("out") != clipOut) {
......
......@@ -520,12 +520,31 @@ void CollapsibleEffectView::slotSaveEffect()
if (paramType == QLatin1String("fixed") || !values.contains(paramName)) {
continue;
}
if (paramType == QLatin1String("multiswitch")) {
// Multiswitch param value is not updated on change, fo fetch real value now
QString val = m_model->getParamFromName(paramName).toString();
params.item(i).toElement().setAttribute(QStringLiteral("value"), val);
continue;
}
params.item(i).toElement().setAttribute(QStringLiteral("value"), values.value(paramName));
}
doc.appendChild(doc.importNode(effect, true));
effect = doc.firstChild().toElement();
effect.removeAttribute(QStringLiteral("kdenlive_ix"));
effect.setAttribute(QStringLiteral("id"), name);
QString namedId = name;
QString sourceId = effect.attribute("id");
// When saving an effect as custom, it might be necessary to keep track of the original
// effect id as it is sometimes used in Kdenlive to trigger special behaviors
if (sourceId.startsWith(QStringLiteral("fade_to_"))) {
namedId.prepend(QStringLiteral("fade_to_"));
} else if (sourceId.startsWith(QStringLiteral("fade_from_"))) {
namedId.prepend(QStringLiteral("fade_from_"));
} if (sourceId.startsWith(QStringLiteral("fadein"))) {
namedId.prepend(QStringLiteral("fadein_"));
} if (sourceId.startsWith(QStringLiteral("fadeout"))) {
namedId.prepend(QStringLiteral("fadeout_"));
}
effect.setAttribute(QStringLiteral("id"), namedId);
QString masterType = effect.attribute(QLatin1String("type"));
effect.setAttribute(QStringLiteral("type"), (masterType == QLatin1String("audio") || masterType == QLatin1String("customAudio")) ? QStringLiteral("customAudio") : QStringLiteral("customVideo"));
......@@ -547,7 +566,7 @@ void CollapsibleEffectView::slotSaveEffect()
QDomText text = doc.createTextNode(enteredDescription);
newNodeTag.appendChild(text);
root.replaceChild(newNodeTag, nodelist);
}
}
if (file.open(QFile::WriteOnly | QFile::Truncate)) {
QTextStream out(&file);
......
......@@ -775,12 +775,12 @@ bool ClipModel::adjustEffectLength(const QString &effectName, int duration, int
QWriteLocker locker(&m_lock);
qDebug() << ".... ADJUSTING FADE LENGTH: " << duration << " / " << effectName;
Fun operation = [this, duration, effectName, originalDuration]() {
return m_effectStack->adjustFadeLength(duration, effectName == QLatin1String("fadein") || effectName == QLatin1String("fade_to_black"), audioEnabled(),
return m_effectStack->adjustFadeLength(duration, effectName.startsWith(QLatin1String("fadein")) || effectName.startsWith(QLatin1String("fade_to_")), audioEnabled(),
!isAudioOnly(), originalDuration > 0);
};
if (operation() && originalDuration > 0) {
Fun reverse = [this, originalDuration, effectName]() {
return m_effectStack->adjustFadeLength(originalDuration, effectName == QLatin1String("fadein") || effectName == QLatin1String("fade_to_black"),
return m_effectStack->adjustFadeLength(originalDuration, effectName.startsWith(QLatin1String("fadein")) || effectName.startsWith(QLatin1String("fade_to_")),
audioEnabled(), !isAudioOnly(), true);
};
UPDATE_UNDO_REDO(operation, reverse, undo, redo);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment