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
${kdenlive_SRCS}
timeline2/model/timelinemodel.cpp
timeline2/model/trackmodel.cpp
timeline2/model/clipmodel.cpp
PARENT_SCOPE)
/***************************************************************************
* 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 "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_parent(parent)
, 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()) {
ptr->registerClip(clip);
} else {
qDebug() << "Error : construction of clip failed because parent timeline is not available anymore";
Q_ASSERT(false);
}
return id;
}
int ClipModel::getId() const
{
return m_id;
}
......@@ -19,21 +19,38 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#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
{
Q_OBJECT
ClipModel() = delete;
/* Creates a clip attached to the given track
public:
/* 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;
public:
/* 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);
private:
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:
TimelineModel();
friend class TrackModel;
friend class ClipModel;
~TimelineModel();
/* @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);
protected:
......@@ -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")
SET(Tests_SRCS
TestMain.cpp
trackmodeltest.cpp
modeltest.cpp
../src/timeline2/model/trackmodel.cpp
../src/timeline2/model/timelinemodel.cpp
../src/timeline2/model/clipmodel.cpp
)
INCLUDE_DIRECTORIES(../src/)
......
......@@ -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