Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 59cf159e authored by Nicolas Carion's avatar Nicolas Carion

Very preliminary effectstack model

parent 7ddd24d2
......@@ -41,6 +41,12 @@ TreeItem* TreeItem::appendChild(const QList<QVariant> &data)
return child;
}
void TreeItem::appendChild(TreeItem *child)
{
child->m_depth = m_depth + 1;
m_childItems.append(child);
}
TreeItem *TreeItem::child(int row)
{
return m_childItems.value(row);
......
......@@ -44,6 +44,11 @@ public:
*/
TreeItem* appendChild(const QList<QVariant> &data);
/* @brief Appends an already created child
Useful for example if the child should be a subclass of TreeItem
*/
void appendChild(TreeItem *child);
/* @brief Retrieves a child of the current item
@param row is the index of the child to retrieve
*/
......
......@@ -4,5 +4,7 @@ set(kdenlive_SRCS
effects/effectlist/view/effectlistwidget.cpp
effects/effectlist/model/effecttreemodel.cpp
effects/effectlist/model/effectfilter.cpp
effects/effectstack/model/effectitemmodel.cpp
effects/effectstack/model/effectstackmodel.cpp
PARENT_SCOPE)
......@@ -28,6 +28,7 @@
#include <QTextStream>
#include <mlt++/Mlt.h>
#include "profiles/profilemodel.hpp"
std::unique_ptr<EffectsRepository> EffectsRepository::instance;
std::once_flag EffectsRepository::m_onceFlag;
......@@ -143,3 +144,16 @@ QString EffectsRepository::assetBlackListPath() const
{
return QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("blacklisted_effects.txt"));
}
Mlt::Filter *EffectsRepository::getEffect(const QString& effectId) const
{
Q_ASSERT(exists(effectId));
QString service_name = m_assets.at(effectId).mltId;
// We create the Mlt element from its name
Mlt::Filter *filter = new Mlt::Filter(
pCore->getCurrentProfile()->profile(),
service_name.toLatin1().constData(),
nullptr
);
return filter;
}
......@@ -51,6 +51,9 @@ public:
//Returns the instance of the Singleton
static std::unique_ptr<EffectsRepository>& get();
/* @brief returns a fresh instance of the given effect */
Mlt::Filter *getEffect(const QString& effectId) const;
protected:
// Constructor is protected because class is a Singleton
EffectsRepository();
......
/***************************************************************************
* Copyright (C) 2017 by Nicolas Carion *
* This file is part of Kdenlive. See www.kdenlive.org. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "effectitemmodel.hpp"
#include "effects/effectsrepository.hpp"
EffectItemModel::EffectItemModel(const QList<QVariant> &data, Mlt::Properties *effect, const QDomElement &xml, const QString &effectId)
: TreeItem(data)
, AssetParameterModel(effect, xml, effectId)
{
}
//static
EffectItemModel* EffectItemModel::construct(const QString & effectId)
{
Q_ASSERT(EffectsRepository::get()->exists(effectId));
QDomElement xml = EffectsRepository::get()->getXml(effectId);
Mlt::Properties *effect = EffectsRepository::get()->getEffect(effectId);
QList<QVariant> data;
data << EffectsRepository::get()->getName(effectId)
<< effectId;
return new EffectItemModel(data, effect, xml, effectId);
}
void EffectItemModel::plant(std::weak_ptr<Mlt::Service> service)
{
if (auto ptr = service.lock()) {
int ret = ptr->attach(filter());
Q_ASSERT(ret == 0);
} else {
qDebug() << "Error : Cannot plant effect because parent service is not available anymore";
Q_ASSERT(false);
}
}
Mlt::Filter& EffectItemModel::filter() const
{
return *static_cast<Mlt::Filter*>(m_asset.get());
}
/***************************************************************************
* Copyright (C) 2017 by Nicolas Carion *
* This file is part of Kdenlive. See www.kdenlive.org. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef EFFECTITEMMODEL_H
#define EFFECTITEMMODEL_H
#include "abstractmodel/treeitem.hpp"
#include "assets/model/assetparametermodel.hpp"
#include <mlt++/MltFilter.h>
/* @brief This represents an effect of the effectstack
*/
class EffectItemModel : public TreeItem, public AssetParameterModel
{
public:
/* This construct an effect of the given id */
static EffectItemModel* construct(const QString & effectId);
/* @brief This function plants the effect into the given service in last position
*/
void plant(std::weak_ptr<Mlt::Service> service);
Mlt::Filter &filter() const;
protected:
EffectItemModel(const QList<QVariant> &data, Mlt::Properties *effect, const QDomElement &xml, const QString &effectId);
};
#endif
/***************************************************************************
* Copyright (C) 2017 by Nicolas Carion *
* This file is part of Kdenlive. See www.kdenlive.org. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "effectstackmodel.hpp"
#include "effectitemmodel.hpp"
EffectStackModel::EffectStackModel(std::weak_ptr<Mlt::Service> service) :
AbstractTreeModel()
, m_service(service)
{
}
std::shared_ptr<EffectStackModel> EffectStackModel::construct(std::weak_ptr<Mlt::Service> service)
{
return std::make_shared<EffectStackModel>(service);
}
void EffectStackModel::appendEffect(const QString& effectId)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
rootItem->appendChild(EffectItemModel::construct(effectId));
endInsertRows();
}
/***************************************************************************
* Copyright (C) 2017 by Nicolas Carion *
* This file is part of Kdenlive. See www.kdenlive.org. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef EFFECTSTACKMODEL_H
#define EFFECTSTACKMODEL_H
#include "abstractmodel/abstracttreemodel.hpp"
#include <memory>
#include <mlt++/Mlt.h>
/* @brief This class an effect stack as viewed by the back-end.
It is responsible for planting and managing effects into the producer it holds a pointer to.
*/
class TreeItem;
class EffectStackModel : public AbstractTreeModel
{
public:
/* @brief Constructs an effect stack and returns a shared ptr to the constucted object
@param service is the mlt object on which we will plant the effects */
static std::shared_ptr<EffectStackModel> construct(std::weak_ptr<Mlt::Service> service);
/* @brief Add an effect at the bottom of the stack */
void appendEffect(const QString& effectId);
EffectStackModel(std::weak_ptr<Mlt::Service> service);
protected:
std::weak_ptr<Mlt::Service> m_service;
};
#endif
......@@ -23,12 +23,14 @@
#include "trackmodel.hpp"
#include "undohelper.hpp"
#include <mlt++/MltProducer.h>
#include "effects/effectstack/model/effectstackmodel.hpp"
#include <QDebug>
ClipModel::ClipModel(std::weak_ptr<TimelineModel> parent, std::weak_ptr<Mlt::Producer> prod, int id) :
ClipModel::ClipModel(std::weak_ptr<TimelineModel> parent, std::shared_ptr<Mlt::Producer> prod, int id) :
MoveableItem<Mlt::Producer>(parent, id)
, m_producer(prod)
, m_effectStack(EffectStackModel::construct(m_producer))
{
}
......
......@@ -32,6 +32,7 @@ namespace Mlt{
}
class TimelineModel;
class TrackModel;
class EffectStackModel;
/* @brief This class represents a Clip object, as viewed by the backend.
In general, the Gui associated with it will send modification queries (such as resize or move), and this class authorize them or not depending on the validity of the modifications
......@@ -45,7 +46,7 @@ class ClipModel : public MoveableItem<Mlt::Producer>
int getPlaytime() const override;
protected:
/* This constructor is not meant to be called, call the static construct instead */
ClipModel(std::weak_ptr<TimelineModel> parent, std::weak_ptr<Mlt::Producer> prod, int id = -1);
ClipModel(std::weak_ptr<TimelineModel> parent, std::shared_ptr<Mlt::Producer> prod, int id = -1);
public:
......@@ -80,6 +81,8 @@ protected:
protected:
std::shared_ptr<Mlt::Producer> m_producer;
std::shared_ptr<EffectStackModel> m_effectStack;
};
#endif
......@@ -28,7 +28,6 @@
#include <QTextStream>
#include <mlt++/Mlt.h>
#include "assets/model/assetparametermodel.hpp"
#include "profiles/profilemodel.hpp"
std::unique_ptr<TransitionsRepository> TransitionsRepository::instance;
......
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