[vlmc-devel] Save and Load filters to Project
Yikai Lu
git at videolan.org
Sun Jun 26 06:01:44 CEST 2016
vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Tue Jun 21 17:26:11 2016 +0900| [ed2b7446c3c0b27a8cfcc542825c68379a0e1e21] | committer: Yikai Lu
Save and Load filters to Project
> https://code.videolan.org/videolan/vlmc/commit/ed2b7446c3c0b27a8cfcc542825c68379a0e1e21
---
src/EffectsEngine/EffectHelper.cpp | 51 +++++++++++++++++++++++++++++++++++++-
src/EffectsEngine/EffectHelper.h | 9 +++++++
src/Library/MediaContainer.cpp | 6 +++++
src/Media/Clip.cpp | 1 +
src/Workflow/TrackWorkflow.cpp | 51 +++++++++++++++-----------------------
5 files changed, 86 insertions(+), 32 deletions(-)
diff --git a/src/EffectsEngine/EffectHelper.cpp b/src/EffectsEngine/EffectHelper.cpp
index 34cc969..b6e1d08 100644
--- a/src/EffectsEngine/EffectHelper.cpp
+++ b/src/EffectsEngine/EffectHelper.cpp
@@ -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
{
diff --git a/src/EffectsEngine/EffectHelper.h b/src/EffectsEngine/EffectHelper.h
index a838f59..5f3c0bb 100644
--- a/src/EffectsEngine/EffectHelper.h
+++ b/src/EffectsEngine/EffectHelper.h
@@ -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;
diff --git a/src/Library/MediaContainer.cpp b/src/Library/MediaContainer.cpp
index 57a7feb..6a43d68 100644
--- a/src/Library/MediaContainer.cpp
+++ b/src/Library/MediaContainer.cpp
@@ -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;
}
diff --git a/src/Media/Clip.cpp b/src/Media/Clip.cpp
index 785fb5f..0be55c5 100644
--- a/src/Media/Clip.cpp
+++ b/src/Media/Clip.cpp
@@ -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 );
}
diff --git a/src/Workflow/TrackWorkflow.cpp b/src/Workflow/TrackWorkflow.cpp
index 681db36..f659c52 100644
--- a/src/Workflow/TrackWorkflow.cpp
+++ b/src/Workflow/TrackWorkflow.cpp
@@ -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
More information about the Vlmc-devel
mailing list