Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions src/configuration/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ ConstString KEY_LINES_OF_SCROLLBACK = "Lines of scrollback";
ConstString KEY_PROXY_LOCAL_PORT = "Local port number";
ConstString KEY_MAP_MODE = "Map Mode";
ConstString KEY_MUSIC_VOLUME = "Music volume";
ConstString KEY_MUSIC_MUTED = "Music muted";
ConstString KEY_SOUND_VOLUME = "Sound volume";
ConstString KEY_SOUND_MUTED = "Sound muted";
ConstString KEY_AUDIO_OUTPUT_DEVICE = "Audio output device";
ConstString KEY_AUDIO_UNLOCKED = "Audio unlocked";
ConstString KEY_MAXIMUM_NUMBER_OF_PATHS = "maximum number of paths";
Expand Down Expand Up @@ -777,7 +779,9 @@ void Configuration::AudioSettings::read(const QSettings &conf)
? false
: conf.value(KEY_AUDIO_UNLOCKED, false).toBool();
m_musicVolume = std::clamp(conf.value(KEY_MUSIC_VOLUME, 50).toInt(), 0, 100);
m_musicMuted = conf.value(KEY_MUSIC_MUTED, false).toBool();
m_soundVolume = std::clamp(conf.value(KEY_SOUND_VOLUME, 50).toInt(), 0, 100);
m_soundMuted = conf.value(KEY_SOUND_MUTED, false).toBool();
m_outputDeviceId = conf.value(KEY_AUDIO_OUTPUT_DEVICE).toByteArray();
}

Expand Down Expand Up @@ -964,7 +968,9 @@ void Configuration::AudioSettings::write(QSettings &conf) const
conf.setValue(KEY_AUDIO_UNLOCKED, m_unlocked);
}
conf.setValue(KEY_MUSIC_VOLUME, m_musicVolume);
conf.setValue(KEY_MUSIC_MUTED, m_musicMuted);
conf.setValue(KEY_SOUND_VOLUME, m_soundVolume);
conf.setValue(KEY_SOUND_MUTED, m_soundMuted);
conf.setValue(KEY_AUDIO_OUTPUT_DEVICE, m_outputDeviceId);
}

Expand Down
16 changes: 16 additions & 0 deletions src/configuration/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ class NODISCARD Configuration final
int m_soundVolume = 50;
QByteArray m_outputDeviceId;
bool m_unlocked = false;
bool m_musicMuted = false;
bool m_soundMuted = false;

public:
explicit AudioSettings() = default;
Expand All @@ -371,13 +373,27 @@ class NODISCARD Configuration final
m_changeMonitor.notifyAll();
}

NODISCARD bool isMusicMuted() const { return m_musicMuted; }
void setMusicMuted(const bool muted)
{
m_musicMuted = muted;
m_changeMonitor.notifyAll();
}

NODISCARD int getSoundVolume() const { return m_soundVolume; }
void setSoundVolume(const int volume)
{
m_soundVolume = volume;
m_changeMonitor.notifyAll();
}

NODISCARD bool isSoundMuted() const { return m_soundMuted; }
void setSoundMuted(const bool muted)
{
m_soundMuted = muted;
m_changeMonitor.notifyAll();
}

NODISCARD const QByteArray &getOutputDeviceId() const { return m_outputDeviceId; }
void setOutputDeviceId(const QByteArray &id)
{
Expand Down
30 changes: 30 additions & 0 deletions src/mainwindow/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,12 @@ void MainWindow::wireConnections()
&FindRoomsDlg::sig_editSelection,
this,
&MainWindow::slot_onEditRoomSelection);

setConfig().audio.registerChangeCallback(m_lifetime, [this]() {
const auto &audio = getConfig().audio;
muteMusicAct->setChecked(audio.isMusicMuted());
muteSoundAct->setChecked(audio.isSoundMuted());
});
}

void MainWindow::slot_log(const QString &mod, const QString &message)
Expand Down Expand Up @@ -1027,6 +1033,26 @@ void MainWindow::createActions()
rebuildMeshesAct->setStatusTip(tr("Reconstruct the world mesh to fix graphical rendering bugs"));
rebuildMeshesAct->setCheckable(false);
connect(rebuildMeshesAct, &QAction::triggered, getCanvas(), &MapCanvas::slot_rebuildMeshes);

muteMusicAct = new QAction(QIcon::fromTheme("audio-volume-muted", QIcon(":/icons/audiocfg.png")),
tr("Mute Music"),
this);
muteMusicAct->setShortcut(tr("Ctrl+M"));
muteMusicAct->setCheckable(true);
muteMusicAct->setStatusTip(tr("Mute/Unmute Music"));
connect(muteMusicAct, &QAction::triggered, this, [](bool checked) {
setConfig().audio.setMusicMuted(checked);
});

