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

EffectHelper: Relocating EffectHelper in a global class.

ie. out of the EffectsEngine class. It is now a class, not a struct.
parent 8237ca22
......@@ -9,6 +9,7 @@ SET(VLMC_SRCS
EffectsEngine/EffectsEngine.cpp
EffectsEngine/Effect.cpp
EffectsEngine/EffectUser.cpp
EffectsEngine/EffectHelper.cpp
EffectsEngine/EffectInstance.cpp
EffectsEngine/EffectSettingValue.cpp
Library/Library.cpp
......@@ -59,6 +60,7 @@ ELSE (WIN32)
ENDIF(WIN32)
SET (VLMC_HDRS
EffectsEngine/EffectHelper.h
EffectsEngine/EffectsEngine.h
EffectsEngine/EffectSettingValue.h
Library/Library.h
......
/*****************************************************************************
* EffectHelper: Contains informations about effects
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
*
* 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.
*****************************************************************************/
#include "EffectHelper.h"
EffectHelper::EffectHelper( EffectInstance *effectInstance, qint64 begin, qint64 end,
const QString &uuid ) :
m_effectInstance( effectInstance ),
m_begin( begin ),
m_end( end )
{
if ( uuid.isNull() == true )
m_uuid = QUuid::createUuid();
else
m_uuid = uuid;
}
qint64
EffectHelper::begin() const
{
return m_begin;
}
qint64
EffectHelper::end() const
{
return m_end;
}
void
EffectHelper::setBegin( qint64 begin )
{
m_begin = begin;
emit lengthUpdated();
}
void
EffectHelper::setEnd(qint64 end)
{
m_end = end;
emit lengthUpdated();
}
void
EffectHelper::setBoundaries( qint64 begin, qint64 end )
{
m_begin = begin;
m_end = end;
emit lengthUpdated();
}
qint64
EffectHelper::length() const
{
return m_end - m_begin;
}
const QUuid&
EffectHelper::uuid() const
{
return m_uuid;
}
EffectInstance*
EffectHelper::effectInstance()
{
return m_effectInstance;
}
const EffectInstance*
EffectHelper::effectInstance() const
{
return m_effectInstance;
}
/*****************************************************************************
* EffectHelper: Contains informations about effects
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
*
* 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 EFFECTHELPER_H
#define EFFECTHELPER_H
class EffectInstance;
#include <QObject>
#include <QUuid>
#include <QMetaType>
class EffectHelper : public QObject
{
Q_OBJECT
public:
EffectHelper( EffectInstance *effectInstance, qint64 begin = 0, qint64 end = -1,
const QString& uuid = QString() );
qint64 begin() const;
qint64 end() const;
void setBegin( qint64 begin );
void setEnd( qint64 end );
void setBoundaries( qint64 begin, qint64 end );
qint64 length() const;
const QUuid &uuid() const;
EffectInstance *effectInstance();
const EffectInstance *effectInstance() const;
private:
EffectInstance *m_effectInstance;
qint64 m_begin;
qint64 m_end;
QUuid m_uuid;
signals:
void lengthUpdated();
};
Q_DECLARE_METATYPE( EffectHelper* );
#endif // EFFECTHELPER_H
......@@ -22,6 +22,7 @@
#include "EffectUser.h"
#include "EffectHelper.h"
#include "EffectInstance.h"
#include "Types.h"
......@@ -42,14 +43,14 @@ EffectUser::~EffectUser()
delete m_effectsLock;
}
EffectsEngine::EffectHelper*
EffectHelper*
EffectUser::addEffect( Effect *effect, qint64 start /*= 0*/, qint64 end /*= -1*/ )
{
//FIXME: Check it the effect type is supported
EffectInstance *effectInstance = effect->createInstance();
if ( m_isRendering == true )
effectInstance->init( m_width, m_height );
EffectsEngine::EffectHelper *ret = new EffectsEngine::EffectHelper( effectInstance, start, end );
EffectHelper *ret = new EffectHelper( effectInstance, start, end );
QWriteLocker lock( m_effectsLock );
if ( effect->type() == Effect::Filter )
......@@ -78,8 +79,8 @@ EffectUser::applyFilters( const Workflow::Frame* frame,
while ( it != ite )
{
if ( (*it)->start < currentFrame &&
( (*it)->end < 0 || (*it)->end > currentFrame ) )
if ( (*it)->begin() < currentFrame &&
( (*it)->end() < 0 || (*it)->end() > currentFrame ) )
{
quint32 **buff;
if ( firstBuff == true )
......@@ -88,7 +89,7 @@ EffectUser::applyFilters( const Workflow::Frame* frame,
buff = &buff2;
if ( *buff == NULL )
*buff = new quint32[frame->nbPixels()];
EffectInstance *effect = (*it)->effect;
EffectInstance *effect = (*it)->effectInstance();
effect->process( time, input, *buff );
input = *buff;
firstBuff = !firstBuff;
......@@ -121,7 +122,7 @@ EffectUser::initFilters()
while ( it != ite )
{
(*it)->effect->init( m_width, m_height );
(*it)->effectInstance()->init( m_width, m_height );
++it;
}
}
......@@ -136,12 +137,12 @@ EffectUser::initMixers()
while ( it != ite )
{
(*it)->effect->init( m_width, m_height );
(*it)->effectInstance()->init( m_width, m_height );
++it;
}
}
EffectsEngine::EffectHelper*
EffectHelper*
EffectUser::getMixer( qint64 currentFrame )
{
QReadLocker lock( m_effectsLock );
......@@ -151,9 +152,9 @@ EffectUser::getMixer( qint64 currentFrame )
while ( it != ite )
{
if ( (*it)->start <= currentFrame && currentFrame <= (*it)->end )
if ( (*it)->begin() <= currentFrame && currentFrame <= (*it)->end() )
{
Q_ASSERT( (*it)->effect->effect()->type() == Effect::Mixer2 );
Q_ASSERT( (*it)->effectInstance()->effect()->type() == Effect::Mixer2 );
return (*it);
}
++it;
......@@ -198,9 +199,9 @@ EffectUser::saveFilters( QXmlStreamWriter &project ) const
while ( it != ite )
{
project.writeStartElement( "effect" );
project.writeAttribute( "name", (*it)->effect->effect()->name() );
project.writeAttribute( "start", QString::number( (*it)->start ) );
project.writeAttribute( "end", QString::number( (*it)->end ) );
project.writeAttribute( "name", (*it)->effectInstance()->effect()->name() );
project.writeAttribute( "start", QString::number( (*it)->begin() ) );
project.writeAttribute( "end", QString::number( (*it)->end() ) );
project.writeEndElement();
++it;
}
......
......@@ -40,7 +40,7 @@ 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 );
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 );
......@@ -59,7 +59,7 @@ class EffectUser : public QObject
void saveFilters( QXmlStreamWriter &project ) const;
//Mixers methods:
EffectsEngine::EffectHelper *getMixer( qint64 currentFrame );
EffectHelper *getMixer( qint64 currentFrame );
protected:
/**
......
......@@ -31,6 +31,7 @@ namespace Workflow
class Frame;
}
class EffectHelper;
class FilterInstance;
class MixerInstance;
......@@ -50,28 +51,8 @@ class EffectsEngine : public QObject, public Singleton<EffectsEngine>
Q_OBJECT
public:
struct EffectHelper
{
EffectHelper( EffectInstance *_effect, qint64 _start = 0, qint64 _end = -1,
const QString& _uuid = QString() ) :
effect( _effect ),
start( _start ),
end( _end )
{
if ( _uuid.isNull() == true )
uuid = QUuid::createUuid();
else
uuid = _uuid;
}
EffectInstance *effect;
qint64 start;
qint64 end;
QUuid uuid;
};
typedef QList<EffectHelper*> EffectList;
static const quint32 MaxFramesForMixer = 3;
typedef QList<EffectHelper*> EffectList;
static const quint32 MaxFramesForMixer = 3;
Effect* effect( const QString& name );
const QStringList& effects( Effect::Type type ) const;
......@@ -94,6 +75,4 @@ class EffectsEngine : public QObject, public Singleton<EffectsEngine>
friend class Singleton<EffectsEngine>;
};
Q_DECLARE_METATYPE(EffectsEngine::EffectHelper*)
#endif // EFFECTSENGINE_H
......@@ -21,6 +21,8 @@
*****************************************************************************/
#include "EffectInstanceListModel.h"
#include "EffectHelper.h"
#include "EffectInstance.h"
#include "EffectUser.h"
......@@ -46,15 +48,15 @@ EffectInstanceListModel::data( const QModelIndex &index, int role ) const
switch ( role )
{
case Qt::DisplayRole:
return m_user->effects( Effect::Filter ).at( index.row() )->effect->effect()->name();
return m_user->effects( Effect::Filter ).at( index.row() )->effectInstance()->effect()->name();
case Qt::ToolTipRole:
return m_user->effects( Effect::Filter ).at( index.row() )->effect->effect()->description();
return m_user->effects( Effect::Filter ).at( index.row() )->effectInstance()->effect()->description();
case Qt::EditRole:
return QVariant::fromValue( m_user->effects( Effect::Filter ).at( index.row() ) );
case Qt::SizeHintRole:
{
const QFontMetrics &fm = QApplication::fontMetrics();
QSize size( fm.width( m_user->effects( Effect::Filter ).at( index.row() )->effect->effect()->name() ), fm.height() );
QSize size( fm.width( m_user->effects( Effect::Filter ).at( index.row() )->effectInstance()->effect()->name() ), fm.height() );
return size;
}
default:
......@@ -93,7 +95,7 @@ EffectInstanceListModel::moveDown( const QModelIndex &index )
emit layoutChanged();
}
EffectsEngine::EffectHelper*
EffectHelper*
EffectInstanceListModel::add( const QString &effectName )
{
if ( effectName.isEmpty() == true )
......@@ -102,7 +104,7 @@ EffectInstanceListModel::add( const QString &effectName )
if ( effect == NULL )
return NULL;
beginInsertRows( QModelIndex(), m_user->count( Effect::Filter ), m_user->count( Effect::Filter ) );
EffectsEngine::EffectHelper *helper = m_user->addEffect( effect );
EffectHelper *helper = m_user->addEffect( effect );
endInsertRows();
return helper;
}
......@@ -37,7 +37,7 @@ class EffectInstanceListModel : public QAbstractListModel
virtual bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() );
void moveUp( const QModelIndex &index );
void moveDown( const QModelIndex &index );
EffectsEngine::EffectHelper* add( const QString &effectName );
EffectHelper* add( const QString &effectName );
private:
EffectUser *m_user;
......
......@@ -22,6 +22,8 @@
#include "EffectStack.h"
#include "ui_EffectStack.h"
#include "EffectHelper.h"
#include "EffectInstance.h"
#include "EffectInstanceWidget.h"
#include "EffectUser.h"
......@@ -51,8 +53,8 @@ EffectStack::EffectStack( EffectUser *user, QWidget *parent ):
//Add an empty instance widget.
m_stackedLayout->addWidget( new EffectInstanceWidget( this ) );
//Create instance widgets for already inserted effects
foreach ( EffectsEngine::EffectHelper *helper, user->effects( Effect::Filter ) )
addInstanceWidget( helper->effect );
foreach ( EffectHelper *helper, user->effects( Effect::Filter ) )
addInstanceWidget( helper->effectInstance() );
}
EffectStack::~EffectStack()
......@@ -73,7 +75,7 @@ EffectStack::addInstanceWidget( EffectInstance *instance )
void
EffectStack::selectedChanged( const QModelIndex &index )
{
EffectInstance *inst = m_model->data( index, Qt::EditRole ).value<EffectsEngine::EffectHelper*>()->effect;
EffectInstance *inst = m_model->data( index, Qt::EditRole ).value<EffectHelper*>()->effectInstance();
m_stackedLayout->setCurrentWidget( m_instanceWidgets[inst->effect()->name()] );
}
......@@ -106,6 +108,6 @@ EffectStack::remove()
void
EffectStack::add()
{
EffectsEngine::EffectHelper *helper = m_model->add( m_ui->addComboBox->currentText() );
addInstanceWidget( helper->effect );
EffectHelper *helper = m_model->add( m_ui->addComboBox->currentText() );
addInstanceWidget( helper->effectInstance() );
}
......@@ -22,6 +22,7 @@
#include "GraphicsEffectItem.h"
#include "EffectHelper.h"
#include "Timeline.h"
#include "TracksView.h"
......@@ -32,13 +33,13 @@ GraphicsEffectItem::GraphicsEffectItem( Effect *effect ) :
m_effectHelper( NULL )
{
setOpacity( 0.8 );
m_effectHelper = new EffectsEngine::EffectHelper( effect->createInstance() );
m_effectHelper = new EffectHelper( effect->createInstance() );
}
const QUuid&
GraphicsEffectItem::uuid() const
{
return m_effectHelper->uuid;
return m_effectHelper->uuid();
}
int
......
......@@ -62,7 +62,7 @@ class GraphicsEffectItem : public AbstractGraphicsItem
private:
Effect *m_effect;
EffectsEngine::EffectHelper *m_effectHelper;
EffectHelper *m_effectHelper;
};
#endif // GRAPHICSEFFECTITEM_H
......@@ -26,10 +26,11 @@
#include "Clip.h"
#include "ClipHelper.h"
#include "AudioClipWorkflow.h"
#include "EffectInstance.h"
#include "EffectHelper.h"
#include "ImageClipWorkflow.h"
#include "MainWorkflow.h"
#include "Media.h"
#include "EffectInstance.h"
#include "Types.h"
#include "VideoClipWorkflow.h"
#include "vlmc.h"
......@@ -329,11 +330,11 @@ TrackWorkflow::getOutput( qint64 currentFrame, qint64 subFrame, bool paused )
//Handle mixers:
if ( m_trackType == Workflow::VideoTrack )
{
EffectsEngine::EffectHelper* mixer = getMixer( currentFrame );
EffectHelper* mixer = getMixer( currentFrame );
if ( mixer != NULL && frames[0] != NULL ) //There's no point using the mixer if there's no frame rendered.
{
//FIXME: We don't handle mixer3 yet.
mixer->effect->process( currentFrame * 1000.0 / m_fps,
mixer->effectInstance()->process( currentFrame * 1000.0 / m_fps,
frames[0]->buffer(),
frames[1] != NULL ? frames[1]->buffer() : MainWorkflow::getInstance()->blackOutput()->buffer(),
NULL, m_mixerBuffer->buffer() );
......
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