aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app/builtincommandlineoption.cpp6
-rw-r--r--src/plugins/Engines/mplayer/mplayerengine.cpp11
-rw-r--r--src/plugins/Engines/mplayer/mplayerengine.h2
-rw-r--r--src/qmmp/abstractengine.h5
-rw-r--r--src/qmmp/outputwriter.cpp9
-rw-r--r--src/qmmp/outputwriter_p.h6
-rw-r--r--src/qmmp/qmmpaudioengine.cpp13
-rw-r--r--src/qmmp/qmmpaudioengine_p.h2
-rw-r--r--src/qmmp/soundcore.cpp19
-rw-r--r--src/qmmp/soundcore.h15
10 files changed, 88 insertions, 0 deletions
diff --git a/src/app/builtincommandlineoption.cpp b/src/app/builtincommandlineoption.cpp
index 3465b4059..48d11f1e1 100644
--- a/src/app/builtincommandlineoption.cpp
+++ b/src/app/builtincommandlineoption.cpp
@@ -42,6 +42,7 @@ BuiltinCommandLineOption::BuiltinCommandLineOption(QObject *parent) : QObject(pa
<< "--jump-to-file" << "-j"
<< "--quit" << "-q"
<< "--volume"
+ << "--toggle-mute"
<< "--next" << "--previous"
<< "--toggle-visibility"
<< "--add-file" << "--add-dir";
@@ -68,6 +69,7 @@ const QString BuiltinCommandLineOption::helpString() const
"-j, --jump-to-file "+tr("Display Jump to File dialog")+ "\n" +
"-q, --quit "+tr("Quit application") + "\n" +
"--volume <0..100> "+tr("Set playback volume (example: qmmp --volume 20)") + "\n"
+ "--toggle-mute "+tr("Mute/Restore volume") + "\n"
"--next "+tr("Skip forward in playlist")+ "\n" +
"--previous "+tr("Skip backwards in playlist")+"\n" +
"--toggle-visibility "+tr("Show/hide application")+ "\n" +
@@ -201,6 +203,10 @@ void BuiltinCommandLineOption::executeCommand(const QString &option_string,
if (ok)
core->setVolume(volume,volume);
}
+ else if (option_string == "--toggle-mute")
+ {
+ core->setMuted(!core->isMuted());
+ }
}
QHash <QString, QStringList> BuiltinCommandLineOption::splitArgs(const QStringList &args) const
diff --git a/src/plugins/Engines/mplayer/mplayerengine.cpp b/src/plugins/Engines/mplayer/mplayerengine.cpp
index d4d8b37ae..e0de42f40 100644
--- a/src/plugins/Engines/mplayer/mplayerengine.cpp
+++ b/src/plugins/Engines/mplayer/mplayerengine.cpp
@@ -88,6 +88,7 @@ MplayerEngine::MplayerEngine(QObject *parent)
m_bitsPerSample = 0;
m_length = 0;
m_currentTime = 0;
+ m_muted = false;
m_process = new QProcess(this);
connect(m_process, SIGNAL(readyReadStandardOutput()), SLOT(readStdOut()));
}
@@ -174,6 +175,14 @@ void MplayerEngine::pause()
m_process->write("pause\n");
}
+void MplayerEngine::setMuted(bool muted)
+{
+ if(m_process->state() == QProcess::Running)
+ {
+ m_process->write(muted ? "mute 1\n" : "mute 0\n");
+ }
+}
+
void MplayerEngine::readStdOut()
{
QString line = QString::fromLocal8Bit(m_process->readAll ()).trimmed();
@@ -246,4 +255,6 @@ void MplayerEngine::startMplayerProcess()
m_source->deleteLater();
m_source = 0;
m_currentTime = 0;
+ if(m_muted)
+ setMuted(true);
}
diff --git a/src/plugins/Engines/mplayer/mplayerengine.h b/src/plugins/Engines/mplayer/mplayerengine.h
index 961a86cb6..de702a7ea 100644
--- a/src/plugins/Engines/mplayer/mplayerengine.h
+++ b/src/plugins/Engines/mplayer/mplayerengine.h
@@ -55,6 +55,7 @@ public:
void seek(qint64);
void stop();
void pause();
+ void setMuted(bool muted);
private slots:
void readStdOut();
@@ -68,6 +69,7 @@ private:
int m_samplerate;
int m_channels;
int m_bitsPerSample;
+ bool m_muted;
qint64 m_currentTime;
qint64 m_length;
QQueue <InputSource*> m_sources;
diff --git a/src/qmmp/abstractengine.h b/src/qmmp/abstractengine.h
index 6ee1e9e3d..d98446e47 100644
--- a/src/qmmp/abstractengine.h
+++ b/src/qmmp/abstractengine.h
@@ -71,6 +71,11 @@ public:
*/
virtual void pause() = 0;
/*!
+ * Mutes/Restores volume. Subclass should reimplement this function.
+ * @param mute - state of volume (\b true - mute, \b false - restore)
+ */
+ virtual void setMuted(bool muted) = 0;
+ /*!
* Returns mutex pointer.
*/
QMutex *mutex();
diff --git a/src/qmmp/outputwriter.cpp b/src/qmmp/outputwriter.cpp
index 1c4353ea3..cb4f81d8f 100644
--- a/src/qmmp/outputwriter.cpp
+++ b/src/qmmp/outputwriter.cpp
@@ -18,6 +18,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
+#include <string.h>
#include "statehandler.h"
#include "visual.h"
#include "output.h"
@@ -70,6 +71,7 @@ OutputWriter::OutputWriter (QObject* parent) : QThread (parent)
m_prev_pause = false;
m_useEq = false;
m_eqEnabled = false;
+ m_muted = false;
m_settings = QmmpSettings::instance();
connect(m_settings,SIGNAL(eqSettingsChanged()), SLOT(updateEqSettings()));
updateEqSettings();
@@ -147,6 +149,11 @@ void OutputWriter::stop()
m_userStop = true;
}
+void OutputWriter::setMuted(bool muted)
+{
+ m_muted = muted;
+}
+
void OutputWriter::finish()
{
m_finish = true;
@@ -342,6 +349,8 @@ void OutputWriter::run()
dispatchVisual(b);
if (SoftwareVolume::instance())
SoftwareVolume::instance()->changeVolume(b, m_channels, m_format);
+ if (m_muted)
+ memset(b->data, 0, b->nbytes);
l = 0;
m = 0;
while (l < b->nbytes && !m_pause)
diff --git a/src/qmmp/outputwriter_p.h b/src/qmmp/outputwriter_p.h
index d744c3776..fcaecfc5f 100644
--- a/src/qmmp/outputwriter_p.h
+++ b/src/qmmp/outputwriter_p.h
@@ -59,6 +59,11 @@ public:
*/
void stop();
/*!
+ * Mutes/Restores volume
+ * @param mute state of volume (\b true - mute, \b false - restore)
+ */
+ void setMuted(bool muted);
+ /*!
* Requests playback to finish.
*/
void finish();
@@ -128,6 +133,7 @@ private:
qint64 m_visBufferSize;
QmmpSettings *m_settings;
Output *m_output;
+ bool m_muted;
};
diff --git a/src/qmmp/qmmpaudioengine.cpp b/src/qmmp/qmmpaudioengine.cpp
index 9a4bb0a33..dae7c967b 100644
--- a/src/qmmp/qmmpaudioengine.cpp
+++ b/src/qmmp/qmmpaudioengine.cpp
@@ -45,6 +45,7 @@ QmmpAudioEngine::QmmpAudioEngine(QObject *parent)
m_bks = 0;
m_decoder = 0;
m_output = 0;
+ m_muted = false;
m_replayGain = new ReplayGain;
m_settings = QmmpSettings::instance();
connect(m_settings,SIGNAL(replayGainSettingsChanged()), SLOT(updateReplayGainSettings()));
@@ -241,6 +242,17 @@ void QmmpAudioEngine::pause()
}
+void QmmpAudioEngine::setMuted(bool muted)
+{
+ m_muted = muted;
+ if(m_output)
+ {
+ m_output->mutex()->lock();
+ m_output->setMuted(muted);
+ m_output->mutex()->unlock();
+ }
+}
+
void QmmpAudioEngine::stop()
{
mutex()->lock ();
@@ -558,6 +570,7 @@ void QmmpAudioEngine::sendMetaData()
OutputWriter *QmmpAudioEngine::createOutput()
{
OutputWriter *output = new OutputWriter(0);
+ output->setMuted(m_muted);
if (!output->initialize(m_ap.sampleRate(), m_ap.channels(), m_ap.format()))
{
delete output;
diff --git a/src/qmmp/qmmpaudioengine_p.h b/src/qmmp/qmmpaudioengine_p.h
index 7878fc7a2..6134d3742 100644
--- a/src/qmmp/qmmpaudioengine_p.h
+++ b/src/qmmp/qmmpaudioengine_p.h
@@ -52,6 +52,7 @@ public:
void seek(qint64 time);
void stop();
void pause();
+ void setMuted(bool muted);
void addEffect(EffectFactory *factory);
void removeEffect(EffectFactory *factory);
@@ -88,6 +89,7 @@ private:
QHash <Decoder*, InputSource*> m_inputs;
AudioParameters m_ap;
bool m_next;
+ bool m_muted;
static QmmpAudioEngine *m_instance;
ReplayGain *m_replayGain;
QmmpSettings *m_settings;
diff --git a/src/qmmp/soundcore.cpp b/src/qmmp/soundcore.cpp
index 3e1d474f2..d57143441 100644
--- a/src/qmmp/soundcore.cpp
+++ b/src/qmmp/soundcore.cpp
@@ -45,6 +45,7 @@ SoundCore::SoundCore(QObject *parent)
m_instance = this;
m_engine = 0;
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)));
@@ -150,11 +151,23 @@ void SoundCore::setEqSettings(const EqSettings &settings)
void SoundCore::setVolume(int L, int R)
{
+ setMuted(false);
L = qBound(0, L, 100);
R = qBound(0, R, 100);
m_volumeControl->setVolume(L, R);
}
+void SoundCore::setMuted(bool mute)
+{
+ if(m_muted != mute)
+ {
+ m_muted = mute;
+ emit mutedChanged(mute);
+ if(m_engine)
+ m_engine->setMuted(mute);
+ }
+}
+
int SoundCore::leftVolume()
{
return m_volumeControl->left();
@@ -165,6 +178,11 @@ int SoundCore::rightVolume()
return m_volumeControl->right();
}
+bool SoundCore::isMuted() const
+{
+ return m_muted;
+}
+
qint64 SoundCore::elapsed()
{
return m_handler->elapsed();
@@ -233,6 +251,7 @@ void SoundCore::startNextSource()
{
if((m_engine = AbstractEngine::create(s, this)))
{
+ m_engine->setMuted(m_muted);
m_engine->play();
m_nextState = NO_ENGINE;
return;
diff --git a/src/qmmp/soundcore.h b/src/qmmp/soundcore.h
index 7e93371e5..d693c2b0c 100644
--- a/src/qmmp/soundcore.h
+++ b/src/qmmp/soundcore.h
@@ -73,6 +73,10 @@ public:
*/
int rightVolume();
/*!
+ * Returns \b true if volume is unmuted, otherwise returns \b false
+ */
+ bool isMuted() const;
+ /*!
* Returns the current time (in milliseconds).
*/
qint64 elapsed();
@@ -126,6 +130,11 @@ public slots:
*/
void setVolume(int left, int right);
/*!
+ * Mutes/Restores volume
+ * @param mute - state of volume (\b true - mute, \b false - restore)
+ */
+ void setMuted(bool mute);
+ /*!
* This function plays file or stream with the given path \p source.
* Returns \b true if playback has been started successful or source is not a local file,
* otherwise returns \b false. Useful for invalid files skipping.
@@ -202,6 +211,11 @@ signals:
*/
void volumeChanged(int left, int right);
/*!
+ * Emitted when volume has muted or restored
+ * @param muted - new state of volume (\b true - muted, \b false - unmuted)
+ */
+ void mutedChanged(bool muted);
+ /*!
* Emitted when equalizer settings have changed.
*/
void eqSettingsChanged();
@@ -232,6 +246,7 @@ private:
AbstractEngine *m_engine;
QQueue<InputSource *> m_sources;
int m_nextState;
+ bool m_muted;
};
#endif