From ad578eb0bd15dfa828c8c43518991ee8ce81e261 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Sat, 23 Jul 2022 18:18:45 +0300 Subject: Suppress application volume when alt-tabbed (#730) * Suppress application volume when alt-tabbed Add a "suppress_audio" slider setting, 50% by default, which decides how much audio remains when the client is not in focus Add a "muted" setting for blip, music, and sfx players Add update_audio_volume func * change "suppress" to "how much audio is suppressed" instead of "how much audio remains" * Fix last commit just flipping the behavior and being ultra wacky * Fix evidence present sound ignoring audio suppression settings Co-authored-by: stonedDiscord Co-authored-by: Salanto <62221668+Salanto@users.noreply.github.com> --- include/aoapplication.h | 3 +++ include/aoblipplayer.h | 3 +++ include/aomusicplayer.h | 2 ++ include/aooptionsdialog.h | 2 ++ include/aosfxplayer.h | 4 +++- include/courtroom.h | 7 +++++++ 6 files changed, 20 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/aoapplication.h b/include/aoapplication.h index cf9eb2b..48b30a1 100644 --- a/include/aoapplication.h +++ b/include/aoapplication.h @@ -204,6 +204,9 @@ public: // Returns the value of default_blip in config.ini int get_default_blip(); + // Returns the value of suppress_audio in config.ini + int get_default_suppress_audio(); + // Returns the value if objections interrupt and skip the message queue // from the config.ini. bool is_instant_objection_enabled(); diff --git a/include/aoblipplayer.h b/include/aoblipplayer.h index a11e29d..ea2dcd3 100644 --- a/include/aoblipplayer.h +++ b/include/aoblipplayer.h @@ -18,6 +18,7 @@ public: void set_blips(QString p_sfx); void blip_tick(); void set_volume(int p_volume); + void set_muted(bool toggle); int m_cycle = 0; @@ -26,6 +27,8 @@ private: AOApplication *ao_app; qreal m_volume; + bool m_muted = false; + void set_volume_internal(qreal p_volume); HSTREAM m_stream_list[5]; diff --git a/include/aomusicplayer.h b/include/aomusicplayer.h index d00ab8e..037525f 100644 --- a/include/aomusicplayer.h +++ b/include/aomusicplayer.h @@ -20,6 +20,7 @@ public: virtual ~AOMusicPlayer(); void set_volume(int p_value, int channel = -1); void set_looping(bool toggle, int channel = 0); + void set_muted(bool toggle); const int m_channelmax = 4; @@ -39,6 +40,7 @@ private: AOApplication *ao_app; bool m_looping = false; + bool m_muted = false; int m_volume[4] = {0, 0, 0, 0}; // Channel 0 = music diff --git a/include/aooptionsdialog.h b/include/aooptionsdialog.h index 2180379..cb9b71b 100644 --- a/include/aooptionsdialog.h +++ b/include/aooptionsdialog.h @@ -127,8 +127,10 @@ private: QLabel *ui_music_volume_lbl; QSpinBox *ui_sfx_volume_spinbox; QSpinBox *ui_blips_volume_spinbox; + QSpinBox *ui_suppress_audio_spinbox; QLabel *ui_sfx_volume_lbl; QLabel *ui_blips_volume_lbl; + QLabel *ui_suppress_audio_lbl; QFrame *ui_volume_blip_divider; QSpinBox *ui_bliprate_spinbox; QLabel *ui_bliprate_lbl; diff --git a/include/aosfxplayer.h b/include/aosfxplayer.h index 7597636..077a7ef 100644 --- a/include/aosfxplayer.h +++ b/include/aosfxplayer.h @@ -20,14 +20,16 @@ public: void stop(int channel = -1); void set_volume(qreal p_volume); void set_looping(bool toggle, int channel = -1); + void set_muted(bool toggle); int m_channel = 0; - + int get_volume() { return m_volume * 100; }; private: QWidget *m_parent; AOApplication *ao_app; qreal m_volume = 0; bool m_looping = true; + bool m_muted = false; void set_volume_internal(qreal p_volume); const int m_channelmax = 5; diff --git a/include/courtroom.h b/include/courtroom.h index 73ef6fb..43cecf3 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -69,6 +69,8 @@ class Courtroom : public QMainWindow { public: explicit Courtroom(AOApplication *p_ao_app); + void update_audio_volume(); + void append_char(char_type p_char) { char_list.append(p_char); } void append_evidence(evi_type p_evi) { evidence_list.append(p_evi); } void append_music(QString f_music) { music_list.append(f_music); } @@ -338,6 +340,9 @@ public: private: AOApplication *ao_app; + // Percentage of audio that is suppressed when client is not in focus + int suppress_audio = 0; + int m_courtroom_width = 714; int m_courtroom_height = 668; @@ -988,6 +993,8 @@ private slots: void on_casing_clicked(); + void on_application_state_changed(Qt::ApplicationState state); + void ping_server(); // Proceed to parse the oldest chatmessage and remove it from the stack -- cgit