Commit 33a5850b authored by Harald Sitter's avatar Harald Sitter
Browse files

implement vlc 2.2's equalizer

BUG: 323331
parent f627846a
......@@ -49,6 +49,10 @@ set(phonon_vlc_SRCS
utils/libvlc.cpp
)
if(${LIBVLC_VERSION} VERSION_GREATER "2.2.0" OR ${LIBVLC_VERSION} VERSION_EQUAL "2.2.0")
list(APPEND phonon_vlc_SRCS equalizereffect.cpp)
endif()
if(NOT PHONON_NO_GRAPHICSVIEW)
list(APPEND phonon_vlc_SRCS video/videographicsobject.cpp)
else()
......
......@@ -38,6 +38,7 @@
#include "devicemanager.h"
#include "effect.h"
#include "effectmanager.h"
#include "equalizereffect.h"
#include "mediaobject.h"
#include "sinknode.h"
#include "utils/debug.h"
......@@ -155,7 +156,7 @@ Backend::~Backend()
PulseSupport::shutdown();
}
QObject *Backend::createObject(BackendInterface::Class c, QObject *parent, const QList<QVariant> &/*args*/)
QObject *Backend::createObject(BackendInterface::Class c, QObject *parent, const QList<QVariant> &args)
{
if (!LibVLC::self || !libvlc)
return 0;
......@@ -183,6 +184,8 @@ QObject *Backend::createObject(BackendInterface::Class c, QObject *parent, const
case VideoGraphicsObjectClass:
return new VideoGraphicsObject(parent);
#endif
case EffectClass:
return effectManager()->createEffect(args[0].toInt(), parent);
case VideoWidgetClass:
return new VideoWidget(qobject_cast<QWidget *>(parent));
// case VolumeFaderEffectClass:
......@@ -219,7 +222,7 @@ QList<int> Backend::objectDescriptionIndexes(ObjectDescriptionType type) const
}
break;
case Phonon::EffectType: {
QList<EffectInfo *> effectList = effectManager()->effects();
QList<EffectInfo> effectList = effectManager()->effects();
for (int eff = 0; eff < effectList.size(); ++eff) {
list.append(eff);
}
......@@ -253,12 +256,12 @@ QHash<QByteArray, QVariant> Backend::objectDescriptionProperties(ObjectDescripti
}
break;
case Phonon::EffectType: {
QList<EffectInfo *> effectList = effectManager()->effects();
const QList<EffectInfo> effectList = effectManager()->effects();
if (index >= 0 && index <= effectList.size()) {
const EffectInfo *effect = effectList[ index ];
ret.insert("name", effect->name());
ret.insert("description", effect->description());
ret.insert("author", effect->author());
const EffectInfo &effect = effectList.at(index);
ret.insert("name", effect.name());
ret.insert("description", effect.description());
ret.insert("author", effect.author());
} else {
Q_ASSERT(1); // Since we use list position as ID, this should not happen
}
......
......@@ -33,17 +33,17 @@ Effect::Effect(EffectManager *p_em, int i_effectId, QObject *p_parent)
: QObject(p_parent)
, SinkNode()
{
p_effectManager = p_em;
const QList<EffectInfo *> effects = p_effectManager->effects();
if (i_effectId >= 0 && i_effectId < effects.size()) {
i_effect_filter = effects[ i_effectId ]->filter();
effect_type = effects[ i_effectId ]->type();
setupEffectParams();
} else {
// effect ID out of range
Q_ASSERT(0);
}
// p_effectManager = p_em;
// const QList<EffectInfo> effects = p_effectManager->effects();
// if (i_effectId >= 0 && i_effectId < effects.size()) {
// i_effect_filter = effects[ i_effectId ]->filter();
// effect_type = effects[ i_effectId ]->type();
// setupEffectParams();
// } else {
// // effect ID out of range
// Q_ASSERT(0);
// }
}
Effect::~Effect()
......
......@@ -21,9 +21,13 @@
#include "effectmanager.h"
#include <vlc/libvlc.h>
#include <vlc/vlc.h>
#include <vlc/libvlc_version.h>
#if (LIBVLC_VERSION_INT >= LIBVLC_VERSION(2, 2, 0, 0))
#include "equalizereffect.h"
#endif
#include "utils/debug.h"
#include "utils/libvlc.h"
......@@ -50,9 +54,7 @@ EffectManager::EffectManager(QObject *parent)
EffectManager::~EffectManager()
{
qDeleteAll(m_audioEffectList);
m_audioEffectList.clear();
qDeleteAll(m_videoEffectList);
m_videoEffectList.clear();
// EffectsList holds the same pointers as audio and video, so qDeleteAll on
......@@ -60,21 +62,28 @@ EffectManager::~EffectManager()
m_effectList.clear();
}
const QList<EffectInfo *> EffectManager::audioEffects() const
const QList<EffectInfo> EffectManager::audioEffects() const
{
return m_audioEffectList;
}
const QList<EffectInfo *> EffectManager::videoEffects() const
const QList<EffectInfo> EffectManager::videoEffects() const
{
return m_videoEffectList;
}
const QList<EffectInfo *> EffectManager::effects() const
const QList<EffectInfo> EffectManager::effects() const
{
return m_effectList;
}
QObject *EffectManager::createEffect(int id, QObject *parent)
{
#if (LIBVLC_VERSION_INT >= LIBVLC_VERSION(2, 2, 0, 0))
return new EqualizerEffect(parent);
#endif
}
void EffectManager::updateEffects()
{
DEBUG_BLOCK;
......@@ -83,23 +92,36 @@ void EffectManager::updateEffects()
m_audioEffectList.clear();
m_videoEffectList.clear();
int moduleCount = -1;
VLC_FOREACH_MODULE(module, libvlc_audio_filter_list_get(libvlc)) {
m_audioEffectList.append(new EffectInfo(module->psz_longname,
module->psz_help,
QString(),
++moduleCount,
EffectInfo::AudioEffect));
}
moduleCount = -1;
VLC_FOREACH_MODULE(module, libvlc_video_filter_list_get(libvlc)) {
m_videoEffectList.append(new EffectInfo(module->psz_longname,
module->psz_help,
QString(),
++moduleCount,
EffectInfo::VideoEffect));
}
// Generic effect activation etc is entirely kaput and equalizer has specific
// API anyway, so we simply manually insert it \o/
#if (LIBVLC_VERSION_INT >= LIBVLC_VERSION(2, 2, 0, 0))
const QString eqName = QString("equalizer-%1bands").arg(QString::number(libvlc_audio_equalizer_get_band_count()));
m_audioEffectList.append(EffectInfo(
eqName,
QString(""),
QString(""),
0,
EffectInfo::AudioEffect));
#endif
// int moduleCount = -1;
// VLC_FOREACH_MODULE(module, libvlc_audio_filter_list_get(libvlc)) {
// m_audioEffectList.append(new EffectInfo(module->psz_longname,
// module->psz_help,
// QString(),
// ++moduleCount,
// EffectInfo::AudioEffect));
// }
// moduleCount = -1;
// VLC_FOREACH_MODULE(module, libvlc_video_filter_list_get(libvlc)) {
// m_videoEffectList.append(new EffectInfo(module->psz_longname,
// module->psz_help,
// QString(),
// ++moduleCount,
// EffectInfo::VideoEffect));
// }
m_effectList.append(m_audioEffectList);
m_effectList.append(m_videoEffectList);
......
......@@ -64,11 +64,11 @@ public:
}
private:
const QString m_name;
const QString m_description;
const QString m_author;
const int m_filter;
const Type m_type;
QString m_name;
QString m_description;
QString m_author;
int m_filter;
Type m_type;
};
/** \brief Manages a list of effects.
......@@ -93,21 +93,23 @@ public:
~EffectManager();
/// Returns a list of available audio effects
const QList<EffectInfo *> audioEffects() const;
const QList<EffectInfo> audioEffects() const;
/// Returns a list of available video effects
const QList<EffectInfo *> videoEffects() const;
const QList<EffectInfo> videoEffects() const;
/// Returns a list of available effects
const QList<EffectInfo *> effects() const;
const QList<EffectInfo> effects() const;
QObject *createEffect(int id, QObject *parent);
private:
/// Generates the aggegated list of effects from both video and audio
void updateEffects();
QList<EffectInfo *> m_effectList;
QList<EffectInfo *> m_audioEffectList;
QList<EffectInfo *> m_videoEffectList;
QList<EffectInfo> m_effectList;
QList<EffectInfo> m_audioEffectList;
QList<EffectInfo> m_videoEffectList;
bool m_equalizerEnabled;
};
......
/*
Copyright (C) 2013 Harald Sitter <sitter@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "equalizereffect.h"
#include "mediaplayer.h"
#include "utils/debug.h"
namespace Phonon {
namespace VLC {
EqualizerEffect::EqualizerEffect(QObject *parent)
: QObject(parent)
, SinkNode()
, EffectInterface()
, m_equalizer(libvlc_audio_equalizer_new())
{
// Amarok decided to make up rules because phonon didn't manage to
// pre-amp string needs to be pre-amp
// bands need to be xxHz
// That way they can be consistently mapped to localized/formatted strings.
EffectParameter preamp(-1, "pre-amp", 0 /* hint */, 0.0f, -20.0f, 20.0f);
m_bands.append(preamp);
const unsigned int bandCount = libvlc_audio_equalizer_get_band_count();
for (unsigned int i = 0; i < bandCount; ++i) {
const float frequency = libvlc_audio_equalizer_get_band_frequency(i);
const QString name = QString("%1Hz").arg(QString::number(frequency));
EffectParameter parameter(i, name, 0 /* hint */, 0.0f, -20.0f, 20.0f);
m_bands.append(parameter);
}
}
EqualizerEffect::~EqualizerEffect()
{
libvlc_audio_equalizer_release(m_equalizer);
}
QList<EffectParameter> EqualizerEffect::parameters() const
{
return m_bands;
}
QVariant EqualizerEffect::parameterValue(const EffectParameter &parameter) const
{
return libvlc_audio_equalizer_get_amp_at_index(m_equalizer, parameter.id());
}
void EqualizerEffect::setParameterValue(const EffectParameter &parameter,
const QVariant &newValue)
{
if (parameter.id() == -1)
libvlc_audio_equalizer_set_preamp(m_equalizer, newValue.toFloat());
else
libvlc_audio_equalizer_set_amp_at_index(m_equalizer, newValue.toFloat(), parameter.id());
}
void EqualizerEffect::handleConnectToMediaObject(MediaObject *mediaObject)
{
m_player->setEqualizer(m_equalizer);
}
} // namespace VLC
} // namespace Phonon
/*
Copyright (C) 2013 Harald Sitter <sitter@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PHONON_VLC_EQUALIZEREFFECT_H
#define PHONON_VLC_EQUALIZEREFFECT_H
#include <QtCore/QObject>
#include <phonon/effectinterface.h>
#include <phonon/effectparameter.h>
#include <vlc/vlc.h>
#include "sinknode.h"
namespace Phonon {
namespace VLC {
class EqualizerEffect : public QObject, public SinkNode, public EffectInterface
{
Q_OBJECT
Q_INTERFACES(Phonon::EffectInterface)
public:
explicit EqualizerEffect(QObject *parent = 0);
~EqualizerEffect();
QList<EffectParameter> parameters() const;
QVariant parameterValue(const EffectParameter &parameter) const;
void setParameterValue(const EffectParameter &parameter, const QVariant &newValue);
void handleConnectToMediaObject(MediaObject *mediaObject);
private:
libvlc_equalizer_t *m_equalizer;
QList <EffectParameter> m_bands;
};
} // namespace VLC
} // namespace Phonon
#endif // PHONON_VLC_EQUALIZEREFFECT_H
......@@ -331,7 +331,12 @@ void MediaPlayer::setCdTrack(int track)
libvlc_media_player_play(m_player);
}
#if (LIBVLC_VERSION_INT >= LIBVLC_VERSION(2, 2, 0, 0))
void MediaPlayer::setEqualizer(libvlc_equalizer_t *equalizer)
{
libvlc_media_player_set_equalizer(m_player, equalizer);
}
#endif
} // namespace VLC
} // namespace Phonon
......@@ -21,6 +21,7 @@
#include <QtCore/QObject>
#include <QtCore/QSize>
#include <vlc/libvlc_version.h>
#include <vlc/vlc.h>
class QImage;
......@@ -159,6 +160,10 @@ public:
bool setAudioTrack(int track);
void setCdTrack(int track);
#if (LIBVLC_VERSION_INT >= LIBVLC_VERSION(2, 2, 0, 0))
void setEqualizer(libvlc_equalizer_t *equalizer);
#endif
signals:
void lengthChanged(qint64 length);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment