[vlmc-devel] [PATCH 5/8] MainWorkflow: Don't use TrackHandler

Yikai Lu luyikei.qmltu at gmail.com
Tue May 3 07:24:44 CEST 2016


---
 src/CMakeLists.txt                             |   1 -
 src/Gui/timeline/AbstractGraphicsMediaItem.cpp |   6 +-
 src/Gui/timeline/GraphicsTrack.cpp             |   6 +-
 src/Gui/timeline/TracksView.cpp                |  35 +++---
 src/Workflow/MainWorkflow.cpp                  | 150 ++++++++++++++-----------
 src/Workflow/MainWorkflow.h                    |  29 ++---
 src/Workflow/TrackWorkflow.cpp                 |  36 ++++--
 src/Workflow/TrackWorkflow.h                   |   4 +-
 8 files changed, 142 insertions(+), 125 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 238bffa..75d6679 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -84,7 +84,6 @@ SET(VLMC_SRCS
     Workflow/Helper.cpp
     Workflow/ImageClipWorkflow.cpp
     Workflow/MainWorkflow.cpp
-    Workflow/TrackHandler.cpp
     Workflow/TrackWorkflow.cpp
     Workflow/Types.cpp
     Workflow/VideoClipWorkflow.cpp
diff --git a/src/Gui/timeline/AbstractGraphicsMediaItem.cpp b/src/Gui/timeline/AbstractGraphicsMediaItem.cpp
index be683d0..270757c 100644
--- a/src/Gui/timeline/AbstractGraphicsMediaItem.cpp
+++ b/src/Gui/timeline/AbstractGraphicsMediaItem.cpp
@@ -111,14 +111,12 @@ AbstractGraphicsMediaItem::contextMenuEvent( QGraphicsSceneContextMenuEvent* eve
         if ( ( m_muted = muteAction->isChecked() ) )
         {
             tracksView()->m_mainWorkflow->muteClip( uuid(),
-                                                    trackId,
-                                                    trackType() );
+                                                    trackId );
         }
         else
         {
             tracksView()->m_mainWorkflow->unmuteClip( uuid(),
-                                                    trackId,
-                                                    trackType() );
+                                                    trackId );
         }
     }
     else if ( selectedAction == linkAction )
diff --git a/src/Gui/timeline/GraphicsTrack.cpp b/src/Gui/timeline/GraphicsTrack.cpp
index 7036ad3..b8a85ea 100644
--- a/src/Gui/timeline/GraphicsTrack.cpp
+++ b/src/Gui/timeline/GraphicsTrack.cpp
@@ -36,7 +36,7 @@ GraphicsTrack::GraphicsTrack( Workflow::TrackType type, quint32 trackNumber,
     m_type = type;
     m_trackNumber = trackNumber;
     m_enabled = true;
-    m_trackWorkflow = Core::instance()->workflow()->track( type, trackNumber );
+    m_trackWorkflow = Core::instance()->workflow()->track( trackNumber );
 
     setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
     setContentsMargins( 0, 0, 0, 0 );
@@ -65,9 +65,9 @@ GraphicsTrack::setTrackEnabled( bool enabled )
     m_enabled = enabled;
 
     if( enabled )
-        Core::instance()->workflow()->unmuteTrack( m_trackNumber, m_type );
+        Core::instance()->workflow()->unmuteTrack( m_trackNumber );
     else
-        Core::instance()->workflow()->muteTrack( m_trackNumber, m_type );
+        Core::instance()->workflow()->muteTrack( m_trackNumber );
 }
 
 bool
