Commit 434a4880 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Clip can be moved between tracks in real time.

The clip QMap has been thread safed for the occasion (and to resolve a
few bugs)
Though, it seems to miss some events sometime (without crashing,
changing position is enough to restore the render preview)
parent 824a3d60
......@@ -203,7 +203,7 @@ void ClipWorkflow::clipEndReached()
setState( EndReached );
}
const Clip* ClipWorkflow::getClip() const
Clip* ClipWorkflow::getClip()
{
return m_clip;
}
......
......@@ -109,7 +109,7 @@ class ClipWorkflow : public QObject
uppon, so that you can query information on it.
\return A pointer to a constant clip instance.
*/
const Clip* getClip() const;
Clip* getClip();
/**
\brief Stop this workflow.
*/
......
......@@ -194,13 +194,24 @@ MainWorkflow* MainWorkflow::getInstance()
return m_instance;
}
void MainWorkflow::clipMoved( QUuid clipUuid, int trackId, qint64 startingFrame )
void MainWorkflow::clipMoved( QUuid clipUuid, int oldTrack, int newTrack, qint64 startingFrame )
{
Q_ASSERT( newTrack < m_trackCount && oldTrack < m_trackCount && oldTrack >= 0 && newTrack >= 0 );
//If the frame was stopped, reactivating it, since it can have something to render after
//the clip displacement
Q_ASSERT( trackId < m_trackCount );
if ( m_tracks[trackId].activated() == false )
m_tracks[trackId].activate();
//And now, just move the clip.
m_tracks[trackId]->moveClip( clipUuid, startingFrame );
if ( m_tracks[newTrack].activated() == false )
m_tracks[newTrack].activate();
if ( oldTrack == newTrack )
{
//And now, just move the clip.
m_tracks[newTrack]->moveClip( clipUuid, startingFrame );
}
else
{
if ( m_tracks[oldTrack].activated() == false )
m_tracks[oldTrack].activate();
Clip* clip = m_tracks[oldTrack]->removeClip( clipUuid );
m_tracks[newTrack]->addClip( clip, startingFrame );
}
}
......@@ -85,7 +85,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
QReadWriteLock* m_renderStartedLock;
public slots:
void clipMoved( QUuid, int, qint64 );
void clipMoved( QUuid, int, int, qint64 );
private slots:
void trackEndReached( unsigned int trackId );
......
......@@ -32,6 +32,7 @@ TrackWorkflow::TrackWorkflow( unsigned int trackId ) :
{
m_mediaPlayer = new LibVLCpp::MediaPlayer();
m_forceRepositionningMutex = new QMutex;
m_clipsLock = new QReadWriteLock;
}
TrackWorkflow::~TrackWorkflow()
......@@ -45,17 +46,20 @@ TrackWorkflow::~TrackWorkflow()
delete it.value();
it = m_clips.erase( it );
}
delete m_clipsLock;
delete m_forceRepositionningMutex;
delete m_mediaPlayer;
}
void TrackWorkflow::addClip( Clip* clip, qint64 start )
{
QWriteLocker lock( m_clipsLock );
ClipWorkflow* cw = new ClipWorkflow( clip );
m_clips.insert( start, cw );
computeLength();
}
//Must be called from a thread safe method (m_clipsLock locked)
void TrackWorkflow::computeLength()
{
if ( m_clips.count() == 0 )
......@@ -215,6 +219,8 @@ void TrackWorkflow::stop()
unsigned char* TrackWorkflow::getOutput( qint64 currentFrame )
{
QReadLocker lock( m_clipsLock );
unsigned char* ret = NULL;
QMap<qint64, ClipWorkflow*>::iterator it = m_clips.begin();
QMap<qint64, ClipWorkflow*>::iterator end = m_clips.end();
......@@ -262,8 +268,10 @@ unsigned char* TrackWorkflow::getOutput( qint64 currentFrame )
return ret;
}
void TrackWorkflow::moveClip( QUuid id, qint64 startingFrame )
void TrackWorkflow::moveClip( const QUuid& id, qint64 startingFrame )
{
QWriteLocker lock( m_clipsLock );
QMap<qint64, ClipWorkflow*>::iterator it = m_clips.begin();
QMap<qint64, ClipWorkflow*>::iterator end = m_clips.end();
......@@ -283,3 +291,23 @@ void TrackWorkflow::moveClip( QUuid id, qint64 startingFrame )
qDebug() << "Track" << m_trackId << "was asked to move clip" << id << "to position" << startingFrame
<< "but this clip doesn't exist in this track";
}
Clip* TrackWorkflow::removeClip( const QUuid& id )
{
QWriteLocker lock( m_clipsLock );
QMap<qint64, ClipWorkflow*>::iterator it = m_clips.begin();
QMap<qint64, ClipWorkflow*>::iterator end = m_clips.end();
while ( it != end )
{
if ( it.value()->getClip()->getUuid() == id )
{
ClipWorkflow* cw = it.value();
m_clips.erase( it );
return cw->getClip();
}
++it;
}
return NULL;
}
......@@ -53,7 +53,9 @@ class TrackWorkflow : public QObject
unsigned char* getOutput( qint64 currentFrame );
qint64 getLength() const;
void stop();
void moveClip( QUuid id, qint64 startingFrame );
void moveClip( const QUuid& id, qint64 startingFrame );
Clip* removeClip( const QUuid& id );
void addClip( Clip*, qint64 start );
//FIXME: this won't be reliable as soon as we change the fps from the configuration
static const unsigned int nbFrameBeforePreload = 60;
......@@ -89,9 +91,7 @@ class TrackWorkflow : public QObject
bool m_forceRepositionning;
QMutex* m_forceRepositionningMutex;
public:
void addClip( Clip*, qint64 start );
QReadWriteLock* m_clipsLock;
signals:
void trackEndReached( unsigned int );
};
......
......@@ -59,8 +59,8 @@ Timeline::Timeline( QWidget *parent ) :
setDuration( 0 );
connect( m_tracksView->horizontalScrollBar(), SIGNAL( valueChanged( int ) ), m_tracksRuler, SLOT( moveRuler( int ) ) );
connect( m_tracksView, SIGNAL( durationChanged(int) ), this, SLOT( setDuration(int) ) );
connect( m_tracksView, SIGNAL( clipMoved( QUuid, int, qint64) ),
MainWorkflow::getInstance(), SLOT( clipMoved( QUuid, int, qint64 ) ) );
connect( m_tracksView, SIGNAL( clipMoved( QUuid, int, int, qint64) ),
MainWorkflow::getInstance(), SLOT( clipMoved( QUuid, int, int, qint64 ) ) );
}
void Timeline::changeEvent( QEvent *e )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment