From 47680f936be878281e65bc11834ec90c63bac17d Mon Sep 17 00:00:00 2001
From: Max Kellermann <max.kellermann@gmail.com>
Date: Fri, 8 Jul 2022 10:35:09 +0200
Subject: [PATCH] mixer/All: auto-open "global" mixers

If a mixer is "global", it is available even if the output isn't
open.  However, since the check was changed from IsEnabled() to
IsReallyEnabled(), enabled outputs have not yet been used have not
been "really" enabled yet, preventing using the mixer.

Fixes a regression by commit 35dbc1a90c5110fbf6ab18e98c43463d1b4ea4f3
(part of https://github.com/MusicPlayerDaemon/MPD/pull/1480).

Closes https://github.com/MusicPlayerDaemon/MPD/issues/1563
---
 NEWS                        | 1 +
 src/mixer/MixerAll.cxx      | 5 ++++-
 src/mixer/MixerInternal.hxx | 4 ++++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index c9f55947e..cb25c1a0e 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ ver 0.23.8 (not yet released)
   - pipewire: fix crash with PipeWire 0.3.53
 * mixer
   - better error messages
+  - alsa: fix setting volume before playback starts
 * support libfmt 9
 
 ver 0.23.7 (2022/05/09)
diff --git a/src/mixer/MixerAll.cxx b/src/mixer/MixerAll.cxx
index 96830e7cc..302a06160 100644
--- a/src/mixer/MixerAll.cxx
+++ b/src/mixer/MixerAll.cxx
@@ -91,7 +91,10 @@ output_mixer_set_volume(AudioOutputControl &ao, unsigned volume)
 
 	/* software mixers are always updated, even if they are
 	   disabled */
-	if (!ao.IsReallyEnabled() && !mixer->IsPlugin(software_mixer_plugin))
+	if (!mixer->IsPlugin(software_mixer_plugin) &&
+	    /* "global" mixers can be used even if the output hasn't
+	       been used yet */
+	    !(mixer->IsGlobal() ? ao.IsEnabled() : ao.IsReallyEnabled()))
 		return SetVolumeResult::DISABLED;
 
 	try {
diff --git a/src/mixer/MixerInternal.hxx b/src/mixer/MixerInternal.hxx
index 9fc92d2bd..68b89df4f 100644
--- a/src/mixer/MixerInternal.hxx
+++ b/src/mixer/MixerInternal.hxx
@@ -63,6 +63,10 @@ public:
 		return &plugin == &other;
 	}
 
+	bool IsGlobal() const noexcept {
+		return plugin.global;
+	}
+
 	/**
 	 * Open mixer device
 	 *