Commit 1b9b2e13 authored by luyikei's avatar luyikei

SequenceWorkflow: Use Track

parent b8ef77aa
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "Backend/MLT/MLTTrack.h" #include "Backend/MLT/MLTTrack.h"
#include "Backend/MLT/MLTMultiTrack.h" #include "Backend/MLT/MLTMultiTrack.h"
#include "EffectsEngine/EffectHelper.h" #include "EffectsEngine/EffectHelper.h"
#include "Track.h"
#include "Workflow/MainWorkflow.h" #include "Workflow/MainWorkflow.h"
#include "Main/Core.h" #include "Main/Core.h"
#include "Library/Library.h" #include "Library/Library.h"
...@@ -41,17 +42,16 @@ SequenceWorkflow::SequenceWorkflow( size_t trackCount ) ...@@ -41,17 +42,16 @@ SequenceWorkflow::SequenceWorkflow( size_t trackCount )
{ {
for ( int i = 0; i < trackCount; ++i ) for ( int i = 0; i < trackCount; ++i )
{ {
auto audioTrack = std::shared_ptr<Backend::ITrack>( new Backend::MLT::MLTTrack ); auto audioTrack = QSharedPointer<Track>( new Track( Workflow::AudioTrack ) );
audioTrack->hide( Backend::HideType::Video ); m_tracks[Workflow::AudioTrack] << audioTrack;
m_tracks[Workflow::AudioTrack] << audioTrack; auto videoTrack = QSharedPointer<Track>( new Track( Workflow::VideoTrack ) );
auto videoTrack = std::shared_ptr<Backend::ITrack>( new Backend::MLT::MLTTrack );
videoTrack->hide( Backend::HideType::Audio );
m_tracks[Workflow::VideoTrack] << videoTrack; m_tracks[Workflow::VideoTrack] << videoTrack;
auto multitrack = std::shared_ptr<Backend::IMultiTrack>( new Backend::MLT::MLTMultiTrack ); auto multitrack = std::shared_ptr<Backend::IMultiTrack>( new Backend::MLT::MLTMultiTrack );
multitrack->setTrack( *videoTrack, 0 ); multitrack->setTrack( audioTrack->input(), 0 );
multitrack->setTrack( *audioTrack, 1 ); multitrack->hide( Backend::HideType::Video, 0 );
multitrack->setTrack( videoTrack->input(), 1 );
multitrack->hide( Backend::HideType::Audio, 1 );
m_multiTracks << multitrack; m_multiTracks << multitrack;
m_multitrack->setTrack( *multitrack, i ); m_multitrack->setTrack( *multitrack, i );
...@@ -68,12 +68,12 @@ QUuid ...@@ -68,12 +68,12 @@ QUuid
SequenceWorkflow::addClip( QSharedPointer<::Clip> clip, quint32 trackId, qint64 pos, const QUuid& uuid, bool isAudioClip ) SequenceWorkflow::addClip( QSharedPointer<::Clip> clip, quint32 trackId, qint64 pos, const QUuid& uuid, bool isAudioClip )
{ {
auto t = track( trackId, isAudioClip ); auto t = track( trackId, isAudioClip );
auto ret = t->insertAt( *clip->input(), pos );
if ( ret == false )
return {};
auto c = QSharedPointer<ClipInstance>::create( clip, auto c = QSharedPointer<ClipInstance>::create( clip,
uuid.isNull() == true ? QUuid::createUuid() : uuid, uuid.isNull() == true ? QUuid::createUuid() : uuid,
trackId, pos, isAudioClip ); trackId, pos, isAudioClip );
auto ret = t->addClip( c, pos );
if ( ret == false )
return {};
vlmcDebug() << "adding" << (isAudioClip ? "audio" : "video") << "clip instance:" << c->uuid; vlmcDebug() << "adding" << (isAudioClip ? "audio" : "video") << "clip instance:" << c->uuid;
m_clips.insert( c->uuid, c ) ; m_clips.insert( c->uuid, c ) ;
clip->setOnTimeline( true ); clip->setOnTimeline( true );
...@@ -91,7 +91,6 @@ SequenceWorkflow::moveClip( const QUuid& uuid, quint32 trackId, qint64 pos ) ...@@ -91,7 +91,6 @@ SequenceWorkflow::moveClip( const QUuid& uuid, quint32 trackId, qint64 pos )
return false; return false;
} }
auto& c = it.value(); auto& c = it.value();
auto clip = c->clip;
auto oldTrackId = c->trackId; auto oldTrackId = c->trackId;
auto oldPosition = c->pos; auto oldPosition = c->pos;
if ( oldPosition == pos && oldTrackId == trackId ) if ( oldPosition == pos && oldTrackId == trackId )
...@@ -101,19 +100,19 @@ SequenceWorkflow::moveClip( const QUuid& uuid, quint32 trackId, qint64 pos ) ...@@ -101,19 +100,19 @@ SequenceWorkflow::moveClip( const QUuid& uuid, quint32 trackId, qint64 pos )
{ {
// Don't call removeClip/addClip as they would destroy & recreate clip instances for nothing. // Don't call removeClip/addClip as they would destroy & recreate clip instances for nothing.
// Simply fiddle with the track to move the clip around // Simply fiddle with the track to move the clip around
t->remove( t->clipIndexAt( oldPosition ) ); t->removeClip( uuid );
auto newTrack = track( trackId, c->isAudio ); auto newTrack = track( trackId, c->isAudio );
if ( newTrack->insertAt( *clip->input(), pos ) == false ) if ( newTrack->addClip( c, pos ) == false )
return false; return false;
c->pos = pos;
c->trackId = trackId; c->trackId = trackId;
} }
else else
{ {
if ( t->move( oldPosition, pos ) == false ) bool ret = t->moveClip( c->uuid, pos );
if ( ret == false )
return false; return false;
c->pos = pos;
} }
c->pos = pos;
emit clipMoved( uuid.toString() ); emit clipMoved( uuid.toString() );
// CAUTION: You must not move a clip to a place where it would overlap another clip! // CAUTION: You must not move a clip to a place where it would overlap another clip!
return true; return true;
...@@ -132,18 +131,19 @@ SequenceWorkflow::resizeClip( const QUuid& uuid, qint64 newBegin, qint64 newEnd, ...@@ -132,18 +131,19 @@ SequenceWorkflow::resizeClip( const QUuid& uuid, qint64 newBegin, qint64 newEnd,
auto trackId = c->trackId; auto trackId = c->trackId;
auto position = c->pos; auto position = c->pos;
auto t = track( trackId, c->isAudio ); auto t = track( trackId, c->isAudio );
auto clipIndex = t->clipIndexAt( position ); bool ret;
// This will only duplicate the clip once; no need to panic about endless duplications // This will only duplicate the clip once; no need to panic about endless duplications
if ( c->duplicateClipForResize( newBegin, newEnd ) == true ) if ( c->duplicateClipForResize( newBegin, newEnd ) == true )
{ {
vlmcDebug() << "Duplicating clip for resize" << c->uuid << "is now using" << c->clip->uuid(); vlmcDebug() << "Duplicating clip for resize" << c->uuid << "is now using" << c->clip->uuid();
t->remove( clipIndex ); t->removeClip( uuid );
t->insertAt( *c->clip->input(), position ); ret = t->addClip( c, position );
} }
auto ret = t->resizeClip( clipIndex, newBegin, newEnd ); else
ret = t->resizeClip( uuid, newBegin, newEnd, newPos );
if ( ret == false ) if ( ret == false )
return false; return false;
ret = moveClip( uuid, trackId, newPos ); c->pos = newPos;
emit clipResized( uuid.toString() ); emit clipResized( uuid.toString() );
return ret; return ret;
} }
...@@ -161,9 +161,8 @@ SequenceWorkflow::removeClip( const QUuid& uuid ) ...@@ -161,9 +161,8 @@ SequenceWorkflow::removeClip( const QUuid& uuid )
auto c = it.value(); auto c = it.value();
auto clip = c->clip; auto clip = c->clip;
auto trackId = c->trackId; auto trackId = c->trackId;
auto position = c->pos;
auto t = track( trackId, c->isAudio ); auto t = track( trackId, c->isAudio );
t->remove( t->clipIndexAt( position ) ); t->removeClip( uuid );
m_clips.erase( it ); m_clips.erase( it );
clip->disconnect( this ); clip->disconnect( this );
bool onTimeline = false; bool onTimeline = false;
...@@ -328,14 +327,14 @@ SequenceWorkflow::trackInput( quint32 trackId ) ...@@ -328,14 +327,14 @@ SequenceWorkflow::trackInput( quint32 trackId )
return m_multiTracks[trackId].get(); return m_multiTracks[trackId].get();
} }
std::shared_ptr<Backend::ITrack> QSharedPointer<Track>
SequenceWorkflow::track( quint32 trackId, bool isAudio ) SequenceWorkflow::track( quint32 trackId, bool isAudio )
{ {
if ( trackId >= (quint32)m_trackCount ) if ( trackId >= m_trackCount )
return nullptr; return {};
if ( isAudio == true ) if ( isAudio == true )
return m_tracks[Workflow::AudioTrack][trackId]; return m_tracks[Workflow::AudioTrack][static_cast<int>( trackId )];
return m_tracks[Workflow::VideoTrack][trackId]; return m_tracks[Workflow::VideoTrack][static_cast<int>( trackId )];
} }
SequenceWorkflow::ClipInstance::ClipInstance(QSharedPointer<::Clip> c, const QUuid& uuid, quint32 tId, qint64 p, bool isAudio ) SequenceWorkflow::ClipInstance::ClipInstance(QSharedPointer<::Clip> c, const QUuid& uuid, quint32 tId, qint64 p, bool isAudio )
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include "Media/Clip.h" #include "Media/Clip.h"
#include "Types.h" #include "Types.h"
class Track;
namespace Backend namespace Backend
{ {
class IMultiTrack; class IMultiTrack;
...@@ -113,12 +115,12 @@ class SequenceWorkflow : public QObject ...@@ -113,12 +115,12 @@ class SequenceWorkflow : public QObject
private: private:
inline std::shared_ptr<Backend::ITrack> track( quint32 trackId, bool audio ); inline QSharedPointer<Track> track( quint32 trackId, bool audio );
QMap<QUuid, QSharedPointer<ClipInstance>> m_clips; QMap<QUuid, QSharedPointer<ClipInstance>> m_clips;
Backend::IMultiTrack* m_multitrack; Backend::IMultiTrack* m_multitrack;
QList<std::shared_ptr<Backend::ITrack>> m_tracks[Workflow::NbTrackType]; QList<QSharedPointer<Track>> m_tracks[Workflow::NbTrackType];
QList<std::shared_ptr<Backend::IMultiTrack>> m_multiTracks; QList<std::shared_ptr<Backend::IMultiTrack>> m_multiTracks;
const size_t m_trackCount; const size_t m_trackCount;
......
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