Browse Source

SoundPlayer: Add 'mute' methods to Player

These methods allow us to mute/unmute the player without needing to
modify the volume level that it has.
Elyse 3 years ago
parent
commit
8f2161c0ee

+ 19 - 0
Userland/Applications/SoundPlayer/Player.cpp

@@ -99,6 +99,15 @@ void Player::set_volume(double volume)
     volume_changed(m_volume);
 }
 
+void Player::set_mute(bool muted)
+{
+    if (m_muted != muted) {
+        m_muted = muted;
+        m_audio_client_connection.set_self_muted(muted);
+        mute_changed(muted);
+    }
+}
+
 void Player::set_shuffle_mode(ShuffleMode mode)
 {
     if (m_shuffle_mode != mode) {
@@ -132,6 +141,16 @@ void Player::stop()
     set_play_state(PlayState::Stopped);
 }
 
+void Player::mute()
+{
+    set_mute(true);
+}
+
+void Player::toggle_mute()
+{
+    set_mute(!m_muted);
+}
+
 void Player::seek(int sample)
 {
     m_playback_manager.seek(sample);

+ 8 - 0
Userland/Applications/SoundPlayer/Player.h

@@ -50,11 +50,16 @@ public:
     double volume() const { return m_volume; }
     void set_volume(double value);
 
+    bool is_muted() const { return m_muted; }
+    void set_mute(bool);
+
     void play();
     void pause();
     void toggle_pause();
     void stop();
     void seek(int sample);
+    void mute();
+    void toggle_mute();
 
     virtual void play_state_changed(PlayState) = 0;
     virtual void loop_mode_changed(LoopMode) = 0;
@@ -64,6 +69,7 @@ public:
     virtual void audio_load_error(StringView, StringView) = 0;
     virtual void shuffle_mode_changed(ShuffleMode) = 0;
     virtual void volume_changed(double) = 0;
+    virtual void mute_changed(bool) = 0;
     virtual void total_samples_changed(int) = 0;
     virtual void sound_buffer_played(RefPtr<Audio::Buffer>, [[maybe_unused]] int sample_rate, [[maybe_unused]] int samples_played) = 0;
 
@@ -74,6 +80,7 @@ protected:
         set_loop_mode(LoopMode::None);
         time_elapsed(0);
         set_volume(1.);
+        set_mute(false);
     }
 
 private:
@@ -87,4 +94,5 @@ private:
 
     String m_loaded_filename;
     double m_volume { 0 };
+    bool m_muted { false };
 };

+ 4 - 0
Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp

@@ -180,6 +180,10 @@ void SoundPlayerWidgetAdvancedView::loop_mode_changed(Player::LoopMode)
 {
 }
 
+void SoundPlayerWidgetAdvancedView::mute_changed(bool)
+{
+}
+
 void SoundPlayerWidgetAdvancedView::sync_previous_next_buttons()
 {
     m_back_button->set_enabled(playlist().size() > 1 && !playlist().shuffling());

+ 1 - 0
Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h

@@ -42,6 +42,7 @@ public:
     virtual void playlist_loaded(StringView, bool) override;
     virtual void audio_load_error(StringView path, StringView error_reason) override;
     virtual void volume_changed(double) override;
+    virtual void mute_changed(bool) override;
     virtual void total_samples_changed(int) override;
     virtual void sound_buffer_played(RefPtr<Audio::Buffer>, int sample_rate, int samples_played) override;