Commit 40839179 authored by Nicolas Carion's avatar Nicolas Carion

[Timeline2][Model] Insertion of clips + tests

parent 7e8bd985
......@@ -2,5 +2,6 @@ set(kdenlive_SRCS
* Copyright (C) 2017 by Nicolas Carion *
* This file is part of Kdenlive. See *
* *
* 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 *
* 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 <>. *
#include "clipmodel.hpp"
#include "timelinemodel.hpp"
#include <mlt++/MltProducer.h>
#include <QDebug>
int ClipModel::next_id = 0;
ClipModel::ClipModel(std::weak_ptr<TimelineModel> parent, std::weak_ptr<Mlt::Producer> prod) :
, m_id(ClipModel::next_id++)
, m_producer(prod)
int ClipModel::construct(std::weak_ptr<TimelineModel> parent, std::weak_ptr<Mlt::Producer> prod)
std::shared_ptr<ClipModel> clip = std::make_shared<ClipModel>(parent, prod);
int id = clip->m_id;
if (auto ptr = parent.lock()) {
} else {
qDebug() << "Error : construction of clip failed because parent timeline is not available anymore";
return id;
int ClipModel::getId() const
return m_id;
......@@ -19,21 +19,38 @@
* along with this program. If not, see <>. *
#include <QSharedPointer>
#include <memory>
#include <QObject>
namespace Mlt{
class Producer;
class TimelineModel;
/* @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
class ClipModel
class ClipModel : public QObject
ClipModel() = delete;
/* Creates a clip attached to the given track
/* 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);
/* @brief Creates a clip, which references itself to the parent timeline
Returns the (unique) id of the created clip
@param parent is a pointer to the timeline
@param producer is the producer to be inserted
ClipModel(QSharedPointer<TrackModel> parent);
static int construct(std::weak_ptr<TimelineModel> parent, std::weak_ptr<Mlt::Producer> prod);
public slots:
/* @brief returns (unique) id of current clip
int getId() const;
/* This is called whenever a resize of the clip is issued
If the resize is accepted, it should send back a signal to the QML interface.
......@@ -60,7 +77,10 @@ signals:
void signalPositionChanged(int);
Mlt::Producer m_producer;
QSharedPointer<TimelineModel> m_timeline;
std::weak_ptr<TimelineModel> m_parent;
int m_id; //this is the creation id of the clip, used for book-keeping
std::weak_ptr<Mlt::Producer> m_producer;
static int next_id; //next valid id to assign
......@@ -46,6 +46,10 @@ int TimelineModel::getTracksNumber()
Q_ASSERT(count == static_cast<int>(m_allTracks.size()));
return count;
int TimelineModel::getClipsNumber()
return m_allClips.size();
void TimelineModel::deleteTrackById(int id)
......@@ -77,6 +81,12 @@ void TimelineModel::registerTrack(std::unique_ptr<TrackModel>&& track, int pos)
m_iteratorTable[id] = it;
void TimelineModel::registerClip(std::shared_ptr<ClipModel> clip)
int id = clip->getId();
Q_ASSERT(m_allClips.count(id) == 0);
m_allClips[id] = clip;
void TimelineModel::deregisterTrack(int id)
......@@ -21,10 +21,12 @@
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <QVector>
#include <mlt++/MltTractor.h>
class TrackModel;
class ClipModel;
/* @brief This class represents a Timeline 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
......@@ -35,12 +37,16 @@ public:
friend class TrackModel;
friend class ClipModel;
/* @brief returns the number of tracks */
int getTracksNumber();
/* @brief returns the number of clips */
int getClipsNumber();
/* @brief Delete track based on its id */
void deleteTrackById(int id);
......@@ -49,6 +55,10 @@ protected:
void registerTrack(std::unique_ptr<TrackModel>&& track, int pos = -1);
/* @brief Register a new track. This is a call-back meant to be called from ClipModel
void registerClip(std::shared_ptr<ClipModel> clip);
/* @brief Deregister and destruct the track with given id.
void deregisterTrack(int id);
......@@ -60,4 +70,5 @@ private:
std::unordered_map<int, std::list<std::unique_ptr<TrackModel>>::iterator> m_iteratorTable; //this logs the iterator associated which each track id. This allows easy access of a track based on its id.
std::unordered_map<int, std::shared_ptr<ClipModel>> m_allClips; //the keys are the clip id, and the values are the corresponding pointers
......@@ -77,9 +77,6 @@ private:
int m_id; //this is the creation id of the track, used for book-keeping
Mlt::Playlist m_playlist;
std::vector<std::unique_ptr<ClipModel>> m_allClips;
static int next_id; //next valid id to assign
......@@ -10,9 +10,10 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fexceptions")
......@@ -5,6 +5,9 @@
#include "timeline2/model/timelinemodel.hpp"
#include "timeline2/model/clipmodel.hpp"
#include <mlt++/MltProducer.h>
#include <mlt++/MltFactory.h>
#include <mlt++/MltProfile.h>
......@@ -33,3 +36,17 @@ TEST_CASE("Basic creation/deletion of a track", "[TrackModel]")
TEST_CASE("Basic creation/deletion of a clip", "[ClipModel]")
std::shared_ptr<TimelineModel> timeline = std::make_shared<TimelineModel>();
Mlt::Factory::init( NULL );
Mlt::Profile profile;
std::shared_ptr<Mlt::Producer> producer = std::make_shared<Mlt::Producer>(profile, "test");
REQUIRE(timeline->getClipsNumber() == 0);
int id1 = ClipModel::construct(timeline, producer);
REQUIRE(timeline->getClipsNumber() == 1);
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