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

EffectSettings: Handle default value for frei0r settings.

parent ec2666b7
......@@ -33,6 +33,8 @@ EffectInstance::EffectInstance( Effect *effect ) :
m_height( 0 ),
m_instance( NULL )
{
init( 1, 1 );
Effect::ParamList::const_iterator it = effect->params().constBegin();
Effect::ParamList::const_iterator ite = effect->params().constEnd();
quint32 i = 0;
......@@ -59,8 +61,7 @@ EffectInstance::settingValueFactory( f0r_param_info_t *info, quint32 index )
if ( info->type == F0R_PARAM_DOUBLE )
flags = SettingValue::Clamped;
EffectSettingValue *val = new EffectSettingValue( EffectSettingValue::frei0rToVlmc( info->type ),
this, index, QVariant(),
info->name, info->explanation );
this, index, info->name, info->explanation );
if ( info->type == F0R_PARAM_DOUBLE )
val->setLimits( 0.0, 1.0 );
return val;
......@@ -81,6 +82,12 @@ EffectInstance::init( quint32 width, quint32 height )
}
}
bool
EffectInstance::isInit() const
{
return m_instance != NULL;
}
Effect*
EffectInstance::effect()
{
......
......@@ -34,6 +34,7 @@ class EffectInstance
public:
typedef QHash<QString, EffectSettingValue*> ParamList;
void init( quint32 width, quint32 height );
bool isInit() const;
Effect* effect();
const ParamList &params() const;
ParamList &params();
......
......@@ -29,14 +29,15 @@
#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 ),
const char *name, const char *desc, Flags flags ) :
SettingValue( type, QVariant(), name, desc, flags ),
m_paramBuff( NULL ),
m_buffSize( 0 ),
m_effectInstance( instance ),
m_index( index )
{
//Fetch the default value.
m_defaultVal = get();
}
EffectSettingValue::~EffectSettingValue()
......@@ -62,30 +63,32 @@ EffectSettingValue::set( const QVariant &val )
copyToFrei0rBuff( &tmp );
break ;
}
case String:
case String:
{
QByteArray bytes = val.toString().toUtf8();
const char* tmp = bytes;
copyToFrei0rBuff( tmp, bytes.length() );
break ;
}
case Bool:
case Bool:
{
bool tmp = val.toBool();
copyToFrei0rBuff( &tmp );
break ;
}
case Color:
case Color:
{
QColor color = val.value<QColor>();
float rgb[3] = { color.redF(), color.greenF(), color.blueF() };
copyToFrei0rBuff( rgb, 3 * sizeof(float) );
break ;
}
case Position:
case Position:
{
QPointF pos = val.value<QPointF>();
double posD[2] = { pos.x(), pos.y() };
copyToFrei0rBuff( posD, 2 * sizeof(double) );
break ;
}
default:
qCritical() << "Setting type" << m_type << "is not handled by the effects engine";
......@@ -102,6 +105,58 @@ EffectSettingValue::apply()
m_paramBuff, m_index );
}
const QVariant&
EffectSettingValue::get()
{
switch ( m_type )
{
case Double:
{
double tmp;
m_effectInstance->effect()->m_f0r_get_param_value( m_effectInstance->m_instance,
&tmp, m_index );
m_val = tmp;
break ;
}
case String:
{
char *tmp;
m_effectInstance->effect()->m_f0r_get_param_value( m_effectInstance->m_instance,
&tmp, m_index );
m_val = QString::fromUtf8( tmp );
break ;
}
case Bool:
{
bool tmp;
m_effectInstance->effect()->m_f0r_get_param_value( m_effectInstance->m_instance,
&tmp, m_index );
m_val = tmp;
break ;
}
case Color:
{
f0r_param_color_t tmp;
m_effectInstance->effect()->m_f0r_get_param_value( m_effectInstance->m_instance,
&tmp, m_index );
m_val = QColor( tmp.r, tmp.g, tmp.b );
break ;
}
case Position:
{
f0r_param_position_t tmp;
m_effectInstance->effect()->m_f0r_get_param_value( m_effectInstance->m_instance,
&tmp, m_index );
m_val = QPointF( tmp.x, tmp.y );
break ;
}
default:
qCritical() << "Setting type" << m_type << "is not handled by the effects engine";
m_val = QVariant();
}
return m_val;
}
quint32
EffectSettingValue::index() const
{
......
......@@ -34,12 +34,12 @@ class EffectSettingValue : public SettingValue
public:
EffectSettingValue( Type type, EffectInstance* instance, quint32 index,
const QVariant& defaultValue, const char* name,
const char* desc, Flags flags = Nothing );
const char* name, const char* desc, Flags flags = Nothing );
virtual ~EffectSettingValue();
f0r_param_t getFrei0rParameter() const;
virtual void set( const QVariant& val );
const QVariant &get();
quint32 index() const;
/**
* \brief Force the parameter to apply, even if no change is detected
......
......@@ -55,7 +55,7 @@ SettingValue::set( const QVariant& _val )
}
const QVariant&
SettingValue::get() const
SettingValue::get()
{
return m_val;
}
......
......@@ -80,7 +80,7 @@ class SettingValue : public QObject
/**
* \brief getter for the m_val member
*/
const QVariant& get() const;
virtual const QVariant& get(); //Not const to avoid a mess with EffectSettingValue.
/**
* \return The setting's description
*/
......
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