From 1a7234e3a27b592565241e9044919f7842fc5f08 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Mon, 11 Jan 2010 15:50:19 +0000 Subject: Added a macro to reduce boilerplate code in Phonon MMF backend Task-number: QTBUG-4659 Reviewed-by: Espen Riskedal --- src/3rdparty/phonon/mmf/abstractaudioeffect.h | 19 +++++++++++++++++++ src/3rdparty/phonon/mmf/audioequalizer.cpp | 15 +++++---------- src/3rdparty/phonon/mmf/audioequalizer.h | 3 +++ src/3rdparty/phonon/mmf/bassboost.cpp | 10 +++------- src/3rdparty/phonon/mmf/bassboost.h | 5 +++++ 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/3rdparty/phonon/mmf/abstractaudioeffect.h b/src/3rdparty/phonon/mmf/abstractaudioeffect.h index 9e5a6eb..b34ad0d 100644 --- a/src/3rdparty/phonon/mmf/abstractaudioeffect.h +++ b/src/3rdparty/phonon/mmf/abstractaudioeffect.h @@ -103,6 +103,25 @@ private: } } + +// Macro for defining functions which depend on the native class name +// for each of the effects. Using this reduces repetition of boilerplate +// in the implementations of the backend effect nodes. + +#define PHONON_MMF_DEFINE_EFFECT_FUNCTIONS(Effect) \ + \ +void Effect##::createEffect(AudioPlayer::NativePlayer *player) \ +{ \ + C##Effect *ptr = 0; \ + QT_TRAP_THROWING(ptr = C##Effect::NewL(*player)); \ + m_effect.reset(ptr); \ +} \ + \ +C##Effect* Effect::concreteEffect() \ +{ \ + return static_cast(m_effect.data()); \ +} + QT_END_NAMESPACE #endif diff --git a/src/3rdparty/phonon/mmf/audioequalizer.cpp b/src/3rdparty/phonon/mmf/audioequalizer.cpp index a4127c4..ab95f30 100644 --- a/src/3rdparty/phonon/mmf/audioequalizer.cpp +++ b/src/3rdparty/phonon/mmf/audioequalizer.cpp @@ -28,7 +28,10 @@ using namespace Phonon::MMF; \internal */ -AudioEqualizer::AudioEqualizer(QObject *parent, const QList ¶meters) +// Define functions which depend on concrete native effect class name +PHONON_MMF_DEFINE_EFFECT_FUNCTIONS(AudioEqualizer) + +AudioEqualizer::AudioEqualizer(QObject *parent, const QList& parameters) : AbstractAudioEffect::AbstractAudioEffect(parent, parameters) { @@ -44,13 +47,6 @@ void AudioEqualizer::parameterChanged(const int pid, } } -void AudioEqualizer::createEffect(AudioPlayer::NativePlayer *player) -{ - CAudioEqualizer *ptr = 0; - QT_TRAP_THROWING(ptr = CAudioEqualizer::NewL(*player)); - m_effect.reset(ptr); -} - void AudioEqualizer::applyParameters() { if (m_effect.data()) { @@ -68,9 +64,8 @@ void AudioEqualizer::setBandLevel(int band, qreal externalLevel) const EffectParameter ¶m = m_params[band-1]; // Band IDs are 1-based const int internalLevel = param.toInternalValue(externalLevel); - CAudioEqualizer *const effect = static_cast(m_effect.data()); // TODO: handle audio effect errors - TRAP_IGNORE(effect->SetBandLevelL(band, internalLevel)); + TRAP_IGNORE(concreteEffect()->SetBandLevelL(band, internalLevel)); } //----------------------------------------------------------------------------- diff --git a/src/3rdparty/phonon/mmf/audioequalizer.h b/src/3rdparty/phonon/mmf/audioequalizer.h index 35592f4..9eda994 100644 --- a/src/3rdparty/phonon/mmf/audioequalizer.h +++ b/src/3rdparty/phonon/mmf/audioequalizer.h @@ -21,6 +21,8 @@ along with this library. If not, see . #include "abstractaudioeffect.h" +class CAudioEqualizer; + QT_BEGIN_NAMESPACE namespace Phonon @@ -54,6 +56,7 @@ protected: 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 642d782..c8c4831 100644 --- a/src/3rdparty/phonon/mmf/bassboost.cpp +++ b/src/3rdparty/phonon/mmf/bassboost.cpp @@ -24,6 +24,9 @@ QT_BEGIN_NAMESPACE using namespace Phonon; using namespace Phonon::MMF; +// Define functions which depend on concrete native effect class name +PHONON_MMF_DEFINE_EFFECT_FUNCTIONS(BassBoost) + /*! \class MMF::BassBoost \internal */ @@ -40,13 +43,6 @@ void BassBoost::parameterChanged(const int, Q_ASSERT_X(false, Q_FUNC_INFO, "BassBoost has no parameters"); } -void BassBoost::createEffect(AudioPlayer::NativePlayer *player) -{ - CBassBoost *ptr = 0; - QT_TRAP_THROWING(ptr = CBassBoost::NewL(*player)); - m_effect.reset(ptr); -} - void BassBoost::applyParameters() { // No parameters to apply diff --git a/src/3rdparty/phonon/mmf/bassboost.h b/src/3rdparty/phonon/mmf/bassboost.h index 241cda9..d3cda34 100644 --- a/src/3rdparty/phonon/mmf/bassboost.h +++ b/src/3rdparty/phonon/mmf/bassboost.h @@ -21,6 +21,8 @@ along with this library. If not, see . #include "abstractaudioeffect.h" +class CBassBoost; + QT_BEGIN_NAMESPACE namespace Phonon @@ -50,6 +52,9 @@ protected: virtual void applyParameters(); virtual void parameterChanged(const int id, const QVariant &value); +private: + CBassBoost *concreteEffect(); + }; } } -- cgit v0.12