EffectSettingValue.cpp 5.44 KB
Newer Older
1 2 3 4 5
/*****************************************************************************
 * EffectSettingValue.cpp: Handle an effect instance.
 *****************************************************************************
 * Copyright (C) 2008-2010 VideoLAN
 *
6
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * 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"

27 28
#include <QColor>
#include <QPoint>
29 30 31
#include <QtDebug>

EffectSettingValue::EffectSettingValue( Type type, EffectInstance* instance, quint32 index,
32 33
                                        const char *name, const char *desc, Flags flags ) :
    SettingValue( type, QVariant(), name, desc, flags ),
34 35
    m_paramBuff( NULL ),
    m_buffSize( 0 ),
36
    m_effectInstance( instance ),
37 38
    m_index( index )
{
39 40
    //Fetch the default value.
    m_defaultVal = get();
41 42
}

43 44 45 46 47
EffectSettingValue::~EffectSettingValue()
{
    delete[] m_paramBuff;
}

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
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 ;
        }
66
    case String:
67 68 69 70 71 72
        {
            QByteArray      bytes = val.toString().toUtf8();
            const char*   tmp = bytes;
            copyToFrei0rBuff( tmp, bytes.length() );
            break ;
        }
73
    case Bool:
74 75 76 77 78
        {
            bool    tmp = val.toBool();
            copyToFrei0rBuff( &tmp );
            break ;
        }
79
    case Color:
80 81
        {
            QColor  color = val.value<QColor>();
82
            qreal   rgb[3] = { color.redF(), color.greenF(), color.blueF() };
83
            copyToFrei0rBuff( rgb, 3 * sizeof(float) );
84
            break ;
85
        }
86
    case Position:
87 88
        {
            QPointF     pos = val.value<QPointF>();
89
            qreal       posD[2] = { pos.x(), pos.y() };
90
            copyToFrei0rBuff( posD, 2 * sizeof(double) );
91
            break ;
92
        }
93 94 95 96
    default:
        qCritical() << "Setting type" << m_type << "is not handled by the effects engine";
        break;
    }
97 98 99 100 101 102 103 104 105
    apply();
}

void
EffectSettingValue::apply()
{
    if ( m_paramBuff != NULL )
        m_effectInstance->effect()->m_f0r_set_param_value( m_effectInstance->m_instance,
                                                           m_paramBuff, m_index );
106 107
}

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
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 );
142
            m_val.setValue( QColor::fromRgbF( tmp.r, tmp.g, tmp.b ) );
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
            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;
}

160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
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;
}