From 310a146a55eb682b2b0b348431016b31d7f0a7e9 Mon Sep 17 00:00:00 2001 From: jcorporation Date: Tue, 6 Sep 2022 21:58:18 +0200 Subject: [PATCH] OutputCommands get ride of global mixer idle events --- src/Partition.cxx | 7 +++++++ src/Partition.hxx | 1 + src/mixer/Listener.hxx | 1 + src/output/OutputCommand.cxx | 10 ++++++---- test/NullMixerListener.hxx | 1 + 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Partition.cxx b/src/Partition.cxx index 7134015bc..de538e88a 100644 --- a/src/Partition.cxx +++ b/src/Partition.cxx @@ -225,6 +225,13 @@ Partition::OnMixerVolumeChanged(Mixer &, int) noexcept EmitIdle(IDLE_MIXER); } +void +Partition::OnMixerChanged() noexcept +{ + /* notify clients */ + EmitIdle(IDLE_MIXER); +} + void Partition::OnIdleMonitor(unsigned mask) noexcept { diff --git a/src/Partition.hxx b/src/Partition.hxx index 6f9de5931..348d9da37 100644 --- a/src/Partition.hxx +++ b/src/Partition.hxx @@ -288,6 +288,7 @@ private: /* virtual methods from class MixerListener */ void OnMixerVolumeChanged(Mixer &mixer, int volume) noexcept override; + void OnMixerChanged() noexcept override; /* callback for #idle_monitor */ void OnIdleMonitor(unsigned mask) noexcept; diff --git a/src/mixer/Listener.hxx b/src/mixer/Listener.hxx index b33927fe2..d83418bb6 100644 --- a/src/mixer/Listener.hxx +++ b/src/mixer/Listener.hxx @@ -30,6 +30,7 @@ class MixerListener { public: virtual void OnMixerVolumeChanged(Mixer &mixer, int volume) noexcept = 0; + virtual void OnMixerChanged() noexcept = 0; }; #endif diff --git a/src/output/OutputCommand.cxx b/src/output/OutputCommand.cxx index 41e51976d..9e889758b 100644 --- a/src/output/OutputCommand.cxx +++ b/src/output/OutputCommand.cxx @@ -29,6 +29,7 @@ #include "Client.hxx" #include "mixer/Mixer.hxx" #include "mixer/Memento.hxx" +#include "mixer/Listener.hxx" #include "Idle.hxx" extern unsigned audio_output_state_version; @@ -47,9 +48,10 @@ audio_output_enable_index(MultipleOutputs &outputs, idle_add(IDLE_OUTPUT); - if (ao.GetMixer() != nullptr) { + auto *mixer = ao.GetMixer(); + if (mixer != nullptr) { mixer_memento.InvalidateHardwareVolume(); - idle_add(IDLE_MIXER); + mixer->listener.OnMixerChanged(); } ao.GetClient().ApplyEnabled(); @@ -77,7 +79,7 @@ audio_output_disable_index(MultipleOutputs &outputs, if (mixer != nullptr) { mixer->LockClose(); mixer_memento.InvalidateHardwareVolume(); - idle_add(IDLE_MIXER); + mixer->listener.OnMixerChanged(); } ao.GetClient().ApplyEnabled(); @@ -104,7 +106,7 @@ audio_output_toggle_index(MultipleOutputs &outputs, if (mixer != nullptr) { mixer->LockClose(); mixer_memento.InvalidateHardwareVolume(); - idle_add(IDLE_MIXER); + mixer->listener.OnMixerChanged(); } } diff --git a/test/NullMixerListener.hxx b/test/NullMixerListener.hxx index 965e2d6dc..5e845a6b5 100644 --- a/test/NullMixerListener.hxx +++ b/test/NullMixerListener.hxx @@ -25,6 +25,7 @@ class NullMixerListener : public MixerListener { public: void OnMixerVolumeChanged(Mixer &, int) noexcept override {} + virtual void OnMixerChanged() noexcept override {} }; #endif