Commit f5320389 authored by Nicolas Carion's avatar Nicolas Carion

First stab at bin saving/loading (WIP)

parent 6187c297
......@@ -26,9 +26,11 @@
#include "projectclip.h"
#include <mlt++/Mlt.h>
QString BinPlaylist::binPlaylistId = "main bin";
BinPlaylist::BinPlaylist()
: m_binPlaylist(new Mlt::Playlist(pCore->getCurrentProfile()->profile()))
{
m_binPlaylist->set("id", binPlaylistId.toUtf8().constData());
}
void BinPlaylist::manageBinItemInsertion(const std::shared_ptr<AbstractProjectItem> &binElem)
......@@ -108,3 +110,9 @@ void BinPlaylist::changeProducer(const QString &id, const std::shared_ptr<Mlt::P
removeBinClip(id);
m_binPlaylist->append(*producer.get());
}
void BinPlaylist::setRetainIn(Mlt::Tractor* modelTractor)
{
QString retain = QStringLiteral("xml_retain %1").arg(binPlaylistId);
modelTractor->set(retain.toUtf8().constData(), m_binPlaylist->get_service(), 0);
}
......@@ -36,6 +36,7 @@ class AbstractProjectItem;
namespace Mlt {
class Playlist;
class Producer;
class Tractor;
}
class BinPlaylist : public QObject
......@@ -55,6 +56,13 @@ public:
*/
void manageBinItemInsertion(const std::shared_ptr<AbstractProjectItem> &binElem);
/* @brief Make sure bin playlist is saved in given tractor.
This has a side effect on the tractor
*/
void setRetainIn(Mlt::Tractor *modelTractor);
// id of the mlt object
static QString binPlaylistId;
protected:
/* @brief This is an helper function that removes a clip from the playlist given its id
*/
......
......@@ -32,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "kdenlivesettings.h"
#include "macros.hpp"
#include "profiles/profilemodel.hpp"
#include "project/projectmanager.h"
#include "projectclip.h"
#include "projectfolder.h"
#include "projectsubclip.h"
......@@ -183,7 +184,7 @@ bool ProjectItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action
// error, malformed clip zone, abort
return false;
}
} else {
} else {
emit itemDropped(ids, parent);
}
return true;
......@@ -731,3 +732,69 @@ bool ProjectItemModel::isIdFree(const QString &id) const
}
return true;
}
void ProjectItemModel::loadBinPlaylist(Mlt::Tractor *documentTractor, Mlt::Tractor *modelTractor)
{
clean();
Mlt::Properties retainList((mlt_properties)documentTractor->get_data("xml_retain"));
qDebug() << "Loading bin playlist...";
if (retainList.is_valid() && (retainList.get_data(BinPlaylist::binPlaylistId.toUtf8().constData()) != nullptr)) {
Mlt::Playlist playlist((mlt_playlist)retainList.get_data(BinPlaylist::binPlaylistId.toUtf8().constData()));
qDebug() << "retain is valid";
if (playlist.is_valid() && playlist.type() == playlist_type) {
qDebug() << "playlist is valid";
// Load bin clips
qDebug() << "init bin";
// Load folders
Mlt::Properties folderProperties;
Mlt::Properties playlistProps(playlist.get_properties());
folderProperties.pass_values(playlistProps, "kdenlive:folder.");
loadFolders(folderProperties);
// Read notes
QString notes = playlistProps.get("kdenlive:documentnotes");
pCore->projectManager()->setDocumentNotes(notes);
Fun undo = []() { return true; };
Fun redo = []() { return true; };
qDebug() << "Found " << playlist.count() << "clips";
int max = playlist.count();
for (int i = 0; i < max; i++) {
QScopedPointer<Mlt::Producer> prod(playlist.get_clip(i));
std::shared_ptr<Mlt::Producer> producer(new Mlt::Producer(prod->parent()));
qDebug() << "dealing with bin clip" << i;
if (producer->is_blank() || !producer->is_valid()) {
qDebug() << "producer is not valid or blank";
continue;
}
QString id = qstrdup(producer->get("kdenlive:id"));
QString parentId = qstrdup(producer->get("kdenlive:folderid"));
qDebug() << "clip id" << id;
if (id.contains(QLatin1Char('_'))) {
// TODO refac ?
/*
// This is a track producer
QString mainId = id.section(QLatin1Char('_'), 0, 0);
// QString track = id.section(QStringLiteral("_"), 1, 1);
if (m_clipList.contains(mainId)) {
// The controller for this track producer already exists
} else {
// Create empty controller for this clip
requestClipInfo info;
info.imageHeight = 0;
info.clipId = id;
info.replaceProducer = true;
emit slotProducerReady(info, ClipController::mediaUnavailable);
}
*/
} else {
// TODO we need a fallback in case the id is for some reason unavailable
requestAddBinClip(id, producer, parentId, undo, redo);
}
}
m_binPlaylist->setRetainIn(modelTractor);
}
}
}
......@@ -92,6 +92,9 @@ public:
/* @brief Load the folders given the property containing them */
bool loadFolders(Mlt::Properties &folders);
/* @brief Parse a bin playlist from the document tractor and reconstruct the tree */
void loadBinPlaylist(Mlt::Tractor *documentTractor, Mlt::Tractor *modelTractor);
/** @brief Returns item data depending on role requested */
QVariant data(const QModelIndex &index, int role) const override;
/** @brief Called when user edits an item */
......
......@@ -26,9 +26,9 @@
#include "../trackmodel.hpp"
#include "../undohelper.hpp"
#include "bin/bin.h"
#include "bin/projectitemmodel.h"
#include "core.h"
#include "kdenlivesettings.h"
#include "mltcontroller/bincontroller.h"
#include <QDebug>
#include <QSet>
#include <mlt++/MltPlaylist.h>
......@@ -45,7 +45,7 @@ bool constructTimelineFromMelt(const std::shared_ptr<TimelineItemModel> &timelin
// First, we destruct the previous tracks
timeline->requestReset(undo, redo);
pCore->binController()->loadBinPlaylist(&tractor, timeline->tractor());
pCore->projectItemModel()->loadBinPlaylist(&tractor, timeline->tractor());
QSet<QString> reserved_names{QLatin1String("playlistmain"), QLatin1String("timeline_preview"), QLatin1String("timeline_overlay"),
QLatin1String("black_track")};
......
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