diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/qmmp/effect.cpp | 26 | ||||
| -rw-r--r-- | src/qmmp/effect.h | 6 | ||||
| -rw-r--r-- | src/qmmp/qmmpaudioengine.cpp | 59 | ||||
| -rw-r--r-- | src/qmmp/qmmpaudioengine.h | 5 |
4 files changed, 94 insertions, 2 deletions
diff --git a/src/qmmp/effect.cpp b/src/qmmp/effect.cpp index 66b6bdf69..eda224d84 100644 --- a/src/qmmp/effect.cpp +++ b/src/qmmp/effect.cpp @@ -21,7 +21,7 @@ #include <QStringList> #include <QDir> #include <QApplication> - +#include "qmmpaudioengine.h" #include "qmmp.h" #include "effectfactory.h" #include "effect.h" @@ -31,6 +31,7 @@ Effect::Effect() m_freq = 0; m_chan = 0; m_res = 0; + m_factory = 0; } Effect::~Effect() @@ -58,6 +59,16 @@ int Effect::bitsPerSample() return m_res; } +const AudioParameters Effect::audioParameters() const +{ + return AudioParameters(m_freq, m_chan, m_res); +} + +EffectFactory* Effect::factory() const +{ + return m_factory; +} + //static members QList<EffectFactory*> *Effect::m_factories = 0; @@ -103,7 +114,10 @@ QList<Effect*> Effect::create() foreach (factory, *m_factories) { if(isEnabled(factory)) + { effects.append(factory->create()); + effects.last()->m_factory = factory; + } } return effects; } @@ -133,10 +147,18 @@ void Effect::setEnabled(EffectFactory* factory, bool enable) if(enable) { if (!effList.contains(name)) + { effList << name; + if(QmmpAudioEngine::instance()) + QmmpAudioEngine::instance()->addEffect(factory); + } } - else + else if (effList.contains(name)) + { effList.removeAll(name); + if(QmmpAudioEngine::instance()) + QmmpAudioEngine::instance()->removeEffect(factory); + } settings.setValue("Effect/enabled_plugins", effList); } diff --git a/src/qmmp/effect.h b/src/qmmp/effect.h index 511ef8f18..325db8e25 100644 --- a/src/qmmp/effect.h +++ b/src/qmmp/effect.h @@ -22,6 +22,7 @@ #include <QList> #include <QStringList> +#include "audioparameters.h" class EffectFactory; @@ -66,6 +67,10 @@ public: * Returns bits per sample. */ int bitsPerSample(); + + const AudioParameters audioParameters() const; + EffectFactory* factory() const; + /*! * Creates a list of enabled effects. */ @@ -91,6 +96,7 @@ public: static bool isEnabled(EffectFactory* factory); private: + EffectFactory *m_factory; quint32 m_freq; int m_chan; int m_res; diff --git a/src/qmmp/qmmpaudioengine.cpp b/src/qmmp/qmmpaudioengine.cpp index 08573da4d..23a0233e3 100644 --- a/src/qmmp/qmmpaudioengine.cpp +++ b/src/qmmp/qmmpaudioengine.cpp @@ -27,6 +27,7 @@ #include "decoder.h" #include "output.h" #include "decoderfactory.h" +#include "effectfactory.h" #include "inputsource.h" #include "qmmpaudioengine.h" #include "metadatamanager.h" @@ -51,6 +52,7 @@ QmmpAudioEngine::QmmpAudioEngine(QObject *parent) m_decoder = 0; m_output = 0; reset(); + m_instance = this; } QmmpAudioEngine::~QmmpAudioEngine() @@ -61,6 +63,7 @@ QmmpAudioEngine::~QmmpAudioEngine() delete [] m_output_buf; m_output_buf = 0; qDeleteAll(m_effects); + m_instance = 0; } void QmmpAudioEngine::reset() @@ -160,6 +163,54 @@ void QmmpAudioEngine::setEQEnabled(bool on) mutex()->unlock(); } +void QmmpAudioEngine::addEffect(EffectFactory *factory) +{ + if(m_output && m_output->isRunning()) + { + Effect *effect = factory->create(); + effect->configure(m_ap.sampleRate(), m_ap.channels(), m_ap.bits()); + if(effect->audioParameters() == m_ap) + { + mutex()->lock(); + m_effects << effect; + mutex()->unlock(); + } + else + { + qDebug("QmmpAudioEngine: restart required"); + delete effect; + } + } +} + +void QmmpAudioEngine::removeEffect(EffectFactory *factory) +{ + Effect *effect = 0; + foreach(effect, m_effects) + { + if(effect->factory() == factory) + break; + } + if(!effect) + return; + int index = m_effects.indexOf(effect); + if(m_output && m_output->isRunning()) + { + if(index == 0 && m_decoder->audioParameters() == effect->audioParameters()) + { + mutex()->lock(); + m_effects.removeAll(effect); + mutex()->unlock(); + } + else if(m_effects.at(index - 1)->audioParameters() == effect->audioParameters()) + { + mutex()->lock(); + m_effects.removeAll(effect); + mutex()->unlock(); + } + } +} + void QmmpAudioEngine::seek(qint64 time) { if (m_output && m_output->isRunning()) @@ -542,3 +593,11 @@ Output *QmmpAudioEngine::createOutput(Decoder *d) output->configure(srate, chan, bps); return output; } + +//static members +QmmpAudioEngine *QmmpAudioEngine::m_instance = 0; + +QmmpAudioEngine *QmmpAudioEngine::instance() +{ + return m_instance; +} diff --git a/src/qmmp/qmmpaudioengine.h b/src/qmmp/qmmpaudioengine.h index e83bda490..3d0e12e0d 100644 --- a/src/qmmp/qmmpaudioengine.h +++ b/src/qmmp/qmmpaudioengine.h @@ -33,6 +33,7 @@ class DecoderFactory; class StateHandler; class Decoder; class InputSource; +class EffectFactory; class QmmpAudioEngine : public AbstractEngine @@ -50,6 +51,9 @@ public: void pause(); void setEQ(double bands[10], double preamp); void setEQEnabled(bool on); + void addEffect(EffectFactory *factory); + void removeEffect(EffectFactory *factory); + static QmmpAudioEngine *instance(); private slots: void finish(); @@ -80,6 +84,7 @@ private: QHash <Decoder*, InputSource*> m_inputs; AudioParameters m_ap; bool m_next; + static QmmpAudioEngine *m_instance; }; |