diff --git a/src/Gui/timeline/TracksView.cpp b/src/Gui/timeline/TracksView.cpp
index 39d69b2..514eb2c 100644
--- a/src/Gui/timeline/TracksView.cpp
+++ b/src/Gui/timeline/TracksView.cpp
@@ -89,27 +89,24 @@ TracksView::TracksView( QGraphicsScene *scene, MainWorkflow *mainWorkflow,
     connect( m_cursorLine, SIGNAL( cursorMoved(qint64) ),
              this, SLOT( ensureCursorVisible() ) );
 
-    for ( quint32 type = Workflow::VideoTrack; type < Workflow::NbTrackType; ++type )
+    for ( quint32 i = 0; i < m_mainWorkflow->trackCount(); ++i )
     {
-        for ( quint32 i = 0; i < m_mainWorkflow->trackCount(); ++i )
-        {
-            TrackWorkflow   *tw = m_mainWorkflow->track( static_cast<Workflow::TrackType>( type ), i );
-            //Clips part:
-            connect( tw, SIGNAL( clipAdded( TrackWorkflow*, Workflow::Helper*, qint64 ) ),
-                     this, SLOT( addItem( TrackWorkflow*, Workflow::Helper*, qint64 ) ) );
-            connect( tw, SIGNAL( clipRemoved( TrackWorkflow*, const QUuid& ) ),
-                     this, SLOT( removeItem( TrackWorkflow*, const QUuid& ) ) );
-            connect( tw, SIGNAL( clipMoved( TrackWorkflow*, const QUuid&, qint64 ) ),
-                     this, SLOT( moveItem( TrackWorkflow*, const QUuid&, qint64 ) ) );
-            //Effect part:
-            connect( tw, SIGNAL( effectAdded( TrackWorkflow*, Workflow::Helper*, qint64 ) ),
-                     this, SLOT(addItem( TrackWorkflow*, Workflow::Helper*, qint64 ) ), Qt::QueuedConnection );
-            connect( tw, SIGNAL( effectRemoved( TrackWorkflow*, QUuid ) ),
-                     this, SLOT( removeItem( TrackWorkflow*, QUuid ) ), Qt::QueuedConnection );
-            connect( tw, SIGNAL( effectMoved( TrackWorkflow*, QUuid, qint64 ) ),
-                     this, SLOT( moveItem( TrackWorkflow*, QUuid, qint64 ) ), Qt::QueuedConnection );
+        TrackWorkflow   *tw = m_mainWorkflow->track( i );
+        //Clips part:
+        connect( tw, SIGNAL( clipAdded( TrackWorkflow*, Workflow::Helper*, qint64 ) ),
+                 this, SLOT( addItem( TrackWorkflow*, Workflow::Helper*, qint64 ) ) );
+        connect( tw, SIGNAL( clipRemoved( TrackWorkflow*, const QUuid& ) ),
+                 this, SLOT( removeItem( TrackWorkflow*, const QUuid& ) ) );
+        connect( tw, SIGNAL( clipMoved( TrackWorkflow*, const QUuid&, qint64 ) ),
+                 this, SLOT( moveItem( TrackWorkflow*, const QUuid&, qint64 ) ) );
+        //Effect part:
+        connect( tw, SIGNAL( effectAdded( TrackWorkflow*, Workflow::Helper*, qint64 ) ),
+                 this, SLOT(addItem( TrackWorkflow*, Workflow::Helper*, qint64 ) ), Qt::QueuedConnection );
+        connect( tw, SIGNAL( effectRemoved( TrackWorkflow*, QUuid ) ),
+                 this, SLOT( removeItem( TrackWorkflow*, QUuid ) ), Qt::QueuedConnection );
+        connect( tw, SIGNAL( effectMoved( TrackWorkflow*, QUuid, qint64 ) ),
+                 this, SLOT( moveItem( TrackWorkflow*, QUuid, qint64 ) ), Qt::QueuedConnection );
 
-        }
     }
 }
 
diff --git a/src/Workflow/MainWorkflow.cpp b/src/Workflow/MainWorkflow.cpp
index 264982b..ceb06fa 100644
--- a/src/Workflow/MainWorkflow.cpp
+++ b/src/Workflow/MainWorkflow.cpp
@@ -30,7 +30,6 @@
 #include "MainWorkflow.h"
 #include "Project/Project.h"
 #include "TrackWorkflow.h"
-#include "TrackHandler.h"
 #include "Settings/Settings.h"
 #include "Tools/VlmcDebug.h"
 #include "Workflow/Types.h"
