Load effects in stack on document open

parent 4e146767
......@@ -41,7 +41,34 @@ std::shared_ptr<EffectItemModel> EffectItemModel::construct(const QString &effec
QDomElement xml = EffectsRepository::get()->getXml(effectId);
Mlt::Properties *effect = EffectsRepository::get()->getEffect(effectId);
effect->set("kdenlive:id", effectId.toUtf8().constData());
effect->set("kdenlive_id", effectId.toUtf8().constData());
QList<QVariant> data;
data << EffectsRepository::get()->getName(effectId) << effectId;
std::shared_ptr<EffectItemModel> self(new EffectItemModel(data, effect, xml, effectId, std::move(stack)));
baseFinishConstruct(self);
return self;
}
// static
std::shared_ptr<EffectItemModel> EffectItemModel::construct(Mlt::Properties *effect, std::shared_ptr<AbstractTreeModel> stack)
{
QString effectId = effect->get("kdenlive_id");
if (effectId.isEmpty()) {
effectId = effect->get("mlt_service");
}
Q_ASSERT(EffectsRepository::get()->exists(effectId));
QDomElement xml = EffectsRepository::get()->getXml(effectId);
QDomNodeList params = xml.elementsByTagName(QStringLiteral("parameter"));
for (int i = 0; i < params.count(); ++i) {
QDomElement currentParameter = params.item(i).toElement();
QString paramName = currentParameter.attribute(QStringLiteral("name"));
QString paramValue = effect->get(paramName.toUtf8().constData());
currentParameter.setAttribute(QStringLiteral("value"), paramValue);
}
QList<QVariant> data;
data << EffectsRepository::get()->getName(effectId) << effectId;
......
......@@ -39,6 +39,8 @@ public:
*/
static std::shared_ptr<EffectItemModel> construct(const QString &effectId, std::shared_ptr<AbstractTreeModel> stack);
static std::shared_ptr<EffectItemModel> construct(Mlt::Properties *effect, std::shared_ptr<AbstractTreeModel> stack);
/* @brief This function plants the effect into the given service in last position
*/
void plant(const std::weak_ptr<Mlt::Service> &service) override;
......
......@@ -46,6 +46,24 @@ std::shared_ptr<EffectStackModel> EffectStackModel::construct(std::weak_ptr<Mlt:
return self;
}
void EffectStackModel::loadEffects()
{
auto ptr = m_service.lock();
if (ptr) {
qDebug()<<"// FOUND FILTERS IN CLIP: "<<ptr->filter_count();
for (int i = 0; i < ptr->filter_count(); i++) {
auto effect = EffectItemModel::construct(ptr->filter(i), shared_from_this());
//effect->setParameters
qDebug()<<"// Adding effect: "<<effect->getAssetId();
Fun redo = addItem_lambda(effect, rootItem->getId());
bool res = redo();
}
} else {
qDebug()<<"// CANNOT LOCK CLIP SEEVCE";
}
}
void EffectStackModel::resetService(std::weak_ptr<Mlt::Service> service)
{
m_service = std::move(service);
......@@ -314,7 +332,6 @@ ObjectId EffectStackModel::getOwnerId() const
return m_ownerId;
}
bool EffectStackModel::checkConsistency()
{
if (!AbstractTreeModel::checkConsistency()) {
......
......@@ -48,6 +48,7 @@ public:
*/
static std::shared_ptr<EffectStackModel> construct(std::weak_ptr<Mlt::Service> service, ObjectId ownerId, std::weak_ptr<DocUndoStack> undo_stack);
void resetService(std::weak_ptr<Mlt::Service> service);
void loadEffects();
protected:
EffectStackModel(std::weak_ptr<Mlt::Service> service, ObjectId ownerId, std::weak_ptr<DocUndoStack> undo_stack);
......
......@@ -64,7 +64,7 @@ int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QSt
std::shared_ptr<ClipModel> clip(new ClipModel(parent, producer, binClipId, id));
id = clip->m_id;
parent->registerClip(clip);
clip->m_effectStack->loadEffects();
return id;
}
......
Markdown is supported
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