Skip to content

Commit d25aed2

Browse files
committed
Add global mute option
1 parent 5be8823 commit d25aed2

File tree

10 files changed

+56
-8
lines changed

10 files changed

+56
-8
lines changed

src/86box.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ int do_auto_pause = 0; /* (C) Auto-pa
213213
int hook_enabled = 1; /* (C) Keyboard hook is enabled */
214214
int test_mode = 0; /* (C) Test mode */
215215
char uuid[MAX_UUID_LEN] = { '\0' }; /* (C) UUID or machine identifier */
216+
int sound_muted = 0; /* (C) Is sound muted? */
216217

217218
int other_ide_present = 0; /* IDE controllers from non-IDE cards are
218219
present */

src/config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ load_general(void)
168168
kbd_req_capture = ini_section_get_int(cat, "kbd_req_capture", 0);
169169
hide_status_bar = ini_section_get_int(cat, "hide_status_bar", 0);
170170
hide_tool_bar = ini_section_get_int(cat, "hide_tool_bar", 0);
171+
sound_muted = ini_section_get_int(cat, "sound_muted", 0);
171172

172173
confirm_reset = ini_section_get_int(cat, "confirm_reset", 1);
173174
confirm_exit = ini_section_get_int(cat, "confirm_exit", 1);
@@ -1846,6 +1847,10 @@ save_general(void)
18461847

18471848
const char *va_name;
18481849

1850+
ini_section_set_int(cat, "sound_muted", sound_muted);
1851+
if (sound_muted == 0)
1852+
ini_section_delete_var(cat, "sound_muted");
1853+
18491854
ini_section_set_int(cat, "vid_resize", vid_resize);
18501855
if (vid_resize == 0)
18511856
ini_section_delete_var(cat, "vid_resize");

src/include/86box/86box.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ extern int other_scsi_present; /* SCSI controllers from non-SCSI ca
158158
extern int hard_reset_pending;
159159
extern int fixed_size_x;
160160
extern int fixed_size_y;
161+
extern int sound_muted; /* (C) Is sound muted? */
161162
extern int do_auto_pause; /* (C) Auto-pause the emulator on focus loss */
162163
extern int auto_paused;
163164
extern double mouse_sensitivity; /* (C) Mouse sensitivity scale */

src/qt/icons/sound_mute.ico

9.4 KB
Binary file not shown.

src/qt/qt_machinestatus.cpp

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern "C" {
3939
#include <86box/network.h>
4040
#include <86box/ui.h>
4141
#include <86box/machine_status.h>
42+
#include <86box/config.h>
4243
};
4344

4445
#include <QIcon>
@@ -89,7 +90,7 @@ struct Pixmaps {
8990
PixmapSetEmptyActive mo;
9091
PixmapSetActive hd;
9192
PixmapSetEmptyActive net;
92-
QPixmap sound;
93+
QPixmap sound, soundMuted;
9394
};
9495

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

219221
cartridge[0].pixmaps = &pixmaps.cartridge;
220222
cartridge[1].pixmaps = &pixmaps.cartridge;
@@ -256,12 +258,19 @@ MachineStatus::MachineStatus(QObject *parent)
256258
, refreshTimer(new QTimer(this))
257259
{
258260
d = std::make_unique<MachineStatus::States>(this);
261+
muteUnmuteAction = nullptr;
259262
connect(refreshTimer, &QTimer::timeout, this, &MachineStatus::refreshIcons);
260263
refreshTimer->start(75);
261264
}
262265

263266
MachineStatus::~MachineStatus() = default;
264267

268+
void
269+
MachineStatus::setSoundGainAction(QAction* action)
270+
{
271+
soundGainAction = action;
272+
}
273+
265274
bool
266275
MachineStatus::hasCassette()
267276
{
@@ -494,6 +503,28 @@ MachineStatus::refresh(QStatusBar *sbar)
494503
}
495504
sbar->removeWidget(d->sound.get());
496505

