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 65117eec authored by Nicolas Carion's avatar Nicolas Carion

Moving bin playlist in its own class

Manage insertion of bin clips
parent 4ff507e0
......@@ -3,6 +3,7 @@ set(kdenlive_SRCS
bin/abstractprojectitem.cpp
bin/bin.cpp
bin/bincommands.cpp
bin/binplaylist.cpp
bin/generators/generators.cpp
bin/model/markerlistmodel.cpp
bin/projectclip.cpp
......
/***************************************************************************
* 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 "binplaylist.hpp"
#include <mlt++/Mlt.h>
#include "abstractprojectitem.h"
#include "core.h"
#include "projectclip.h"
#include "profiles/profilemodel.hpp"
BinPlaylist::BinPlaylist()
: m_binPlaylist(new Mlt::Playlist(pCore->getCurrentProfile()->profile()))
{
}
void BinPlaylist::manageBinClipInsertion(const std::shared_ptr<AbstractProjectItem> &binElem)
{
QString id = binElem->clipId();
switch (binElem->itemType()) {
case AbstractProjectItem::FolderItem: {
// When a folder is inserted, we have to store its path into the properties
if (binElem->parent()) {
QString propertyName = "kdenlive:folder." + binElem->parent()->clipId() + QLatin1Char('.') + id;
m_binPlaylist->set(propertyName.toUtf8().constData(), binElem->name().toUtf8().constData());
}
break;
}
case AbstractProjectItem::ClipItem: {
Q_ASSERT(m_allClips.count(id) == 0);
auto clip = std::static_pointer_cast<ProjectClip>(binElem);
if (clip->isValid()) {
m_binPlaylist->append(*clip->originalProducer().get());
} else {
// if clip is not loaded yet, we insert a dummy producer
Mlt::Producer dummy(pCore->getCurrentProfile()->profile(), "color:blue");
dummy.set("kdenlive:id", id.toUtf8().constData());
m_binPlaylist->append(dummy);
}
m_allClips.insert(id);
break;
}
default:
break;
}
}
void BinPlaylist::manageBinClipDeletion(AbstractProjectItem *binElem)
{
QString id = binElem->clipId();
switch (binElem->itemType()) {
case AbstractProjectItem::FolderItem: {
// When a folder is removed, we clear the path info
if (!binElem->lastParentId().isEmpty()) {
QString propertyName = "kdenlive:folder." + binElem->lastParentId() + QLatin1Char('.') + binElem->clipId();
m_binPlaylist->set(propertyName.toUtf8().constData(), (char *)nullptr);
}
break;
}
case AbstractProjectItem::ClipItem: {
Q_ASSERT(m_allClips.count(id) > 0);
m_allClips.erase(id);
removeBinClip(id);
}
default:
break;
}
}
void BinPlaylist::removeBinClip(const QString &id)
{
// we iterate on the clips of the timeline to find the correct one
bool ok = false;
int size = m_binPlaylist->count();
for (int i = 0; !ok && i < size; i++) {
QScopedPointer<Mlt::Producer> prod(m_binPlaylist->get_clip(i));
QString prodId = prod->parent().get("kdenlive:id");
if (prodId == id) {
m_binPlaylist->remove(i);
ok = true;
}
}
Q_ASSERT(ok);
}
/***************************************************************************
* 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 BINPLAYLIST_H
#define BINPLAYLIST_H
#include <memory>
#include <unordered_set>
#include "definitions.h"
/** @brief This class is a wrapper around a melt playlist that allows to store the Bin.
Clips that are in the bin must be added into this playlist so that they are savedn in the project's xml even if not inserted in the actual timeline.
The folder structure is also saved as properties.
*/
class AbstractProjectItem;
namespace Mlt {
class Playlist;
}
class BinPlaylist
{
public:
// Constructor is protected because class is a Singleton
BinPlaylist();
/* @brief This function updates the underlying binPlaylist object to reflect deletion of a bin item
@param binElem is the bin item deleted. Note that exceptionnally, this function takes a raw pointer instead of a smart one.
This is because the function will be called in the middle of the element's destructor, so no smart pointer is available at that time.
*/
void manageBinClipDeletion(AbstractProjectItem *binElem);
/* @brief This function updates the underlying binPlaylist object to reflect insertion of a bin item
@param binElem is the bin item inserted
*/
void manageBinClipInsertion(const std::shared_ptr<AbstractProjectItem> &binElem);
protected:
/* @brief This is an helper function that removes a clip from the playlist given its id
*/
void removeBinClip(const QString &id);
private:
/** @brief The MLT playlist holding our Producers */
std::unique_ptr<Mlt::Playlist> m_binPlaylist;
/** @brief Set of the bin inserted */
std::unordered_set<QString> m_allClips;
};
#endif
......@@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "projectitemmodel.h"
#include "abstractprojectitem.h"
#include "binplaylist.hpp"
#include "core.h"
#include "doc/kdenlivedoc.h"
#include "kdenlivesettings.h"
......@@ -40,7 +41,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
ProjectItemModel::ProjectItemModel(QObject *parent)
: AbstractTreeModel(parent)
, m_lock(QReadWriteLock::Recursive)
, m_binPlaylist(new Mlt::Playlist(pCore->getCurrentProfile()->profile()))
, m_binPlaylist(new BinPlaylist())
, m_clipCounter(1)
, m_folderCounter(1)
{
......@@ -407,47 +408,16 @@ bool ProjectItemModel::requestBinClipDeletion(std::shared_ptr<AbstractProjectIte
void ProjectItemModel::registerItem(const std::shared_ptr<TreeItem> &item)
{
auto clip = std::static_pointer_cast<AbstractProjectItem>(item);
manageBinClipInsertion(clip);
m_binPlaylist->manageBinClipInsertion(clip);
AbstractTreeModel::registerItem(item);
}
void ProjectItemModel::deregisterItem(int id, TreeItem *item)
{
auto clip = static_cast<AbstractProjectItem *>(item);
manageBinClipDeletion(clip);
m_binPlaylist->manageBinClipDeletion(clip);
AbstractTreeModel::deregisterItem(id, item);
}
void ProjectItemModel::manageBinClipInsertion(const std::shared_ptr<AbstractProjectItem> &binElem)
{
switch (binElem->itemType()) {
case AbstractProjectItem::FolderItem: {
// When a folder is inserted, we have to store its path into the properties
if (binElem->parent()) {
QString propertyName = "kdenlive:folder." + binElem->parent()->clipId() + QLatin1Char('.') + binElem->clipId();
m_binPlaylist->set(propertyName.toUtf8().constData(), binElem->name().toUtf8().constData());
}
break;
}
default:
break;
}
}
void ProjectItemModel::manageBinClipDeletion(AbstractProjectItem *binElem)
{
switch (binElem->itemType()) {
case AbstractProjectItem::FolderItem: {
// When a folder is removed, we clear the path info
if (!binElem->lastParentId().isEmpty()) {
QString propertyName = "kdenlive:folder." + binElem->lastParentId() + QLatin1Char('.') + binElem->clipId();
m_binPlaylist->set(propertyName.toUtf8().constData(), (char *)nullptr);
}
break;
}
default:
break;
}
}
int ProjectItemModel::getFreeFolderId()
{
......
......@@ -33,6 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <kimagecache.h>
class AbstractProjectItem;
class BinPlaylist;
class ProjectClip;
class ProjectFolder;
......@@ -135,15 +136,6 @@ protected:
/* @brief Deregister the existence of a new element*/
void deregisterItem(int id, TreeItem *item) override;
/* @brief This function updates the underlying binPlaylist object to reflect deletion of a bin item
@param binElem is the bin item deleted. Note that exceptionnally, this function takes a raw pointer instead of a smart one.
This is because the function will be called in the middle of the element's destructor, so no smart pointer is available at that time.
*/
void manageBinClipDeletion(AbstractProjectItem *binElem);
/* @brief This function updates the underlying binPlaylist object to reflect insertion of a bin item
@param binElem is the bin item inserted
*/
void manageBinClipInsertion(const std::shared_ptr<AbstractProjectItem> &binElem);
/* @brief Retrieves the next id available for attribution to a folder */
int getFreeFolderId();
......@@ -165,8 +157,7 @@ private:
mutable QReadWriteLock m_lock; // This is a lock that ensures safety in case of concurrent access
/** @brief The MLT playlist holding our Producers */
std::unique_ptr<Mlt::Playlist> m_binPlaylist;
std::unique_ptr<BinPlaylist> m_binPlaylist;
int m_clipCounter;
int m_folderCounter;
......
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