Move tractor creation in timelinemodel

parent 969633f4
......@@ -305,9 +305,9 @@ KdenliveDoc::~KdenliveDoc()
}
}
Mlt::Producer *KdenliveDoc::getProjectProducer()
const QByteArray KdenliveDoc::getProjectXml()
{
return new Mlt::Producer(pCore->getCurrentProfile()->profile(), "xml-string", m_document.toString().toUtf8().constData());
return m_document.toString().toUtf8();
}
void KdenliveDoc::loadThumbs()
......
......@@ -69,7 +69,7 @@ public:
const QMap<QString, QString> &metadata, const QPoint &tracks, bool *openBackup, MainWindow *parent = nullptr);
~KdenliveDoc();
/** @brief Get current document's producer. */
Mlt::Producer *getProjectProducer();
const QByteArray getProjectXml();
QDomNodeList producersList();
double fps() const;
int width() const;
......
......@@ -189,10 +189,10 @@ void BinController::createIfNeeded(Mlt::Profile *profile)
m_binPlaylist->set("id", kPlaylistTrackId);
}
void BinController::loadBinPlaylist(Mlt::Tractor &tractor)
void BinController::loadBinPlaylist(Mlt::Tractor *tractor)
{
destroyBin();
Mlt::Properties retainList((mlt_properties)tractor.get_data("xml_retain"));
Mlt::Properties retainList((mlt_properties)tractor->get_data("xml_retain"));
if (retainList.is_valid() && (retainList.get_data(binPlaylistId().toUtf8().constData()) != nullptr)) {
Mlt::Playlist playlist((mlt_playlist)retainList.get_data(binPlaylistId().toUtf8().constData()));
if (playlist.is_valid() && playlist.type() == playlist_type) {
......@@ -202,7 +202,7 @@ void BinController::loadBinPlaylist(Mlt::Tractor &tractor)
}
// If no Playlist found, create new one
if (!m_binPlaylist) {
m_binPlaylist.reset(new Mlt::Playlist(*tractor.profile()));
m_binPlaylist.reset(new Mlt::Playlist(*tractor->profile()));
m_binPlaylist->set("id", kPlaylistTrackId);
}
}
......
......@@ -89,7 +89,7 @@ public:
void destroyBin();
/** @brief Load the Bin's main playlist from an existing tractor */
void loadBinPlaylist(Mlt::Tractor &tractor);
void loadBinPlaylist(Mlt::Tractor *tractor);
/** @brief Initialize the bin's playlist from MLT's data
* @param playlist The MLT playlist containing our bin's clips
......
......@@ -214,10 +214,7 @@ void ProjectManager::newFile(bool showProjectSettings, bool force)
pCore->window()->m_timelineArea->addTab(m_trackView, QIcon::fromTheme(QStringLiteral("kdenlive")), doc->description());*/
// END of things to delete
m_project = doc;
QScopedPointer<Mlt::Producer> prod(doc->getProjectProducer());
Mlt::Service s(*prod);
Mlt::Tractor t(s);
updateTimeline(t);
updateTimeline();
/*if (!ok) {
// MLT is broken
//pCore->window()->m_timelineArea->setEnabled(false);
......@@ -576,9 +573,7 @@ void ProjectManager::doOpenFile(const QUrl &url, KAutoSaveFile *stale)
disableEffects->blockSignals(false);
}
}*/
Mlt::Service s(*doc->getProjectProducer());
Mlt::Tractor t(s);
updateTimeline(t);
updateTimeline();
pCore->window()->connectDocument();
emit docOpened(m_project);
......@@ -861,10 +856,11 @@ void ProjectManager::slotMoveFinished(KJob *job)
}
}
void ProjectManager::updateTimeline(Mlt::Tractor tractor)
void ProjectManager::updateTimeline()
{
pCore->producerQueue()->abortOperations();
pCore->binController()->loadBinPlaylist(tractor);
m_mainTimelineModel = TimelineItemModel::construct(&pCore->getCurrentProfile()->profile(), m_project->getGuideModel(), m_project->commandStack(), m_project->getProjectXml());
pCore->binController()->loadBinPlaylist(m_mainTimelineModel->tractor());
const QStringList ids = pCore->binController()->getClipIds();
for (const QString &id : ids) {
if (id == QLatin1String("black")) {
......@@ -877,7 +873,6 @@ void ProjectManager::updateTimeline(Mlt::Tractor tractor)
info.replaceProducer = true;
pCore->bin()->slotProducerReady(info, pCore->binController()->getController(id).get());
}
m_mainTimelineModel = TimelineItemModel::construct(&pCore->getCurrentProfile()->profile(), m_project->getGuideModel(), m_project->commandStack(), tractor);
m_mainTimelineModel->loadTractor();
//pCore->binController()->setBinPlaylist(m_mainTimelineModel->tractor());
//constructTimelineFromMelt(m_mainTimelineModel, tractor);
......
......@@ -152,7 +152,7 @@ signals:
// void projectOpened(Project *project);
protected:
void updateTimeline(Mlt::Tractor tractor);
void updateTimeline();
private:
/** @brief Checks that the Kdenlive mime type is correctly installed.
......
......@@ -35,15 +35,15 @@
#include <mlt++/MltTransition.h>
#include <utility>
TimelineItemModel::TimelineItemModel(Mlt::Profile *profile, std::weak_ptr<DocUndoStack> undo_stack, Mlt::Tractor mlt_timeline)
: TimelineModel(profile, undo_stack, mlt_timeline)
TimelineItemModel::TimelineItemModel(Mlt::Profile *profile, std::weak_ptr<DocUndoStack> undo_stack, const QByteArray xml)
: TimelineModel(profile, undo_stack, xml)
{
}
std::shared_ptr<TimelineItemModel> TimelineItemModel::construct(Mlt::Profile *profile, std::shared_ptr<MarkerListModel> guideModel,
std::weak_ptr<DocUndoStack> undo_stack, Mlt::Tractor mlt_timeline)
std::weak_ptr<DocUndoStack> undo_stack, const QByteArray xml)
{
std::shared_ptr<TimelineItemModel> ptr(new TimelineItemModel(profile, std::move(undo_stack), mlt_timeline));
std::shared_ptr<TimelineItemModel> ptr(new TimelineItemModel(profile, std::move(undo_stack), xml));
ptr->m_groups = std::unique_ptr<GroupsModel>(new GroupsModel(ptr));
guideModel->registerSnapModel(ptr->m_snaps);
return ptr;
......
......@@ -55,14 +55,14 @@ public:
@param guideModel ptr to the guide model of the project
*/
static std::shared_ptr<TimelineItemModel> construct(Mlt::Profile *profile, std::shared_ptr<MarkerListModel> guideModel,
std::weak_ptr<DocUndoStack> undo_stack, Mlt::Tractor mlt_timeline);
std::weak_ptr<DocUndoStack> undo_stack, const QByteArray xml);
friend bool constructTimelineFromMelt(const std::shared_ptr<TimelineItemModel> &timeline, Mlt::Tractor mlt_timeline);
friend bool constructTimelineFromMelt(const std::shared_ptr<TimelineItemModel> &timeline, Mlt::Tractor tractor);
protected:
/* @brief this constructor should not be called. Call the static construct instead
*/
TimelineItemModel(Mlt::Profile *profile, std::weak_ptr<DocUndoStack> undo_stack, Mlt::Tractor mlt_timeline);
TimelineItemModel(Mlt::Profile *profile, std::weak_ptr<DocUndoStack> undo_stack, const QByteArray xml);
public:
~TimelineItemModel();
......
......@@ -48,9 +48,8 @@
int TimelineModel::next_id = 0;
TimelineModel::TimelineModel(Mlt::Profile *profile, std::weak_ptr<DocUndoStack> undo_stack, Mlt::Tractor mlt_timeline)
TimelineModel::TimelineModel(Mlt::Profile *profile, std::weak_ptr<DocUndoStack> undo_stack, const QByteArray xml)
: QAbstractItemModel()
, m_tractor(new Mlt::Tractor(mlt_timeline))
, m_snaps(new SnapModel())
, m_undoStack(undo_stack)
, m_profile(profile)
......@@ -58,6 +57,10 @@ TimelineModel::TimelineModel(Mlt::Profile *profile, std::weak_ptr<DocUndoStack>
, m_timelineEffectsEnabled(true)
, m_id(getNextId())
{
QScopedPointer<Mlt::Producer> prod(new Mlt::Producer(*profile, "xml-string", xml.constData()));
Mlt::Service s(*prod);
m_tractor = std::unique_ptr<Mlt::Tractor>(new Mlt::Tractor(s));
// Load black background track
QScopedPointer <Mlt::Producer> bgTrack(m_tractor->track(0));
Mlt::Playlist bgPlaylist(*bgTrack);
......
......@@ -87,7 +87,7 @@ class TimelineModel : public QAbstractItemModel, public std::enable_shared_from_
protected:
/* @brief this constructor should not be called. Call the static construct instead
*/
TimelineModel(Mlt::Profile *profile, std::weak_ptr<DocUndoStack> undo_stack, Mlt::Tractor mlt_timeline);
TimelineModel(Mlt::Profile *profile, std::weak_ptr<DocUndoStack> undo_stack, const QByteArray xml);
public:
friend class TrackModel;
......
......@@ -40,11 +40,10 @@ TEST_CASE("Basic creation/deletion of a composition", "[CompositionModel]")
REQUIRE(mlt_transition->is_valid());
Mlt::Profile testProfile;
Mlt::Tractor tractor(testProfile);
QByteArray xml;
std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);
std::shared_ptr<MarkerListModel> guideModel(new MarkerListModel(undoStack));
std::shared_ptr<TimelineItemModel> timeline = TimelineItemModel::construct(new Mlt::Profile(), guideModel, undoStack, tractor);
std::shared_ptr<TimelineItemModel> timeline = TimelineItemModel::construct(new Mlt::Profile(), guideModel, undoStack, xml);
REQUIRE(timeline->getCompositionsCount() == 0);
int id1 = CompositionModel::construct(timeline, aCompo);
......@@ -67,11 +66,10 @@ TEST_CASE("Basic creation/deletion of a composition", "[CompositionModel]")
TEST_CASE("Composition manipulation", "[CompositionModel]")
{
Mlt::Profile testProfile;
Mlt::Tractor tractor(testProfile);
QByteArray xml;
std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);
std::shared_ptr<MarkerListModel> guideModel(new MarkerListModel(undoStack));
std::shared_ptr<TimelineItemModel> timeline = TimelineItemModel::construct(new Mlt::Profile(), guideModel, undoStack, tractor);
std::shared_ptr<TimelineItemModel> timeline = TimelineItemModel::construct(new Mlt::Profile(), guideModel, undoStack, xml);
int tid0 = TrackModel::construct(timeline);
int tid1 = TrackModel::construct(timeline);
......
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