muteSoundAct = new QAction(QIcon::fromTheme("audio-volume-muted", QIcon(":/icons/audiocfg.png")),
tr("Mute Sound"),
this);
muteSoundAct->setShortcut(tr("Ctrl+Shift+M"));
muteSoundAct->setCheckable(true);
muteSoundAct->setStatusTip(tr("Mute/Unmute Sound"));
connect(muteSoundAct, &QAction::triggered, this, [](bool checked) {
setConfig().audio.setSoundMuted(checked);
});
}

static void setConfigMapMode(const MapModeEnum mode)
Expand Down Expand Up @@ -1211,6 +1237,10 @@ void MainWindow::setupMenuBar()
}
viewMenu->addAction(alwaysOnTopAct);

QMenu *audioMenu = menuBar()->addMenu(tr("&Audio"));
audioMenu->addAction(muteMusicAct);
audioMenu->addAction(muteSoundAct);

settingsMenu = menuBar()->addMenu(tr("&Tools"));
QMenu *clientMenu = settingsMenu->addMenu(QIcon(":/icons/terminal.png"),
tr("&Integrated Mud Client"));
Expand Down
2 changes: 2 additions & 0 deletions src/mainwindow/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ class NODISCARD_QOBJECT MainWindow final : public QMainWindow
QAction *forceRoomAct = nullptr;
QAction *releaseAllPathsAct = nullptr;
QAction *rebuildMeshesAct = nullptr;
QAction *muteMusicAct = nullptr;
QAction *muteSoundAct = nullptr;

std::unique_ptr<ConfigDialog> m_configDialog;

Expand Down
8 changes: 5 additions & 3 deletions src/media/MusicManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void MusicManager::updateVolumes()

auto &cfg = getConfig().audio;
float masterVol = static_cast<float>(cfg.getMusicVolume()) / 100.0f;
bool canPlay = cfg.isUnlocked() && masterVol > 0;
bool canPlay = cfg.isUnlocked() && masterVol > 0 && !cfg.isMusicMuted();
auto &active = m_channels[m_activeChannel];
if (canPlay && active.player->playbackState() == QMediaPlayer::StoppedState
&& !active.file.isEmpty()) {
Expand All @@ -251,7 +251,8 @@ void MusicManager::updateVolumes()
}
active.player->play();
applyPendingPosition(m_activeChannel);
} else if (masterVol <= 0 && active.player->playbackState() == QMediaPlayer::PlayingState) {
} else if ((masterVol <= 0 || cfg.isMusicMuted())
&& active.player->playbackState() == QMediaPlayer::PlayingState) {
if (!active.file.isEmpty()) {
m_cachedPositions.insert(active.file, new qint64(active.player->position()));
}
Expand Down Expand Up @@ -293,7 +294,8 @@ void MusicManager::applyPendingPosition(int channelIndex)

void MusicManager::updateChannelVolume(int channelIndex)
{
float masterVol = static_cast<float>(getConfig().audio.getMusicVolume()) / 100.0f;
auto &cfg = getConfig().audio;
float masterVol = cfg.isMusicMuted() ? 0.0f : static_cast<float>(cfg.getMusicVolume()) / 100.0f;
m_channels[channelIndex].audioOutput->setVolume(masterVol * m_channels[channelIndex].fadeVolume);
}

Expand Down
8 changes: 5 additions & 3 deletions src/media/SfxManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SfxManager::SfxManager(MediaLibrary &library, QObject *const parent)
void SfxManager::playSound(MAYBE_UNUSED const QString &soundName)
{
auto &cfg = getConfig().audio;
if (!cfg.isUnlocked() || cfg.getSoundVolume() <= 0) {
if (!cfg.isUnlocked() || cfg.getSoundVolume() <= 0 || cfg.isSoundMuted()) {
return;
}

Expand Down Expand Up @@ -60,7 +60,7 @@ void SfxManager::playFromData(const QByteArray &data, const QString &soundName)
}

auto &cfg = getConfig().audio;
if (!cfg.isUnlocked() || cfg.getSoundVolume() <= 0) {
if (!cfg.isUnlocked() || cfg.getSoundVolume() <= 0 || cfg.isSoundMuted()) {
return;
}

Expand Down Expand Up @@ -106,7 +106,9 @@ void SfxManager::startEffect(const QUrl &url, const QString &tmpToDelete)
void SfxManager::updateVolume()
{
#ifndef MMAPPER_NO_AUDIO
m_output->setVolume(static_cast<float>(getConfig().audio.getSoundVolume()) / 100.0f);
auto &cfg = getConfig().audio;
float volume = cfg.isSoundMuted() ? 0.0f : static_cast<float>(cfg.getSoundVolume()) / 100.0f;
m_output->setVolume(volume);
#endif
}

Expand Down
Loading