@@ -48,21 +47,19 @@ MainWorkflow::MainWorkflow( Settings* projectSettings, int trackCount ) :
 {
     m_currentFrameLock = new QReadWriteLock;
 
-    m_tracks = new TrackHandler*[Workflow::NbTrackType];
-    QVariantList l;
     for ( unsigned int i = 0; i < Workflow::NbTrackType; ++i )
-    {
-        Workflow::TrackType trackType = static_cast<Workflow::TrackType>(i);
-        m_tracks[i] = new TrackHandler( trackCount, trackType );
-        connect( m_tracks[i], SIGNAL( tracksEndReached() ),
-                 this, SLOT( tracksEndReached() ) );
-        connect( m_tracks[i], SIGNAL( lengthChanged(qint64) ),
-                 this, SLOT( lengthUpdated( qint64 ) ) );
         m_currentFrame[i] = 0;
-        l << QVariantHash();
+
+    for ( int i = 0; i < trackCount; ++i )
+    {
+        Toggleable<TrackWorkflow*> track;
+        m_tracks << track;
+        m_tracks[i].setPtr( new TrackWorkflow( i ) );
+        connect( m_tracks[i], SIGNAL( lengthChanged( qint64 ) ),
+                 this, SLOT( lengthUpdated(qint64) ) );
     }
 
-    m_settings->createVar( SettingValue::List, "tracks", l, "", "", SettingValue::Nothing );
+    m_settings->createVar( SettingValue::List, "tracks", QVariantList(), "", "", SettingValue::Nothing );
     connect( m_settings, &Settings::postLoad, this, &MainWorkflow::postLoad, Qt::DirectConnection );
     connect( m_settings, &Settings::preSave, this, &MainWorkflow::preSave, Qt::DirectConnection );
     projectSettings->addSettings( "Workspace", *m_settings );
@@ -70,10 +67,10 @@ MainWorkflow::MainWorkflow( Settings* projectSettings, int trackCount ) :
 
 MainWorkflow::~MainWorkflow()
 {
+    for ( auto track : m_tracks )
+        delete track;
+    m_tracks.clear();
     delete m_currentFrameLock;
-    for ( unsigned int i = 0; i < Workflow::NbTrackType; ++i )
-        delete m_tracks[i];
-    delete[] m_tracks;
     delete m_blackOutput;
     delete m_settings;
 }
@@ -83,10 +80,10 @@ MainWorkflow::computeLength()
 {
     qint64      maxLength = 0;
 
-    for ( unsigned int i = 0; i < Workflow::NbTrackType; ++i )
+    for ( auto track : m_tracks )
     {
-        if ( m_tracks[i]->getLength() > maxLength )
-            maxLength = m_tracks[i]->getLength();
+        if ( track->getLength() > maxLength )
+            maxLength = track->getLength();
     }
     if ( m_lengthFrame != maxLength )
     {
@@ -107,8 +104,10 @@ MainWorkflow::startRender( quint32 width, quint32 height )
         delete m_blackOutput;
     m_blackOutput = new Workflow::Frame( m_width, m_height );
     memset( m_blackOutput->buffer(), 0, m_blackOutput->size() );
-    for ( unsigned int i = 0; i < Workflow::NbTrackType; ++i )
-        m_tracks[i]->startRender( width, height );
+    m_endReached = ( m_lengthFrame == 0 ) ? true : false;
+    if ( m_lengthFrame > 0 )
+        for ( auto track : m_tracks )
+            track->initRender( width, height );
     computeLength();
 }
 
@@ -126,8 +125,26 @@ MainWorkflow::getOutput( Workflow::TrackType trackType, bool paused )
             subFrame = m_currentFrame[trackType];
         }
 
-        Workflow::OutputBuffer  *ret = m_tracks[trackType]->getOutput( currentFrame,
-                                                                       subFrame, paused );
+        bool        validTrack = false;
+        Workflow::OutputBuffer  *ret = nullptr;
+
+        for ( int i = m_trackCount - 1; i >= 0; --i )
+        {
+            if ( m_tracks[i].activated() == false || m_tracks[i]->hasNoMoreFrameToRender( currentFrame ) )
+                continue ;
+            validTrack = true;
+            ret = m_tracks[i]->getOutput( trackType, currentFrame, subFrame, paused );
+            if ( ret == nullptr )
+                continue ;
+            else
+                break ;
+        }
+        if ( validTrack == false )
+        {
+            m_endReached = true;
+            emit mainWorkflowEndReached();
+        }
+
         if ( trackType == Workflow::VideoTrack )
         {
             if ( ret == nullptr )
@@ -165,10 +182,10 @@ MainWorkflow::getLengthFrame() const
 }
 
 qint64
-MainWorkflow::getClipPosition( const QUuid& uuid, unsigned int trackId,
-                               Workflow::TrackType trackType ) const
+MainWorkflow::getClipPosition( const QUuid& uuid, unsigned int trackId ) const
 {
-    return m_tracks[trackType]->getClipPosition( uuid, trackId );
+    Q_ASSERT( trackId < m_trackCount );
+    return m_tracks[trackId]->getClipPosition( uuid );
 }
 
 void
@@ -181,44 +198,45 @@ MainWorkflow::stop()
     */
     m_renderStarted = false;
     for (unsigned int i = 0; i < Workflow::NbTrackType; ++i)
-    {
-        m_tracks[i]->stop();
         m_currentFrame[i] = 0;
-    }
+    for ( auto track : m_tracks )
+        track->stop();
     emit frameChanged( 0, Vlmc::Renderer );
 }
 
 void
 MainWorkflow::stopFrameComputing()
 {
-    for ( qint32 type = 0; type < Workflow::NbTrackType; ++type )
-        m_tracks[type]->stopFrameComputing();
+    for ( auto track : m_tracks )
+        track->stopFrameComputing();
 }
 
 void
-MainWorkflow::muteTrack( unsigned int trackId, Workflow::TrackType trackType )
+MainWorkflow::muteTrack( unsigned int trackId )
 {
-    m_tracks[trackType]->muteTrack( trackId );
+    Q_ASSERT( trackId < m_trackCount );
+    m_tracks[trackId].deactivate();
 }
 
 void
-MainWorkflow::unmuteTrack( unsigned int trackId, Workflow::TrackType trackType )
+MainWorkflow::unmuteTrack( unsigned int trackId )
 {
-    m_tracks[trackType]->unmuteTrack( trackId );
+    Q_ASSERT( trackId < m_trackCount );
+    m_tracks[trackId].activate();
 }
 
 void
-MainWorkflow::muteClip( const QUuid& uuid, unsigned int trackId,
-                        Workflow::TrackType trackType )
+MainWorkflow::muteClip( const QUuid& uuid, unsigned int trackId )
 {
-    m_tracks[trackType]->muteClip( uuid, trackId );
+    Q_ASSERT( trackId < m_trackCount );
+    m_tracks[trackId]->muteClip( uuid );
 }
 
 void
-MainWorkflow::unmuteClip( const QUuid& uuid, unsigned int trackId,
-                          Workflow::TrackType trackType )
+MainWorkflow::unmuteClip( const QUuid& uuid, unsigned int trackId )
 {
-    m_tracks[trackType]->unmuteClip( uuid, trackId );
+    Q_ASSERT( trackId < m_trackCount );
+    m_tracks[trackId]->unmuteClip( uuid );
 }
 
 void
@@ -232,35 +250,32 @@ MainWorkflow::setCurrentFrame( qint64 currentFrame, Vlmc::FrameChangedReason rea
 }
 
 ClipHelper*
-MainWorkflow::getClipHelper( const QUuid &uuid, unsigned int trackId,
-                                Workflow::TrackType trackType )
+MainWorkflow::getClipHelper( const QUuid &uuid, unsigned int trackId )
 {
-    return m_tracks[trackType]->getClipHelper( uuid, trackId );
+    Q_ASSERT( trackId < m_trackCount );
+    return m_tracks[trackId]->getClipHelper( uuid );
 }
 
 void
 MainWorkflow::clear()
 {
-    for ( unsigned int i = 0; i < Workflow::NbTrackType; ++i )
-        m_tracks[i]->clear();
+    for ( auto track : m_tracks )
+        track->clear();
     emit cleared();
 }
 
 void
 MainWorkflow::tracksEndReached()
 {
-    for ( unsigned int i = 0; i < Workflow::NbTrackType; ++i )
-    {
-        if ( m_tracks[i]->endIsReached() == false )
-            return ;
-    }
+    if ( m_endReached == false )
+        return ;
     emit mainWorkflowEndReached();
 }
 
 int
-MainWorkflow::getTrackCount( Workflow::TrackType trackType ) const
+MainWorkflow::getTrackCount() const
 {
-    return m_tracks[trackType]->getTrackCount();
+    return m_trackCount;
 }
 
 qint64
@@ -291,8 +306,9 @@ MainWorkflow::getHeight() const
 void
 MainWorkflow::renderOneFrame()
 {
-    for ( unsigned int i = 0; i < Workflow::NbTrackType; ++i )
-        m_tracks[i]->renderOneFrame();
+    for ( auto track : m_tracks )
+        if ( track.activated() == true )
+            track->renderOneFrame();
     nextFrame( Workflow::VideoTrack );
     nextFrame( Workflow::AudioTrack );
 }
@@ -300,15 +316,15 @@ MainWorkflow::renderOneFrame()
 void
 MainWorkflow::setFullSpeedRender( bool val )
 {
-    for ( unsigned int i = 0; i < Workflow::NbTrackType; ++i )
-        m_tracks[i]->setFullSpeedRender( val );
+    for ( auto track : m_tracks )
+        track->setFullSpeedRender( val );
 }
 
 bool
 MainWorkflow::contains( const QUuid &uuid ) const
 {
-    for ( qint32 type = 0; type < Workflow::NbTrackType; ++type )
-        if ( m_tracks[type]->contains( uuid ) == true )
+    for ( auto track : m_tracks )
+        if ( track->contains( uuid ) == true )
             return true;
     return false;
 }
@@ -329,8 +345,8 @@ void
 MainWorkflow::preSave()
 {
     QVariantList l;
-    for ( unsigned int i = 0; i < Workflow::NbTrackType; ++i )
-        l << m_tracks[i]->toVariant();
+    for ( auto track : m_tracks )
+        l << track->toVariant();
     m_settings->value( "tracks" )->set( l );
 }
 
@@ -338,7 +354,7 @@ void
 MainWorkflow::postLoad()
 {
     QVariantList l = m_settings->value( "tracks" )->get().toList();
-    for ( unsigned int i = 0; i < Workflow::NbTrackType; ++i )
+    for ( int i = 0; i < l.size(); ++i )
         m_tracks[i]->loadFromVariant( l[i] );
 }
 
@@ -347,20 +363,20 @@ MainWorkflow::lengthUpdated( qint64 )
 {
     qint64  maxLength = 0;
 
-    for ( unsigned int i = 0; i < Workflow::NbTrackType; ++i )
+    for ( auto track : m_tracks )
     {
-        if ( m_tracks[i]->getLength() > maxLength )
-            maxLength = m_tracks[i]->getLength();
+        if ( track->getLength() > maxLength )
+            maxLength = track->getLength();
     }
     if ( m_lengthFrame != maxLength )
     {
         m_lengthFrame = maxLength;
-        emit lengthChanged( m_lengthFrame );
+        emit ( m_lengthFrame );
     }
 }
 
 TrackWorkflow*
-MainWorkflow::track( Workflow::TrackType type, quint32 trackId )
+MainWorkflow::track( quint32 trackId )
 {
-    return m_tracks[type]->track( trackId );
+    return m_tracks[ trackId ];
 }
diff --git a/src/Workflow/MainWorkflow.h b/src/Workflow/MainWorkflow.h
index 4f6a2bd..09c2a0b 100644
--- a/src/Workflow/MainWorkflow.h
+++ b/src/Workflow/MainWorkflow.h
@@ -27,6 +27,7 @@
 #include "EffectsEngine/EffectsEngine.h"
 #include <QXmlStreamWriter>
 #include "Types.h"
+#include "Tools/Toggleable.hpp"
 
 class   Clip;
 class   ClipHelper;
@@ -145,8 +146,7 @@ class   MainWorkflow : public QObject
          *  \return                 The given clip position, in frame. If not found, -1
          *                          is returned.
          */
-        qint64                  getClipPosition( const QUuid& uuid, unsigned int trackId,
-                                                Workflow::TrackType trackType ) const;
+        qint64                  getClipPosition( const QUuid& uuid, unsigned int trackId ) const;
 
         /**
          *  \brief      Mute a track.
@@ -157,8 +157,7 @@ class   MainWorkflow : public QObject
          *  \param  trackType   The type of the track to mute.
          *  \sa     unmuteTrack( unsigned int, Workflow::TrackType );
          */
-        void                    muteTrack( unsigned int trackId,
-                                           Workflow::TrackType trackType );
+        void                    muteTrack( unsigned int trackId );
         /**
          *  \brief      Unmute a track.
          *
@@ -166,8 +165,7 @@ class   MainWorkflow : public QObject
          *  \param  trackType   The type of the track to unmute.
          *  \sa     muteTrack( unsigned int, Workflow::TrackType );
          */
-        void                    unmuteTrack( unsigned int trackId,
-                                             Workflow::TrackType trackType );
+        void                    unmuteTrack( unsigned int trackId );
 
         /**
          *  \brief      Mute a clip.
@@ -176,8 +174,7 @@ class   MainWorkflow : public QObject
          *  \param  trackId     The id of the track containing the clip.
          *  \param  trackType   The type of the track containing the clip.
          */
-        void                    muteClip( const QUuid& uuid, unsigned int trackId,
-                                          Workflow::TrackType trackType );
+        void                    muteClip( const QUuid& uuid, unsigned int trackId );
 
         /**
          *  \brief      Unmute a clip.
@@ -186,8 +183,7 @@ class   MainWorkflow : public QObject
          *  \param  trackId     The id of the track containing the clip.
          *  \param  trackType   The type of the track containing the clip.
          */
-        void                    unmuteClip( const QUuid& uuid, unsigned int trackId,
-                                          Workflow::TrackType trackType );
+        void                    unmuteClip( const QUuid& uuid, unsigned int trackId );
 
         /**
          *  \brief              Get the number of track for a specific type
@@ -195,7 +191,7 @@ class   MainWorkflow : public QObject
          *  \param  trackType   The type of the tracks to count
          *  \return             The number of track for the type trackType
          */
-        int                     getTrackCount( Workflow::TrackType trackType ) const;
+        int                     getTrackCount() const;
 
         /**
          *  \brief      Get the width used for rendering.
@@ -251,7 +247,7 @@ class   MainWorkflow : public QObject
          */
         void                    stopFrameComputing();
 
-        TrackWorkflow           *track( Workflow::TrackType type, quint32 trackId );
+        TrackWorkflow           *track( quint32 trackId );
 
         const Workflow::Frame   *blackOutput() const;
 
@@ -276,13 +272,13 @@ class   MainWorkflow : public QObject
          *  \param      trackType : the track type (audio or video)
          *  \returns    The clip helper that matches the given UUID, or nullptr.
          */
-        ClipHelper*             getClipHelper( const QUuid& uuid, unsigned int trackId,
-                                               Workflow::TrackType trackType );
+        ClipHelper*             getClipHelper( const QUuid& uuid, unsigned int trackId );
 
         void                    preSave();
         void                    postLoad();
 
     private:
+        QList<Toggleable<TrackWorkflow*>>     m_tracks;
         /// Pre-filled buffer used when there's nothing to render
         Workflow::Frame         *m_blackOutput;
 
@@ -304,9 +300,6 @@ class   MainWorkflow : public QObject
         /// This boolean describe is a render has been started
         bool                            m_renderStarted;
 
-        /// Contains the trackhandler, indexed by Workflow::TrackType
-        TrackHandler**                  m_tracks;
-
         /// Width used for the render
         quint32                         m_width;
         /// Height used for the render
@@ -314,6 +307,8 @@ class   MainWorkflow : public QObject
         /// Store the number of track for each track type.
         const quint32                   m_trackCount;
 
+        bool                            m_endReached;
+
         Settings*                       m_settings;
 
     private slots:
diff --git a/src/Workflow/TrackWorkflow.cpp b/src/Workflow/TrackWorkflow.cpp
index acb2e2d..295fc75 100644
--- a/src/Workflow/TrackWorkflow.cpp
+++ b/src/Workflow/TrackWorkflow.cpp
@@ -44,10 +44,9 @@
 #include <QReadLocker>
 #include <QMutex>
 
-TrackWorkflow::TrackWorkflow( Workflow::TrackType type, quint32 trackId  ) :
+TrackWorkflow::TrackWorkflow( quint32 trackId  ) :
         m_length( 0 ),
-        m_trackType( type ),
-        m_lastFrame( 0 ),
+        m_trackType( Workflow::NbTrackType ),
         m_trackId( trackId )
 {
     m_clipsLock = new QReadWriteLock;
@@ -80,15 +79,21 @@ void
 TrackWorkflow::addClip( ClipHelper* ch, qint64 start )
 {
     ClipWorkflow* cw;
-    if ( m_trackType == Workflow::VideoTrack )
-    {
-        if ( ch->clip()->media()->fileType() == Media::Video )
+    if ( ch->clip()->media()->fileType() == Media::FileType::Video )
+        // FIXME: This whole if statement will be gone as soon as I implement a united ClipWorkflow,
+        //        which can generate both audio and video buffers.
+        if ( ch->formats() & ClipHelper::Video )
             cw = new VideoClipWorkflow( ch );
+        else if ( ch->formats() & ClipHelper::Audio )
+            cw = new AudioClipWorkflow( ch );
         else
-            cw = new ImageClipWorkflow( ch );
-    }
-    else
+            vlmcFatal( "Nothing to render from this clip!" );
+    else if ( ch->clip()->media()->fileType() == Media::FileType::Audio )
         cw = new AudioClipWorkflow( ch );
+    else if ( ch->clip()->media()->fileType() == Media::FileType::Image )
+        cw = new ImageClipWorkflow( ch );
+    else
+        vlmcFatal( "Unknown file type!" );
     ch->setClipWorkflow( cw );
     addClip( cw, start );
 }
@@ -268,7 +273,7 @@ TrackWorkflow::stop()
 }
 
 Workflow::OutputBuffer*
-TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
+TrackWorkflow::getOutput( Workflow::TrackType trackType, qint64 currentFrame, qint64 subFrame, bool paused )
 {
     QReadLocker     lock( m_clipsLock );
 
@@ -301,12 +306,19 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
     {
         qint64          start = it.key();
         ClipWorkflow*   cw = it.value();
+
+        if ( trackType != cw->type() )
+        {
+            ++it;
+            continue ;
+        }
+
         //Is the clip supposed to render now?
         if ( start <= currentFrame && currentFrame <= start + cw->getClipHelper()->length() )
         {
             ret = renderClip( cw, currentFrame, start, needRepositioning,
                               renderOneFrame, paused );
-            if ( m_trackType == Workflow::VideoTrack )
+            if ( trackType == Workflow::VideoTrack )
             {
                 frames[frameId] = static_cast<Workflow::Frame*>( ret );
                 ++frameId;
@@ -322,7 +334,7 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
         ++it;
     }
     //Handle mixers:
-    if ( m_trackType == Workflow::VideoTrack )
+    if ( trackType == Workflow::VideoTrack )
     {
         EffectHelper*   mixer = getMixer( currentFrame );
         if ( mixer != nullptr && frames[0] != nullptr ) //There's no point using the mixer if there's no frame rendered.
diff --git a/src/Workflow/TrackWorkflow.h b/src/Workflow/TrackWorkflow.h
index 4569c75..6f51cb6 100644
--- a/src/Workflow/TrackWorkflow.h
+++ b/src/Workflow/TrackWorkflow.h
@@ -49,10 +49,10 @@ class   TrackWorkflow : public EffectUser
     Q_OBJECT
 
     public:
-        TrackWorkflow( Workflow::TrackType type, quint32 trackId );
+        TrackWorkflow( quint32 trackId );
         ~TrackWorkflow();
 
-        Workflow::OutputBuffer                  *getOutput( qint64 currentFrame,
+        Workflow::OutputBuffer                  *getOutput( Workflow::TrackType trackType, qint64 currentFrame,
                                                            qint64 subFrame, bool paused );
         qint64                                  getLength() const;
         void                                    stop();
-- 
1.9.1



More information about the Vlmc-devel mailing list