diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-09-27 20:49:23 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-09-27 20:49:23 +0000 |
| commit | d26eba2fad30b2bf23135d0e9b203fdee2a935b5 (patch) | |
| tree | 9caac3416b5ffa0f0b2030a57e2462a64a1e330f | |
| parent | 3503bb88cdb79aa9114b88f7fe5c8478f824caf6 (diff) | |
| download | qmmp-d26eba2fad30b2bf23135d0e9b203fdee2a935b5.tar.gz qmmp-d26eba2fad30b2bf23135d0e9b203fdee2a935b5.tar.bz2 qmmp-d26eba2fad30b2bf23135d0e9b203fdee2a935b5.zip | |
volume control api
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@568 90c681e8-e032-0410-971d-27865f9a5e38
| -rw-r--r-- | src/plugins/Output/alsa/outputalsa.cpp | 89 | ||||
| -rw-r--r-- | src/plugins/Output/alsa/outputalsa.h | 34 | ||||
| -rw-r--r-- | src/plugins/Output/alsa/outputalsafactory.cpp | 5 | ||||
| -rw-r--r-- | src/plugins/Output/alsa/outputalsafactory.h | 1 | ||||
| -rw-r--r-- | src/qmmp/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/qmmp/output.cpp | 36 | ||||
| -rw-r--r-- | src/qmmp/output.h | 9 | ||||
| -rw-r--r-- | src/qmmp/outputfactory.h | 2 | ||||
| -rw-r--r-- | src/qmmp/qmmp.pro | 9 | ||||
| -rw-r--r-- | src/qmmp/soundcore.cpp | 17 | ||||
| -rw-r--r-- | src/qmmp/soundcore.h | 3 | ||||
| -rw-r--r-- | src/qmmp/volumecontrol.cpp | 38 | ||||
| -rw-r--r-- | src/qmmp/volumecontrol.h | 45 | ||||
| -rw-r--r-- | src/ui/pluginitem.cpp | 4 |
14 files changed, 229 insertions, 66 deletions
diff --git a/src/plugins/Output/alsa/outputalsa.cpp b/src/plugins/Output/alsa/outputalsa.cpp index 5ec6b7748..1491c4584 100644 --- a/src/plugins/Output/alsa/outputalsa.cpp +++ b/src/plugins/Output/alsa/outputalsa.cpp @@ -49,21 +49,21 @@ OutputALSA::OutputALSA(QObject * parent, bool useVolume) pcm_name = strdup(dev_name.toAscii().data()); pcm_handle = 0; //alsa mixer - mixer = 0; + /*mixer = 0; if (useVolume) { QString card = settings.value("ALSA/mixer_card","hw:0").toString(); QString dev = settings.value("ALSA/mixer_device", "PCM").toString(); setupMixer(card, dev); - } + }*/ } OutputALSA::~OutputALSA() { uninitialize(); free (pcm_name); - if (mixer) - snd_mixer_close(mixer); + /*if (mixer) + snd_mixer_close(mixer);*/ } void OutputALSA::stop() @@ -487,7 +487,53 @@ void OutputALSA::uninitialize() } /* ****** MIXER ******* */ -int OutputALSA::setupMixer(QString card, QString device) +VolumeControlALSA::VolumeControlALSA(QObject *parent) : VolumeControl(parent) +{ + //alsa mixer + mixer = 0; + QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); + QString card = settings.value("ALSA/mixer_card","hw:0").toString(); + QString dev = settings.value("ALSA/mixer_device", "PCM").toString(); + setupMixer(card, dev); +} + + +VolumeControlALSA::~VolumeControlALSA() +{ + if (mixer) + snd_mixer_close(mixer); +} + +void VolumeControlALSA::setVolume(int l, int r) +{ + + if (!pcm_element) + return; + + snd_mixer_selem_set_playback_volume(pcm_element, + SND_MIXER_SCHN_FRONT_LEFT, l); + snd_mixer_selem_set_playback_volume(pcm_element, + SND_MIXER_SCHN_FRONT_RIGHT, r); +} + +void VolumeControlALSA::volume(int *l, int *r) +{ + if (!pcm_element) + return; + + long ll = *l, lr = *r; + snd_mixer_handle_events(mixer); + snd_mixer_selem_get_playback_volume(pcm_element, + SND_MIXER_SCHN_FRONT_LEFT, &ll); + snd_mixer_selem_get_playback_volume(pcm_element, + SND_MIXER_SCHN_FRONT_RIGHT, &lr); + *l = ll; + *r = lr; +} + + + +int VolumeControlALSA::setupMixer(QString card, QString device) { char *name; long int a, b; @@ -539,7 +585,7 @@ int OutputALSA::setupMixer(QString card, QString device) return 0; } -void OutputALSA::parseMixerName(char *str, char **name, int *index) +void VolumeControlALSA::parseMixerName(char *str, char **name, int *index) { char *end; @@ -559,7 +605,7 @@ void OutputALSA::parseMixerName(char *str, char **name, int *index) } } -snd_mixer_elem_t* OutputALSA::getMixerElem(snd_mixer_t *mixer, char *name, int index) +snd_mixer_elem_t* VolumeControlALSA::getMixerElem(snd_mixer_t *mixer, char *name, int index) { snd_mixer_selem_id_t* selem_id; snd_mixer_elem_t* elem; @@ -575,34 +621,7 @@ snd_mixer_elem_t* OutputALSA::getMixerElem(snd_mixer_t *mixer, char *name, int i return elem; } -void OutputALSA::setVolume(int l, int r) -{ - - if (!pcm_element) - return; - - snd_mixer_selem_set_playback_volume(pcm_element, - SND_MIXER_SCHN_FRONT_LEFT, l); - snd_mixer_selem_set_playback_volume(pcm_element, - SND_MIXER_SCHN_FRONT_RIGHT, r); -} - -void OutputALSA::volume(int *l, int *r) -{ - if (!pcm_element) - return; - - long ll = *l, lr = *r; - snd_mixer_handle_events(mixer); - snd_mixer_selem_get_playback_volume(pcm_element, - SND_MIXER_SCHN_FRONT_LEFT, &ll); - snd_mixer_selem_get_playback_volume(pcm_element, - SND_MIXER_SCHN_FRONT_RIGHT, &lr); - *l = ll; - *r = lr; -} - -int OutputALSA::getMixer(snd_mixer_t **mixer, QString card) +int VolumeControlALSA::getMixer(snd_mixer_t **mixer, QString card) { char *dev; int err; diff --git a/src/plugins/Output/alsa/outputalsa.h b/src/plugins/Output/alsa/outputalsa.h index a3bb817ee..abf7cb1e5 100644 --- a/src/plugins/Output/alsa/outputalsa.h +++ b/src/plugins/Output/alsa/outputalsa.h @@ -25,22 +25,27 @@ class OutputALSA; #include <QObject> -extern "C" { +extern "C" +{ #include <alsa/asoundlib.h> } #include <qmmp/output.h> +#include <qmmp/volumecontrol.h> class OutputALSA : public Output { -Q_OBJECT + Q_OBJECT public: OutputALSA(QObject * parent = 0, bool useVolume = TRUE); ~OutputALSA(); bool initialize(); - bool isInitialized() const { return m_inited; } + bool isInitialized() const + { + return m_inited; + } void uninitialize(); void configure(quint32, int, int); void stop(); @@ -72,6 +77,29 @@ private: size_t m_bits_per_frame; //alsa mixer + /*int setupMixer(QString card, QString device); + void parseMixerName(char *str, char **name, int *index); + int getMixer(snd_mixer_t **mixer, QString card); + snd_mixer_elem_t* getMixerElem(snd_mixer_t *mixer, char *name, int index); + snd_mixer_t *mixer; + snd_mixer_elem_t *pcm_element;*/ + bool m_use_mmap; +}; + +class VolumeControlALSA : public VolumeControl +{ + Q_OBJECT +public: + VolumeControlALSA(QObject *parent = 0); + ~VolumeControlALSA(); + + void setVolume(int left, int right) ; + +protected: + void volume(int *left, int *right); + +private: + //alsa mixer int setupMixer(QString card, QString device); void parseMixerName(char *str, char **name, int *index); int getMixer(snd_mixer_t **mixer, QString card); diff --git a/src/plugins/Output/alsa/outputalsafactory.cpp b/src/plugins/Output/alsa/outputalsafactory.cpp index 641ff1278..d9ecce6af 100644 --- a/src/plugins/Output/alsa/outputalsafactory.cpp +++ b/src/plugins/Output/alsa/outputalsafactory.cpp @@ -39,6 +39,11 @@ Output* OutputALSAFactory::create(QObject* parent, bool volume) return new OutputALSA(parent, volume); } +VolumeControl *OutputALSAFactory::createVolumeControl(QObject *parent) +{ + return new VolumeControlALSA(parent); +} + void OutputALSAFactory::showSettings(QWidget* parent) { SettingsDialog *s = new SettingsDialog(parent); diff --git a/src/plugins/Output/alsa/outputalsafactory.h b/src/plugins/Output/alsa/outputalsafactory.h index 4375f4916..b772248d3 100644 --- a/src/plugins/Output/alsa/outputalsafactory.h +++ b/src/plugins/Output/alsa/outputalsafactory.h @@ -39,6 +39,7 @@ Q_INTERFACES(OutputFactory); public: const OutputProperties properties() const; Output* create(QObject* parent, bool volume); + VolumeControl *createVolumeControl(QObject *parent); void showSettings(QWidget* parent); void showAbout(QWidget *parent); QTranslator *createTranslator(QObject *parent); diff --git a/src/qmmp/CMakeLists.txt b/src/qmmp/CMakeLists.txt index 70fbee619..3ae48d448 100644 --- a/src/qmmp/CMakeLists.txt +++ b/src/qmmp/CMakeLists.txt @@ -44,6 +44,7 @@ SET(libqmmp_SRCS effect.cpp qmmp.cpp statehandler.cpp + volumecontrol.cpp ) SET(libqmmp_MOC_HDRS @@ -66,6 +67,7 @@ SET(libqmmp_MOC_HDRS effect.h qmmp.h statehandler.h + volumecontrol.h ) SET(libqmmp_DEVEL_HDRS @@ -85,6 +87,7 @@ SET(libqmmp_DEVEL_HDRS effect.h qmmp.h statehandler.h + volumecontrol.h ) diff --git a/src/qmmp/output.cpp b/src/qmmp/output.cpp index 0a0e6cef1..2ffe11aaf 100644 --- a/src/qmmp/output.cpp +++ b/src/qmmp/output.cpp @@ -17,7 +17,6 @@ Output::Output (QObject* parent) : QThread (parent), m_recycler (stackSize()) { - //qRegisterMetaType<OutputState>("OutputState"); m_bl = -1; m_br = -1; m_handler = 0; @@ -42,7 +41,7 @@ Output::~Output() {} void Output::dispatchVisual (Buffer *buffer, unsigned long written, - int chan, int prec) + int chan, int prec) { if (!buffer) return; @@ -68,7 +67,7 @@ void Output::clearVisuals() void Output::checkVolume() { int ll = 0, lr = 0; - volume(&ll,&lr); + //volume(&ll,&lr); ll = (ll > 100) ? 100 : ll; lr = (lr > 100) ? 100 : lr; ll = (ll < 0) ? 0 : ll; @@ -161,14 +160,16 @@ Output *Output::create (QObject *parent) qDebug("Output: unable to find output plugins"); return output; } - OutputFactory *fact = 0; - foreach(fact, *m_factories) + OutputFactory *fact = Output::currentFactory(); + if (!fact && !m_factories->isEmpty()) + fact = m_factories->at(0); + /*foreach(fact, *m_factories) { if (isEnabled(fact)) break; else fact = m_factories->at(0); - } + }*/ QSettings settings (QDir::homePath() +"/.qmmp/qmmprc", QSettings::IniFormat); bool useVolume = !settings.value("Volume/software_volume", FALSE).toBool(); if (fact) @@ -200,24 +201,33 @@ QStringList Output::outputFiles() return m_files; } -void Output::setEnabled(OutputFactory* factory) +void Output::setCurrentFactory(OutputFactory* factory) { checkFactories(); if (!m_factories->contains(factory)) return; QString name = m_files.at(m_factories->indexOf(factory)).section('/',-1); + //TODO use plugin id instead QSettings settings (QDir::homePath() +"/.qmmp/qmmprc", QSettings::IniFormat); settings.setValue ("Output/plugin_file", name); } -bool Output::isEnabled(OutputFactory* factory) +OutputFactory *Output::currentFactory() { checkFactories(); - if (!m_factories->contains(factory)) - return FALSE; - QString name = m_files.at(m_factories->indexOf(factory)).section('/',-1); QSettings settings (QDir::homePath() +"/.qmmp/qmmprc", QSettings::IniFormat); - return name == settings.value("Output/plugin_file", "libalsa.so").toString(); + QString name = settings.value("Output/plugin_file", "libalsa.so").toString(); + foreach(QString path, m_files) + { + if (path.section('/',-1) == name) + { + int i = m_files.indexOf(path); + if (i < 0) + return 0; + else + return m_factories->at(i); + } + } + return 0; } - diff --git a/src/qmmp/output.h b/src/qmmp/output.h index 2cd294af4..86e5d3aef 100644 --- a/src/qmmp/output.h +++ b/src/qmmp/output.h @@ -43,8 +43,8 @@ public: virtual qint64 written() = 0; virtual qint64 latency() = 0; virtual void seek(qint64) = 0; - virtual void setVolume(int, int){}; - virtual void volume(int *, int *){}; + //virtual void setVolume(int, int){}; + //virtual void volume(int *, int *){}; Recycler *recycler(); QMutex *mutex(); @@ -54,8 +54,8 @@ public: static Output *create(QObject *); static QList<OutputFactory*> *outputFactories(); static QStringList outputFiles(); - static void setEnabled(OutputFactory* factory); - static bool isEnabled(OutputFactory* factory); + static void setCurrentFactory(OutputFactory* factory); + static OutputFactory *currentFactory(); public slots: void checkVolume(); @@ -79,6 +79,7 @@ private: StateHandler *m_handler; static void checkFactories(); + //TODO use QMap instead static QList<OutputFactory*> *m_factories; static QStringList m_files; static QTimer *m_timer; diff --git a/src/qmmp/outputfactory.h b/src/qmmp/outputfactory.h index 2a5513759..3e3e6cd01 100644 --- a/src/qmmp/outputfactory.h +++ b/src/qmmp/outputfactory.h @@ -26,6 +26,7 @@ class QString; class QIODevice; class QWidget; class QTranslator; +class VolumeControl; class Decoder; class Output; @@ -43,6 +44,7 @@ public: virtual ~OutputFactory() {} virtual const OutputProperties properties() const = 0; virtual Output *create(QObject *, bool) = 0; + virtual VolumeControl *createVolumeControl(QObject *) = 0; virtual void showSettings(QWidget *parent) = 0; virtual void showAbout(QWidget *parent) = 0; virtual QTranslator *createTranslator(QObject *parent) = 0; diff --git a/src/qmmp/qmmp.pro b/src/qmmp/qmmp.pro index 85b4838a5..127693e43 100644 --- a/src/qmmp/qmmp.pro +++ b/src/qmmp/qmmp.pro @@ -19,7 +19,8 @@ HEADERS += recycler.h \ effectfactory.h \ statehandler.h \ qmmp.h \ - fileinfo.h + fileinfo.h \ + volumecontrol.h SOURCES += recycler.cpp \ decoder.cpp \ output.cpp \ @@ -33,7 +34,8 @@ SOURCES += recycler.cpp \ effect.cpp \ statehandler.cpp \ qmmp.cpp \ - fileinfo.cpp + fileinfo.cpp \ + volumecontrol.cpp TARGET = ../../lib/qmmp CONFIG += release \ @@ -74,7 +76,8 @@ devel.files += recycler.h \ visual.h \ visualfactory.h \ effect.h \ - effectfactory.h + effectfactory.h \ + volumecontrol.h devel.path = /include/qmmp diff --git a/src/qmmp/soundcore.cpp b/src/qmmp/soundcore.cpp index e53be7259..b104a8403 100644 --- a/src/qmmp/soundcore.cpp +++ b/src/qmmp/soundcore.cpp @@ -29,6 +29,7 @@ #include "streamreader.h" #include "effect.h" #include "statehandler.h" +#include "volumecontrol.h" #include "soundcore.h" @@ -50,7 +51,6 @@ SoundCore::SoundCore(QObject *parent) m_vis = 0; m_parentWidget = 0; m_factory = 0; - //m_state = Qmmp::Stopped; for (int i = 1; i < 10; ++i) m_bands[i] = 0; m_handler = new StateHandler(this); @@ -61,6 +61,7 @@ SoundCore::SoundCore(QObject *parent) connect(m_handler, SIGNAL(channelsChanged(int)), SIGNAL(channelsChanged(int))); connect(m_handler, SIGNAL(metaDataChanged ()), SIGNAL(metaDataChanged ())); connect(m_handler, SIGNAL(stateChanged (Qmmp::State)), SIGNAL(stateChanged(Qmmp::State))); + m_volumeControl = VolumeControl::create(this); } @@ -176,6 +177,9 @@ void SoundCore::stop() m_input = 0; } qApp->processEvents(); + //update VolumeControl + delete m_volumeControl; + m_volumeControl = VolumeControl::create(this); } void SoundCore::pause() @@ -253,7 +257,8 @@ void SoundCore::setEQEnabled(bool on) void SoundCore::setVolume(int L, int R) { - QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); + m_volumeControl->setVolume(L, R); + /*QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); bool sofVolume = settings.value("Volume/software_volume", FALSE).toBool(); if (sofVolume) { @@ -268,8 +273,8 @@ void SoundCore::setVolume(int L, int R) if (m_output) m_output->checkSoftwareVolume(); } - else if (m_output) - m_output->setVolume(L,R); +/* else if (m_output) + m_output->setVolume(L,R);*/ } void SoundCore::volume(int *left, int *right) @@ -281,8 +286,8 @@ void SoundCore::volume(int *left, int *right) *left = settings.value("Volume/left", 0).toInt(); *right = settings.value("Volume/right", 0).toInt(); } - else if (m_output) - m_output->volume(left,right); + /*else if (m_output) + m_output->volume(left,right);*/ return; } diff --git a/src/qmmp/soundcore.h b/src/qmmp/soundcore.h index 00bf876e7..9ad766bce 100644 --- a/src/qmmp/soundcore.h +++ b/src/qmmp/soundcore.h @@ -35,6 +35,8 @@ class QIODevice; +class VolumeControl; + class SoundCore : public QObject { Q_OBJECT @@ -168,6 +170,7 @@ private: QWidget *m_parentWidget; static SoundCore* m_instance; StateHandler *m_handler; + VolumeControl *m_volumeControl; }; #endif diff --git a/src/qmmp/volumecontrol.cpp b/src/qmmp/volumecontrol.cpp new file mode 100644 index 000000000..ab6d142c9 --- /dev/null +++ b/src/qmmp/volumecontrol.cpp @@ -0,0 +1,38 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "output.h" + +#include "volumecontrol.h" + +VolumeControl::VolumeControl(QObject *parent) + : QObject(parent) +{ +} + + +VolumeControl::~VolumeControl() +{ +} + +VolumeControl *VolumeControl::create(QObject *parent) +{ + return Output::currentFactory()->createVolumeControl(parent); +} diff --git a/src/qmmp/volumecontrol.h b/src/qmmp/volumecontrol.h new file mode 100644 index 000000000..0f81a707a --- /dev/null +++ b/src/qmmp/volumecontrol.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef VOLUMECONTROL_H +#define VOLUMECONTROL_H + +#include <QObject> + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class VolumeControl : public QObject +{ + Q_OBJECT +public: + VolumeControl(QObject *parent = 0); + + ~VolumeControl(); + + virtual void setVolume(int left, int right) = 0; + + static VolumeControl *create(QObject *parent = 0); + +protected: + virtual void volume(int *left, int *right) = 0; + +}; + +#endif diff --git a/src/ui/pluginitem.cpp b/src/ui/pluginitem.cpp index 1d5b7a3d8..9141eaf05 100644 --- a/src/ui/pluginitem.cpp +++ b/src/ui/pluginitem.cpp @@ -70,12 +70,12 @@ OutputPluginItem::~OutputPluginItem() void OutputPluginItem::select() { - Output::setEnabled(m_factory); + Output::setCurrentFactory(m_factory); } bool OutputPluginItem::isSelected() { - return Output::isEnabled(m_factory); + return Output::currentFactory() == m_factory; } OutputFactory *OutputPluginItem::factory() |
