1
/*  This file is part of the KDE project.
2
3
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
5
This library is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 2.1 or 3 of the License.
8
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
GNU Lesser General Public License for more details.
13
14
You should have received a copy of the GNU Lesser General Public License
15
along with this library.  If not, see <http://www.gnu.org/licenses/>.
16
17
*/
18
19
#include "effectparameter.h"
20
21
QT_BEGIN_NAMESPACE
22
23
using namespace Phonon;
24
using namespace Phonon::MMF;
25
26
/*! \class MMF::EffectParameter
27
  \internal
28
*/
29
30
MMF::EffectParameter::EffectParameter()
31
    :   m_hasInternalRange(false)
32
{
33
34
}
35
36
MMF::EffectParameter::EffectParameter(
37
            int parameterId, const QString &name, Hints hints,
38
            const QVariant &defaultValue, const QVariant &min,
39
            const QVariant &max, const QVariantList &values,
40
            const QString &description)
41
    :   Phonon::EffectParameter(parameterId, name, hints, defaultValue,
42
            min, max, values, description)
43
    ,   m_hasInternalRange(false)
44
{
45
46
}
47
48
void MMF::EffectParameter::setInternalRange(qint32 min, qint32 max)
49
{
50
    Q_ASSERT_X(max >= min, Q_FUNC_INFO, "Invalid range");
51
    m_internalRange = QPair<qint32, qint32>(min, max);
52
    m_hasInternalRange = true;
53
}
54
55
qint32 MMF::EffectParameter::toInternalValue(qreal external) const
56
{
57
    Q_ASSERT_X(m_hasInternalRange, Q_FUNC_INFO, "Does not have internal range");
58
    const qint32 range = m_internalRange.second - m_internalRange.first;
59
    return m_internalRange.first + ((1.0 + external) / 2) * range;
60
}
61
62
qreal MMF::EffectParameter::toExternalValue
63
    (qint32 value, qint32 min, qint32 max)
64
{
65
    Q_ASSERT_X(max >= min, Q_FUNC_INFO, "Invalid range");
66
    const qint32 range = max - min;
67
    return range == 0 ? 0.0 : ((2.0 * value - min) / range) - 1.0;
68
}
69
70
QT_END_NAMESPACE