When copy/paste between 2 kdenlive windows, correctly load bin clip effects

This commit is contained in:
Jean-Baptiste Mardelle
2025-12-05 12:36:07 +01:00
parent d3f024c256
commit ddd31bbef7
5 changed files with 78 additions and 45 deletions

View File

@@ -386,6 +386,28 @@ QDomElement EffectStackModel::rowToXml(int row, QDomDocument &document)
return container;
}
bool EffectStackModel::fromMltXml(const QDomElement &effectsXml)
{
QDomNodeList nodeList = effectsXml.elementsByTagName(QStringLiteral("filter"));
for (int i = 0; i < nodeList.count(); ++i) {
QDomElement node = nodeList.item(i).toElement();
if (!Xml::hasXmlProperty(node, QStringLiteral("kdenlive_id")) || Xml::hasXmlProperty(node, QStringLiteral("internal_added"))) {
// Internal effect, ignore
continue;
}
if (Xml::hasXmlProperty(node, QStringLiteral("kdenlive:builtin")) && Xml::getXmlProperty(node, QStringLiteral("disable")) == QLatin1String("1")) {
// Disabled built-in effect, ignore
continue;
}
const QString effectId = Xml::getXmlProperty(node, QStringLiteral("kdenlive_id"));
Fun undo = []() { return true; };
Fun redo = []() { return true; };
stringMap params = Xml::getXmlPropertyByWildcard(node, QString());
doAppendEffect(effectId, false, params, undo, redo);
}
return true;
}
bool EffectStackModel::fromXml(const QDomElement &effectsXml, Fun &undo, Fun &redo)
{
QDomNodeList nodeList = effectsXml.elementsByTagName(QStringLiteral("effect"));

View File

@@ -137,6 +137,8 @@ public:
QDomElement rowToXml(int row, QDomDocument &document);
/** @brief Load an effect stack from an XML representation */
bool fromXml(const QDomElement &effectsXml, Fun &undo, Fun &redo);
/** @brief Load an effect stack from an MLT XML representation */
bool fromMltXml(const QDomElement &effectsXml);
/** @brief Delete active effect from stack */
void removeCurrentEffect();

View File

@@ -69,6 +69,9 @@ ClipController::ClipController(const QString &clipId, const std::shared_ptr<Mlt:
} else {
m_controlUuid = QUuid::createUuid();
}
if (description.elementsByTagName(QStringLiteral("filter")).count() > 0) {
m_effectsToLoad = description;
}
}
}
@@ -123,13 +126,19 @@ void ClipController::addMasterProducer(const std::shared_ptr<Mlt::Producer> &pro
if (!m_masterProducer->is_valid()) {
m_masterProducer = std::shared_ptr<Mlt::Producer>(pCore->mediaUnavailable->cut());
qCDebug(KDENLIVE_LOG) << "// WARNING, USING INVALID PRODUCER";
} else {
connectEffectStack();
return;
}
setProducerProperty(QStringLiteral("kdenlive:id"), m_controllerBinId);
if (!m_properties->property_exists("kdenlive:control_uuid")) {
m_properties->set("kdenlive:control_uuid", m_controlUuid.toString().toUtf8().constData());
}
getInfoForProducer();
checkAudioVideo();
if (!m_effectsToLoad.isNull()) {
m_effectStack->fromMltXml(m_effectsToLoad);
m_effectsToLoad.clear();
}
if (!m_hasMultipleVideoStreams && m_service.startsWith(QLatin1String("avformat")) && (m_clipType == ClipType::AV || m_clipType == ClipType::Video)) {
// Check if clip has multiple video streams
QList<int> videoStreams;
@@ -174,7 +183,6 @@ void ClipController::addMasterProducer(const std::shared_ptr<Mlt::Producer> &pro
Q_ARG(QList<int>, videoStreams), Q_ARG(QList<int>, audioStreams));
}
}
}
connectEffectStack();
}

View File

@@ -251,6 +251,7 @@ private:
/** @brief Temporarily store clip properties until producer is available */
QMap <QString, QVariant> m_tempProps;
QString m_controllerBinId;
QDomElement m_effectsToLoad;
/** @brief Build the audio info object */
void buildAudioInfo(int audioIndex);
};

View File

@@ -218,7 +218,7 @@ QMap<QString, QString> Xml::getXmlPropertyByWildcard(const QDomElement &element,
QDomNodeList params = element.elementsByTagName(QStringLiteral("property"));
for (int i = 0; i < params.count(); ++i) {
QDomElement e = params.item(i).toElement();
if (e.attribute(QStringLiteral("name")).startsWith(propertyName)) {
if (propertyName.isEmpty() || e.attribute(QStringLiteral("name")).startsWith(propertyName)) {
props.insert(e.attribute(QStringLiteral("name")), e.text());
}
}