Commit 4d37e6b0 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Effects: Adding parameter management.

parent 754ac3e3
......@@ -9,6 +9,7 @@ SET(VLMC_SRCS
EffectsEngine/EffectsEngine.cpp
EffectsEngine/Effect.cpp
EffectsEngine/EffectInstance.cpp
EffectsEngine/EffectSettingValue.cpp
EffectsEngine/FilterInstance.cpp
EffectsEngine/MixerInstance.cpp
Library/Library.cpp
......@@ -59,6 +60,7 @@ SET (VLMC_HDRS
EffectsEngine/EffectsEngine.h
EffectsEngine/Effect.h
EffectsEngine/EffectInstance.h
EffectsEngine/EffectSettingValue.h
Library/Library.h
Library/MediaContainer.h
LibVLCpp/VLCInstance.h
......
......@@ -37,6 +37,8 @@ Effect::Effect( const QString &fileName ) :
Effect::~Effect()
{
m_f0r_deinit();
qDeleteAll( m_params );
m_params.clear();
}
#define LOAD_FREI0R_SYMBOL( dest, symbolName ) \
......@@ -61,6 +63,9 @@ Effect::load()
LOAD_FREI0R_SYMBOL_CHECKED( m_f0r_destruct, "f0r_destruct" )
LOAD_FREI0R_SYMBOL( m_f0r_update, "f0r_update" );
LOAD_FREI0R_SYMBOL( m_f0r_update2, "f0r_update2" );
LOAD_FREI0R_SYMBOL_CHECKED( m_f0r_get_param_value, "f0r_get_param_value" );
LOAD_FREI0R_SYMBOL_CHECKED( m_f0r_set_param_value, "f0r_set_param_value" );
LOAD_FREI0R_SYMBOL_CHECKED( m_f0r_get_param_info, "f0r_get_param_info" );
//Initializing structures
f0r_plugin_info_t infos;
......@@ -83,6 +88,11 @@ Effect::load()
qCritical() << "Failed to load symbol f0r_update2. Dropping module" << fileName();
return false;
}
for ( qint32 i = 0; i < m_nbParams; ++i )
{
f0r_param_info_t *param = new f0r_param_info_t;
m_f0r_get_param_info( param, i );
}
return true;
}
......@@ -149,3 +159,9 @@ Effect::destroyInstance( EffectInstance *instance )
if ( m_instCount.fetchAndAddAcquire( -1 ) == 1 )
unload();
}
const Effect::ParamList&
Effect::params() const
{
return m_params;
}
......@@ -40,6 +40,7 @@ class Effect : public QLibrary
Mixer2 = F0R_PLUGIN_TYPE_MIXER2,
Mixer3 = F0R_PLUGIN_TYPE_MIXER3
};
typedef QList<f0r_param_info_t*> ParamList;
typedef int (*f0r_init_t)();
typedef void (*f0r_deinit_t)();
......@@ -48,6 +49,9 @@ class Effect : public QLibrary
typedef void (*f0r_destruct_t)( f0r_instance_t );
typedef void (*f0r_update_t)( f0r_instance_t, double, const unsigned int*, unsigned int * );
typedef void (*f0r_update2_t)( f0r_instance_t, double, const unsigned int*, const unsigned int*, const unsigned int*, unsigned int * );
typedef void (*f0r_get_param_value_t)( f0r_instance_t, f0r_param_t, int );
typedef void (*f0r_set_param_value_t)( f0r_instance_t, f0r_param_t, int );
typedef void (*f0r_get_param_info_t)( f0r_param_info_t*, int );
Effect( const QString& fileName );
virtual ~Effect();
......@@ -56,6 +60,7 @@ class Effect : public QLibrary
const QString& name();
const QString& description();
Type type();
const ParamList &params() const;
//This breaks coding convention, but it would be safe just to undef major/minor.
int getMajor();
int getMinor();
......@@ -65,26 +70,31 @@ class Effect : public QLibrary
void destroyInstance( EffectInstance* instance );
private:
QString m_name;
QString m_desc;
Type m_type;
int m_major;
int m_minor;
int m_nbParams;
QAtomicInt m_instCount;
QString m_name;
QString m_desc;
Type m_type;
int m_major;
int m_minor;
int m_nbParams;
QAtomicInt m_instCount;
ParamList m_params;
//Symbols:
f0r_init_t m_f0r_init;
f0r_deinit_t m_f0r_deinit;
f0r_get_info_t m_f0r_info;
f0r_construct_t m_f0r_construct;
f0r_destruct_t m_f0r_destruct;
f0r_update_t m_f0r_update;
f0r_update2_t m_f0r_update2;
f0r_init_t m_f0r_init;
f0r_deinit_t m_f0r_deinit;
f0r_get_info_t m_f0r_info;
f0r_construct_t m_f0r_construct;
f0r_destruct_t m_f0r_destruct;
f0r_update_t m_f0r_update;
f0r_update2_t m_f0r_update2;
f0r_get_param_value_t m_f0r_get_param_value;
f0r_set_param_value_t m_f0r_set_param_value;
f0r_get_param_info_t m_f0r_get_param_info;
friend class EffectInstance;
friend class FilterInstance;
friend class MixerInstance;
friend class EffectSettingValue;
};
#endif // EFFECT_H
......@@ -21,6 +21,7 @@
*****************************************************************************/
#include "EffectInstance.h"
#include "EffectSettingValue.h"
#include "Effect.h"
......@@ -30,6 +31,19 @@ EffectInstance::EffectInstance( Effect *effect ) :
m_height( 0 ),
m_instance( NULL )
{
Effect::ParamList::const_iterator it = effect->params().constBegin();
Effect::ParamList::const_iterator ite = effect->params().constEnd();
quint32 i = 0;
while ( it != ite )
{
f0r_param_info_t *info= *it;
m_params.push_back( new EffectSettingValue( EffectSettingValue::frei0rToVlmc( info->type ),
this, i, QVariant(),
info->name, info->explanation ) );
++it;
++i;
}
}
EffectInstance::~EffectInstance()
......
......@@ -25,26 +25,27 @@
class Effect;
#include <QtGlobal>
#include <QList>
#include "frei0r.h"
class EffectSettingValue;
class EffectInstance
{
public:
void init( quint32 width, quint32 height );
Effect* effect();
protected:
EffectInstance( Effect *effect );
~EffectInstance();
Effect *m_effect;
quint32 m_width;
quint32 m_height;
f0r_instance_t m_instance;
Effect *m_effect;
quint32 m_width;
quint32 m_height;
f0r_instance_t m_instance;
QList<EffectSettingValue*> m_params;
friend class Effect;
};
#endif // EFFECTINSTANCE_H
/*****************************************************************************
* EffectSettingValue.cpp: Handle an effect instance.
*****************************************************************************
* 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 "Effect.h"
#include "EffectSettingValue.h"
#include "EffectInstance.h"
#include <QtDebug>
EffectSettingValue::EffectSettingValue( Type type, EffectInstance* instance, quint32 index,
const QVariant &defaultValue, const char *name,
const char *desc, Flags flags ) :
SettingValue( type, defaultValue, name, desc, flags ),
m_paramBuff( NULL ),
m_buffSize( 0 ),
m_instance( instance ),
m_index( index )
{
}
f0r_param_t
EffectSettingValue::getFrei0rParameter() const
{
return reinterpret_cast<void*>( m_paramBuff );
}
void
EffectSettingValue::set( const QVariant &val )
{
SettingValue::set( val );
switch ( m_type )
{
case Double:
{
double tmp = val.toDouble();
copyToFrei0rBuff( &tmp );
break ;
}
// case String:
// case Bool:
// case Color:
// case Position:
default:
qCritical() << "Setting type" << m_type << "is not handled by the effects engine";
break;
}
m_instance->effect()->m_f0r_set_param_value( m_instance, m_paramBuff, m_index );
}
quint32
EffectSettingValue::index() const
{
return m_index;
}
SettingValue::Type
EffectSettingValue::frei0rToVlmc( int type )
{
switch ( type )
{
case F0R_PARAM_BOOL:
return Bool;
case F0R_PARAM_DOUBLE:
return Double;
case F0R_PARAM_COLOR:
return Color;
case F0R_PARAM_POSITION:
return Position;
case F0R_PARAM_STRING:
return String;
default:
qCritical() << "Invalid effect setting type ! Undefined behaviour";
}
//Keeping compiler happy.
return Double;
}
/*****************************************************************************
* EffectSettingValue.h: Handle an effect instance.
*****************************************************************************
* 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 EFFECTSETTINGVALUE_H
#define EFFECTSETTINGVALUE_H
#include "SettingValue.h"
#include "frei0r.h"
class EffectInstance;
class EffectSettingValue : public SettingValue
{
Q_OBJECT
public:
EffectSettingValue( Type type, EffectInstance* instance, quint32 index,
const QVariant& defaultValue, const char* name,
const char* desc, Flags flags = Nothing );
f0r_param_t getFrei0rParameter() const;
virtual void set( const QVariant& val );
quint32 index() const;
static Type frei0rToVlmc( int type );
private:
template <typename T>
void copyToFrei0rBuff( const T* ptr, quint32 size = sizeof( T ) )
{
if ( m_buffSize != size || m_paramBuff == NULL )
{
delete[] m_paramBuff; //Won't hurt if paramBuff is NULL
m_paramBuff = new qint8[size];
}
memcpy( m_paramBuff, ptr, size );
}
private:
qint8 *m_paramBuff;
quint32 m_buffSize;
EffectInstance *m_instance;
quint32 m_index;
};
#endif // EFFECTSETTINGVALUE_H
......@@ -46,6 +46,9 @@ class SettingValue : public QObject
Language,
KeyboardShortcut,
Path,
//For effect engine settings:
Color,
Position
};
enum Flag
{
......@@ -72,7 +75,7 @@ class SettingValue : public QObject
* \param val the value wich will be affected to m_val
*/
void set( const QVariant& val );
virtual void set( const QVariant& val );
/**
* \brief getter for the m_val member
......@@ -95,7 +98,7 @@ class SettingValue : public QObject
const QVariant& min() const;
const QVariant& max() const;
private:
protected:
/**
* \brief the QVariant containingthe value of the settings
*/
......
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