Commit ee5c4dad authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Refactoring "adding clip to timeline/workflow" process.

parent 1aa19362
......@@ -23,9 +23,10 @@
#include "config.h"
#include "Clip.h"
#include "ClipHelper.h"
#include "Commands.h"
#include "MainWorkflow.h"
#include "ClipHelper.h"
#include "TrackWorkflow.h"
#ifdef WITH_GUI
# include "UndoStack.h"
......@@ -43,17 +44,12 @@ void Commands::trigger( Commands::Generic* command )
Commands::MainWorkflow::AddClip::AddClip( ClipHelper* ch,
unsigned int trackNumber, qint64 pos,
Workflow::TrackType trackType,
bool undoRedoAction /*= false*/ ) :
m_trackNumber( trackNumber ),
m_pos( pos ),
m_trackType( trackType ),
Commands::MainWorkflow::AddClip::AddClip( ClipHelper* ch, TrackWorkflow* tw, qint64 pos ) :
m_clipHelper( ch ),
m_undoRedoAction( undoRedoAction )
{
setText( QObject::tr( "Adding clip to track %1" ).arg( QString::number( trackNumber ) ) );
m_trackWorkflow( tw ),
m_pos( pos )
{//Fixme !
setText( QObject::tr( "Adding clip to track %1" ).arg( -1 ) );
}
Commands::MainWorkflow::AddClip::~AddClip()
......@@ -62,13 +58,12 @@ Commands::MainWorkflow::AddClip::~AddClip()
void Commands::MainWorkflow::AddClip::redo()
{
::MainWorkflow::getInstance()->addClip( m_clipHelper, m_trackNumber, m_pos, m_trackType, m_undoRedoAction );
m_undoRedoAction = false;
m_trackWorkflow->addClip( m_clipHelper, m_pos );
}
void Commands::MainWorkflow::AddClip::undo()
{
::MainWorkflow::getInstance()->removeClip( m_clipHelper->uuid(), m_trackNumber, m_trackType );
m_trackWorkflow->removeClip( m_clipHelper->uuid() );
}
Commands::MainWorkflow::MoveClip::MoveClip( ::MainWorkflow* workflow, const QUuid& uuid,
......@@ -100,21 +95,20 @@ void Commands::MainWorkflow::MoveClip::undo()
m_undoRedoAction = true;
}
Commands::MainWorkflow::RemoveClip::RemoveClip( ClipHelper* ch, quint32 trackNumber,
qint64 pos, Workflow::TrackType trackType ) :
m_clipHelper( ch ), m_trackNumber( trackNumber ),
m_pos( pos ), m_trackType( trackType )
Commands::MainWorkflow::RemoveClip::RemoveClip( ClipHelper* ch, TrackWorkflow* tw ) :
m_clipHelper( ch ), m_trackWorkflow( tw )
{
setText( QObject::tr( "Remove clip" ) );
m_pos = tw->getClipPosition( ch->uuid() );
}
void Commands::MainWorkflow::RemoveClip::redo()
{
::MainWorkflow::getInstance()->removeClip( m_clipHelper->uuid(), m_trackNumber, m_trackType );
m_trackWorkflow->removeClip( m_clipHelper->uuid() );
}
void Commands::MainWorkflow::RemoveClip::undo()
{
::MainWorkflow::getInstance()->addClip( m_clipHelper, m_trackNumber, m_pos, m_trackType, true );
m_trackWorkflow->addClip( m_clipHelper, m_pos );
}
Commands::MainWorkflow::ResizeClip::ResizeClip( ClipHelper* clipHelper,
......@@ -179,10 +173,10 @@ Commands::MainWorkflow::SplitClip::~SplitClip()
void Commands::MainWorkflow::SplitClip::redo()
{
m_newClip = ::MainWorkflow::getInstance()->split( m_toSplit, m_newClip, m_trackId, m_newClipPos, m_newClipBegin, m_trackType );
// m_newClip = ::MainWorkflow::getInstance()->split( m_toSplit, m_newClip, m_trackId, m_newClipPos, m_newClipBegin, m_trackType );
}
void Commands::MainWorkflow::SplitClip::undo()
{
::MainWorkflow::getInstance()->unsplit( m_toSplit, m_newClip, m_trackId, m_trackType );
// ::MainWorkflow::getInstance()->unsplit( m_toSplit, m_newClip, m_trackId, m_trackType );
}
......@@ -63,17 +63,14 @@ namespace Commands
NEW_COMMAND( AddClip )
{
public:
AddClip( ClipHelper* ch, unsigned int trackNumber, qint64 pos,
Workflow::TrackType trackType, bool undoRedoAction = false );
AddClip( ClipHelper* ch, TrackWorkflow* tw, qint64 pos );
virtual ~AddClip();
virtual void redo();
virtual void undo();
private:
unsigned int m_trackNumber;
qint64 m_pos;
Workflow::TrackType m_trackType;
ClipHelper *m_clipHelper;
bool m_undoRedoAction;
TrackWorkflow *m_trackWorkflow;
qint64 m_pos;
};
NEW_COMMAND( MoveClip )
......@@ -99,16 +96,14 @@ namespace Commands
NEW_COMMAND( RemoveClip )
{
public:
RemoveClip( ClipHelper* clip, unsigned int trackNumber,
qint64 pos, Workflow::TrackType trackType );
RemoveClip( ClipHelper* clip, TrackWorkflow* tw );
virtual void redo();
virtual void undo();
private:
ClipHelper* m_clipHelper;
unsigned int m_trackNumber;
ClipHelper *m_clipHelper;
TrackWorkflow *m_trackWorkflow;
qint64 m_pos;
Workflow::TrackType m_trackType;
};
/**
......
......@@ -23,8 +23,9 @@
#include "TracksScene.h"
#include "Commands.h"
#include "GraphicsMovieItem.h"
#include "GraphicsAudioItem.h"
#include "GraphicsMovieItem.h"
#include "GraphicsTrack.h"
#include "SettingsManager.h"
#include "Timeline.h"
#include "UndoStack.h"
......@@ -105,10 +106,7 @@ TracksScene::askRemoveSelectedItems()
AbstractGraphicsMediaItem* item = qgraphicsitem_cast<AbstractGraphicsMediaItem*>( items.at(i) );
if ( !item ) return;
Commands::trigger( new Commands::MainWorkflow::RemoveClip( item->clipHelper(),
item->trackNumber(),
item->startPos(),
item->mediaType() ) );
Commands::trigger( new Commands::MainWorkflow::RemoveClip( item->clipHelper(), item->track()->trackWorkflow() ) );
}
UndoStack::getInstance()->endMacro();
......
......@@ -676,9 +676,8 @@ TracksView::dropEvent( QDropEvent *event )
m_dragAudioItem->oldPosition = (qint64)mappedXPos;
Commands::trigger( new Commands::MainWorkflow::AddClip( m_dragAudioItem->clipHelper(),
m_dragAudioItem->trackNumber(),
(qint64)mappedXPos,
Workflow::AudioTrack ) );
m_dragAudioItem->track()->trackWorkflow(),
(qint64)mappedXPos ) );
m_dragAudioItem = NULL;
}
......@@ -693,9 +692,8 @@ TracksView::dropEvent( QDropEvent *event )
m_dragVideoItem->oldPosition = (qint64)mappedXPos;
Commands::trigger( new Commands::MainWorkflow::AddClip( m_dragVideoItem->clipHelper(),
m_dragVideoItem->trackNumber(),
(qint64)mappedXPos,
Workflow::VideoTrack ) );
m_dragVideoItem->track()->trackWorkflow(),
(qint64)mappedXPos ) );
m_dragVideoItem = NULL;
}
......
......@@ -72,17 +72,17 @@ MainWorkflow::~MainWorkflow()
delete m_blackOutput;
}
void
MainWorkflow::addClip( ClipHelper *clipHelper, unsigned int trackId,
qint64 start, Workflow::TrackType trackType,
bool informGui )
{
m_tracks[trackType]->addClip( clipHelper, trackId, start );
computeLength();
//Inform the GUI
if ( informGui == true )
emit clipAdded( clipHelper, trackId, start, trackType );
}
//void
//MainWorkflow::addClip( ClipHelper *clipHelper, unsigned int trackId,
// qint64 start, Workflow::TrackType trackType,
// bool informGui )
//{
// m_tracks[trackType]->addClip( clipHelper, trackId, start );
// computeLength();
// //Inform the GUI
// if ( informGui == true )
// emit clipAdded( clipHelper, trackId, start, trackType );
//}
EffectsEngine::EffectHelper*
MainWorkflow::addEffect( Effect *effect, quint32 trackId, const QUuid &uuid, Workflow::TrackType type )
......@@ -331,7 +331,7 @@ MainWorkflow::loadProject( const QDomElement &root )
{
ClipHelper *ch = new ClipHelper( c, begin.toLongLong(),
end.toLongLong(), chUuid );
addClip( ch, trackId, startFrame.toLongLong(), type, true );
track( type, trackId )->addClip( ch, startFrame.toLongLong() );
QDomElement effects = clip.firstChildElement( "effects" );
if ( effects.isNull() == false )
......@@ -438,19 +438,19 @@ MainWorkflow::setFullSpeedRender( bool val )
m_tracks[i]->setFullSpeedRender( val );
}
ClipHelper*
MainWorkflow::split( ClipHelper* toSplit, ClipHelper* newClip, quint32 trackId,
qint64 newClipPos, qint64 newClipBegin, Workflow::TrackType trackType )
{
QMutexLocker lock( m_renderStartedMutex );
//ClipHelper*
//MainWorkflow::split( ClipHelper* toSplit, ClipHelper* newClip, quint32 trackId,
// qint64 newClipPos, qint64 newClipBegin, Workflow::TrackType trackType )
//{
// QMutexLocker lock( m_renderStartedMutex );
if ( newClip == NULL )
newClip = new ClipHelper( toSplit->clip(), newClipBegin, toSplit->end() );
// if ( newClip == NULL )
// newClip = new ClipHelper( toSplit->clip(), newClipBegin, toSplit->end() );
toSplit->setEnd( newClipBegin );
addClip( newClip, trackId, newClipPos, trackType, true );
return newClip;
}
// toSplit->setEnd( newClipBegin );
// addClip( newClip, trackId, newClipPos, trackType, true );
// return newClip;
//}
void
MainWorkflow::resizeClip( ClipHelper* clipHelper, qint64 newBegin, qint64 newEnd, qint64 newPos,
......
......@@ -71,8 +71,8 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
* \sa removeClip( const QUuid&, unsigned int, Workflow::TrackType )
* \sa clipAdded( Clip*, unsigned int, qint64, Workflow::TrackType )
*/
void addClip( ClipHelper* clipHelper, quint32 trackId, qint64 start,
Workflow::TrackType type, bool informGui );
// void addClip( ClipHelper* clipHelper, quint32 trackId, qint64 start,
// Workflow::TrackType type, bool informGui );
EffectsEngine::EffectHelper *addEffect( Effect* effect, quint32 trackId,
......@@ -83,7 +83,7 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
*
* \param width The width to use with this render session.
* \param height The height to use with this render session.
* This will basically activate all the tracks, so they can render.
* This will basically activate all the tracks, newLengthso they can render.
*/
void startRender( quint32 width, quint32 height, double fps );
/**
......@@ -296,9 +296,9 @@ class MainWorkflow : public QObject, public Singleton<MainWorkflow>
*/
void setFullSpeedRender( bool val );
ClipHelper* split( ClipHelper* toSplit, ClipHelper* newClip, quint32 trackId,
qint64 newClipPos, qint64 newClipBegin,
Workflow::TrackType trackType );
// ClipHelper* split( ClipHelper* toSplit, ClipHelper* newClip, quint32 trackId,
// qint64 newClipPos, qint64 newClipBegin,
// Workflow::TrackType trackType );
void resizeClip( ClipHelper* clipHelper, qint64 newBegin, qint64 newEnd,
qint64 newPos, quint32 trackId,
......
......@@ -48,19 +48,6 @@ TrackHandler::~TrackHandler()
delete[] m_tracks;
}
void
TrackHandler::addClip( ClipHelper* ch, unsigned int trackId, qint64 start )
{
Q_ASSERT_X( trackId < m_trackCount, "MainWorkflow::addClip",
"The specified trackId isn't valid, for it's higher than the number of tracks");
m_tracks[trackId]->addClip( ch, start );
//Now check if this clip addition has changed something about the workflow's length
if ( m_tracks[trackId]->getLength() > m_length )
m_length = m_tracks[trackId]->getLength();
}
EffectsEngine::EffectHelper*
TrackHandler::addEffect( Effect *effect, quint32 trackId, const QUuid &uuid )
{
......@@ -71,7 +58,6 @@ void
TrackHandler::startRender( quint32 width, quint32 height, double fps )
{
m_endReached = false;
computeLength();
if ( m_length == 0 )
m_endReached = true;
else
......@@ -83,19 +69,6 @@ TrackHandler::startRender( quint32 width, quint32 height, double fps )
}
}
void
TrackHandler::computeLength()
{
qint64 maxLength = 0;
for ( unsigned int i = 0; i < m_trackCount; ++i )
{
if ( m_tracks[i]->getLength() > maxLength )
maxLength = m_tracks[i]->getLength();
}
m_length = maxLength;
}
qint64
TrackHandler::getLength() const
{
......@@ -154,7 +127,6 @@ TrackHandler::moveClip(const QUuid &clipUuid, unsigned int oldTrack,
ClipWorkflow* cw = m_tracks[oldTrack]->removeClipWorkflow( clipUuid );
m_tracks[newTrack]->addClip( cw, startingFrame );
}
computeLength();
}
Clip*
......@@ -163,7 +135,6 @@ TrackHandler::removeClip( const QUuid& uuid, unsigned int trackId )
Q_ASSERT( trackId < m_trackCount );
Clip* clip = m_tracks[trackId]->removeClip( uuid );
computeLength();
return clip;
}
......
......@@ -38,16 +38,6 @@ class TrackHandler : public QObject
TrackHandler( unsigned int nbTracks, Workflow::TrackType trackType );
~TrackHandler();
/**
* \brief Insert a clip in the workflow.
*
* This will instantiate a new ClipWorkflow and returns its uuid.
* \param clip The clip to insert.
* \param trackId The track identifier.
* \param start The new clip starting position.
*/
void addClip( ClipHelper* clip, unsigned int trackId, qint64 start );
EffectsEngine::EffectHelper *addEffect( Effect *effect, quint32 trackId, const QUuid &uuid );
/**
* Returns the number of tracks in this handler
......@@ -106,7 +96,6 @@ class TrackHandler : public QObject
TrackWorkflow *track( quint32 trackId );
private:
void computeLength();
void allTracksEnded();
private:
......
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