Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling StelAudioMgr at runtime #3775

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions guide/app_config_ini.tex
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ \subsection{\big[astrocalc\big]}
graphs\_second\_id & int & 2 & Identificator for right graph (yellow line).\\\bottomrule
\end{longtable}

\subsection{\big[audio\big]}
%\label{sec:config.ini:audio}

This section includes settings for Audio features.

\noindent%
\begin{longtable}{l|l|l|p{65mm}}
\toprule
\emph{ID} & \emph{Type} & \emph{Default} & \emph{Description}\\\midrule
enabled & bool & true & Enable sound output\\\bottomrule
\end{longtable}

\subsection{\big[color\big]}
%\label{sec:config.ini:color}

Expand Down
3 changes: 2 additions & 1 deletion guide/ch_advanced_use.tex
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ \chapter{Command Line Options}
-\/-mesa-mode or -m & {[}none{]} & Use MESA as software OpenGL rendering engine.\footref{FN:WinOnly}\\
-\/-single-buffer & {[}none{]} & Use single-buffering. This reportedly avoids screen blanking problems with some Intel GPUs. \\
-\/-opengl-compat or -C & {[}none{]} & Request OpenGL 3.3 Compatibility Profile. Might fix graphics problems in some driver configurations.\\
-\/-low-graphics or -L & {[}none{]} & Force low-graphics mode. May be useful on old GPUs that do support OpenGL 3.3 but perform too slowly.\\
-\/-low-graphics or -L & {[}none{]} & Force low-graphics mode. May be useful on old GPUs that do support OpenGL 3.3 but perform too slowly.\\\midrule
-\/-no-audio & {[}none{]} & Disable sound output (avoids initialisation problems on Virtual Machines or special builds).\\
\bottomrule
\end{longtable}

