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
#include "effect.h"
19
#include <phonon/effectparameter.h>
20
21
#include <medparam.h>
22
#include <dmo.h>
23
#include <dmodshow.h>
24
25
QT_BEGIN_NAMESPACE
26
27
#ifndef QT_NO_PHONON_EFFECT
28
29
namespace Phonon
30
{
31
    namespace DS9
32
    {
33
        Effect::Effect(CLSID effectClass, QObject *parent)
34
            : BackendNode(parent)
35
        {
36
            //creation of the filter
37
            for(int i = 0; i < FILTER_COUNT; ++i) {
38
                Filter &filter = m_filters[i];
39
                filter = Filter(CLSID_DMOWrapperFilter, IID_IBaseFilter);
40
                Q_ASSERT(filter);
41
                ComPointer<IDMOWrapperFilter> wrapper(filter, IID_IDMOWrapperFilter);
42
                Q_ASSERT(wrapper);
43
                wrapper->Init(effectClass, DMOCATEGORY_AUDIO_EFFECT);
44
            }
45
        }
46
47
        Effect::Effect(QObject *parent) : BackendNode(parent)
48
        {
49
            //at this point the QVector of Filter should be filled
50
        }
51
52
        Effect::~Effect()
53
        {
54
        }
55
56
        QList<Phonon::EffectParameter> Effect::parameters() const
57
        {
58
            QList<Phonon::EffectParameter> ret;
59
            ComPointer<IMediaParamInfo> paramInfo(m_filters[0], IID_IMediaParamInfo);
60
            if (!paramInfo) {
61
                return ret;
62
            }
63
            DWORD paramCount = 0;
64
            paramInfo->GetParamCount( &paramCount);
65
66
            for(quint32 i = 0; i < paramCount; i++) {
67
                MP_PARAMINFO info;
68
                HRESULT hr = paramInfo->GetParamInfo(i, &info);
69
                Q_ASSERT(SUCCEEDED(hr));
70
                WCHAR *name = 0;
71
                hr = paramInfo->GetParamText(i, &name);
72
                Q_ASSERT(SUCCEEDED(hr));
73
                QVariant def, min, max;
74
75
                QVariantList values;
76
77
                switch(info.mpType)
78
                {
79
                case MPT_ENUM:
80
                    {
81
                        WCHAR *current = name;
82
                        current += wcslen(current) + 1; //skip the name
83
                        current += wcslen(current) + 1; //skip the unit
84
                        for(; *current; current += wcslen(current) + 1) {
85
                            values.append( QString::fromWCharArray(current) );
86
                        }
87
                    }
88
                    //FALLTHROUGH
89
                case MPT_INT:
90
                    def = int(info.mpdNeutralValue);
91
                    min = int(info.mpdMinValue);
92
                    max = int(info.mpdMaxValue);
93
                    break;
94
                case MPT_FLOAT:
95
                    def = info.mpdNeutralValue;
96
                    min = info.mpdMinValue;
97
                    max = info.mpdMaxValue;
98
                    break;
99
                case MPT_BOOL:
100
                    def = bool(info.mpdNeutralValue);
101
                    break;
102
                case MPT_MAX:
103
                    //Reserved ms-help://MS.PSDKSVR2003R2.1033/directshow/htm/mp_typeenumeration.htm
104
                    break;
105
                }
106
107
                Phonon::EffectParameter::Hints hint = info.mopCaps == MP_CAPS_CURVE_INVSQUARE ?
108
                    Phonon::EffectParameter::LogarithmicHint : Phonon::EffectParameter::Hints(0);
109
110
                const QString n = QString::fromWCharArray(name);
111
                ret.append(Phonon::EffectParameter(i, n, hint, def, min, max, values));
112
                ::CoTaskMemFree(name); //let's free the memory
113
            }
114
            return ret;
115
        }
116
117
        QVariant Effect::parameterValue(const Phonon::EffectParameter &p) const
118
        {
119
            QVariant ret;
120
            ComPointer<IMediaParams> params(m_filters[0], IID_IMediaParams);
121
            Q_ASSERT(params);
122
            MP_DATA data;
123
            HRESULT hr = params->GetParam(p.id(), &data);
124
            if(SUCCEEDED(hr))
125
                return data;
126
            else
127
                return QVariant();
128
        }
129
130
        void Effect::setParameterValue(const Phonon::EffectParameter &p, const QVariant &v)
131
        {
132
            if (v.isNull()) {
133
                return;
134
            }
135
136
            for(int i=0; i < FILTER_COUNT ; ++i) {
137
                const Filter &filter = m_filters[i];
138
                ComPointer<IMediaParams> params(filter, IID_IMediaParams);
139
                Q_ASSERT(params);
140
141
                params->SetParam(p.id(), v.toFloat());
142
            }
143
        }
144
145
    }
146
}
147
148
#endif //QT_NO_PHONON_EFFECT
149
150
QT_END_NAMESPACE
151
152
#include "moc_effect.cpp"