Commit 227f8ea1 authored by luyikei's avatar luyikei

Remove TrackWorkflow

parent 6523f102
......@@ -30,7 +30,6 @@
#include "Main/Core.h"
#include "Media/Clip.h"
#include "EffectsEngine/EffectHelper.h"
#include "Workflow/TrackWorkflow.h"
#include "Workflow/SequenceWorkflow.h"
#include "Workflow/MainWorkflow.h"
#include "AbstractUndoStack.h"
......
......@@ -43,7 +43,6 @@
#include "Tools/VlmcLogger.h"
#include "Backend/IBackend.h"
#include "Workflow/MainWorkflow.h"
#include "Workflow/TrackWorkflow.h"
#include "Renderer/ClipRenderer.h"
#include "Commands/AbstractUndoStack.h"
......
......@@ -27,7 +27,6 @@
#include "Timeline.h"
#include "Main/Core.h"
#include "Workflow/TrackWorkflow.h"
#include "Workflow/MainWorkflow.h"
#include "Gui/MainWindow.h"
#include "Gui/effectsengine/EffectStack.h"
......
......@@ -43,7 +43,6 @@
#include "Library/Library.h"
#include "MainWorkflow.h"
#include "Project/Project.h"
#include "TrackWorkflow.h"
#include "SequenceWorkflow.h"
#include "Settings/Settings.h"
#include "Tools/VlmcDebug.h"
......
/*****************************************************************************
* TrackWorkflow.cpp : Will query the Clip workflow for each successive clip in the track
*****************************************************************************
* Copyright (C) 2008-2016 VideoLAN
*
* Authors: Yikei Lu <luyikei.qmltu@gmail.com>
* Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "TrackWorkflow.h"
#include "Project/Project.h"
#include "Media/Clip.h"
#include "EffectsEngine/EffectHelper.h"
#include "Backend/MLT/MLTTrack.h"
#include "Backend/MLT/MLTMultiTrack.h"
#include "Main/Core.h"
#include "Library/Library.h"
#include "MainWorkflow.h"
#include "Media/Media.h"
#include "Types.h"
#include "vlmc.h"
#include "Tools/VlmcDebug.h"
#include <QReadLocker>
#include <QMutex>
TrackWorkflow::TrackWorkflow( quint32 trackId, Backend::IMultiTrack* multitrack ) :
m_trackId( trackId )
{
m_clipsLock = new QReadWriteLock;
auto audioTrack = new Backend::MLT::MLTTrack;
audioTrack->setVideoEnabled( false );
m_audioTrack = audioTrack;
auto videoTrack = new Backend::MLT::MLTTrack;
videoTrack->setMute( true );
m_videoTrack = videoTrack;
m_multitrack = new Backend::MLT::MLTMultiTrack;
m_multitrack->setTrack( *m_videoTrack, 0 );
m_multitrack->setTrack( *m_audioTrack, 1 );
multitrack->setTrack( *m_multitrack, trackId );
}
TrackWorkflow::~TrackWorkflow()
{
delete m_audioTrack;
delete m_videoTrack;
delete m_multitrack;
delete m_clipsLock;
}
inline 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( std::shared_ptr<Clip> const& clip, qint64 start )
{
trackFromFormats( clip->formats() )->insertAt( *clip->input(), start );
m_clips.insertMulti( start, clip );
}
qint64
TrackWorkflow::getClipPosition( const QUuid& uuid ) const
{
auto it = m_clips.begin();
auto end = m_clips.end();
while ( it != end )
{
if ( it.value()->uuid() == uuid )
return it.key();
++it;
}
return -1;
}
std::shared_ptr<Clip>
TrackWorkflow::clip( const QUuid& uuid )
{
auto it = m_clips.begin();
auto end = m_clips.end();
while ( it != end )
{
if ( it.value()->uuid() == uuid )
return it.value();
++it;
}
return nullptr;
}
void
TrackWorkflow::moveClip( const QUuid& id, qint64 startingFrame )
{
QWriteLocker lock( m_clipsLock );
auto it = m_clips.begin();
auto end = m_clips.end();
while ( it != end )
{
if ( it.value()->uuid() == id )
{
auto clip = it.value();
auto track = trackFromFormats( it.value()->formats() );
track->move( it.key(), startingFrame );
m_clips.erase( it );
m_clips.insertMulti( startingFrame, clip );
return ;
}
++it;
}
}
void
TrackWorkflow::resizeClip( const QUuid &id, qint64 begin, qint64 end, qint64 pos )
{
{
QWriteLocker lock( m_clipsLock );
for ( auto it = m_clips.begin(); it != m_clips.end(); ++it )
{
auto clip = it.value();
if ( clip->uuid() == id )
{
auto track = trackFromFormats( clip->formats() );
track->resizeClip( track->clipIndexAt( it.key() ), begin, end );
break;
}
}
}
moveClip( id, pos );
}
void
TrackWorkflow::clipDestroyed( const QUuid& id )
{
QWriteLocker lock( m_clipsLock );
auto it = m_clips.begin();
auto end = m_clips.end();
while ( it != end )
{
if ( it.value()->uuid() == id )
{
auto clip = it.value();
m_clips.erase( it );
clip->disconnect( this );
return ;
}
++it;
}
}
std::shared_ptr<Clip>
TrackWorkflow::removeClip( const QUuid& id )
{
QWriteLocker lock( m_clipsLock );
auto it = m_clips.begin();
auto end = m_clips.end();
while ( it != end )
{
if ( it.value()->uuid() == id )
{
auto clip = it.value();
auto track = trackFromFormats( clip->formats() );
track->remove( track->clipIndexAt( it.key() ) );
m_clips.erase( it );
clip->disconnect( this );
return clip;
}
++it;
}
return nullptr;
}
QVariant
TrackWorkflow::toVariant() const
{
QVariantList l;
for ( auto it = m_clips.begin(); it != m_clips.end(); ++it )
{
auto clip = it.value();
auto h = clip->toVariant().toHash();
h.insert( "startFrame", it.key() );
l << h;
}
QVariantHash h{ { "clips", l }, { "filters", EffectHelper::toVariant( m_multitrack ) } };
return h;
}
void
TrackWorkflow::loadFromVariant( const QVariant &variant )
{
for ( auto& var : variant.toMap()[ "clips" ].toList() )
{
auto m = var.toMap();
auto c = std::shared_ptr<Clip>( Core::instance()->workflow()->createClip( m["parent"].toString(), trackId() ) );
c->setBoundaries( m["begin"].toULongLong(),
m["end"].toULongLong()
);
c->setFormats( (Clip::Formats)m["formats"].toInt() );
c->setUuid( m["uuid"].toString() );
auto isLinked = m["linked"].toBool();
c->setLinked( isLinked );
if ( isLinked == true )
c->setLinkedClipUuid( m["linkedClip"].toString() );
EffectHelper::loadFromVariant( m["filters"], c->input() );
addClip( c, m["startFrame"].toLongLong() );
emit Core::instance()->workflow()->clipAdded( c->uuid().toString() );
}
EffectHelper::loadFromVariant( variant.toMap()["filters"], m_multitrack );
}
void
TrackWorkflow::clear()
{
QWriteLocker lock( m_clipsLock );
m_clips.clear();
}
void
TrackWorkflow::mute( bool muted, Workflow::TrackType trackType )
{
if ( trackType == Workflow::AudioTrack )
m_audioTrack->setMute( muted );
else
m_videoTrack->setVideoEnabled( !muted );
}
void
TrackWorkflow::muteClip( const QUuid &uuid )
{
/* TODO
QWriteLocker lock( m_clipsLock );
auto it = m_clips.begin();
auto end = m_clips.end();
while ( it != end )
{
if ( it.value()->uuid() == uuid )
{
it.value()->mute();
return ;
}
++it;
}
vlmcWarning() << "Failed to mute clip" << uuid << "it probably doesn't exist "
"in this track";
*/
}
void
TrackWorkflow::unmuteClip( const QUuid &uuid )
{
/* TODO
QWriteLocker lock( m_clipsLock );
auto it = m_clips.begin();
auto end = m_clips.end();
while ( it != end )
{
if ( it.value()->uuid() == uuid )
{
it.value()->unmute();
return ;
}
++it;
}
vlmcWarning() << "Failed to unmute clip" << uuid << "it probably doesn't exist "
"in this track";
*/
}
bool
TrackWorkflow::contains( const QUuid &uuid ) const
{
auto it = m_clips.begin();
auto end = m_clips.end();
while ( it != end )
{
if ( it.value()->uuid() == uuid ||
it.value()->isChild( uuid ) )
return true;
++it;
}
return false;
}
quint32
TrackWorkflow::trackId() const
{
return m_trackId;
}
Backend::IInput*
TrackWorkflow::input()
{
return m_multitrack;
}
/*****************************************************************************
* TrackWorkflow.h : Will query the Clip workflow for each successive clip in the track
*****************************************************************************
* Copyright (C) 2008-2016 VideoLAN
*
* Authors: Yikei Lu <luyikei.qmltu@gmail.com>
* Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef TRACKWORKFLOW_H
#define TRACKWORKFLOW_H
#include "Types.h"
#include <QObject>
#include <QMap>
#include <QXmlStreamWriter>
#include <memory>
#include "Media/Clip.h"
class MainWorkflow;
class EffectHelper;
namespace Backend
{
class ITrack;
class IMultiTrack;
class IInput;
}
namespace Workflow
{
class Helper;
}
class QMutex;
class QReadWriteLock;
class QWaitCondition;
class TrackWorkflow : public QObject
{
Q_OBJECT
public:
TrackWorkflow( quint32 trackId, Backend::IMultiTrack* multitrack );
~TrackWorkflow();
inline Backend::ITrack* trackFromFormats( Clip::Formats formats );
void moveClip( const QUuid& id, qint64 startingFrame );
void resizeClip( const QUuid& id, qint64 begin, qint64 end, qint64 pos );
std::shared_ptr<Clip> removeClip( const QUuid& id );
void addClip( std::shared_ptr<Clip> const& clip, qint64 start );
qint64 getClipPosition( const QUuid& uuid ) const;
std::shared_ptr<Clip> clip( const QUuid& uuid );
virtual QVariant toVariant() const;
void loadFromVariant( const QVariant& variant );
void clear();
void mute( bool muted, Workflow::TrackType trackType );
/**
* \brief Mute a clip
*
* Mutting a clip will prevent it to be rendered.
* \param uuid The uuid of the clip to mute.
*/
void muteClip( const QUuid& uuid );
void unmuteClip( const QUuid& uuid );
bool contains( const QUuid& uuid ) const;
quint32 trackId() const;
Backend::IInput* input();
private:
Backend::IMultiTrack* m_multitrack;
Backend::ITrack* m_audioTrack;
Backend::ITrack* m_videoTrack;
QMap<qint64, std::shared_ptr<Clip>> m_clips;
QReadWriteLock* m_clipsLock;
const quint32 m_trackId;
private slots:
void clipDestroyed( const QUuid &uuid );
signals:
void lengthChanged( qint64 newLength );
//these signals are here to ease connection with tracksview, as it only
//monitors tracks
void effectAdded( TrackWorkflow*, std::shared_ptr<EffectHelper> const& helper, qint64 );
void effectRemoved( TrackWorkflow*, const QUuid& );
void effectMoved( TrackWorkflow*, const QUuid&, qint64 );
};
#endif // TRACKWORKFLOW_H
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