Skip to content

Commit

Permalink
Add global mute option
Browse files Browse the repository at this point in the history
  • Loading branch information
Cacodemon345 committed Mar 6, 2025
1 parent 5be8823 commit d25aed2
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/86box.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ int do_auto_pause = 0; /* (C) Auto-pa
int hook_enabled = 1; /* (C) Keyboard hook is enabled */
int test_mode = 0; /* (C) Test mode */
char uuid[MAX_UUID_LEN] = { '\0' }; /* (C) UUID or machine identifier */
int sound_muted = 0; /* (C) Is sound muted? */

int other_ide_present = 0; /* IDE controllers from non-IDE cards are
present */
Expand Down
5 changes: 5 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ load_general(void)
kbd_req_capture = ini_section_get_int(cat, "kbd_req_capture", 0);
hide_status_bar = ini_section_get_int(cat, "hide_status_bar", 0);
hide_tool_bar = ini_section_get_int(cat, "hide_tool_bar", 0);
sound_muted = ini_section_get_int(cat, "sound_muted", 0);

confirm_reset = ini_section_get_int(cat, "confirm_reset", 1);
confirm_exit = ini_section_get_int(cat, "confirm_exit", 1);
Expand Down Expand Up @@ -1846,6 +1847,10 @@ save_general(void)

const char *va_name;

ini_section_set_int(cat, "sound_muted", sound_muted);
if (sound_muted == 0)
ini_section_delete_var(cat, "sound_muted");

ini_section_set_int(cat, "vid_resize", vid_resize);
if (vid_resize == 0)
ini_section_delete_var(cat, "vid_resize");
Expand Down
1 change: 1 addition & 0 deletions src/include/86box/86box.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ extern int other_scsi_present; /* SCSI controllers from non-SCSI ca
extern int hard_reset_pending;
extern int fixed_size_x;
extern int fixed_size_y;
extern int sound_muted; /* (C) Is sound muted? */
extern int do_auto_pause; /* (C) Auto-pause the emulator on focus loss */
extern int auto_paused;
extern double mouse_sensitivity; /* (C) Mouse sensitivity scale */
Expand Down
Binary file added src/qt/icons/sound_mute.ico
Binary file not shown.
45 changes: 39 additions & 6 deletions src/qt/qt_machinestatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern "C" {
#include <86box/network.h>
#include <86box/ui.h>
#include <86box/machine_status.h>
#include <86box/config.h>
};

#include <QIcon>
Expand Down Expand Up @@ -89,7 +90,7 @@ struct Pixmaps {
PixmapSetEmptyActive mo;
PixmapSetActive hd;
PixmapSetEmptyActive net;
QPixmap sound;
QPixmap sound, soundMuted;
};

