diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2012-03-07 20:04:51 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2012-03-07 20:04:51 +0000 |
| commit | 74afcc2d9356fef5dbd25f4e7aaabb021c0bfc29 (patch) | |
| tree | f76222901b123facc552c614bf9d1753e2da0afc | |
| parent | 7559299d77b3c375e9b718f986bc079215bf1d27 (diff) | |
| download | qmmp-74afcc2d9356fef5dbd25f4e7aaabb021c0bfc29.tar.gz qmmp-74afcc2d9356fef5dbd25f4e7aaabb021c0bfc29.tar.bz2 qmmp-74afcc2d9356fef5dbd25f4e7aaabb021c0bfc29.zip | |
some volume api changes
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@2673 90c681e8-e032-0410-971d-27865f9a5e38
32 files changed, 257 insertions, 231 deletions
diff --git a/src/plugins/Output/Output.pro b/src/plugins/Output/Output.pro index 8ded62f9f..858665e64 100644 --- a/src/plugins/Output/Output.pro +++ b/src/plugins/Output/Output.pro @@ -25,7 +25,7 @@ contains(CONFIG, ALSA_PLUGIN){ } contains(CONFIG, OSS4_PLUGIN){ - SUBDIRS += oss4 + SUBDIRS += oss4 } } diff --git a/src/plugins/Output/alsa/outputalsa.cpp b/src/plugins/Output/alsa/outputalsa.cpp index 097e7790e..8aad0fb58 100644 --- a/src/plugins/Output/alsa/outputalsa.cpp +++ b/src/plugins/Output/alsa/outputalsa.cpp @@ -359,7 +359,7 @@ void OutputALSA::uninitialize() } /* ****** MIXER ******* */ -VolumeControlALSA::VolumeControlALSA(QObject *parent) : VolumeControl(parent) +VolumeALSA::VolumeALSA() { //alsa mixer mixer = 0; @@ -370,42 +370,40 @@ VolumeControlALSA::VolumeControlALSA(QObject *parent) : VolumeControl(parent) } -VolumeControlALSA::~VolumeControlALSA() +VolumeALSA::~VolumeALSA() { if (mixer) snd_mixer_close(mixer); } -void VolumeControlALSA::setVolume(int l, int r) +void VolumeALSA::setVolume(int channel, int value) { - 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); + _snd_mixer_selem_channel_id channel_id = SND_MIXER_SCHN_FRONT_LEFT; + if(channel == Volume::RIGHT_CHANNEL) + channel_id = SND_MIXER_SCHN_FRONT_RIGHT; + + snd_mixer_selem_set_playback_volume(pcm_element, channel_id, value); } -void VolumeControlALSA::volume(int *l, int *r) +int VolumeALSA::volume(int channel) { if (!pcm_element) - return; + return 0; - long ll = *l, lr = *r; + _snd_mixer_selem_channel_id channel_id = SND_MIXER_SCHN_FRONT_LEFT; + if(channel == Volume::RIGHT_CHANNEL) + channel_id = SND_MIXER_SCHN_FRONT_RIGHT; + + long value = 0; 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; + snd_mixer_selem_get_playback_volume(pcm_element, channel_id, &value); + return value; } - - -int VolumeControlALSA::setupMixer(QString card, QString device) +int VolumeALSA::setupMixer(QString card, QString device) { char *name; int err, index; @@ -439,7 +437,7 @@ int VolumeControlALSA::setupMixer(QString card, QString device) return 0; } -void VolumeControlALSA::parseMixerName(char *str, char **name, int *index) +void VolumeALSA::parseMixerName(char *str, char **name, int *index) { char *end; @@ -459,7 +457,7 @@ void VolumeControlALSA::parseMixerName(char *str, char **name, int *index) } } -snd_mixer_elem_t* VolumeControlALSA::getMixerElem(snd_mixer_t *mixer, char *name, int index) +snd_mixer_elem_t* VolumeALSA::getMixerElem(snd_mixer_t *mixer, char *name, int index) { snd_mixer_selem_id_t* selem_id; snd_mixer_elem_t* elem; @@ -475,7 +473,7 @@ snd_mixer_elem_t* VolumeControlALSA::getMixerElem(snd_mixer_t *mixer, char *name return elem; } -int VolumeControlALSA::getMixer(snd_mixer_t **mixer, QString card) +int VolumeALSA::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 dc1a75dce..50974c629 100644 --- a/src/plugins/Output/alsa/outputalsa.h +++ b/src/plugins/Output/alsa/outputalsa.h @@ -31,7 +31,7 @@ extern "C" } #include <qmmp/output.h> -#include <qmmp/volumecontrol.h> +#include <qmmp/volume.h> class OutputALSA : public Output @@ -70,17 +70,14 @@ private: bool m_can_pause; }; -class VolumeControlALSA : public VolumeControl +class VolumeALSA : public Volume { - Q_OBJECT public: - VolumeControlALSA(QObject *parent = 0); - ~VolumeControlALSA(); - - void setVolume(int left, int right) ; + VolumeALSA(); + ~VolumeALSA(); -protected: - void volume(int *left, int *right); + void setVolume(int channel, int value); + int volume(int channel); private: //alsa mixer diff --git a/src/plugins/Output/alsa/outputalsafactory.cpp b/src/plugins/Output/alsa/outputalsafactory.cpp index dcd003cb0..4553110c7 100644 --- a/src/plugins/Output/alsa/outputalsafactory.cpp +++ b/src/plugins/Output/alsa/outputalsafactory.cpp @@ -40,9 +40,9 @@ Output* OutputALSAFactory::create(QObject* parent) return new OutputALSA(parent); } -VolumeControl *OutputALSAFactory::createVolumeControl(QObject *parent) +Volume *OutputALSAFactory::createVolume() { - return new VolumeControlALSA(parent); + return new VolumeALSA(); } void OutputALSAFactory::showSettings(QWidget* parent) diff --git a/src/plugins/Output/alsa/outputalsafactory.h b/src/plugins/Output/alsa/outputalsafactory.h index 98f35ed4f..9649f8fb8 100644 --- a/src/plugins/Output/alsa/outputalsafactory.h +++ b/src/plugins/Output/alsa/outputalsafactory.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007-2008 by Ilya Kotov * + * Copyright (C) 2007-2012 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -34,12 +34,12 @@ class OutputALSAFactory : public QObject, OutputFactory { Q_OBJECT -Q_INTERFACES(OutputFactory); +Q_INTERFACES(OutputFactory) public: const OutputProperties properties() const; Output* create(QObject* parent); - VolumeControl *createVolumeControl(QObject *parent); + Volume *createVolume(); void showSettings(QWidget* parent); void showAbout(QWidget *parent); QTranslator *createTranslator(QObject *parent); diff --git a/src/plugins/Output/jack/jack.pro b/src/plugins/Output/jack/jack.pro index 9f9cf889a..75c05fd01 100644 --- a/src/plugins/Output/jack/jack.pro +++ b/src/plugins/Output/jack/jack.pro @@ -12,7 +12,7 @@ TARGET=$$PLUGINS_PREFIX/Output/jack QMAKE_CLEAN =$$PLUGINS_PREFIX/Output/libjack.so -DEFINES += JACK_NEW_API +#DEFINES += JACK_NEW_API INCLUDEPATH += ../../../ diff --git a/src/plugins/Output/jack/outputjackfactory.cpp b/src/plugins/Output/jack/outputjackfactory.cpp index 0dd9314e7..c1e6ab09b 100644 --- a/src/plugins/Output/jack/outputjackfactory.cpp +++ b/src/plugins/Output/jack/outputjackfactory.cpp @@ -39,7 +39,7 @@ Output* OutputJACKFactory::create(QObject* parent) return new OutputJACK(parent); } -VolumeControl *OutputJACKFactory::createVolumeControl(QObject *) +Volume *OutputJACKFactory::createVolume() { return 0; } diff --git a/src/plugins/Output/jack/outputjackfactory.h b/src/plugins/Output/jack/outputjackfactory.h index 0847b8a0b..208202b09 100644 --- a/src/plugins/Output/jack/outputjackfactory.h +++ b/src/plugins/Output/jack/outputjackfactory.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006-2008 by Ilya Kotov * + * Copyright (C) 2006-2012 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -30,16 +30,15 @@ #include <qmmp/outputfactory.h> -class OutputJACKFactory : public QObject, - OutputFactory +class OutputJACKFactory : public QObject, OutputFactory { Q_OBJECT -Q_INTERFACES(OutputFactory); +Q_INTERFACES(OutputFactory) public: const OutputProperties properties() const; Output* create(QObject* parent); - VolumeControl *createVolumeControl(QObject *parent); + Volume *createVolume(); void showSettings(QWidget* parent); void showAbout(QWidget *parent); QTranslator *createTranslator(QObject *parent); diff --git a/src/plugins/Output/null/outputnull.h b/src/plugins/Output/null/outputnull.h index 7dc6260fe..6497df1ea 100644 --- a/src/plugins/Output/null/outputnull.h +++ b/src/plugins/Output/null/outputnull.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Ilya Kotov * + * Copyright (C) 2010-2012 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * diff --git a/src/plugins/Output/null/outputnullfactory.cpp b/src/plugins/Output/null/outputnullfactory.cpp index 2ef0fb560..36a03aa78 100644 --- a/src/plugins/Output/null/outputnullfactory.cpp +++ b/src/plugins/Output/null/outputnullfactory.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Ilya Kotov * + * Copyright (C) 2010-2012 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -39,7 +39,7 @@ Output* OutputNullFactory::create(QObject* parent) return new OutputNull(parent); } -VolumeControl *OutputNullFactory::createVolumeControl(QObject *) +Volume *OutputNullFactory::createVolume() { return 0; } diff --git a/src/plugins/Output/null/outputnullfactory.h b/src/plugins/Output/null/outputnullfactory.h index 566d299dd..3917c77ad 100644 --- a/src/plugins/Output/null/outputnullfactory.h +++ b/src/plugins/Output/null/outputnullfactory.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Ilya Kotov * + * Copyright (C) 2010-2012 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -30,16 +30,15 @@ #include <qmmp/outputfactory.h> -class OutputNullFactory : public QObject, - OutputFactory +class OutputNullFactory : public QObject, OutputFactory { Q_OBJECT -Q_INTERFACES(OutputFactory); +Q_INTERFACES(OutputFactory) public: const OutputProperties properties() const; Output* create(QObject* parent); - VolumeControl *createVolumeControl(QObject *parent); + Volume *createVolume(); void showSettings(QWidget* parent); void showAbout(QWidget *parent); QTranslator *createTranslator(QObject *parent); diff --git a/src/plugins/Output/oss/outputoss.cpp b/src/plugins/Output/oss/outputoss.cpp index a612b0d23..db2165353 100644 --- a/src/plugins/Output/oss/outputoss.cpp +++ b/src/plugins/Output/oss/outputoss.cpp @@ -180,7 +180,7 @@ void OutputOSS::reset() } /***** MIXER *****/ -VolumeControlOSS::VolumeControlOSS(QObject *parent) : VolumeControl(parent) +VolumeOSS::VolumeOSS() { m_master = true; m_mixer_fd = -1; @@ -190,7 +190,7 @@ VolumeControlOSS::VolumeControlOSS(QObject *parent) : VolumeControl(parent) } -VolumeControlOSS::~VolumeControlOSS() +VolumeOSS::~VolumeOSS() { if (m_mixer_fd >= 0) { @@ -199,11 +199,14 @@ VolumeControlOSS::~VolumeControlOSS() } } -void VolumeControlOSS::setVolume(int l, int r) +void VolumeOSS::setVolume(int channel, int value) { if (m_mixer_fd < 0) return; - int v; + + int l = (channel == Volume::LEFT_CHANNEL) ? value : volume(Volume::LEFT_CHANNEL); + int r = (channel == Volume::RIGHT_CHANNEL) ? value : volume(Volume::RIGHT_CHANNEL); + long cmd; int devs = 0; ioctl(m_mixer_fd, SOUND_MIXER_READ_DEVMASK, &devs); @@ -216,16 +219,14 @@ void VolumeControlOSS::setVolume(int l, int r) //close(mifd); return; } - v = (r << 8) | l; + int v = (r << 8) | l; ioctl(m_mixer_fd, cmd, &v); } -void VolumeControlOSS::volume(int *ll,int *rr) +int VolumeOSS::volume(int channel) { - *ll = 0; - *rr = 0; if(m_mixer_fd < 0) - return; + return 0; int cmd; int v, devs = 0; ioctl(m_mixer_fd, SOUND_MIXER_READ_DEVMASK, &devs); @@ -235,19 +236,15 @@ void VolumeControlOSS::volume(int *ll,int *rr) else if ((devs & SOUND_MASK_VOLUME) && m_master) cmd = SOUND_MIXER_READ_VOLUME; else - return; + return 0; ioctl(m_mixer_fd, cmd, &v); - *ll = (v & 0xFF00) >> 8; - *rr = (v & 0x00FF); - - *ll = (*ll > 100) ? 100 : *ll; - *rr = (*rr > 100) ? 100 : *rr; - *ll = (*ll < 0) ? 0 : *ll; - *rr = (*rr < 0) ? 0 : *rr; + if(channel == Volume::LEFT_CHANNEL) + return (v & 0xFF00) >> 8; + return (v & 0x00FF); } -void VolumeControlOSS::openMixer() +void VolumeOSS::openMixer() { if (m_mixer_fd >= 0) return; diff --git a/src/plugins/Output/oss/outputoss.h b/src/plugins/Output/oss/outputoss.h index 8864339c4..a04e6f474 100644 --- a/src/plugins/Output/oss/outputoss.h +++ b/src/plugins/Output/oss/outputoss.h @@ -26,7 +26,7 @@ class OutputOSS; #include <qmmp/output.h> -#include <qmmp/volumecontrol.h> +#include <qmmp/volume.h> class OutputOSS : public Output { @@ -43,8 +43,7 @@ private: qint64 writeAudio(unsigned char *data, qint64 maxSize); void drain(); void reset(); - -private: + //oss void post(); void sync(); QString m_audio_device; @@ -54,15 +53,14 @@ private: long bl, br; }; -class VolumeControlOSS : public VolumeControl +class VolumeOSS : public Volume { - Q_OBJECT public: - VolumeControlOSS(QObject *parent = 0); - ~VolumeControlOSS(); + VolumeOSS(); + ~VolumeOSS(); - void setVolume(int left, int right); - void volume(int *left, int *right); + void setVolume(int channel, int value); + int volume(int channel); private: //oss mixer diff --git a/src/plugins/Output/oss/outputossfactory.cpp b/src/plugins/Output/oss/outputossfactory.cpp index 982419c62..2005d843f 100644 --- a/src/plugins/Output/oss/outputossfactory.cpp +++ b/src/plugins/Output/oss/outputossfactory.cpp @@ -40,9 +40,9 @@ const OutputProperties OutputOSSFactory::properties() const return properties; } -VolumeControl *OutputOSSFactory::createVolumeControl(QObject *parent) +Volume *OutputOSSFactory::createVolume() { - return new VolumeControlOSS(parent); + return new VolumeOSS; } void OutputOSSFactory::showSettings(QWidget* parent) diff --git a/src/plugins/Output/oss/outputossfactory.h b/src/plugins/Output/oss/outputossfactory.h index 22e9f35a5..83fa2f936 100644 --- a/src/plugins/Output/oss/outputossfactory.h +++ b/src/plugins/Output/oss/outputossfactory.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006 by Ilya Kotov * + * Copyright (C) 2006-2012 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -30,16 +30,15 @@ #include <qmmp/outputfactory.h> -class OutputOSSFactory : public QObject, - OutputFactory +class OutputOSSFactory : public QObject, OutputFactory { Q_OBJECT -Q_INTERFACES(OutputFactory); +Q_INTERFACES(OutputFactory) public: const OutputProperties properties() const; Output* create(QObject* parent); - VolumeControl *createVolumeControl(QObject *parent); + Volume *createVolume(); void showSettings(QWidget* parent); void showAbout(QWidget *parent); QTranslator *createTranslator(QObject *parent); diff --git a/src/plugins/Output/oss4/outputoss4.cpp b/src/plugins/Output/oss4/outputoss4.cpp index 71cda5dda..6d3bad527 100644 --- a/src/plugins/Output/oss4/outputoss4.cpp +++ b/src/plugins/Output/oss4/outputoss4.cpp @@ -45,7 +45,7 @@ extern "C" #include "outputoss4.h" OutputOSS4 *OutputOSS4::m_instance = 0; -VolumeControlOSS4 *OutputOSS4::m_vc = 0; +VolumeOSS4 *OutputOSS4::m_vc = 0; OutputOSS4::OutputOSS4(QObject *parent) : Output(parent) { @@ -194,7 +194,7 @@ void OutputOSS4::reset() } /***** MIXER *****/ -VolumeControlOSS4::VolumeControlOSS4(QObject *parent) : VolumeControl(parent) +VolumeOSS4::VolumeOSS4() { QSettings settings(Qmmp::configFile(), QSettings::IniFormat); m_volume = settings.value("OSS4/volume", 0x3232).toInt(); @@ -202,15 +202,17 @@ VolumeControlOSS4::VolumeControlOSS4(QObject *parent) : VolumeControl(parent) restore(); } -VolumeControlOSS4::~VolumeControlOSS4() +VolumeOSS4::~VolumeOSS4() { OutputOSS4::m_vc = 0; QSettings settings(Qmmp::configFile(), QSettings::IniFormat); settings.setValue("OSS4/volume", m_volume); } -void VolumeControlOSS4::setVolume(int l, int r) +void VolumeOSS4::setVolume(int channel, int value) { + int l = (channel == Volume::LEFT_CHANNEL) ? value : volume(Volume::LEFT_CHANNEL); + int r = (channel == Volume::RIGHT_CHANNEL) ? value : volume(Volume::RIGHT_CHANNEL); m_volume = (r << 8) | l; if(OutputOSS4::instance() && OutputOSS4::instance()->fd() >= 0) { @@ -218,27 +220,27 @@ void VolumeControlOSS4::setVolume(int l, int r) } } -void VolumeControlOSS4::volume(int *ll,int *rr) +int VolumeOSS4::volume(int channel) { - *ll = 0; - *rr = 0; if(OutputOSS4::instance() && OutputOSS4::instance()->fd() >= 0) { int v = 0; if (ioctl(OutputOSS4::instance()->fd(), SNDCTL_DSP_GETPLAYVOL, &v) < 0) v = 0; - *rr = (v & 0xFF00) >> 8; - *ll = (v & 0x00FF); m_volume = v; + if(channel == Volume::LEFT_CHANNEL) + return (v & 0x00FF); + return (v & 0xFF00) >> 8; } else { - *rr = (m_volume & 0xFF00) >> 8; - *ll = (m_volume & 0x00FF); + if(channel == Volume::LEFT_CHANNEL) + return (m_volume & 0x00FF); + return (m_volume & 0xFF00) >> 8; } } -void VolumeControlOSS4::restore() +void VolumeOSS4::restore() { setVolume((m_volume & 0x00FF), (m_volume & 0xFF00) >> 8); } diff --git a/src/plugins/Output/oss4/outputoss4.h b/src/plugins/Output/oss4/outputoss4.h index 90c9eb85a..06d4b13e3 100644 --- a/src/plugins/Output/oss4/outputoss4.h +++ b/src/plugins/Output/oss4/outputoss4.h @@ -22,12 +22,12 @@ #define OUTPUTOSS4_H #include <qmmp/output.h> -#include <qmmp/volumecontrol.h> +#include <qmmp/volume.h> #define DEFAULT_DEV "/dev/dsp" #define DEFAULT_MIXER "/dev/mixer" -class VolumeControlOSS4; +class VolumeOSS4; /** @author Ilya Kotov <forkotov@hotmail.ru> @@ -36,7 +36,7 @@ class OutputOSS4 : public Output { Q_OBJECT public: - OutputOSS4(QObject * parent); + OutputOSS4(); virtual ~OutputOSS4(); bool initialize(quint32, int, Qmmp::AudioFormat format); @@ -44,7 +44,7 @@ public: qint64 latency(); static OutputOSS4 *instance(); - static VolumeControlOSS4 *m_vc; + static VolumeOSS4 *m_vc; private: //output api @@ -62,15 +62,15 @@ private: }; -class VolumeControlOSS4 : public VolumeControl +class VolumeOSS4 : public Volume { Q_OBJECT public: - VolumeControlOSS4(QObject *parent); - ~VolumeControlOSS4(); + VolumeOSS4(QObject *parent); + ~VolumeOSS4(); - void setVolume(int left, int right); - void volume(int *left, int *right); + void setVolume(int channel, int value); + int volume(int channel); void restore(); private: diff --git a/src/plugins/Output/oss4/outputoss4factory.cpp b/src/plugins/Output/oss4/outputoss4factory.cpp index 95b5340a2..aeac150dd 100644 --- a/src/plugins/Output/oss4/outputoss4factory.cpp +++ b/src/plugins/Output/oss4/outputoss4factory.cpp @@ -40,9 +40,9 @@ const OutputProperties OutputOSS4Factory::properties() const return properties; } -VolumeControl *OutputOSS4Factory::createVolumeControl(QObject *parent) +Volume *OutputOSS4Factory::createVolumeControl() { - return new VolumeControlOSS4(parent); + return new VolumeOSS4; } void OutputOSS4Factory::showSettings(QWidget* parent) diff --git a/src/plugins/Output/oss4/outputoss4factory.h b/src/plugins/Output/oss4/outputoss4factory.h index 04855d54c..ead729e4a 100644 --- a/src/plugins/Output/oss4/outputoss4factory.h +++ b/src/plugins/Output/oss4/outputoss4factory.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006 by Ilya Kotov * + * Copyright (C) 2006-2012 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -29,16 +29,15 @@ #include <qmmp/outputfactory.h> -class OutputOSS4Factory : public QObject, - OutputFactory +class OutputOSS4Factory : public QObject, OutputFactory { Q_OBJECT -Q_INTERFACES(OutputFactory); +Q_INTERFACES(OutputFactory) public: const OutputProperties properties() const; Output* create(QObject* parent); - VolumeControl *createVolumeControl(QObject *parent); + Volume *createVolume(); void showSettings(QWidget* parent); void showAbout(QWidget *parent); QTranslator *createTranslator(QObject *parent); diff --git a/src/plugins/Output/pulseaudio/outputpulseaudiofactory.cpp b/src/plugins/Output/pulseaudio/outputpulseaudiofactory.cpp index e2b0d00bf..0d8c3a41e 100644 --- a/src/plugins/Output/pulseaudio/outputpulseaudiofactory.cpp +++ b/src/plugins/Output/pulseaudio/outputpulseaudiofactory.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007-2008 by Ilya Kotov * + * Copyright (C) 2007-2012 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -39,7 +39,7 @@ Output* OutputPulseAudioFactory::create(QObject* parent) return new OutputPulseAudio(parent); } -VolumeControl *OutputPulseAudioFactory::createVolumeControl(QObject *) +Volume *OutputPulseAudioFactory::createVolume() { return 0; } diff --git a/src/plugins/Output/pulseaudio/outputpulseaudiofactory.h b/src/plugins/Output/pulseaudio/outputpulseaudiofactory.h index 864455415..d693f1aff 100644 --- a/src/plugins/Output/pulseaudio/outputpulseaudiofactory.h +++ b/src/plugins/Output/pulseaudio/outputpulseaudiofactory.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007-2008 by Ilya Kotov * + * Copyright (C) 2007-2012 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -34,12 +34,12 @@ class OutputPulseAudioFactory : public QObject, OutputFactory { Q_OBJECT -Q_INTERFACES(OutputFactory); +Q_INTERFACES(OutputFactory) public: const OutputProperties properties() const; Output* create(QObject* parent); - VolumeControl *createVolumeControl(QObject *parent); + Volume *createVolume(); void showSettings(QWidget* parent); void showAbout(QWidget *parent); QTranslator *createTranslator(QObject *parent); diff --git a/src/plugins/Output/waveout/outputwaveoutfactory.cpp b/src/plugins/Output/waveout/outputwaveoutfactory.cpp index 38c7a0a67..35b18b26f 100644 --- a/src/plugins/Output/waveout/outputwaveoutfactory.cpp +++ b/src/plugins/Output/waveout/outputwaveoutfactory.cpp @@ -19,7 +19,6 @@ ***************************************************************************/
#include <QtGui>
-
#include "outputwaveout.h"
#include "outputwaveoutfactory.h"
@@ -39,7 +38,7 @@ Output* OutputWaveOutFactory::create(QObject* parent) return new OutputWaveOut(parent);
}
-VolumeControl *OutputWaveOutFactory::createVolumeControl(QObject *)
+Volume *OutputWaveOutFactory::createVolume()
{
return 0;
}
diff --git a/src/plugins/Output/waveout/outputwaveoutfactory.h b/src/plugins/Output/waveout/outputwaveoutfactory.h index ac43dfcbf..2ffd1da59 100644 --- a/src/plugins/Output/waveout/outputwaveoutfactory.h +++ b/src/plugins/Output/waveout/outputwaveoutfactory.h @@ -36,7 +36,7 @@ Q_INTERFACES(OutputFactory) public:
const OutputProperties properties() const;
Output* create(QObject* parent);
- VolumeControl *createVolumeControl(QObject *parent);
+ Volume *createVolume();
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 4e4c1218c..f3cd1a1d0 100644 --- a/src/qmmp/CMakeLists.txt +++ b/src/qmmp/CMakeLists.txt @@ -79,6 +79,7 @@ SET(libqmmp_HDRS inputsourcefactory.h enginefactory.h metadatamanager.h + volume.h ) SET(libqmmp_MOC_HDRS @@ -86,7 +87,7 @@ SET(libqmmp_MOC_HDRS output.h soundcore.h statehandler.h - volumecontrol.h + volumecontrol_p.h metadatamodel.h qmmpaudioengine_p.h abstractengine.h @@ -111,7 +112,7 @@ SET(libqmmp_DEVEL_HDRS effect.h qmmp.h statehandler.h - volumecontrol.h + volume.h metadatamodel.h tagmodel.h abstractengine.h diff --git a/src/qmmp/output.cpp b/src/qmmp/output.cpp index f5f2d7553..4370f9ee3 100644 --- a/src/qmmp/output.cpp +++ b/src/qmmp/output.cpp @@ -13,7 +13,7 @@ #include "audioparameters.h" #include "qmmpsettings.h" #include "buffer.h" -#include "volumecontrol.h" +#include "volumecontrol_p.h" #include "qmmp.h" #include "output.h" diff --git a/src/qmmp/outputfactory.h b/src/qmmp/outputfactory.h index 6c9646ac1..5f01bfc31 100644 --- a/src/qmmp/outputfactory.h +++ b/src/qmmp/outputfactory.h @@ -26,7 +26,7 @@ class QString; class QIODevice; class QWidget; class QTranslator; -class VolumeControl; +class Volume; class Decoder; class Output; @@ -73,7 +73,7 @@ public: * Returns \b 0 if volume control is not supported by plugin. * @param parent Parent object. */ - virtual VolumeControl *createVolumeControl(QObject *parent) = 0; + virtual Volume *createVolume() = 0; /*! * Shows settings dialog. * @param parent Parent widget. diff --git a/src/qmmp/qmmp.pro b/src/qmmp/qmmp.pro index 4a7138ace..549156c79 100644 --- a/src/qmmp/qmmp.pro +++ b/src/qmmp/qmmp.pro @@ -1,6 +1,6 @@ unix:include(../../qmmp.pri) win32:include(../../qmmp.pri) -HEADERS += recycler.h \ +HEADERS += \ buffer.h \ decoder.h \ output.h \ @@ -17,7 +17,6 @@ HEADERS += recycler.h \ statehandler.h \ qmmp.h \ fileinfo.h \ - volumecontrol.h \ metadatamodel.h \ tagmodel.h \ abstractengine.h \ @@ -33,7 +32,10 @@ HEADERS += recycler.h \ audioconverter_p.h \ qmmpsettings.h \ eqsettings.h \ - qmmpevents_p.h + qmmpevents_p.h \ + volume.h \ + volumecontrol_p.h \ + recycler.h SOURCES += recycler.cpp \ decoder.cpp \ output.cpp \ @@ -81,7 +83,7 @@ contains(CONFIG, SVN_VERSION) { } unix { target.path = $$LIB_DIR - devel.files += recycler.h \ + devel.files += \ buffer.h \ decoder.h \ output.h \ @@ -95,7 +97,6 @@ unix { statehandler.h \ qmmp.h \ fileinfo.h \ - volumecontrol.h \ metadatamodel.h \ tagmodel.h \ abstractengine.h \ @@ -105,10 +106,19 @@ unix { enginefactory.h \ metadatamanager.h \ qmmpsettings.h \ - eqsettings.h + eqsettings.h \ + volume.h \ + recycler.h devel.path = /include/qmmp INSTALLS += target \ devel DESTDIR = . } INCLUDEPATH += ./ + + + + + + + diff --git a/src/qmmp/soundcore.cpp b/src/qmmp/soundcore.cpp index 856f035e5..f56d8c963 100644 --- a/src/qmmp/soundcore.cpp +++ b/src/qmmp/soundcore.cpp @@ -29,7 +29,7 @@ #include "effect.h" #include "statehandler.h" #include "inputsource.h" -#include "volumecontrol.h" +#include "volumecontrol_p.h" #include "enginefactory.h" #include "metadatamanager.h" #include "qmmpsettings.h" @@ -46,18 +46,18 @@ SoundCore::SoundCore(QObject *parent) m_decoder = 0; m_parentWidget = 0; m_engine = 0; - m_volumeControl = 0; m_nextState = NO_ENGINE; m_handler = new StateHandler(this); + m_volumeControl = new VolumeControl(this); connect(m_handler, SIGNAL(elapsedChanged(qint64)), SIGNAL(elapsedChanged(qint64))); connect(m_handler, SIGNAL(bitrateChanged(int)), SIGNAL(bitrateChanged(int))); connect(m_handler, SIGNAL(frequencyChanged(quint32)), SIGNAL(frequencyChanged(quint32))); connect(m_handler, SIGNAL(sampleSizeChanged(int)), SIGNAL(sampleSizeChanged(int))); connect(m_handler, SIGNAL(channelsChanged(int)), SIGNAL(channelsChanged(int))); connect(m_handler, SIGNAL(bufferingProgress(int)), SIGNAL(bufferingProgress(int))); - updateVolume(); connect(QmmpSettings::instance(), SIGNAL(eqSettingsChanged()), SIGNAL(eqSettingsChanged())); - connect(QmmpSettings::instance(), SIGNAL(audioSettingsChanged()), SLOT(updateVolume())); + connect(QmmpSettings::instance(), SIGNAL(audioSettingsChanged()), m_volumeControl, SLOT(reload())); + connect(m_volumeControl, SIGNAL(volumeChanged(int, int)), SIGNAL(volumeChanged(int, int))); } SoundCore::~SoundCore() @@ -108,7 +108,7 @@ void SoundCore::stop() qDeleteAll(m_sources); m_sources.clear(); m_nextState = NO_ENGINE; - updateVolume(); + m_volumeControl->reload(); if(state() == Qmmp::NormalError || state() == Qmmp::FatalError || state() == Qmmp::Buffering) StateHandler::instance()->dispatch(Qmmp::Stopped); //clear error and buffering state } @@ -167,18 +167,6 @@ int SoundCore::rightVolume() return m_volumeControl->right(); } -void SoundCore::updateVolume() -{ - if (m_engine) - m_engine->mutex()->lock(); - if(m_volumeControl) - delete m_volumeControl; - m_volumeControl = VolumeControl::create(this); - connect(m_volumeControl, SIGNAL(volumeChanged(int, int)), SIGNAL(volumeChanged(int, int))); - if (m_engine) - m_engine->mutex()->unlock(); -} - qint64 SoundCore::elapsed() { return m_handler->elapsed(); diff --git a/src/qmmp/soundcore.h b/src/qmmp/soundcore.h index e1be74c93..9e7e593b0 100644 --- a/src/qmmp/soundcore.h +++ b/src/qmmp/soundcore.h @@ -213,7 +213,6 @@ signals: private slots: void startNextSource(); void startNextEngine(); - void updateVolume(); private: bool event(QEvent *e); diff --git a/src/qmmp/volume.h b/src/qmmp/volume.h new file mode 100644 index 000000000..678bb1917 --- /dev/null +++ b/src/qmmp/volume.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2012 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 VOLUME_H +#define VOLUME_H + +#endif // VOLUME_H + + +/*! @brief The Volume class is a provides volume API + * @author Ilya Kotov <forkotov02@hotmail.ru> + */ +class Volume +{ +public: + virtual ~Volume(){} + /*! + * Volume control channel enum + */ + enum Channel + { + LEFT_CHANNEL = 0, /*!< Right channel */ + RIGHT_CHANNEL /*!< Left channel */ + }; + /*! + * Setups volume level. + * Subclass should reimplement this fucntion. + * @param channel Channel + * @param value Volume level. It should be \b 0..100 + */ + virtual void setVolume(int channel, int value) = 0; + /*! + * Returns volume level of the \b channel. + */ + virtual int volume(int channel) = 0; +}; diff --git a/src/qmmp/volumecontrol.cpp b/src/qmmp/volumecontrol.cpp index 7f6e848df..3a2d20770 100644 --- a/src/qmmp/volumecontrol.cpp +++ b/src/qmmp/volumecontrol.cpp @@ -23,7 +23,7 @@ #include <QSettings> #include "qmmpsettings.h" #include "output.h" -#include "volumecontrol.h" +#include "volumecontrol_p.h" VolumeControl::VolumeControl(QObject *parent) : QObject(parent) @@ -31,30 +31,28 @@ VolumeControl::VolumeControl(QObject *parent) m_left = 0; m_right = 0; m_prev_block = false; + m_volume = 0; + m_timer = new QTimer(this); + connect(m_timer, SIGNAL(timeout()), SLOT(checkVolume())); + reload(); } VolumeControl::~VolumeControl() { + if(m_volume) + delete m_volume; } -VolumeControl *VolumeControl::create(QObject *parent) +int VolumeControl::left() { - if(QmmpSettings::instance()->useSoftVolume()) - return new SoftwareVolume(parent); - VolumeControl *control = 0; - if (Output::currentFactory()) - control = Output::currentFactory()->createVolumeControl(parent); - if (!control) - return new SoftwareVolume(parent); - QTimer *m_timer = new QTimer(control); - connect(m_timer, SIGNAL(timeout()), control, SLOT(checkVolume())); - m_timer->start(125); - return control; + return m_left; } -int VolumeControl::left() +void VolumeControl::setVolume(int left, int right) { - return m_left; + m_volume->setVolume(Volume::LEFT_CHANNEL, left); + m_volume->setVolume(Volume::RIGHT_CHANNEL, right); + checkVolume(); } int VolumeControl::right() @@ -64,8 +62,9 @@ int VolumeControl::right() void VolumeControl::checkVolume() { - int l = 0, r = 0; - volume(&l, &r); + int l = m_volume->volume(Volume::LEFT_CHANNEL); + int r = m_volume->volume(Volume::RIGHT_CHANNEL); + l = (l > 100) ? 100 : l; r = (r > 100) ? 100 : r; l = (l < 0) ? 0 : l; @@ -81,18 +80,36 @@ void VolumeControl::checkVolume() m_prev_block = signalsBlocked (); } +void VolumeControl::reload() +{ + m_timer->stop(); + if(m_volume) + { + delete m_volume; + m_volume = 0; + } + if(!QmmpSettings::instance()->useSoftVolume()) + { + m_volume = Output::currentFactory()->createVolume(); + m_timer->start(150); + } + if(!m_volume) + { + m_volume = new SoftwareVolume; + blockSignals(true); + checkVolume(); + blockSignals(false); + QTimer::singleShot(125, this, SLOT(checkVolume())); + } +} + SoftwareVolume *SoftwareVolume::m_instance = 0; -SoftwareVolume::SoftwareVolume(QObject *parent) - : VolumeControl(parent) +SoftwareVolume::SoftwareVolume() { QSettings settings(Qmmp::configFile(), QSettings::IniFormat); m_left = settings.value("Volume/left", 80).toInt(); m_right = settings.value("Volume/right", 80).toInt(); - blockSignals(true); - checkVolume(); - blockSignals(false); - QTimer::singleShot(125, this, SLOT(checkVolume())); m_scaleLeft = (double)m_left/100.0; m_scaleRight = (double)m_right/100.0; m_instance = this; @@ -106,19 +123,21 @@ SoftwareVolume::~SoftwareVolume() m_instance = 0; } -void SoftwareVolume::setVolume(int left, int right) +void SoftwareVolume::setVolume(int channel, int value) { - m_left = left; - m_right = right; - checkVolume(); + if(channel == Volume::LEFT_CHANNEL) + m_left = value; + else + m_right = value; m_scaleLeft = (double)m_left/100.0; m_scaleRight = (double)m_right/100.0; } -void SoftwareVolume::volume(int *left, int *right) +int SoftwareVolume::volume(int channel) { - *left = m_left; - *right = m_right; + if(channel == Volume::LEFT_CHANNEL) + return m_left; + return m_right; } void SoftwareVolume::changeVolume(Buffer *b, int chan, Qmmp::AudioFormat format) diff --git a/src/qmmp/volumecontrol.h b/src/qmmp/volumecontrol_p.h index dddb64a8f..246d25154 100644 --- a/src/qmmp/volumecontrol.h +++ b/src/qmmp/volumecontrol_p.h @@ -17,14 +17,18 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef VOLUMECONTROL_H -#define VOLUMECONTROL_H +#ifndef VOLUMECONTROL_P_H +#define VOLUMECONTROL_P_H #include <QObject> #include "qmmp.h" +#include "volume.h" #include "buffer.h" -/*! @brief The VolumeControl class provides the base interface class for volume control. +class QTimer; +class SoftwareVolume; + +/*! @brief The VolumeControl class provides volume control access * @author Ilya Kotov <forkotov02@hotmail.ru> */ class VolumeControl : public QObject @@ -46,7 +50,7 @@ public: * @param left Left channel volume level. It should be \b 0..100 * @param right Right channel volume level. It should be \b 0..100 */ - virtual void setVolume(int left, int right) = 0; + void setVolume(int left, int right); /*! * Returns left channel volume. */ @@ -55,11 +59,6 @@ public: * Returns right channel volume. */ int right(); - /*! - * Creates output volume control object if implemented, \b otherwise it creates SoftwareVolume object. - * @param parent Parent object. - */ - static VolumeControl *create(QObject *parent = 0); signals: /*! @@ -74,62 +73,32 @@ public slots: * Forces the volumeChanged signal to emit. */ void checkVolume(); - -protected: /*! - * Gets current volume. - * @param left Pointer to the left volume level. - * @param right Pointer to the right volume level + * */ - virtual void volume(int *left, int *right) = 0; + void reload(); private: int m_left, m_right; bool m_prev_block; + Volume *m_volume; + QTimer *m_timer; }; /*! @brief The SoftwareVolume class provides access to the software volume control. * @author Ilya Kotov <forkotov02@hotmail.ru> */ -class SoftwareVolume : public VolumeControl +class SoftwareVolume : public Volume { - Q_OBJECT public: - /*! - * Object constructor. - * @param parent Parent object. - */ - SoftwareVolume(QObject *parent = 0); - /*! - * Destructor. - */ + SoftwareVolume(); ~SoftwareVolume(); - /*! - * Setups volume level. - * Subclass should reimplement this fucntion. - * @param left Left channel volume level. It should be \b 0..100 - * @param right Right channel volume level. It should be \b 0..100 - */ - void setVolume(int left, int right); - /*! - * Changes volume of buffer. - * @param b Pointer to the buffer object. - * @param chan Number of channels. - * @param format Audio format. - */ + + void setVolume(int channel, int value); + int volume(int channel); void changeVolume(Buffer *b, int chan, Qmmp::AudioFormat format); - /*! - * Returns software volume object instance. - */ - static SoftwareVolume *instance(); -protected: - /*! @internal - * Gets current volume. - * @param left Pointer to the left volume level. - * @param right Pointer to the right volume level - */ - void volume(int *left, int *right); + static SoftwareVolume *instance(); private: int m_left, m_right; |
