Commit 653f3156 authored by Hugo Beauzée-Luyssen's avatar 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.
parent ceff8337
......@@ -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;
}
......@@ -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();
......
......@@ -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();
}
......@@ -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
......@@ -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 ) ) );
......
......@@ -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
......@@ -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();
}
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