Commit ed2b7446 authored by luyikei's avatar luyikei

Save and Load filters to Project

parent 2d9a4828
......@@ -73,6 +73,12 @@ EffectHelper::EffectHelper( Backend::IFilter *filter, const QString& uuid )
initParams();
}
EffectHelper::EffectHelper( const QVariant& variant )
: EffectHelper( variant.toMap()["identifier"].toString() )
{
loadFromVariant( variant );
}
EffectHelper::~EffectHelper()
{
delete m_filter;
......@@ -147,7 +153,7 @@ EffectHelper::set( SettingValue* value, const QVariant& variant )
}
QVariant
EffectHelper::defaultValue( const char *id, SettingValue::Type type )
EffectHelper::defaultValue( const char* id, SettingValue::Type type )
{
switch ( type )
{
......@@ -168,6 +174,49 @@ EffectHelper::value( const QString& key )
return m_settings.value( key );
}
void
EffectHelper::loadFromVariant( const QVariant& variant )
{
auto m = variant.toMap()["parameters"].toMap();
for ( auto it = m.cbegin(); it != m.cend(); ++it )
value( it.key() )->set( it.value() );
}
QVariant
EffectHelper::toVariant()
{
QVariantHash h;
for ( const auto param : filterInfo()->paramInfos() )
{
auto val = value( QString::fromStdString( param->identifier() ) );
h.insert( val->key(), val->get() );
}
return QVariantHash{ { "identifier", identifier() }, { "parameters", h } };
}
QVariant
EffectHelper::toVariant( Backend::IService* service )
{
QVariantList filters;
for ( int i = 0; i < service->filterCount(); ++ i )
{
EffectHelper helper( service->filter( i ) );
filters << helper.toVariant();
}
return filters;
}
void
EffectHelper::loadFromVariant( const QVariant& variant, Backend::IService* service )
{
for ( auto& var : variant.toList() )
{
EffectHelper helper( var );
service->attach( *helper.filter() );
helper.filter()->connect( *helper.filter() );
}
}
qint64
EffectHelper::begin() const
{
......
......@@ -54,6 +54,7 @@ class EffectHelper : public Workflow::Helper
const QString& uuid = QString() );
EffectHelper( Backend::IFilter* filter,
const QString& uuid = QString() );
EffectHelper( const QVariant& variant );
~EffectHelper();
virtual qint64 begin() const override;
......@@ -75,6 +76,14 @@ class EffectHelper : public Workflow::Helper
SettingValue* value( const QString& key );
// Handle one filter.
void loadFromVariant( const QVariant& variant );
QVariant toVariant();
// Handle one service
static QVariant toVariant( Backend::IService* service );
static void loadFromVariant( const QVariant& variant, Backend::IService* service );
private:
Backend::MLT::MLTFilter* m_filter;
Backend::IService* m_service;
......
......@@ -27,6 +27,7 @@
#include "MediaContainer.h"
#include "Media/Clip.h"
#include "Media/Media.h"
#include "EffectsEngine/EffectHelper.h"
#include "Settings/Settings.h"
#include "Tools/VlmcDebug.h"
#include "Project/Workspace.h"
......@@ -211,5 +212,10 @@ MediaContainer::createClipFromVariant( const QVariant &var, Clip* parent )
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->producer() );
return c;
}
......@@ -261,6 +261,7 @@ Clip::toVariant() const
h.insert( "begin", begin() );
h.insert( "end", end() );
}
h.insert( "filters", EffectHelper::toVariant( m_producer ) );
return QVariant( h );
}
......
......@@ -212,22 +212,21 @@ TrackWorkflow::removeClip( const QUuid& id )
QVariant
TrackWorkflow::toVariant() const
{
/*
QVariantList l;
for ( auto it = m_clips.cbegin(); it != m_clips.cend(); it++ )
for ( auto it = m_clips.begin(); it != m_clips.end(); ++it )
{
auto clip = it.value();
l << QVariantHash{
{ "clip", clip->uuid() },
{ "begin", clip->begin() },
{ "end", clip->end() },
{ "startFrame", it.key() },
{ "filters", clip->toVariant() }
};
QVariantHash h;
h.insert( "parent", clip->parent()->uuid().toString() );
h.insert( "begin", clip->begin() );
h.insert( "end", clip->end() );
h.insert( "formats", (int)clip->formats() );
h.insert( "filters", EffectHelper::toVariant( clip->producer() ) );
h.insert( "startFrame", it.key() );
l << h;
}
QVariantHash h{ { "clips", l } };
return QVariant( h );*/
return QVariant();
QVariantHash h{ { "clips", l }, { "filters", EffectHelper::toVariant( m_tractor ) } };
return QVariant( h );
}
void
......@@ -235,26 +234,16 @@ TrackWorkflow::loadFromVariant( const QVariant &variant )
{
for ( auto& var : variant.toMap()[ "clips" ].toList() )
{
QVariantMap m = var.toMap();
const QString& uuid = m["clip"].toString();
qint64 startFrame = m["startFrame"].toLongLong();
qint64 begin = m["begin"].toLongLong();
qint64 end = m["end"].toLongLong();
if ( uuid.isEmpty() )
{
vlmcWarning() << "Invalid clip node";
return ;
}
Clip *clip = Core::instance()->workflow()->createClip( QUuid( uuid ) );
if ( clip == nullptr )
continue ;
clip->setBoundaries( begin, end );
addClip( clip, startFrame );
// TODO clip->clipWorkflow()->loadFromVariant( m["filters"] );
auto m = var.toMap();
auto c = Core::instance()->workflow()->createClip( m["parent"].toString() );
c->setBoundaries( m["begin"].toULongLong(),
m["end"].toULongLong()
);
c->setFormats( (Clip::Formats)m["formats"].toInt() );
EffectHelper::loadFromVariant( m["filters"], c->producer() );
addClip( c, m["startFrame"].toLongLong() );
}
EffectHelper::loadFromVariant( variant.toMap()["filters"], m_tractor );
}
void
......
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