[vlmc-devel] MainWorkflow: addClip and moveClip
Yikai Lu
git at videolan.org
Sun Jul 10 18:03:32 CEST 2016
vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Sat Jul 9 00:25:50 2016 +0900| [3a5366d8d46a8ace344900573a431f0e7f2274a2] | committer: Yikai Lu
MainWorkflow: addClip and moveClip
> https://code.videolan.org/videolan/vlmc/commit/3a5366d8d46a8ace344900573a431f0e7f2274a2
---
src/Workflow/MainWorkflow.cpp | 79 ++++++++++++++++++++++++++++++++++++++----
src/Workflow/MainWorkflow.h | 12 +++++--
src/Workflow/TrackWorkflow.cpp | 2 +-
3 files changed, 82 insertions(+), 11 deletions(-)
diff --git a/src/Workflow/MainWorkflow.cpp b/src/Workflow/MainWorkflow.cpp
index 41ccc6b..9c71bf5 100644
--- a/src/Workflow/MainWorkflow.cpp
+++ b/src/Workflow/MainWorkflow.cpp
@@ -24,6 +24,8 @@
#include "vlmc.h"
+#include "Commands/Commands.h"
+#include "Commands/AbstractUndoStack.h"
#include "Backend/MLT/MLTOutput.h"
#include "Backend/MLT/MLTMultiTrack.h"
#include "Backend/MLT/MLTTrack.h"
@@ -33,6 +35,7 @@
#endif
#include "Project/Project.h"
#include "Media/Clip.h"
+#include "Media/Media.h"
#include "Library/Library.h"
#include "MainWorkflow.h"
#include "Project/Project.h"
@@ -55,6 +58,10 @@ MainWorkflow::MainWorkflow( Settings* projectSettings, int trackCount ) :
connect( m_renderer->eventWatcher(), &RendererEventWatcher::lengthChanged, this, &MainWorkflow::lengthChanged );
connect( m_renderer->eventWatcher(), &RendererEventWatcher::endReached, this, &MainWorkflow::mainWorkflowEndReached );
+ connect( m_renderer->eventWatcher(), &RendererEventWatcher::positionChanged, this, [this]( qint64 pos )
+ {
+ emit frameChanged( pos, Vlmc::Renderer );
+ } );
for ( int i = 0; i < trackCount; ++i )
m_tracks << new TrackWorkflow( i, m_multitrack );
@@ -125,6 +132,12 @@ MainWorkflow::clear()
emit cleared();
}
+void
+MainWorkflow::setPosition( qint64 newFrame )
+{
+ m_renderer->setPosition( newFrame );
+}
+
AbstractRenderer*
MainWorkflow::renderer()
{
@@ -153,7 +166,7 @@ MainWorkflow::trackCount() const
}
std::shared_ptr<Clip>
-MainWorkflow::createClip( const QUuid& uuid )
+MainWorkflow::createClip( const QUuid& uuid, quint32 trackId )
{
Clip* clip = Core::instance()->library()->clip( uuid );
if ( clip == nullptr )
@@ -162,30 +175,82 @@ MainWorkflow::createClip( const QUuid& uuid )
return nullptr;
}
auto newClip = std::make_shared<Clip>( clip );
- m_clips << newClip;
+ m_clips.insertMulti( trackId, newClip );
return newClip;
}
QString
-MainWorkflow::createClip( const QString& uuid )
+MainWorkflow::addClip( const QString& uuid, quint32 trackId, qint32 pos, bool isAudioClip )
{
- auto newClip = createClip( QUuid( uuid ) );
+ auto newClip = createClip( uuid, trackId );
+
+ if ( isAudioClip == true )
+ newClip->setFormats( Clip::Audio );
+ else
+ newClip->setFormats( Clip::Video );
+
+ Commands::trigger( new Commands::Clip::Add( newClip, track( trackId ), pos ) );
+
return newClip->uuid().toString();
}
QJsonObject
MainWorkflow::clipInfo( const QString& uuid )
{
- for ( auto clip : m_clips )
+ auto lClip = Core::instance()->library()->clip( uuid );
+ if ( lClip != nullptr )
+ {
+ auto h = lClip->toVariant().toHash();
+ h["length"] = lClip->length();
+ h["name"] = lClip->media()->fileName();
+ h["audio"] = lClip->formats().testFlag( Clip::Audio );
+ h["video"] = lClip->formats().testFlag( Clip::Video );
+ if ( lClip->isRootClip() == true )
+ {
+ h["begin"] = lClip->begin();
+ h["end"] = lClip->end();
+ }
+ return QJsonObject::fromVariantHash( h );
+ }
+
+ for ( auto it = m_clips.begin(); it != m_clips.end(); ++it )
{
- if ( clip->uuid().toString() == uuid )
+ if ( it.value()->uuid().toString() == uuid )
{
- return QJsonObject::fromVariantHash( clip->toVariant().toHash() );
+ auto clip = it.value();
+ auto h = clip->toVariant().toHash();
+ h["length"] = clip->length();
+ h["name"] = clip->media()->fileName();
+ h["audio"] = clip->formats().testFlag( Clip::Audio );
+ h["video"] = clip->formats().testFlag( Clip::Video );
+ h["position"] = track( it.key() )->getClipPosition( uuid );
+ return QJsonObject::fromVariantHash( h );
}
}
return QJsonObject();
}
+void
+MainWorkflow::moveClip( quint32 trackId, const QString& uuid, qint64 startFrame )
+{
+ for ( auto it = m_clips.begin(); it != m_clips.end(); ++it )
+ {
+ if ( it.value()->uuid().toString() == uuid )
+ {
+ auto oldTrackId = it.key();
+ auto clip = it.value();
+
+ if ( startFrame == getClipPosition( uuid, oldTrackId ) )
+ return;
+
+ Commands::trigger( new Commands::Clip::Move( track( oldTrackId ), track( trackId ), clip, startFrame ) );
+
+ m_clips.erase( it );
+ m_clips.insertMulti( trackId, clip );
+ }
+ }
+}
+
bool
MainWorkflow::startRenderToFile( const QString &outputFileName, quint32 width, quint32 height,
double fps, const QString &ar, quint32 vbitrate, quint32 abitrate,
diff --git a/src/Workflow/MainWorkflow.h b/src/Workflow/MainWorkflow.h
index d638fe6..d621dfe 100644
--- a/src/Workflow/MainWorkflow.h
+++ b/src/Workflow/MainWorkflow.h
@@ -47,6 +47,7 @@ class MediaContainer;
#include <QObject>
#include <QUuid>
+#include <QMap>
/**
* \class Represent the Timeline backend.
@@ -136,16 +137,19 @@ class MainWorkflow : public QObject
* The clip will be added to this MediaContainer, not to the Library.
* The parent clip should be in the Library.
*/
- std::shared_ptr<Clip> createClip( const QUuid& uuid );
+ std::shared_ptr<Clip> createClip( const QUuid& uuid, quint32 trackId );
Q_INVOKABLE
- QString createClip( const QString& uuid );
+ QString addClip( const QString& uuid, quint32 trackId, qint32 pos, bool isAudioClip );
Q_INVOKABLE
QJsonObject clipInfo( const QString& uuid );
+ Q_INVOKABLE
+ void moveClip( quint32 trackId, const QString& uuid, qint64 startFrame );
+
bool startRenderToFile( const QString& outputFileName, quint32 width, quint32 height,
double fps, const QString& ar, quint32 vbitrate, quint32 abitrate,
quint32 nbChannels, quint32 sampleRate );
@@ -169,7 +173,7 @@ class MainWorkflow : public QObject
private:
QList<TrackWorkflow*> m_tracks;
- QList<std::shared_ptr<Clip>> m_clips;
+ QMap<qint32, std::shared_ptr<Clip>> m_clips;
const quint32 m_trackCount;
Settings* m_settings;
@@ -189,6 +193,8 @@ class MainWorkflow : public QObject
*/
void clear();
+ void setPosition( qint64 newFrame );
+
signals:
/**
* \brief Used to notify a change to the timeline and preview widget cursor
diff --git a/src/Workflow/TrackWorkflow.cpp b/src/Workflow/TrackWorkflow.cpp
index 1492b9f..2837a83 100644
--- a/src/Workflow/TrackWorkflow.cpp
+++ b/src/Workflow/TrackWorkflow.cpp
@@ -234,7 +234,7 @@ TrackWorkflow::loadFromVariant( const QVariant &variant )
for ( auto& var : variant.toMap()[ "clips" ].toList() )
{
auto m = var.toMap();
- auto c = std::shared_ptr<Clip>( Core::instance()->workflow()->createClip( QUuid( m["parent"].toString() ) ) );
+ auto c = std::shared_ptr<Clip>( Core::instance()->workflow()->createClip( m["parent"].toString(), trackId() ) );
c->setBoundaries( m["begin"].toULongLong(),
m["end"].toULongLong()
);
More information about the Vlmc-devel
mailing list