From 69f741e8a636d2fac87c4af4bb2d75454a4195cc Mon Sep 17 00:00:00 2001
From: Max Kellermann <max.kellermann@gmail.com>
Date: Mon, 8 Aug 2022 23:31:25 +0200
Subject: [PATCH] mixer/Memento: move IDLE_MIXER out of SetVolume()

Make this idle event per-partition.
---
 src/command/OtherCommands.cxx | 5 ++++-
 src/mixer/Memento.cxx         | 2 --
 src/mixer/Memento.hxx         | 2 ++
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/command/OtherCommands.cxx b/src/command/OtherCommands.cxx
index 217bcaaec..7f68cf83f 100644
--- a/src/command/OtherCommands.cxx
+++ b/src/command/OtherCommands.cxx
@@ -338,6 +338,7 @@ handle_setvol(Client &client, Request args, Response &)
 
 	auto &partition = client.GetPartition();
 	partition.mixer_memento.SetVolume(partition.outputs, level);
+	partition.EmitIdle(IDLE_MIXER);
 	return CommandResult::OK;
 }
 
@@ -362,8 +363,10 @@ handle_volume(Client &client, Request args, Response &r)
 	else if (new_volume > 100)
 		new_volume = 100;
 
-	if (new_volume != old_volume)
+	if (new_volume != old_volume) {
 		mixer_memento.SetVolume(outputs, new_volume);
+		partition.EmitIdle(IDLE_MIXER);
+	}
 
 	return CommandResult::OK;
 }
diff --git a/src/mixer/Memento.cxx b/src/mixer/Memento.cxx
index c2ec128ab..f8d943426 100644
--- a/src/mixer/Memento.cxx
+++ b/src/mixer/Memento.cxx
@@ -68,8 +68,6 @@ MixerMemento::SetVolume(MultipleOutputs &outputs, unsigned volume)
 
 	volume_software_set = volume;
 
-	idle_add(IDLE_MIXER);
-
 	SetHardwareVolume(outputs, volume);
 }
 
diff --git a/src/mixer/Memento.hxx b/src/mixer/Memento.hxx
index 32d23fdc9..357e154dd 100644
--- a/src/mixer/Memento.hxx
+++ b/src/mixer/Memento.hxx
@@ -49,6 +49,8 @@ public:
 
 	/**
 	 * Throws on error.
+	 *
+	 * Note: the caller is responsible for emitting #IDLE_MIXER.
 	 */
 	void SetVolume(MultipleOutputs &outputs, unsigned volume);