File indexing completed on 2024-12-01 04:21:25

0001 /*
0002     Copyright (C) 2007-2008 Tanguy Krotoff <tkrotoff@gmail.com>
0003     Copyright (C) 2008 Lukas Durfina <lukas.durfina@gmail.com>
0004     Copyright (C) 2009 Fathi Boudra <fabo@kde.org>
0005     Copyright (C) 2009-2011 vlc-phonon AUTHORS <kde-multimedia@kde.org>
0006     Copyright (C) 2011 Harald Sitter <sitter@kde.org>
0007 
0008     This library is free software; you can redistribute it and/or
0009     modify it under the terms of the GNU Lesser General Public
0010     License as published by the Free Software Foundation; either
0011     version 2.1 of the License, or (at your option) any later version.
0012 
0013     This library is distributed in the hope that it will be useful,
0014     but WITHOUT ANY WARRANTY; without even the implied warranty of
0015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016     Lesser General Public License for more details.
0017 
0018     You should have received a copy of the GNU Lesser General Public
0019     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0020 */
0021 
0022 #include "effectmanager.h"
0023 
0024 #include <vlc/vlc.h>
0025 #include <vlc/libvlc_version.h>
0026 
0027 #include "equalizereffect.h"
0028 
0029 #include "utils/debug.h"
0030 #include "utils/libvlc.h"
0031 
0032 namespace Phonon {
0033 namespace VLC {
0034 
0035 EffectInfo::EffectInfo(const QString &name, const QString &description,
0036                        const QString &author, int filter, Type type)
0037     : m_name(name)
0038     , m_description(description)
0039     , m_author(author)
0040     , m_filter(filter)
0041     , m_type(type)
0042 {}
0043 
0044 EffectManager::EffectManager(QObject *parent)
0045     : QObject(parent)
0046 {
0047     if (!pvlc_libvlc)
0048         return;
0049 
0050     updateEffects();
0051 }
0052 
0053 EffectManager::~EffectManager()
0054 {
0055     m_audioEffectList.clear();
0056     m_videoEffectList.clear();
0057 
0058     // EffectsList holds the same pointers as audio and video, so qDeleteAll on
0059     // this container would cause a double freeing.
0060     m_effectList.clear();
0061 }
0062 
0063 const QList<EffectInfo> EffectManager::audioEffects() const
0064 {
0065     return m_audioEffectList;
0066 }
0067 
0068 const QList<EffectInfo> EffectManager::videoEffects() const
0069 {
0070     return m_videoEffectList;
0071 }
0072 
0073 const QList<EffectInfo> EffectManager::effects() const
0074 {
0075     return m_effectList;
0076 }
0077 
0078 QObject *EffectManager::createEffect(int id, QObject *parent)
0079 {
0080     Q_UNUSED(id);
0081     return new EqualizerEffect(parent);
0082 }
0083 
0084 void EffectManager::updateEffects()
0085 {
0086     DEBUG_BLOCK;
0087 
0088     m_effectList.clear();
0089     m_audioEffectList.clear();
0090     m_videoEffectList.clear();
0091 
0092     // Generic effect activation etc is entirely kaput and equalizer has specific
0093     // API anyway, so we simply manually insert it \o/
0094 
0095     const QString eqName = QString("equalizer-%1bands").arg(QString::number(libvlc_audio_equalizer_get_band_count()));
0096     m_audioEffectList.append(EffectInfo(
0097                                  eqName,
0098                                  QString(""),
0099                                  QString(""),
0100                                  0,
0101                                  EffectInfo::AudioEffect));
0102 
0103 //    int moduleCount = -1;
0104 //    VLC_FOREACH_MODULE(module, libvlc_audio_filter_list_get(libvlc)) {
0105 //        m_audioEffectList.append(new EffectInfo(module->psz_longname,
0106 //                                                module->psz_help,
0107 //                                                QString(),
0108 //                                                ++moduleCount,
0109 //                                                EffectInfo::AudioEffect));
0110 //    }
0111 
0112 //    moduleCount = -1;
0113 //    VLC_FOREACH_MODULE(module, libvlc_video_filter_list_get(libvlc)) {
0114 //        m_videoEffectList.append(new EffectInfo(module->psz_longname,
0115 //                                                module->psz_help,
0116 //                                                QString(),
0117 //                                                ++moduleCount,
0118 //                                                EffectInfo::VideoEffect));
0119 //    }
0120 
0121     m_effectList.append(m_audioEffectList);
0122     m_effectList.append(m_videoEffectList);
0123 }
0124 
0125 } // namespace VLC
0126 } // namespace Phonon