[vlmc-devel] TrackWorkflow: Implement a helper to get a track from media format

Yikai Lu git at videolan.org
Sun Jun 26 06:01:49 CEST 2016


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Sat Jun 25 20:11:52 2016 +0900| [cff1540eed80498b50b8d76af23148d097f99ebe] | committer: Yikai Lu

TrackWorkflow: Implement a helper to get a track from media format

> https://code.videolan.org/videolan/vlmc/commit/cff1540eed80498b50b8d76af23148d097f99ebe
---

 src/Workflow/TrackWorkflow.cpp | 21 ++++++++++++++-------
 src/Workflow/TrackWorkflow.h   |  5 ++++-
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/Workflow/TrackWorkflow.cpp b/src/Workflow/TrackWorkflow.cpp
index 4a18d02..e1a30ad 100644
--- a/src/Workflow/TrackWorkflow.cpp
+++ b/src/Workflow/TrackWorkflow.cpp
@@ -69,13 +69,20 @@ TrackWorkflow::~TrackWorkflow()
     delete m_clipsLock;
 }
 
+Backend::ITrack*
+TrackWorkflow::trackFromFormats( Clip::Formats formats )
+{
+    if ( formats.testFlag( Clip::Audio ) )
+        return m_audioTrack;
+    else if ( formats.testFlag( Clip::Video ) )
+        return m_videoTrack;
+    return nullptr;
+}
+
 void
 TrackWorkflow::addClip( Clip* clip, qint64 start )
 {
-    if ( clip->formats().testFlag( Clip::Audio ) )
-        m_audioTrack->insertAt( *clip->producer(), start );
-    else if ( clip->formats().testFlag( Clip::Video ) )
-        m_videoTrack->insertAt( *clip->producer(), start );
+    trackFromFormats( clip->formats() )->insertAt( *clip->producer(), start );
     m_clips.insertMulti( start, clip );
     emit clipAdded( this, clip, start );
 }
@@ -123,7 +130,7 @@ TrackWorkflow::moveClip( const QUuid& id, qint64 startingFrame )
         if ( it.value()->uuid() == id )
         {
             auto clip = it.value();
-            auto track = ( clip->formats().testFlag( Clip::Audio ) ) ? m_audioTrack : m_videoTrack;
+            auto track = trackFromFormats( it.value()->formats() );
             auto producer = track->clipAt( it.key() );
             track->remove( track->clipIndexAt( it.key() ) );
             track->insertAt( *producer, startingFrame );
@@ -148,7 +155,7 @@ TrackWorkflow::resizeClip( const QUuid &id, qint64 begin, qint64 end )
         auto clip = it.value();
         if ( clip->uuid() == id )
         {
-            auto track = ( clip->formats().testFlag( Clip::Audio ) ) ? m_audioTrack : m_videoTrack;
+            auto track = trackFromFormats( clip->formats() );
             track->resizeClip( track->clipIndexAt( it.key() ), begin, end );
         }
     }
@@ -189,7 +196,7 @@ TrackWorkflow::removeClip( const QUuid& id )
         if ( it.value()->uuid() == id )
         {
             auto    clip = it.value();
-            auto    track = ( clip->formats().testFlag( Clip::Audio ) ) ? m_audioTrack : m_videoTrack;
+            auto    track = trackFromFormats( clip->formats() );
             track->remove( track->clipIndexAt( it.key() ) );
             m_clips.erase( it );
             clip->disconnect( this );
diff --git a/src/Workflow/TrackWorkflow.h b/src/Workflow/TrackWorkflow.h
index e3e6746..66eb2fd 100644
--- a/src/Workflow/TrackWorkflow.h
+++ b/src/Workflow/TrackWorkflow.h
@@ -30,7 +30,8 @@
 #include <QMap>
 #include <QXmlStreamWriter>
 
-class   Clip;
+#include "Media/Clip.h"
+
 class   MainWorkflow;
 
 class   EffectHelper;
@@ -59,6 +60,8 @@ class   TrackWorkflow : public QObject
         TrackWorkflow( quint32 trackId, Backend::ITractor* tractor );
         ~TrackWorkflow();
 
+        Backend::ITrack*                        trackFromFormats( Clip::Formats formats );
+
         void                                    moveClip( const QUuid& id, qint64 startingFrame );
         void                                    resizeClip( const QUuid& id, qint64 begin, qint64 end );
         Clip*                                   removeClip( const QUuid& id );



More information about the Vlmc-devel mailing list