Commit 34508ae4 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

MediaContainer: Move createClipFromVariant to Clip class

parent 076e08d8
......@@ -78,7 +78,11 @@ Library::postLoad()
}
for ( const auto& var : m_settings->value( "clips" )->get().toList() )
createClipFromVariant( var, nullptr );
{
auto c = Clip::fromVariant( var );
if ( c != nullptr )
addClip( c );
}
}
Library::~Library()
......@@ -123,6 +127,12 @@ Library::isInCleanState() const
return m_cleanState;
}
Media*
Library::media(const QString& mrl)
{
return m_medias.value( mrl );
}
void
Library::setCleanState( bool newState )
{
......
......@@ -54,6 +54,7 @@ public:
virtual Media *addMedia( const QFileInfo &fileInfo );
virtual bool addClip( Clip *clip );
bool isInCleanState() const;
Media* media( const QString& mrl );
private:
void setCleanState( bool newState );
......
......@@ -192,27 +192,3 @@ MediaContainer::count() const
{
return m_clips.size();
}
Clip*
MediaContainer::createClipFromVariant( const QVariant &var, Clip* parent )
{
QVariantMap h = var.toMap();
Clip* c = nullptr;
if ( h.contains( "parent" ) )
c = new Clip( parent, h["begin"].toULongLong(),
h["end"].toULongLong(), h["uuid"].toString() );
else {
c = new Clip( m_medias[ h["media"].toString() ], 0, -1, h["uuid"].toString() );
addClip( c );
}
if ( h.contains( "subClips" ) )
for ( auto& var : h["subClips"].toList() )
c->addSubclip( createClipFromVariant( var, c ) );
if ( h.contains( "filters" ) )
for ( auto& var : h["filters"].toList() )
EffectHelper::loadFromVariant( var, c->input() );
return c;
}
......@@ -121,8 +121,6 @@ protected:
Clip* m_parent;
Clip* createClipFromVariant( const QVariant& var, Clip* parent );
public slots:
/**
* \brief Removes a Clip from the container and delete it
......
......@@ -36,6 +36,7 @@
#include "Media/Media.h"
#include "Project/Workspace.h"
#include "EffectsEngine/EffectHelper.h"
#include "Tools/VlmcDebug.h"
#include <QVariant>
Clip::Clip( Media *media, qint64 begin /*= 0*/, qint64 end /*= Backend::IInput::EndOfMedia */, const QString& uuid /*= QString()*/ ) :
......@@ -342,6 +343,89 @@ Clip::input()
return m_input.get();
}
Clip*
Clip::fromVariant( const QVariant& v )
{
auto m = v.toMap();
if ( m.contains( "parent" ) )
{
vlmcWarning() << "Refusing to load a root clip with a parent field";
return nullptr;
}
auto mediaMrl = m["media"].toString();
if ( mediaMrl.isEmpty() == true )
{
vlmcWarning() << "Refusing to load an invalid root clip with no base media";
return nullptr;
}
auto uuid = m["uuid"].toString();
if ( uuid.isEmpty() == true )
{
vlmcWarning() << "Refusing to load an invalid root clip with no UUID";
return nullptr;
}
auto media = Core::instance()->library()->media( mediaMrl );
auto clip = new Clip( media, 0, -1, uuid );
clip->loadVariant( m );
return clip;
}
Clip*
Clip::fromVariant( const QVariant& v, Clip* parent )
{
auto m = v.toMap();
if ( m.contains( "parent" ) == false )
{
vlmcWarning() << "Refusing to load a subclip with no parent field";
return nullptr;
}
auto mediaMrl = m["media"].toString();
if ( mediaMrl.isEmpty() == true )
{
vlmcWarning() << "Refusing to load an invalid root clip with no base media";
return nullptr;
}
auto uuid = m["uuid"].toString();
if ( uuid.isEmpty() == true )
{
vlmcWarning() << "Refusing to load an invalid root clip with no UUID";
return nullptr;
}
auto begin = m["begin"].toLongLong();
auto end = m["end"].toLongLong();
auto media = Core::instance()->library()->media( mediaMrl );
auto clip = new Clip( parent, begin, end, uuid );
clip->loadVariant( m );
return clip;
}
void
Clip::loadVariant( const QVariantMap& m )
{
if ( m.contains( "subClips" ) )
{
auto children = m["subClips"].toList();
for ( const auto& clipMap : children )
m_childs->addClip( fromVariant( clipMap, this ) );
}
if ( m.contains( "filters" ) )
{
const auto& filters = m["filters"].toList();
for ( const auto& f : filters )
EffectHelper::loadFromVariant( f, input() );
}
}
void
Clip::mediaMetadataUpdated()
{
......
......@@ -144,6 +144,12 @@ class Clip : public Workflow::Helper
Backend::IInput* input();
static Clip* fromVariant( const QVariant& v );
private:
static Clip* fromVariant( const QVariant& v, Clip* parent );
void loadVariant(const QVariantMap& v );
private:
Media* m_media;
std::unique_ptr<Backend::IInput> m_input;
......
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