Expand Down
2 changes: 2 additions & 0 deletions src/CLIProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ void CLIProcessor::parseCLIArgsPostConfig(const QStringList& argList, QSettings*
{
bool dumpOpenGLDetails = argsGetOption(argList, "-d", "--dump-opengl-details");
qApp->setProperty("dump_OpenGL_details", dumpOpenGLDetails);
bool no_audio = argsGetOption(argList, "", "--no-audio");
qApp->setProperty("onetime_no-audio", no_audio);
fullScreen = argsGetYesNoOption(argList, "-f", "--full-screen", -1);
landscapeId = argsGetOptionWithArg(argList, "", "--landscape", "").toString();
homePlanet = argsGetOptionWithArg(argList, "", "--home-planet", "").toString();
Expand Down
6 changes: 4 additions & 2 deletions src/core/StelApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,13 @@ void StelApp::init(QSettings* conf)

// Init audio manager
SplashScreen::showMessage(q_("Initializing audio..."));
alex-w marked this conversation as resolved.
Show resolved Hide resolved
audioMgr = new StelAudioMgr();
const bool audioOK = !(qApp->property("onetime_no-audio").toBool())
&& confSettings->value("audio/enabled", true).toBool();
audioMgr = new StelAudioMgr(audioOK);

// Init video manager
SplashScreen::showMessage(q_("Initializing video..."));
videoMgr = new StelVideoMgr();
videoMgr = new StelVideoMgr(audioOK);
videoMgr->init();
getModuleMgr().registerModule(videoMgr);

Expand Down
45 changes: 35 additions & 10 deletions src/core/StelAudioMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@

#include <QMediaPlayer>

StelAudioMgr::StelAudioMgr()
StelAudioMgr::StelAudioMgr(bool enable)
{
enabled = enable;
gzotti marked this conversation as resolved.
Show resolved Hide resolved
#if (QT_VERSION>=QT_VERSION_CHECK(6,0,0))
audioOutput=new QAudioOutput();
audioOutput=(enabled ? new QAudioOutput() : nullptr);
#endif
}

Expand All @@ -37,20 +38,26 @@ StelAudioMgr::~StelAudioMgr()
while (it.hasNext())
{
it.next();
if (it.value()!=Q_NULLPTR)
if (it.value()!=nullptr)
{
it.value()->stop();
it.remove();
}
}
#if (QT_VERSION>=QT_VERSION_CHECK(6,0,0))
delete audioOutput;
audioOutput=Q_NULLPTR;
audioOutput=nullptr;
#endif
}

void StelAudioMgr::loadSound(const QString& filename, const QString& id)
{
if (!enabled)
{
qWarning() << "Not loading sound -- audio system disabled by configuration.";
return;
}

if (audioObjects.contains(id))
{
qWarning() << "Audio object with ID" << id << "already exists, dropping it";
Expand All @@ -69,9 +76,12 @@ void StelAudioMgr::loadSound(const QString& filename, const QString& id)

void StelAudioMgr::playSound(const QString& id)
{
if (!enabled)
return;

if (audioObjects.contains(id))
{
if (audioObjects[id]!=Q_NULLPTR)
if (audioObjects[id]!=nullptr)
{
// if already playing, stop and play from the start
#if (QT_VERSION>=QT_VERSION_CHECK(6,0,0))
Expand All @@ -94,9 +104,12 @@ void StelAudioMgr::playSound(const QString& id)

void StelAudioMgr::pauseSound(const QString& id)
{
if (!enabled)
return;

if (audioObjects.contains(id))
{
if (audioObjects[id]!=Q_NULLPTR)
if (audioObjects[id]!=nullptr)
audioObjects[id]->pause();
else
qDebug() << "StelAudioMgr: Cannot pause sound, " << id << "not correctly loaded.";
Expand All @@ -107,9 +120,12 @@ void StelAudioMgr::pauseSound(const QString& id)

void StelAudioMgr::stopSound(const QString& id)
{
if (!enabled)
return;

if (audioObjects.contains(id))
{
if (audioObjects[id]!=Q_NULLPTR)
if (audioObjects[id]!=nullptr)
audioObjects[id]->stop();
else
qDebug() << "StelAudioMgr: Cannot stop sound, " << id << "not correctly loaded.";
Expand All @@ -120,12 +136,15 @@ void StelAudioMgr::stopSound(const QString& id)

void StelAudioMgr::dropSound(const QString& id)
{
if (!enabled)
return;

if (!audioObjects.contains(id))
{
qDebug() << "StelAudioMgr: Cannot drop sound, " << id << "not loaded.";
return;
}
if (audioObjects[id]!=Q_NULLPTR)
if (audioObjects[id]!=nullptr)
{
audioObjects[id]->stop();
delete audioObjects[id];
Expand All @@ -136,12 +155,15 @@ void StelAudioMgr::dropSound(const QString& id)

qint64 StelAudioMgr::position(const QString& id)
{
if (!enabled)
return -1;

if (!audioObjects.contains(id))
{
qDebug() << "StelAudioMgr: Cannot report position for sound, " << id << "not loaded.";
return(-1);
}
if (audioObjects[id]!=Q_NULLPTR)
if (audioObjects[id]!=nullptr)
{
return audioObjects[id]->position();
}
Expand All @@ -150,12 +172,15 @@ qint64 StelAudioMgr::position(const QString& id)

qint64 StelAudioMgr::duration(const QString& id)
{
if (!enabled)
return -1;

if (!audioObjects.contains(id))
{
qDebug() << "StelAudioMgr: Cannot report duration for sound, " << id << "not loaded.";
return(-1);
}
if (audioObjects[id]!=Q_NULLPTR)
if (audioObjects[id]!=nullptr)
{
return audioObjects[id]->duration();
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/StelAudioMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class StelAudioMgr : public QObject
Q_OBJECT

public:
StelAudioMgr();
StelAudioMgr(bool enable);
~StelAudioMgr() override;

public slots:
Expand All @@ -56,6 +56,7 @@ public slots:
qint64 duration(const QString& id);

private:
bool enabled; // global switch configured by constructor
QMap<QString, QMediaPlayer*> audioObjects;
#if (QT_VERSION>=QT_VERSION_CHECK(6,0,0)) && defined(ENABLE_MEDIA)
QAudioOutput *audioOutput;
Expand Down
Loading
Loading