[vlmc-devel] commit: EffectStack: Use the new EffectUser class. ( Hugo Beauzée-Luyssen )
git at videolan.org
git at videolan.org
Wed Sep 1 03:10:44 CEST 2010
vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Wed Sep 1 03:20:07 2010 +0200| [653f3156573a2a1f407349fe579543e086c3a251] | committer: Hugo Beauzée-Luyssen
EffectStack: Use the new EffectUser class.
This adds thread safety, and prepare the effect addition, as we now can
add an effect without having to care if the EffectUser is rendering or
not, since its handled internally.
> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=653f3156573a2a1f407349fe579543e086c3a251
---
src/EffectsEngine/EffectUser.cpp | 51 +++++++++++++++++++++
src/EffectsEngine/EffectUser.h | 4 ++
src/Gui/effectsengine/EffectInstanceListModel.cpp | 27 +++++------
src/Gui/effectsengine/EffectInstanceListModel.h | 6 ++-
src/Gui/effectsengine/EffectStack.cpp | 6 +-
src/Gui/effectsengine/EffectStack.h | 6 +-
src/Gui/widgets/TrackControls.cpp | 2 +-
7 files changed, 79 insertions(+), 23 deletions(-)
diff --git a/src/EffectsEngine/EffectUser.cpp b/src/EffectsEngine/EffectUser.cpp
index 13fd5bf..c204152 100644
--- a/src/EffectsEngine/EffectUser.cpp
+++ b/src/EffectsEngine/EffectUser.cpp
@@ -207,3 +207,54 @@ EffectUser::saveFilters( QXmlStreamWriter &project ) const
project.writeEndElement();
}
+const EffectsEngine::EffectList&
+EffectUser::effects( Effect::Type type ) const
+{
+ if ( type == Effect::Filter )
+ return m_filters;
+ if ( type != Effect::Mixer2 )
+ qCritical() << "Only Filters and Mixer2 are handled. This is going to be nasty !";
+ return m_mixers;
+}
+
+void
+EffectUser::removeEffect( Effect::Type type, quint32 idx )
+{
+ QWriteLocker lock( m_effectsLock );
+
+ if ( type == Effect::Filter )
+ {
+ if ( idx < m_filters.size() )
+ m_filters.removeAt( idx );
+ }
+ else if ( type == Effect::Mixer2 )
+ {
+ if ( idx < m_mixers.size() )
+ m_mixers.removeAt( idx );
+ }
+ else
+ qCritical() << "Unhandled effect type";
+}
+
+void
+EffectUser::swapFilters( quint32 idx, quint32 idx2 )
+{
+ if ( idx >= m_filters.size() || idx2 > m_filters.size() )
+ return ;
+ QWriteLocker lock( m_effectsLock );
+
+ m_filters.swap( idx, idx2 );
+}
+
+quint32
+EffectUser::count( Effect::Type type ) const
+{
+ QReadLocker lock( m_effectsLock );
+
+ if ( type == Effect::Filter )
+ return m_filters.count();
+ if ( type == Effect::Mixer2 )
+ return m_mixers.count();
+ qCritical() << "Unhandled effect type";
+ return 0;
+}
diff --git a/src/EffectsEngine/EffectUser.h b/src/EffectsEngine/EffectUser.h
index e517487..4d7ef32 100644
--- a/src/EffectsEngine/EffectUser.h
+++ b/src/EffectsEngine/EffectUser.h
@@ -41,6 +41,10 @@ class EffectUser : public QObject
* \param effect The effect instance. Can be either mixer or filter.
*/
EffectsEngine::EffectHelper *addEffect( Effect *effect, qint64 start = 0, qint64 end = -1 );
+ const EffectsEngine::EffectList &effects( Effect::Type type ) const;
+ void removeEffect( Effect::Type type, quint32 idx );
+ void swapFilters( quint32 idx, quint32 idx2 );
+ quint32 count( Effect::Type type ) const;
protected:
EffectUser();
diff --git a/src/Gui/effectsengine/EffectInstanceListModel.cpp b/src/Gui/effectsengine/EffectInstanceListModel.cpp
index 2c5c851..00ef722 100644
--- a/src/Gui/effectsengine/EffectInstanceListModel.cpp
+++ b/src/Gui/effectsengine/EffectInstanceListModel.cpp
@@ -22,21 +22,22 @@
#include "EffectInstanceListModel.h"
#include "EffectInstance.h"
+#include "EffectUser.h"
#include <QApplication>
#include <QFontMetrics>
#include <QtDebug>
-EffectInstanceListModel::EffectInstanceListModel( EffectsEngine::EffectList *list ) :
- m_list( list )
+EffectInstanceListModel::EffectInstanceListModel( EffectUser *user ) :
+ m_user( user )
{
}
qint32
EffectInstanceListModel::rowCount( const QModelIndex& ) const
{
- return m_list->size();
+ return m_user->effects( Effect::Filter ).size();
}
QVariant
@@ -45,15 +46,15 @@ EffectInstanceListModel::data( const QModelIndex &index, int role ) const
switch ( role )
{
case Qt::DisplayRole:
- return m_list->at( index.row() )->effect->effect()->name();
+ return m_user->effects( Effect::Filter ).at( index.row() )->effect->effect()->name();
case Qt::ToolTipRole:
- return m_list->at( index.row() )->effect->effect()->description();
+ return m_user->effects( Effect::Filter ).at( index.row() )->effect->effect()->description();
case Qt::EditRole:
- return QVariant::fromValue( m_list->at( index.row() ) );
+ return QVariant::fromValue( m_user->effects( Effect::Filter ).at( index.row() ) );
case Qt::SizeHintRole:
{
const QFontMetrics &fm = QApplication::fontMetrics();
- QSize size( fm.width( m_list->at( index.row() )->effect->effect()->name() ), fm.height() );
+ QSize size( fm.width( m_user->effects( Effect::Filter ).at( index.row() )->effect->effect()->name() ), fm.height() );
return size;
}
default:
@@ -66,10 +67,8 @@ EffectInstanceListModel::removeRows( int row, int count, const QModelIndex& inde
{
if ( count != 1 )
return false;
- if ( row < 0 || row >= m_list->size() )
- return false;
beginRemoveRows( index, row, row );
- m_list->removeAt( row );
+ m_user->removeEffect( Effect::Filter, row );
endRemoveRows();
return true;
}
@@ -77,19 +76,19 @@ EffectInstanceListModel::removeRows( int row, int count, const QModelIndex& inde
void
EffectInstanceListModel::moveUp( const QModelIndex &index )
{
- if ( index.row() == 0 || index.row() >= m_list->size() )
+ if ( index.row() == 0 || index.row() >= m_user->count( Effect::Filter ) )
return ;
emit layoutAboutToBeChanged();
- m_list->swap( index.row(), index.row() - 1 );
+ m_user->swapFilters( index.row(), index.row() - 1 );
emit layoutChanged();
}
void
EffectInstanceListModel::moveDown( const QModelIndex &index )
{
- if ( index.row() >= m_list->size() - 1 )
+ if ( index.row() >= m_user->count( Effect::Filter ) - 1 )
return ;
emit layoutAboutToBeChanged();
- m_list->swap( index.row(), index.row() + 1 );
+ m_user->swapFilters( index.row(), index.row() + 1 );
emit layoutChanged();
}
diff --git a/src/Gui/effectsengine/EffectInstanceListModel.h b/src/Gui/effectsengine/EffectInstanceListModel.h
index 75bcc9e..eeb4dc1 100644
--- a/src/Gui/effectsengine/EffectInstanceListModel.h
+++ b/src/Gui/effectsengine/EffectInstanceListModel.h
@@ -24,13 +24,15 @@
#define EFFECTINSTANCELISTMODEL_H
#include "EffectsEngine.h"
+class EffectUser;
+
#include <QAbstractListModel>
class EffectInstanceListModel : public QAbstractListModel
{
public:
- EffectInstanceListModel( EffectsEngine::EffectList *list );
+ EffectInstanceListModel( EffectUser *user );
virtual qint32 rowCount( const QModelIndex &parent ) const;
virtual QVariant data( const QModelIndex &index, int role ) const;
virtual bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() );
@@ -38,7 +40,7 @@ class EffectInstanceListModel : public QAbstractListModel
void moveDown( const QModelIndex &index );
private:
- EffectsEngine::EffectList *m_list;
+ EffectUser *m_user;
};
#endif // EFFECTINSTANCELISTMODEL_H
diff --git a/src/Gui/effectsengine/EffectStack.cpp b/src/Gui/effectsengine/EffectStack.cpp
index d328149..7db0197 100644
--- a/src/Gui/effectsengine/EffectStack.cpp
+++ b/src/Gui/effectsengine/EffectStack.cpp
@@ -25,14 +25,14 @@
#include "EffectInstanceListModel.h"
-EffectStack::EffectStack( EffectsEngine::EffectList *list, QWidget *parent ):
+EffectStack::EffectStack( EffectUser *user, QWidget *parent ):
QDialog( parent ),
m_ui( new Ui::EffectStack ),
- m_list( list )
+ m_user( user )
{
m_ui->setupUi( this );
- m_model = new EffectInstanceListModel( list );
+ m_model = new EffectInstanceListModel( user );
m_ui->list->setModel( m_model );
connect( m_ui->list, SIGNAL( clicked( QModelIndex ) ),
this, SLOT( selectedChanged( QModelIndex ) ) );
diff --git a/src/Gui/effectsengine/EffectStack.h b/src/Gui/effectsengine/EffectStack.h
index 7964ae3..0deca57 100644
--- a/src/Gui/effectsengine/EffectStack.h
+++ b/src/Gui/effectsengine/EffectStack.h
@@ -25,7 +25,7 @@
#include <QDialog>
-#include "EffectsEngine.h"
+class EffectUser;
#include <QStandardItemModel>
@@ -41,7 +41,7 @@ class EffectStack : public QDialog
Q_OBJECT
public:
- explicit EffectStack( EffectsEngine::EffectList* list, QWidget *parent = 0 );
+ explicit EffectStack( EffectUser *user, QWidget *parent = 0 );
~EffectStack();
private slots:
@@ -53,7 +53,7 @@ class EffectStack : public QDialog
private:
Ui::EffectStack *m_ui;
EffectInstanceListModel *m_model;
- EffectsEngine::EffectList *m_list;
+ EffectUser *m_user;
};
#endif // EFFECTSTACK_H
diff --git a/src/Gui/widgets/TrackControls.cpp b/src/Gui/widgets/TrackControls.cpp
index 85579d6..d0c221d 100644
--- a/src/Gui/widgets/TrackControls.cpp
+++ b/src/Gui/widgets/TrackControls.cpp
@@ -133,6 +133,6 @@ TrackControls::trackNameDoubleClicked()
void
TrackControls::fxButtonClicked()
{
- EffectStack *stack = new EffectStack( m_track->trackWorkflow()->filters() );
+ EffectStack *stack = new EffectStack( m_track->trackWorkflow() );
stack->show();
}
More information about the Vlmc-devel
mailing list