506+
if (!muteUnmuteAction) {
507+
muteUnmuteAction = new QAction;
508+
connect(muteUnmuteAction, &QAction::triggered, this, [this]() {
509+
sound_muted ^= 1;
510+
config_save();
511+
if (d->sound)
512+
d->sound->setPixmap(sound_muted ? d->pixmaps.soundMuted : d->pixmaps.sound);
513+
514+
muteUnmuteAction->setText(sound_muted ? tr("&Unmute") : tr("&Mute"));
515+
});
516+
}
517+
518+
if (!soundMenu) {
519+
soundMenu = new QMenu((QWidget*)parent());
520+
521+
soundMenu->addAction(muteUnmuteAction);
522+
soundMenu->addSeparator();
523+
soundMenu->addAction(soundGainAction);
524+
525+
muteUnmuteAction->setParent(soundMenu);
526+
}
527+
497528
if (cassette_enable) {
498529
d->cassette.label = std::make_unique<ClickableLabel>();
499530
d->cassette.setEmpty(QString(cassette_fname).isEmpty());
@@ -662,12 +693,14 @@ MachineStatus::refresh(QStatusBar *sbar)
662693
}
663694

664695
d->sound = std::make_unique<ClickableLabel>();
665-
d->sound->setPixmap(d->pixmaps.sound);
666-
667-
connect(d->sound.get(), &ClickableLabel::doubleClicked, d->sound.get(), [](QPoint pos) {
668-
SoundGain gain(main_window);
669-
gain.exec();
696+
d->sound->setPixmap(sound_muted ? d->pixmaps.soundMuted : d->pixmaps.sound);
697+
if (muteUnmuteAction)
698+
muteUnmuteAction->setText(sound_muted ? tr("&Unmute") : tr("&Mute"));
699+
700+
connect(d->sound.get(), &ClickableLabel::clicked, this, [this](QPoint pos) {
701+
this->soundMenu->popup(pos - QPoint(0, this->soundMenu->sizeHint().height()));
670702
});
703+
671704
d->sound->setToolTip(tr("Sound"));
672705
sbar->addWidget(d->sound.get());
673706
d->text = std::make_unique<QLabel>();

src/qt/qt_machinestatus.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef QT_MACHINESTATUS_HPP
22
#define QT_MACHINESTATUS_HPP
33

4+
#include <QAction>
5+
#include <QMenu>
46
#include <QWidget>
57
#include <QLabel>
68
#include <QMouseEvent>
@@ -71,6 +73,7 @@ class MachineStatus : public QObject {
7173

7274
QString getMessage();
7375
void clearActivity();
76+
void setSoundGainAction(QAction* action);
7477
public slots:
7578
void refresh(QStatusBar *sbar);
7679
void message(const QString &msg);
@@ -82,6 +85,9 @@ public slots:
8285
struct States;
8386
std::unique_ptr<States> d;
8487
QTimer *refreshTimer;
88+
QAction *soundGainAction;
89+
QAction *muteUnmuteAction;
90+
QMenu *soundMenu;
8591
};
8692

8793
#endif // QT_MACHINESTATUS_HPP

src/qt/qt_mainwindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ MainWindow::MainWindow(QWidget *parent)
178178
extern MainWindow *main_window;
179179
main_window = this;
180180
ui->setupUi(this);
181+
status->setSoundGainAction(ui->actionSound_gain);
181182
ui->stackedWidget->setMouseTracking(true);
182183
statusBar()->setVisible(!hide_status_bar);
183184
statusBar()->setStyleSheet("QStatusBar::item {border: None; } QStatusBar QLabel { margin-right: 2px; margin-bottom: 1px; }");

src/qt_resources.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<file>qt/icons/other_removable_devices.ico</file>
4444
<file>qt/icons/ports.ico</file>
4545
<file>qt/icons/sound.ico</file>
46+
<file>qt/icons/sound_mute.ico</file>
4647
<file>qt/icons/storage_controllers.ico</file>
4748
<file>qt/icons/zip.ico</file>
4849
<file>qt/icons/zip_active.ico</file>

src/sound/openal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ givealbuffer_common(const void *buf, const uint8_t src, const int size, const in
278278

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

284284
alSourceUnqueueBuffers(source[src], 1, &buffer);

src/sound/xaudio2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ givealbuffer_common(const void *buf, IXAudio2SourceVoice *sourcevoice, const siz
245245
if (!initialized)
246246
return;
247247

248-
(void) IXAudio2MasteringVoice_SetVolume(mastervoice, pow(10.0, (double) sound_gain / 20.0),
248+
(void) IXAudio2MasteringVoice_SetVolume(mastervoice, sound_muted ? 0.0 : pow(10.0, (double) sound_gain / 20.0),
249249
XAUDIO2_COMMIT_NOW);
250250
XAUDIO2_BUFFER buffer = { 0 };
251251
buffer.Flags = 0;

0 commit comments

Comments
 (0)