Skip to content

Commit 424a0e6

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

File tree

10 files changed

+50
-8
lines changed

10 files changed

+50
-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: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct Pixmaps {
8989
PixmapSetEmptyActive mo;
9090
PixmapSetActive hd;
9191
PixmapSetEmptyActive net;
92-
QPixmap sound;
92+
QPixmap sound, soundMuted;
9393
};
9494

9595
struct StateActive {
@@ -215,6 +215,7 @@ struct MachineStatus::States {
215215
pixmaps.hd.load("/hard_disk%1.ico");
216216
pixmaps.net.load("/network%1.ico");
217217
pixmaps.sound = ProgSettings::loadIcon("/sound.ico").pixmap(pixmap_size);
218+
pixmaps.soundMuted = ProgSettings::loadIcon("/sound_mute.ico").pixmap(pixmap_size);
218219

219220
cartridge[0].pixmaps = &pixmaps.cartridge;
220221
cartridge[1].pixmaps = &pixmaps.cartridge;
@@ -262,6 +263,12 @@ MachineStatus::MachineStatus(QObject *parent)
262263

263264
MachineStatus::~MachineStatus() = default;
264265

266+
void
267+
MachineStatus::setSoundGainAction(QAction* action)
268+
{
269+
soundGainAction = action;
270+
}
271+
265272
bool
266273
MachineStatus::hasCassette()
267274
{
@@ -494,6 +501,25 @@ MachineStatus::refresh(QStatusBar *sbar)
494501
}
495502
sbar->removeWidget(d->sound.get());
496503

504+
if (!muteUnmuteAction) {
505+
muteUnmuteAction = new QAction(this);
506+
connect(muteUnmuteAction, &QAction::triggered, this, [this]() {
507+
sound_muted ^= 1;
508+
if (d->sound)
509+
d->sound->setPixmap(sound_muted ? d->pixmaps.soundMuted : d->pixmaps.sound);
510+
511+
muteUnmuteAction->setText(sound_muted ? tr("&Unmute") : tr("&Mute"));
512+
});
513+
}
514+
515+
if (!soundMenu) {
516+
soundMenu = new QMenu(sbar);
517+
518+
soundMenu->addAction(muteUnmuteAction);
519+
soundMenu->addSeparator();
520+
soundMenu->addAction(soundGainAction);
521+
}
522+
497523
if (cassette_enable) {
498524
d->cassette.label = std::make_unique<ClickableLabel>();
499525
d->cassette.setEmpty(QString(cassette_fname).isEmpty());
@@ -662,12 +688,13 @@ MachineStatus::refresh(QStatusBar *sbar)
662688
}
663689

664690
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();
691+
d->sound->setPixmap(sound_muted ? d->pixmaps.soundMuted : d->pixmaps.sound);
692+
muteUnmuteAction->setText(sound_muted ? tr("&Unmute") : tr("&Mute"));
693+
694+
connect(d->sound.get(), &ClickableLabel::clicked, this, [this](QPoint pos) {
695+
this->soundMenu->popup(pos - QPoint(0, this->soundMenu->sizeHint().height()));
670696
});
697+
671698
d->sound->setToolTip(tr("Sound"));
672699
sbar->addWidget(d->sound.get());
673700
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)