diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2019-03-09 08:02:24 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2019-03-09 08:02:24 +0000 |
| commit | 432a7f1e84ea211210b2f6b3d2acddf0c33d4ef2 (patch) | |
| tree | 58b1b06715a382ab683e9363c28f9468fc4ab5b3 /src | |
| parent | 567b27e47befd4978c736851f900014c827d5ca2 (diff) | |
| download | qmmp-432a7f1e84ea211210b2f6b3d2acddf0c33d4ef2.tar.gz qmmp-432a7f1e84ea211210b2f6b3d2acddf0c33d4ef2.tar.bz2 qmmp-432a7f1e84ea211210b2f6b3d2acddf0c33d4ef2.zip | |
changed volume api
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8746 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/Output/alsa/outputalsa.cpp | 4 | ||||
| -rw-r--r-- | src/plugins/Output/alsa/outputalsa.h | 2 | ||||
| -rw-r--r-- | src/plugins/Output/pulseaudio/outputpulseaudio.cpp | 23 | ||||
| -rw-r--r-- | src/plugins/Output/pulseaudio/outputpulseaudio.h | 9 | ||||
| -rw-r--r-- | src/qmmp/output.cpp | 5 | ||||
| -rw-r--r-- | src/qmmp/output.h | 5 | ||||
| -rw-r--r-- | src/qmmp/outputwriter.cpp | 8 | ||||
| -rw-r--r-- | src/qmmp/outputwriter_p.h | 2 | ||||
| -rw-r--r-- | src/qmmp/qmmpaudioengine.cpp | 5 | ||||
| -rw-r--r-- | src/qmmp/soundcore.cpp | 16 | ||||
| -rw-r--r-- | src/qmmp/soundcore.h | 1 | ||||
| -rw-r--r-- | src/qmmp/volume.cpp | 14 | ||||
| -rw-r--r-- | src/qmmp/volume.h | 22 | ||||
| -rw-r--r-- | src/qmmp/volumecontrol.cpp | 63 | ||||
| -rw-r--r-- | src/qmmp/volumecontrol_p.h | 10 |
15 files changed, 119 insertions, 70 deletions
diff --git a/src/plugins/Output/alsa/outputalsa.cpp b/src/plugins/Output/alsa/outputalsa.cpp index 0f4dd5d37..8a383558d 100644 --- a/src/plugins/Output/alsa/outputalsa.cpp +++ b/src/plugins/Output/alsa/outputalsa.cpp @@ -558,7 +558,7 @@ int VolumeALSA::getMixer(snd_mixer_t **mixer, QString card) return (*mixer != NULL); } -bool VolumeALSA::hasNotifySignal() const +/*bool VolumeALSA::hasNotifySignal() const { return true; -} +}*/ diff --git a/src/plugins/Output/alsa/outputalsa.h b/src/plugins/Output/alsa/outputalsa.h index 91ac401b6..57d850b3f 100644 --- a/src/plugins/Output/alsa/outputalsa.h +++ b/src/plugins/Output/alsa/outputalsa.h @@ -77,7 +77,7 @@ public: void setVolume(const VolumeSettings &vol) override; VolumeSettings volume() const override; - bool hasNotifySignal() const override; + //bool hasNotifySignal() const override; private: //alsa mixer diff --git a/src/plugins/Output/pulseaudio/outputpulseaudio.cpp b/src/plugins/Output/pulseaudio/outputpulseaudio.cpp index 65fa0bff6..4017e5a87 100644 --- a/src/plugins/Output/pulseaudio/outputpulseaudio.cpp +++ b/src/plugins/Output/pulseaudio/outputpulseaudio.cpp @@ -163,6 +163,8 @@ bool OutputPulseAudio::initialize(quint32 freq, ChannelMap map, Qmmp::AudioForma return false; } success = false; + if(volumeControl) + setMuted(volumeControl->isMuted()); op = pa_context_get_sink_input_info(m_ctx, pa_stream_get_index(m_stream), OutputPulseAudio::info_cb, &success); if(!process(op) || !success) { @@ -313,7 +315,7 @@ void OutputPulseAudio::info_cb(pa_context *ctx, const pa_sink_input_info *info, return; if(volumeControl && pa_context_get_state(ctx) == PA_CONTEXT_READY) - volumeControl->updateVolume(info->volume); + volumeControl->updateVolume(info->volume, info->mute > 0); if(data) *(bool *) data = true; @@ -348,9 +350,10 @@ VolumePulseAudio::~VolumePulseAudio() OutputPulseAudio::volumeControl = nullptr; } -void VolumePulseAudio::updateVolume(const pa_cvolume &v) +void VolumePulseAudio::updateVolume(const pa_cvolume &v, bool muted) { m_volume = cvolumeToVolumeSettings(v); + m_muted = muted; emit changed(); } @@ -366,9 +369,21 @@ VolumeSettings VolumePulseAudio::volume() const return m_volume; } -bool VolumePulseAudio::hasNotifySignal() const +bool VolumePulseAudio::isMuted() const { - return true; + return m_muted; +} + +void VolumePulseAudio::setMuted(bool mute) +{ + if(OutputPulseAudio::instance) + OutputPulseAudio::instance->setMuted(mute); + m_muted = mute; +} + +Volume::VolumeFlags VolumePulseAudio::flags() const +{ + return Volume::IsMuteSupported | Volume::HasNotifySignal; } VolumeSettings VolumePulseAudio::cvolumeToVolumeSettings(const pa_cvolume &v) diff --git a/src/plugins/Output/pulseaudio/outputpulseaudio.h b/src/plugins/Output/pulseaudio/outputpulseaudio.h index ff320abf8..fca728bf1 100644 --- a/src/plugins/Output/pulseaudio/outputpulseaudio.h +++ b/src/plugins/Output/pulseaudio/outputpulseaudio.h @@ -48,7 +48,7 @@ public: void reset() override; void suspend() override; void resume() override; - void setMuted(bool mute) override; + void setMuted(bool mute); void setVolume(const VolumeSettings &v); static OutputPulseAudio *instance; @@ -81,15 +81,18 @@ public: VolumePulseAudio(); ~VolumePulseAudio(); - void updateVolume(const pa_cvolume &v); + void updateVolume(const pa_cvolume &v, bool muted); void setVolume(const VolumeSettings &vol) override; VolumeSettings volume() const override; - bool hasNotifySignal() const override; + bool isMuted() const override; + void setMuted(bool mute) override; + VolumeFlags flags() const override; static VolumeSettings cvolumeToVolumeSettings(const pa_cvolume &v); static pa_cvolume volumeSettingsToCvolume(const VolumeSettings &v, int channels); private: VolumeSettings m_volume; + bool m_muted = false; }; #endif // OUTPUTPULSEAUDIO_H diff --git a/src/qmmp/output.cpp b/src/qmmp/output.cpp index cc3555558..ff5bd0495 100644 --- a/src/qmmp/output.cpp +++ b/src/qmmp/output.cpp @@ -65,11 +65,6 @@ void Output::suspend() void Output::resume() {} -void Output::setMuted(bool mute) -{ - Q_UNUSED(mute); -} - void Output::setTrackInfo(const TrackInfo &info) { Q_UNUSED(info); diff --git a/src/qmmp/output.h b/src/qmmp/output.h index 26cb1e8a9..8a2b359ce 100644 --- a/src/qmmp/output.h +++ b/src/qmmp/output.h @@ -77,11 +77,6 @@ public: */ virtual void resume(); /*! - * Mutes/Restores volume. Default implementation does nothing. - * @param mute - state of volume (\b true - mute, \b false - restore) - */ - virtual void setMuted(bool mute); - /*! * Sets track information for output. * Default implementation does nothing. * Reimplement this function to receive metadata. diff --git a/src/qmmp/outputwriter.cpp b/src/qmmp/outputwriter.cpp index d2bf74ce2..f09620d98 100644 --- a/src/qmmp/outputwriter.cpp +++ b/src/qmmp/outputwriter.cpp @@ -108,7 +108,7 @@ void OutputWriter::stop() m_user_stop = true; } -void OutputWriter::setMuted(bool muted) +/*void OutputWriter::setMuted(bool muted) { m_muted = muted; if(isRunning() && m_output) @@ -117,7 +117,7 @@ void OutputWriter::setMuted(bool muted) m_output->setMuted(muted); m_mutex.unlock(); } -} +}*/ void OutputWriter::finish() { @@ -234,8 +234,6 @@ void OutputWriter::run() m_mutex.unlock (); return; } - if(m_muted) - m_output->setMuted(true); m_mutex.unlock (); bool done = false; @@ -304,8 +302,6 @@ void OutputWriter::run() dispatchVisual(b); if (SoftwareVolume::instance()) SoftwareVolume::instance()->changeVolume(b, m_channels); - //if (m_muted) - // memset(b->data, 0, b->size * sizeof(float)); if(m_channel_converter) m_channel_converter->applyEffect(b); l = 0; diff --git a/src/qmmp/outputwriter_p.h b/src/qmmp/outputwriter_p.h index 7ec46d97b..a0fb6f9c7 100644 --- a/src/qmmp/outputwriter_p.h +++ b/src/qmmp/outputwriter_p.h @@ -66,7 +66,7 @@ public: * Mutes/Restores volume * @param mute state of volume (\b true - mute, \b false - restore) */ - void setMuted(bool muted); + //void setMuted(bool muted); /*! * Requests playback to finish. */ diff --git a/src/qmmp/qmmpaudioengine.cpp b/src/qmmp/qmmpaudioengine.cpp index d140a5bea..07f1e6d3c 100644 --- a/src/qmmp/qmmpaudioengine.cpp +++ b/src/qmmp/qmmpaudioengine.cpp @@ -252,10 +252,6 @@ void QmmpAudioEngine::pause() void QmmpAudioEngine::setMuted(bool muted) { m_muted = muted; - if(m_output) - { - m_output->setMuted(muted); - } } void QmmpAudioEngine::stop() @@ -622,7 +618,6 @@ void QmmpAudioEngine::attachMetaData(Decoder *decoder, DecoderFactory *factory, OutputWriter *QmmpAudioEngine::createOutput() { OutputWriter *output = new OutputWriter(nullptr); - output->setMuted(m_muted); if (!output->initialize(m_ap.sampleRate(), m_ap.channelMap())) { delete output; diff --git a/src/qmmp/soundcore.cpp b/src/qmmp/soundcore.cpp index 5b18a9bfe..2f21941e7 100644 --- a/src/qmmp/soundcore.cpp +++ b/src/qmmp/soundcore.cpp @@ -46,7 +46,6 @@ SoundCore::SoundCore(QObject *parent) m_instance = this; m_engine = nullptr; m_nextState = NO_ENGINE; - m_muted = false; m_handler = new StateHandler(this); m_volumeControl = new VolumeControl(this); connect(m_handler, SIGNAL(elapsedChanged(qint64)), SIGNAL(elapsedChanged(qint64))); @@ -58,6 +57,7 @@ SoundCore::SoundCore(QObject *parent) connect(m_volumeControl, SIGNAL(volumeChanged(int, int)), SIGNAL(volumeChanged(int, int))); connect(m_volumeControl, SIGNAL(volumeChanged(int)), SIGNAL(volumeChanged(int))); connect(m_volumeControl, SIGNAL(balanceChanged(int)), SIGNAL(balanceChanged(int))); + connect(m_volumeControl, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged(bool))); } SoundCore::~SoundCore() @@ -158,13 +158,9 @@ void SoundCore::setVolume(int L, int R) void SoundCore::setMuted(bool mute) { - if(m_muted != mute) - { - m_muted = mute; - emit mutedChanged(mute); - if(m_engine) - m_engine->setMuted(mute); - } + m_volumeControl->setMuted(mute); + if(m_engine) + m_engine->setMuted(mute); } void SoundCore::changeVolume(int delta) @@ -217,7 +213,7 @@ int SoundCore::balance() const bool SoundCore::isMuted() const { - return m_muted; + return m_volumeControl->isMuted(); } qint64 SoundCore::elapsed() const @@ -283,7 +279,7 @@ void SoundCore::startNextSource() { if((m_engine = AbstractEngine::create(s, this))) { - m_engine->setMuted(m_muted); + m_engine->setMuted(m_volumeControl->isMuted()); m_engine->play(); m_nextState = NO_ENGINE; return; diff --git a/src/qmmp/soundcore.h b/src/qmmp/soundcore.h index 1d47199df..b28c2124f 100644 --- a/src/qmmp/soundcore.h +++ b/src/qmmp/soundcore.h @@ -274,7 +274,6 @@ private: AbstractEngine *m_engine; QQueue<InputSource *> m_sources; int m_nextState; - bool m_muted; }; #endif diff --git a/src/qmmp/volume.cpp b/src/qmmp/volume.cpp index d4e37197d..ddea0a6f1 100644 --- a/src/qmmp/volume.cpp +++ b/src/qmmp/volume.cpp @@ -20,7 +20,17 @@ #include "volume.h" -bool Volume::hasNotifySignal() const +bool Volume::isMuted() const { - return false; + return m_mutedInternal; +} + +void Volume::setMuted(bool mute) +{ + m_mutedInternal = mute; +} + +Volume::VolumeFlags Volume::flags() const +{ + return Volume::NoFlags; } diff --git a/src/qmmp/volume.h b/src/qmmp/volume.h index 8259e241d..69d2c02bf 100644 --- a/src/qmmp/volume.h +++ b/src/qmmp/volume.h @@ -22,6 +22,7 @@ #define VOLUME_H #include <QObject> +#include <QFlags> #include "qmmp_export.h" /*! @brief The VolumeSettings structure stores volume levels @@ -41,6 +42,14 @@ class QMMP_EXPORT Volume : public QObject { Q_OBJECT public: + enum VolumeFlag + { + NoFlags = 0x0, + IsMuteSupported = 0x1, + HasNotifySignal = 0x2, /*!< Indicates the object supports change notification via + * emitting changed() signal so polling the volume is not needed */ + }; + Q_DECLARE_FLAGS(VolumeFlags, VolumeFlag) /*! * Destructor. */ @@ -55,17 +64,24 @@ public: * Returns volume level of the \b channel. */ virtual VolumeSettings volume() const = 0; + virtual bool isMuted() const; /*! - * Returns true if the object supports change notification via - * emitting changed() signal so polling the volume is not needed. + * Mutes/Restores volume. Default implementation does nothing. + * @param mute - state of volume (\b true - mute, \b false - restore) */ - virtual bool hasNotifySignal() const; + virtual void setMuted(bool mute); + virtual VolumeFlags flags() const; signals: /*! * Emitted if volume is changed. */ void changed(); + +private: + bool m_mutedInternal = false; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(Volume::VolumeFlags) + #endif // VOLUME_H diff --git a/src/qmmp/volumecontrol.cpp b/src/qmmp/volumecontrol.cpp index b2fb0317a..27dd59732 100644 --- a/src/qmmp/volumecontrol.cpp +++ b/src/qmmp/volumecontrol.cpp @@ -25,13 +25,8 @@ #include "output.h" #include "volumecontrol_p.h" -VolumeControl::VolumeControl(QObject *parent) - : QObject(parent) +VolumeControl::VolumeControl(QObject *parent) : QObject(parent) { - m_left = 0; - m_right = 0; - m_prev_block = false; - m_volume = nullptr; m_timer = new QTimer(this); connect(m_timer, SIGNAL(timeout()), SLOT(checkVolume())); reload(); @@ -71,6 +66,15 @@ void VolumeControl::setBalance(int balance) volume()+qMin(balance,0)*volume()/100); } +void VolumeControl::setMuted(bool muted) +{ + if(m_muted != muted) + { + m_volume->setMuted(muted); + checkVolume(); + } +} + int VolumeControl::left() const { return m_left; @@ -92,16 +96,26 @@ int VolumeControl::balance() const return v > 0 ? (m_right - m_left)*100/v : 0; } +bool VolumeControl::isMuted() const +{ + return m_muted; +} + void VolumeControl::checkVolume() { VolumeSettings v = m_volume->volume(); int l = v.left; int r = v.right; + bool muted = m_volume->isMuted(); + + l = qBound(0, l, 100); + r = qBound(0, r, 100); + if(m_muted != muted || (m_prev_block && !signalsBlocked ())) + { + m_muted = muted; + emit mutedChanged(m_muted); + } - l = (l > 100) ? 100 : l; - r = (r > 100) ? 100 : r; - l = (l < 0) ? 0 : l; - r = (r < 0) ? 0 : r; if (m_left != l || m_right != r) //volume has been changed { m_left = l; @@ -122,26 +136,37 @@ void VolumeControl::checkVolume() void VolumeControl::reload() { m_timer->stop(); + bool restore = false; if(m_volume) { + restore = true; delete m_volume; m_volume = nullptr; } + if(!QmmpSettings::instance()->useSoftVolume() && Output::currentFactory()) + m_volume = Output::currentFactory()->createVolume(); + + if(m_volume) { - if((m_volume = Output::currentFactory()->createVolume())) + if(restore) + m_volume->setMuted(m_muted); + + if(m_volume->flags() & Volume::HasNotifySignal) + { + checkVolume(); + connect(m_volume, SIGNAL(changed()), SLOT(checkVolume())); + } + else { - if(m_volume->hasNotifySignal()) - { - checkVolume(); - connect(m_volume, SIGNAL(changed()), SLOT(checkVolume())); - } - else - m_timer->start(150); // fallback to polling if change notification is not available. + m_timer->start(150); // fallback to polling if change notification is not available. } } - if(!m_volume) + else { + if(restore) + m_volume->setMuted(m_muted); + m_volume = new SoftwareVolume; blockSignals(true); checkVolume(); diff --git a/src/qmmp/volumecontrol_p.h b/src/qmmp/volumecontrol_p.h index 1f5e5f84b..c685cc0d0 100644 --- a/src/qmmp/volumecontrol_p.h +++ b/src/qmmp/volumecontrol_p.h @@ -66,6 +66,7 @@ public: * @param balance balance between left and right channels \b [-100..100]. */ void setBalance(int balance); + void setMuted(bool muted); /*! * Returns left channel volume. */ @@ -83,6 +84,7 @@ public: */ int balance() const; + bool isMuted() const; signals: /*! @@ -101,6 +103,7 @@ signals: * @param volume new balance value. */ void balanceChanged(int balance); + void mutedChanged(bool muted); public slots: /*! @@ -113,9 +116,10 @@ public slots: void reload(); private: - int m_left, m_right; - bool m_prev_block; - Volume *m_volume; + int m_left = 0, m_right = 0; + bool m_prev_block = false; + bool m_muted = false; + Volume *m_volume = nullptr; QTimer *m_timer; }; |
