[vlmc-devel] Add Transition.cpp
Yikai Lu
git at videolan.org
Mon Aug 7 19:18:26 CEST 2017
vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Tue Aug 8 01:05:10 2017 +0900| [c7ce956cef80761583e0ea268149412329e55411] | committer: Yikai Lu
Add Transition.cpp
> https://code.videolan.org/videolan/vlmc/commit/c7ce956cef80761583e0ea268149412329e55411
---
Makefile.am | 1 +
src/Transition/Transition.cpp | 151 ++++++++++++++++++++++++++++++++++++++++++
src/Transition/Transition.h | 53 +++++++++++++++
3 files changed, 205 insertions(+)
diff --git a/Makefile.am b/Makefile.am
index 0e46cb7c..d7b20f3a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -23,6 +23,7 @@ vlmc_SOURCES = \
src/Main/main.cpp \
src/Media/Clip.cpp \
src/Media/Media.cpp \
+ src/Transition/Transition.cpp \
src/Project/Project.cpp \
src/Project/Workspace.cpp \
src/Project/WorkspaceWorker.cpp \
diff --git a/src/Transition/Transition.cpp b/src/Transition/Transition.cpp
new file mode 100644
index 00000000..c603cde9
--- /dev/null
+++ b/src/Transition/Transition.cpp
@@ -0,0 +1,151 @@
+#include "Transition.h"
+
+#include "Backend/MLT/MLTTrack.h"
+#include "Backend/MLT/MLTTransition.h"
+#include "Backend/MLT/MLTMultiTrack.h"
+#include "Workflow/Track.h"
+#include "Tools/VlmcDebug.h"
+
+#include <mlt++/MltPlaylist.h>
+#include <mlt++/MltTransition.h>
+
+Transition::Transition( const QString& identifier, qint64 position, qint64 endPosition, Workflow::TrackType type )
+ : Helper( QUuid::createUuid() )
+ , m_identifier( identifier )
+ , m_begin( position )
+ , m_end( endPosition )
+ , m_type( type )
+{
+ if ( identifier == QStringLiteral( "dissolve" ) )
+ {
+ if ( m_type == Workflow::AudioTrack )
+ {
+ auto mix = new Backend::MLT::MLTTransition( "mix" );
+ mix->properties()->set( "start", -1 );
+ addTransition( QSharedPointer<Backend::ITransition>( mix ) );
+ }
+ else if ( m_type == Workflow::VideoTrack )
+ {
+ auto luma = new Backend::MLT::MLTTransition( "luma" );
+ addTransition( QSharedPointer<Backend::ITransition>( luma ) );
+ }
+ }
+ else
+ addTransition( QSharedPointer<Backend::ITransition>(
+ new Backend::MLT::MLTTransition( qPrintable( identifier ) ) ) );
+}
+
+Transition::~Transition()
+{
+}
+
+const QUuid&
+Transition::uuid() const
+{
+ return m_uuid;
+}
+
+void
+Transition::setUuid( const QUuid& uuid )
+{
+ m_uuid = uuid;
+}
+
+qint64
+Transition::begin() const
+{
+ return m_begin;
+}
+
+qint64
+Transition::end() const
+{
+ return m_end;
+}
+
+void
+Transition::setBegin( qint64 begin )
+{
+ m_begin = begin;
+ for ( auto& transition : m_transitions )
+ transition->setBoundaries( m_begin, m_end );
+}
+
+void
+Transition::setEnd( qint64 end )
+{
+ m_end = end;
+ for ( auto& transition : m_transitions )
+ transition->setBoundaries( m_begin, m_end );
+}
+
+qint64
+Transition::length() const
+{
+ return m_end - m_begin + 1;
+}
+
+void
+Transition::setBoundaries( qint64 begin, qint64 end )
+{
+ m_begin = begin;
+ m_end = end;
+ for ( auto& transition : m_transitions )
+ transition->setBoundaries( begin, end );
+}
+
+Workflow::TrackType
+Transition::type() const
+{
+ return m_type;
+}
+
+void
+Transition::setType( Workflow::TrackType type )
+{
+ m_type = type;
+}
+
+void
+Transition::setTracks( quint32 trackAId, quint32 trackBId )
+{
+ for ( auto& transition : m_transitions )
+ dynamic_cast<Backend::MLT::MLTTransition*>( transition.data() )->transition()->set_tracks( trackAId, trackBId );
+}
+
+void
+Transition::addTransition( QSharedPointer<Backend::ITransition> transition )
+{
+ m_transitions << transition;
+ transition->setBoundaries( m_begin, m_end );
+}
+
+void
+Transition::apply( Backend::IMultiTrack& multitrack )
+{
+ for ( auto& transition : m_transitions )
+ if ( multitrack.count() >= 2 )
+ multitrack.addTransition( *transition.data(), 0, multitrack.count() - 1 );
+}
+
+void
+Transition::apply( Backend::IMultiTrack& multitrack, quint32 trackAId, quint32 trackBId )
+{
+ for ( auto& transition : m_transitions )
+ if ( multitrack.count() >= 2 )
+ multitrack.addTransition( *transition.data(), trackAId, trackBId );
+}
+
+QVariant
+Transition::toVariant() const
+{
+ QVariantHash h;
+ return QVariantHash{
+ { "uuid", uuid().toString() },
+ { "begin", begin() },
+ { "end", end() },
+ { "length", length() },
+ { "audio", type() == Workflow::AudioTrack },
+ { "identifier", m_identifier }
+ };
+}
diff --git a/src/Transition/Transition.h b/src/Transition/Transition.h
new file mode 100644
index 00000000..0ddc2a24
--- /dev/null
+++ b/src/Transition/Transition.h
@@ -0,0 +1,53 @@
+#ifndef TRANSITION_H
+#define TRANSITION_H
+
+#include "Workflow/Types.h"
+#include "Workflow/Helper.h"
+#include "Workflow/SequenceWorkflow.h"
+
+#include <QUuid>
+#include <QSharedPointer>
+
+namespace Backend {
+class ITransition;
+class IMultiTrack;
+}
+
+class Transition : public Workflow::Helper
+{
+public:
+ explicit Transition( const QString& identifier, qint64 begin, qint64 end, Workflow::TrackType type );
+ virtual ~Transition();
+
+ virtual const QUuid& uuid() const override;
+ void setUuid( const QUuid& uuid );
+
+ virtual qint64 begin() const override;
+ virtual qint64 end() const override;
+
+ virtual void setBegin( qint64 begin ) override;
+ virtual void setEnd( qint64 end ) override;
+ virtual qint64 length() const override;
+ virtual void setBoundaries( qint64 begin, qint64 end ) override;
+
+ Workflow::TrackType type() const;
+ void setType( Workflow::TrackType type );
+
+ void setTracks( quint32 trackAId, quint32 trackBId );
+ void addTransition( QSharedPointer<Backend::ITransition> transition );
+
+ void apply( Backend::IMultiTrack& multitrack );
+ void apply( Backend::IMultiTrack& multitrack, quint32 trackAId, quint32 trackBId );
+
+ QVariant toVariant() const;
+
+private:
+ QString m_identifier;
+ qint64 m_begin;
+ qint64 m_end;
+ Workflow::TrackType m_type;
+
+ QList<QSharedPointer<Backend::ITransition>> m_transitions;
+};
+
+#endif // TRANSITION_H
More information about the Vlmc-devel
mailing list