From 99acb8f8e53767e59a5634609b0d3582ae5b0d7c Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Mon, 11 Jan 2010 16:05:17 +0000 Subject: Refactored AbstractAudioEffect to reduce redundancy in derived classes Task-number: QTBUG-4659 Reviewed-by: Espen Riskedal --- src/3rdparty/phonon/mmf/abstractaudioeffect.cpp | 21 +++++++++++++-- src/3rdparty/phonon/mmf/abstractaudioeffect.h | 6 ++--- src/3rdparty/phonon/mmf/audioequalizer.cpp | 35 +++++++------------------ src/3rdparty/phonon/mmf/audioequalizer.h | 5 ++-- src/3rdparty/phonon/mmf/bassboost.cpp | 7 +---- src/3rdparty/phonon/mmf/bassboost.h | 4 +-- 6 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/3rdparty/phonon/mmf/abstractaudioeffect.cpp b/src/3rdparty/phonon/mmf/abstractaudioeffect.cpp index cdddf02..3bce86b 100644 --- a/src/3rdparty/phonon/mmf/abstractaudioeffect.cpp +++ b/src/3rdparty/phonon/mmf/abstractaudioeffect.cpp @@ -70,7 +70,8 @@ void AbstractAudioEffect::setParameterValue(const Phonon::EffectParameter ¶m m_values.insert(param.id(), newValue); if (m_effect.data()) { - parameterChanged(param.id(), newValue); + const EffectParameter& internalParam = internalParameter(param.id()); + parameterChanged(internalParam, newValue); // TODO: handle audio effect errors TRAP_IGNORE(m_effect->ApplyL()); } @@ -122,11 +123,27 @@ void AbstractAudioEffect::createEffect() } if (m_effect.data()) { - applyParameters(); + EffectParameter param; + foreach (param, m_params) { + const QVariant value = parameterValue(param); + parameterChanged(param, value); + } + // TODO: handle audio effect errors TRAP_IGNORE(m_effect->EnableL()); } } +const MMF::EffectParameter& AbstractAudioEffect::internalParameter(int id) const +{ + const EffectParameter *result = 0; + for (int i=0; i m_effect; - const QList m_params; private: + const QList m_params; AbstractMediaPlayer * m_player; QHash m_values; }; diff --git a/src/3rdparty/phonon/mmf/audioequalizer.cpp b/src/3rdparty/phonon/mmf/audioequalizer.cpp index e3b1ab3..1584cf7 100644 --- a/src/3rdparty/phonon/mmf/audioequalizer.cpp +++ b/src/3rdparty/phonon/mmf/audioequalizer.cpp @@ -37,35 +37,18 @@ AudioEqualizer::AudioEqualizer(QObject *parent, const QList& pa } -void AudioEqualizer::parameterChanged(const int pid, +void AudioEqualizer::parameterChanged(const EffectParameter ¶m, const QVariant &value) { - const int band = pid; - const qreal level = value.toReal(); - setBandLevel(band, level); -} - -void AudioEqualizer::applyParameters() -{ - if (m_effect.data()) { - Phonon::EffectParameter param; - foreach (param, parameters()) { - const int band = param.id(); - const qreal level = parameterValue(param).toReal(); - setBandLevel(band, level); - } - } -} - -void AudioEqualizer::setBandLevel(int band, qreal externalLevel) -{ - const EffectParameter ¶m = m_params[band-1]; // Band IDs are 1-based + const int band = param.id() + 1; + const qreal externalLevel = value.toReal(); const int internalLevel = param.toInternalValue(externalLevel); // TODO: handle audio effect errors TRAP_IGNORE(concreteEffect()->SetBandLevelL(band, internalLevel)); } + //----------------------------------------------------------------------------- // Static functions //----------------------------------------------------------------------------- @@ -92,10 +75,12 @@ bool AudioEqualizer::getParameters(CMdaAudioOutputStream *stream, const int bandCount = effect->NumberOfBands(); - // For some reason, band IDs are 1-based, as opposed to the - // 0-based indices used in just about other Symbian API...! - for (int i = 1; i <= bandCount; ++i) { - const qint32 hz = effect->CenterFrequency(i); + 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; + + const qint32 hz = effect->CenterFrequency(band); // We pass a floating-point parameter range of -1.0 to +1.0 for // each band in order to work around a limitation in diff --git a/src/3rdparty/phonon/mmf/audioequalizer.h b/src/3rdparty/phonon/mmf/audioequalizer.h index 9eda994..3a9a5ca 100644 --- a/src/3rdparty/phonon/mmf/audioequalizer.h +++ b/src/3rdparty/phonon/mmf/audioequalizer.h @@ -51,11 +51,10 @@ public: protected: // AbstractAudioEffect virtual void createEffect(AudioPlayer::NativePlayer *player); - virtual void applyParameters(); - virtual void parameterChanged(const int id, const QVariant &value); + virtual void parameterChanged(const EffectParameter ¶m, + const QVariant &value); private: - void setBandLevel(int band, qreal externalLevel); CAudioEqualizer *concreteEffect(); }; diff --git a/src/3rdparty/phonon/mmf/bassboost.cpp b/src/3rdparty/phonon/mmf/bassboost.cpp index c8c4831..997bae4 100644 --- a/src/3rdparty/phonon/mmf/bassboost.cpp +++ b/src/3rdparty/phonon/mmf/bassboost.cpp @@ -37,17 +37,12 @@ BassBoost::BassBoost(QObject *parent, const QList ¶meters) } -void BassBoost::parameterChanged(const int, +void BassBoost::parameterChanged(const EffectParameter &, const QVariant &) { Q_ASSERT_X(false, Q_FUNC_INFO, "BassBoost has no parameters"); } -void BassBoost::applyParameters() -{ - // No parameters to apply -} - //----------------------------------------------------------------------------- // Static functions //----------------------------------------------------------------------------- diff --git a/src/3rdparty/phonon/mmf/bassboost.h b/src/3rdparty/phonon/mmf/bassboost.h index d3cda34..b2bc854 100644 --- a/src/3rdparty/phonon/mmf/bassboost.h +++ b/src/3rdparty/phonon/mmf/bassboost.h @@ -49,8 +49,8 @@ public: protected: // AbstractAudioEffect virtual void createEffect(AudioPlayer::NativePlayer *player); - virtual void applyParameters(); - virtual void parameterChanged(const int id, const QVariant &value); + virtual void parameterChanged(const EffectParameter ¶m, + const QVariant &value); private: CBassBoost *concreteEffect(); -- cgit v0.12