struct StateActive {
Expand Down Expand Up @@ -215,6 +216,7 @@ struct MachineStatus::States {
pixmaps.hd.load("/hard_disk%1.ico");
pixmaps.net.load("/network%1.ico");
pixmaps.sound = ProgSettings::loadIcon("/sound.ico").pixmap(pixmap_size);
pixmaps.soundMuted = ProgSettings::loadIcon("/sound_mute.ico").pixmap(pixmap_size);

cartridge[0].pixmaps = &pixmaps.cartridge;
cartridge[1].pixmaps = &pixmaps.cartridge;
Expand Down Expand Up @@ -256,12 +258,19 @@ MachineStatus::MachineStatus(QObject *parent)
, refreshTimer(new QTimer(this))
{
d = std::make_unique<MachineStatus::States>(this);
muteUnmuteAction = nullptr;
connect(refreshTimer, &QTimer::timeout, this, &MachineStatus::refreshIcons);
refreshTimer->start(75);
}

MachineStatus::~MachineStatus() = default;

void
MachineStatus::setSoundGainAction(QAction* action)
{
soundGainAction = action;
}

bool
MachineStatus::hasCassette()
{
Expand Down Expand Up @@ -494,6 +503,28 @@ MachineStatus::refresh(QStatusBar *sbar)
}
sbar->removeWidget(d->sound.get());

if (!muteUnmuteAction) {
muteUnmuteAction = new QAction;
connect(muteUnmuteAction, &QAction::triggered, this, [this]() {
sound_muted ^= 1;
config_save();
if (d->sound)
d->sound->setPixmap(sound_muted ? d->pixmaps.soundMuted : d->pixmaps.sound);

muteUnmuteAction->setText(sound_muted ? tr("&Unmute") : tr("&Mute"));
});
}

if (!soundMenu) {
soundMenu = new QMenu((QWidget*)parent());

soundMenu->addAction(muteUnmuteAction);
soundMenu->addSeparator();
soundMenu->addAction(soundGainAction);

muteUnmuteAction->setParent(soundMenu);
}

if (cassette_enable) {
d->cassette.label = std::make_unique<ClickableLabel>();
d->cassette.setEmpty(QString(cassette_fname).isEmpty());
Expand Down Expand Up @@ -662,12 +693,14 @@ MachineStatus::refresh(QStatusBar *sbar)
}

d->sound = std::make_unique<ClickableLabel>();
d->sound->setPixmap(d->pixmaps.sound);

connect(d->sound.get(), &ClickableLabel::doubleClicked, d->sound.get(), [](QPoint pos) {
SoundGain gain(main_window);
gain.exec();
d->sound->setPixmap(sound_muted ? d->pixmaps.soundMuted : d->pixmaps.sound);
if (muteUnmuteAction)
muteUnmuteAction->setText(sound_muted ? tr("&Unmute") : tr("&Mute"));

connect(d->sound.get(), &ClickableLabel::clicked, this, [this](QPoint pos) {
this->soundMenu->popup(pos - QPoint(0, this->soundMenu->sizeHint().height()));
});

d->sound->setToolTip(tr("Sound"));
sbar->addWidget(d->sound.get());
d->text = std::make_unique<QLabel>();
Expand Down
6 changes: 6 additions & 0 deletions src/qt/qt_machinestatus.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef QT_MACHINESTATUS_HPP
#define QT_MACHINESTATUS_HPP

#include <QAction>
#include <QMenu>
#include <QWidget>
#include <QLabel>
#include <QMouseEvent>
Expand Down Expand Up @@ -71,6 +73,7 @@ class MachineStatus : public QObject {

QString getMessage();
void clearActivity();
void setSoundGainAction(QAction* action);
public slots:
void refresh(QStatusBar *sbar);
void message(const QString &msg);
Expand All @@ -82,6 +85,9 @@ public slots:
struct States;
std::unique_ptr<States> d;
QTimer *refreshTimer;
QAction *soundGainAction;
QAction *muteUnmuteAction;
QMenu *soundMenu;
};

#endif // QT_MACHINESTATUS_HPP
1 change: 1 addition & 0 deletions src/qt/qt_mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ MainWindow::MainWindow(QWidget *parent)
extern MainWindow *main_window;
main_window = this;
ui->setupUi(this);
status->setSoundGainAction(ui->actionSound_gain);
ui->stackedWidget->setMouseTracking(true);
statusBar()->setVisible(!hide_status_bar);
statusBar()->setStyleSheet("QStatusBar::item {border: None; } QStatusBar QLabel { margin-right: 2px; margin-bottom: 1px; }");
Expand Down
1 change: 1 addition & 0 deletions src/qt_resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<file>qt/icons/other_removable_devices.ico</file>
<file>qt/icons/ports.ico</file>
<file>qt/icons/sound.ico</file>
<file>qt/icons/sound_mute.ico</file>
<file>qt/icons/storage_controllers.ico</file>
<file>qt/icons/zip.ico</file>
<file>qt/icons/zip_active.ico</file>
Expand Down
2 changes: 1 addition & 1 deletion src/sound/openal.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ givealbuffer_common(const void *buf, const uint8_t src, const int size, const in

alGetSourcei(source[src], AL_BUFFERS_PROCESSED, &processed);
if (processed >= 1) {
const double gain = pow(10.0, (double) sound_gain / 20.0);
const double gain = sound_muted ? 0.0 : pow(10.0, (double) sound_gain / 20.0);
alListenerf(AL_GAIN, (float) gain);

alSourceUnqueueBuffers(source[src], 1, &buffer);
Expand Down
2 changes: 1 addition & 1 deletion src/sound/xaudio2.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ givealbuffer_common(const void *buf, IXAudio2SourceVoice *sourcevoice, const siz
if (!initialized)
return;

(void) IXAudio2MasteringVoice_SetVolume(mastervoice, pow(10.0, (double) sound_gain / 20.0),
(void) IXAudio2MasteringVoice_SetVolume(mastervoice, sound_muted ? 0.0 : pow(10.0, (double) sound_gain / 20.0),
XAUDIO2_COMMIT_NOW);
XAUDIO2_BUFFER buffer = { 0 };
buffer.Flags = 0;
Expand Down

0 comments on commit d25aed2

Please sign in to comment.