src/3rdparty/phonon/mmf/audioequalizer.cpp
branchRCL_3
changeset 4 3b1da2848fc7
parent 0 1918ee327afb
child 33 3e2da88830cd
--- a/src/3rdparty/phonon/mmf/audioequalizer.cpp	Tue Feb 02 00:43:10 2010 +0200
+++ b/src/3rdparty/phonon/mmf/audioequalizer.cpp	Fri Feb 19 23:40:16 2010 +0200
@@ -16,6 +16,7 @@
 
 */
 
+#include <AudioEqualizerBase.h>
 #include "audioequalizer.h"
 
 QT_BEGIN_NAMESPACE
@@ -27,61 +28,79 @@
   \internal
 */
 
-AudioEqualizer::AudioEqualizer(QObject *parent) : AbstractAudioEffect::AbstractAudioEffect(parent, createParams())
+// Define functions which depend on concrete native effect class name
+PHONON_MMF_DEFINE_EFFECT_FUNCTIONS(AudioEqualizer)
+
+AudioEqualizer::AudioEqualizer(QObject *parent, const QList<EffectParameter>& parameters)
+    :   AbstractAudioEffect::AbstractAudioEffect(parent, parameters)
 {
+
 }
 
-void AudioEqualizer::parameterChanged(const int pid,
+int AudioEqualizer::effectParameterChanged(const EffectParameter &param,
                                       const QVariant &value)
 {
-    // There is no way to return an error from this function, so we just
-    // have to trap and ignore exceptions.
-    TRAP_IGNORE(static_cast<CAudioEqualizer *>(m_effect.data())->SetBandLevelL(pid, value.toInt()));
+    const int band = param.id() - ParameterBase + 1;
+
+    const qreal externalLevel = value.toReal();
+    const int internalLevel = param.toInternalValue(externalLevel);
+
+    TRAPD(err, concreteEffect()->SetBandLevelL(band, internalLevel));
+    return err;
 }
 
-bool AudioEqualizer::activateOn(CPlayerType *player)
+
+//-----------------------------------------------------------------------------
+// Static functions
+//-----------------------------------------------------------------------------
+
+const char* AudioEqualizer::description()
 {
-    CAudioEqualizer *ptr = 0;
-    QT_TRAP_THROWING(ptr = CAudioEqualizer::NewL(*player));
-    m_effect.reset(ptr);
-
-    return true;
+    return "Audio equalizer";
 }
 
-QList<EffectParameter> AudioEqualizer::createParams()
+bool AudioEqualizer::getParameters(CMdaAudioOutputStream *stream,
+    QList<EffectParameter>& parameters)
 {
-    QList<EffectParameter> retval;
+    bool supported = false;
 
-    // We temporarily create an AudioPlayer, and run the effect on it, so
-    // we can extract the readonly data we need.
-    AudioPlayer dummyPlayer;
+    QScopedPointer<CAudioEqualizer> effect;
+    TRAPD(err, effect.reset(CAudioEqualizer::NewL(*stream)));
 
-    CAudioEqualizer *eqPtr = 0;
-    QT_TRAP_THROWING(eqPtr = CAudioEqualizer::NewL(*dummyPlayer.player());)
-    QScopedPointer<CAudioEqualizer> e(eqPtr);
+    if (KErrNone == err) {
+        supported = true;
 
-    TInt32 dbMin;
-    TInt32 dbMax;
-    e->DbLevelLimits(dbMin, dbMax);
+        TInt32 dbMin;
+        TInt32 dbMax;
+        effect->DbLevelLimits(dbMin, dbMax);
+
+        const int bandCount = effect->NumberOfBands();
 
-    const int bandCount = e->NumberOfBands();
+        for (int i = 0; i < bandCount; ++i) {
+            // For some reason, band IDs are 1-based, as opposed to the
+            // 0-based indices used in just about other Symbian API...!
+            const int band = i + 1;
 
-    for (int i = 0; i < bandCount; ++i) {
-        const qint32 hz = e->CenterFrequency(i);
-
-        const qint32 defVol = e->BandLevel(i);
+            const qint32 hz = effect->CenterFrequency(band);
 
-        retval.append(EffectParameter(i,
-                                      tr("Frequency band, %1 Hz").arg(hz),
-                                      EffectParameter::LogarithmicHint,
-                                      QVariant(qint32(defVol)),
-                                      QVariant(qint32(dbMin)),
-                                      QVariant(qint32(dbMax)),
-                                      QVariantList(),
-                                      QString()));
+            // We pass a floating-point parameter range of -1.0 to +1.0 for
+            // each band in order to work around a limitation in
+            // Phonon::EffectWidget.  See documentation of EffectParameter
+            // for more details.
+            EffectParameter param(
+                 /* parameterId */        ParameterBase + i,
+                 /* name */               tr("%1 Hz").arg(hz),
+                 /* hints */              EffectParameter::LogarithmicHint,
+                 /* defaultValue */       QVariant(qreal(0.0)),
+                 /* minimumValue */       QVariant(qreal(-1.0)),
+                 /* maximumValue */       QVariant(qreal(+1.0)));
+
+            param.setInternalRange(dbMin, dbMax);
+            parameters.append(param);
+        }
     }
 
-    return retval;
+    return supported;
 }
 
 QT_END_NAMESPACE