[vlmc-devel] commit: EffectSettings: Handle default value for frei0r settings. ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Sun Aug 22 22:54:19 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Sun Aug 22 00:16:32 2010 +0200| [dfd68c249e335cbf48db20e20024f6c291638006] | committer: Hugo Beauzée-Luyssen 

EffectSettings: Handle default value for frei0r settings.

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=dfd68c249e335cbf48db20e20024f6c291638006
---

 src/EffectsEngine/EffectInstance.cpp     |   11 ++++-
 src/EffectsEngine/EffectInstance.h       |    1 +
 src/EffectsEngine/EffectSettingValue.cpp |   69 +++++++++++++++++++++++++++---
 src/EffectsEngine/EffectSettingValue.h   |    4 +-
 src/Settings/SettingValue.cpp            |    2 +-
 src/Settings/SettingValue.h              |    2 +-
 6 files changed, 76 insertions(+), 13 deletions(-)

diff --git a/src/EffectsEngine/EffectInstance.cpp b/src/EffectsEngine/EffectInstance.cpp
index 630ebe5..e77f2c1 100644
--- a/src/EffectsEngine/EffectInstance.cpp
+++ b/src/EffectsEngine/EffectInstance.cpp
@@ -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()
 {
diff --git a/src/EffectsEngine/EffectInstance.h b/src/EffectsEngine/EffectInstance.h
index 7557232..d4ea152 100644
--- a/src/EffectsEngine/EffectInstance.h
+++ b/src/EffectsEngine/EffectInstance.h
@@ -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();
diff --git a/src/EffectsEngine/EffectSettingValue.cpp b/src/EffectsEngine/EffectSettingValue.cpp
index d70b530..d8fe9ab 100644
--- a/src/EffectsEngine/EffectSettingValue.cpp
+++ b/src/EffectsEngine/EffectSettingValue.cpp
@@ -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
 {
diff --git a/src/EffectsEngine/EffectSettingValue.h b/src/EffectsEngine/EffectSettingValue.h
index d570a1a..d4d8a3c 100644
--- a/src/EffectsEngine/EffectSettingValue.h
+++ b/src/EffectsEngine/EffectSettingValue.h
@@ -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
diff --git a/src/Settings/SettingValue.cpp b/src/Settings/SettingValue.cpp
index 9568b6e..c9a53e9 100644
--- a/src/Settings/SettingValue.cpp
+++ b/src/Settings/SettingValue.cpp
@@ -55,7 +55,7 @@ SettingValue::set( const QVariant& _val )
 }
 
 const QVariant&
-SettingValue::get() const
+SettingValue::get()
 {
     return m_val;
 }
diff --git a/src/Settings/SettingValue.h b/src/Settings/SettingValue.h
index 84f9f06..dd299fb 100644
--- a/src/Settings/SettingValue.h
+++ b/src/Settings/SettingValue.h
@@ -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
          */



More information about the Vlmc-devel mailing list