| 1 | /* |
| 2 | Copyright (C) 2013 Harald Sitter <sitter@kde.org> |
| 3 | |
| 4 | This library is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU Lesser General Public |
| 6 | License as published by the Free Software Foundation; either |
| 7 | version 2.1 of the License, or (at your option) any later version. |
| 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 GNU |
| 12 | Lesser General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public |
| 15 | License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | #include "equalizereffect.h" |
| 19 | |
| 20 | #include "mediaplayer.h" |
| 21 | #include "utils/debug.h" |
| 22 | |
| 23 | namespace Phonon { |
| 24 | namespace VLC { |
| 25 | |
| 26 | EqualizerEffect::EqualizerEffect(QObject *parent) |
| 27 | : QObject(parent) |
| 28 | , SinkNode() |
| 29 | , EffectInterface() |
| 30 | , m_equalizer(libvlc_audio_equalizer_new()) |
| 31 | { |
| 32 | // Amarok decided to make up rules because phonon didn't manage to |
| 33 | // pre-amp string needs to be pre-amp |
| 34 | // bands need to be xxHz |
| 35 | // That way they can be consistently mapped to localized/formatted strings. |
| 36 | |
| 37 | EffectParameter preamp(-1, "pre-amp" , {} /* hint */, 0.0f, -20.0f, 20.0f); |
| 38 | m_bands.append(t: preamp); |
| 39 | |
| 40 | const unsigned int bandCount = libvlc_audio_equalizer_get_band_count(); |
| 41 | for (unsigned int i = 0; i < bandCount; ++i) { |
| 42 | const float frequency = libvlc_audio_equalizer_get_band_frequency(u_index: i); |
| 43 | const QString name = QString("%1Hz" ).arg(a: QString::number(frequency)); |
| 44 | EffectParameter parameter(i, name, {} /* hint */, 0.0f, -20.0f, 20.0f); |
| 45 | m_bands.append(t: parameter); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | EqualizerEffect::~EqualizerEffect() |
| 50 | { |
| 51 | libvlc_audio_equalizer_release(p_equalizer: m_equalizer); |
| 52 | } |
| 53 | |
| 54 | QList<EffectParameter> EqualizerEffect::parameters() const |
| 55 | { |
| 56 | return m_bands; |
| 57 | } |
| 58 | |
| 59 | QVariant EqualizerEffect::parameterValue(const EffectParameter ¶meter) const |
| 60 | { |
| 61 | return libvlc_audio_equalizer_get_amp_at_index(p_equalizer: m_equalizer, u_band: parameter.id()); |
| 62 | } |
| 63 | |
| 64 | void EqualizerEffect::setParameterValue(const EffectParameter ¶meter, |
| 65 | const QVariant &newValue) |
| 66 | { |
| 67 | if (parameter.id() == -1) |
| 68 | libvlc_audio_equalizer_set_preamp(p_equalizer: m_equalizer, f_preamp: newValue.toFloat()); |
| 69 | else |
| 70 | libvlc_audio_equalizer_set_amp_at_index(p_equalizer: m_equalizer, f_amp: newValue.toFloat(), u_band: parameter.id()); |
| 71 | } |
| 72 | |
| 73 | void EqualizerEffect::handleConnectToMediaObject(MediaObject *mediaObject) |
| 74 | { |
| 75 | Q_UNUSED(mediaObject); |
| 76 | m_player->setEqualizer(m_equalizer); |
| 77 | } |
| 78 | |
| 79 | } // namespace VLC |
| 80 | } // namespace Phonon |
| 81 | |