| 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 | #ifndef PHONON_MMF_ABSTRACTEFFECT_H
 | 
|---|
| 20 | #define PHONON_MMF_ABSTRACTEFFECT_H
 | 
|---|
| 21 | 
 | 
|---|
| 22 | #include <QScopedPointer>
 | 
|---|
| 23 | 
 | 
|---|
| 24 | #include <AudioEffectBase.h>
 | 
|---|
| 25 | 
 | 
|---|
| 26 | #include <phonon/effectinterface.h>
 | 
|---|
| 27 | 
 | 
|---|
| 28 | #include "audioplayer.h"
 | 
|---|
| 29 | #include "effectparameter.h"
 | 
|---|
| 30 | #include "mmf_medianode.h"
 | 
|---|
| 31 | 
 | 
|---|
| 32 | class CMdaAudioOutputStream;
 | 
|---|
| 33 | 
 | 
|---|
| 34 | QT_BEGIN_NAMESPACE
 | 
|---|
| 35 | 
 | 
|---|
| 36 | namespace Phonon
 | 
|---|
| 37 | {
 | 
|---|
| 38 | namespace MMF
 | 
|---|
| 39 | {
 | 
|---|
| 40 | class AbstractPlayer;
 | 
|---|
| 41 | class AbstractMediaPlayer;
 | 
|---|
| 42 | 
 | 
|---|
| 43 | /**
 | 
|---|
| 44 |  * @short Base class for all effects for MMF.
 | 
|---|
| 45 |  *
 | 
|---|
| 46 |  * Adhering to Phonon with MMF is cumbersome because of a number of reasons:
 | 
|---|
| 47 |  *
 | 
|---|
| 48 |  * - MMF has no concept of effect chaining. Simply, an effect is a applied
 | 
|---|
| 49 |  *   to PlayerUtility, that's it. This means that the order of effects is
 | 
|---|
| 50 |  *   undefined.
 | 
|---|
| 51 |  * - We apply an effect to a PlayerUtility, and MediaObject has that one.
 | 
|---|
| 52 |  *   However, effects might be created before MediaObject, but nevertheless
 | 
|---|
| 53 |  *   needs to work. We solve this by that we are aware of the whole connection
 | 
|---|
| 54 |  *   chain, and whenever a connection happens, we walk the chain, find effects
 | 
|---|
| 55 |  *   that aren't applied, and apply it if we have a media object.
 | 
|---|
| 56 |  * - There are plenty of corner cases which we don't handle and where behavior
 | 
|---|
| 57 |  *   are undefined. For instance, graphs with more than one MediaObject.
 | 
|---|
| 58 |  */
 | 
|---|
| 59 | class AbstractAudioEffect : public MediaNode
 | 
|---|
| 60 |                           , public EffectInterface
 | 
|---|
| 61 | {
 | 
|---|
| 62 |     Q_OBJECT
 | 
|---|
| 63 |     Q_INTERFACES(Phonon::EffectInterface)
 | 
|---|
| 64 | public:
 | 
|---|
| 65 |     AbstractAudioEffect(QObject *parent,
 | 
|---|
| 66 |                         const QList<EffectParameter> ¶ms);
 | 
|---|
| 67 | 
 | 
|---|
| 68 |     // Phonon::EffectInterface
 | 
|---|
| 69 |     virtual QList<Phonon::EffectParameter> parameters() const;
 | 
|---|
| 70 |     virtual QVariant parameterValue(const Phonon::EffectParameter ¶m) const;
 | 
|---|
| 71 |     virtual void setParameterValue(const Phonon::EffectParameter &,
 | 
|---|
| 72 |                                    const QVariant &newValue);
 | 
|---|
| 73 | 
 | 
|---|
| 74 |     // Parameters which are shared by all effects
 | 
|---|
| 75 |     enum CommonParameters
 | 
|---|
| 76 |     {
 | 
|---|
| 77 |         ParameterEnable = 0,
 | 
|---|
| 78 |         ParameterBase // must be last entry in enum
 | 
|---|
| 79 |     };
 | 
|---|
| 80 | 
 | 
|---|
| 81 | public Q_SLOTS:
 | 
|---|
| 82 |     void abstractPlayerChanged(AbstractPlayer *player);
 | 
|---|
| 83 |     void stateChanged(Phonon::State newState,
 | 
|---|
| 84 |                       Phonon::State oldState);
 | 
|---|
| 85 | 
 | 
|---|
| 86 | protected:
 | 
|---|
| 87 |     // MediaNode
 | 
|---|
| 88 |     void connectMediaObject(MediaObject *mediaObject);
 | 
|---|
| 89 |     void disconnectMediaObject(MediaObject *mediaObject);
 | 
|---|
| 90 | 
 | 
|---|
| 91 |     virtual void createEffect(AudioPlayer::NativePlayer *player) = 0;
 | 
|---|
| 92 | 
 | 
|---|
| 93 |     // Effect-specific parameter changed
 | 
|---|
| 94 |     virtual int effectParameterChanged(const EffectParameter ¶m,
 | 
|---|
| 95 |                                   const QVariant &value);
 | 
|---|
| 96 | 
 | 
|---|
| 97 | private:
 | 
|---|
| 98 |     void createEffect();
 | 
|---|
| 99 |     void setEnabled(bool enabled);
 | 
|---|
| 100 |     const EffectParameter& internalParameter(int id) const;
 | 
|---|
| 101 |     int parameterChanged(const EffectParameter ¶m,
 | 
|---|
| 102 |             const QVariant &value);
 | 
|---|
| 103 | 
 | 
|---|
| 104 | protected:
 | 
|---|
| 105 |     QScopedPointer<CAudioEffect>    m_effect;
 | 
|---|
| 106 | 
 | 
|---|
| 107 | private:
 | 
|---|
| 108 |     const QList<EffectParameter>    m_params;
 | 
|---|
| 109 |     AbstractMediaPlayer *           m_player;
 | 
|---|
| 110 |     QHash<int, QVariant>            m_values;
 | 
|---|
| 111 | };
 | 
|---|
| 112 | 
 | 
|---|
| 113 | }
 | 
|---|
| 114 | }
 | 
|---|
| 115 | 
 | 
|---|
| 116 | 
 | 
|---|
| 117 | // Macro for defining functions which depend on the native class name
 | 
|---|
| 118 | // for each of the effects.  Using this reduces repetition of boilerplate
 | 
|---|
| 119 | // in the implementations of the backend effect nodes.
 | 
|---|
| 120 | 
 | 
|---|
| 121 | #ifdef Q_CC_NOKIAX86
 | 
|---|
| 122 | #   pragma warn_illtokenpasting off
 | 
|---|
| 123 | #endif
 | 
|---|
| 124 | 
 | 
|---|
| 125 | #define PHONON_MMF_DEFINE_EFFECT_FUNCTIONS(Effect)                      \
 | 
|---|
| 126 |                                                                         \
 | 
|---|
| 127 | void Effect##::createEffect(AudioPlayer::NativePlayer *player)          \
 | 
|---|
| 128 | {                                                                       \
 | 
|---|
| 129 |     C##Effect *ptr = 0;                                                 \
 | 
|---|
| 130 |     QT_TRAP_THROWING(ptr = C##Effect::NewL(*player));                   \
 | 
|---|
| 131 |     m_effect.reset(ptr);                                                \
 | 
|---|
| 132 | }                                                                       \
 | 
|---|
| 133 |                                                                         \
 | 
|---|
| 134 | C##Effect* Effect::concreteEffect()                                     \
 | 
|---|
| 135 | {                                                                       \
 | 
|---|
| 136 |     return static_cast<C##Effect *>(m_effect.data());                   \
 | 
|---|
| 137 | }
 | 
|---|
| 138 | 
 | 
|---|
| 139 | QT_END_NAMESPACE
 | 
|---|
| 140 | 
 | 
|---|
| 141 | #endif
 | 
|---|
| 142 | 
 | 
|---|