output/Command: trigger IDLE_OUTPUT only for the current partition

Closes https://github.com/MusicPlayerDaemon/MPD/issues/1622
This commit is contained in:
Max Kellermann 2024-07-08 15:48:06 +02:00
parent bdc5602244
commit 553c2e9e2b
3 changed files with 23 additions and 33 deletions

View File

@ -19,8 +19,7 @@ handle_enableoutput(Client &client, Request args, Response &r)
auto &partition = client.GetPartition(); auto &partition = client.GetPartition();
if (!audio_output_enable_index(partition.outputs, if (!audio_output_enable_index(partition,
partition.mixer_memento,
device)) { device)) {
r.Error(ACK_ERROR_NO_EXIST, "No such audio output"); r.Error(ACK_ERROR_NO_EXIST, "No such audio output");
return CommandResult::ERROR; return CommandResult::ERROR;
@ -37,8 +36,7 @@ handle_disableoutput(Client &client, Request args, Response &r)
auto &partition = client.GetPartition(); auto &partition = client.GetPartition();
if (!audio_output_disable_index(partition.outputs, if (!audio_output_disable_index(partition,
partition.mixer_memento,
device)) { device)) {
r.Error(ACK_ERROR_NO_EXIST, "No such audio output"); r.Error(ACK_ERROR_NO_EXIST, "No such audio output");
return CommandResult::ERROR; return CommandResult::ERROR;
@ -55,8 +53,7 @@ handle_toggleoutput(Client &client, Request args, Response &r)
auto &partition = client.GetPartition(); auto &partition = client.GetPartition();
if (!audio_output_toggle_index(partition.outputs, if (!audio_output_toggle_index(partition,
partition.mixer_memento,
device)) { device)) {
r.Error(ACK_ERROR_NO_EXIST, "No such audio output"); r.Error(ACK_ERROR_NO_EXIST, "No such audio output");
return CommandResult::ERROR; return CommandResult::ERROR;

View File

@ -9,20 +9,20 @@
*/ */
#include "OutputCommand.hxx" #include "OutputCommand.hxx"
#include "MultipleOutputs.hxx"
#include "Client.hxx" #include "Client.hxx"
#include "mixer/Mixer.hxx" #include "mixer/Mixer.hxx"
#include "mixer/Memento.hxx" #include "mixer/Memento.hxx"
#include "mixer/Listener.hxx" #include "mixer/Listener.hxx"
#include "Idle.hxx" #include "IdleFlags.hxx"
#include "Partition.hxx"
extern unsigned audio_output_state_version; extern unsigned audio_output_state_version;
bool bool
audio_output_enable_index(MultipleOutputs &outputs, audio_output_enable_index(Partition &partition,
MixerMemento &mixer_memento,
unsigned idx) unsigned idx)
{ {
auto &outputs = partition.outputs;
if (idx >= outputs.Size()) if (idx >= outputs.Size())
return false; return false;
@ -30,11 +30,11 @@ audio_output_enable_index(MultipleOutputs &outputs,
if (!ao.LockSetEnabled(true)) if (!ao.LockSetEnabled(true))
return true; return true;
idle_add(IDLE_OUTPUT); partition.EmitIdle(IDLE_OUTPUT);
auto *mixer = ao.GetMixer(); auto *mixer = ao.GetMixer();
if (mixer != nullptr) { if (mixer != nullptr) {
mixer_memento.InvalidateHardwareVolume(); partition.mixer_memento.InvalidateHardwareVolume();
mixer->listener.OnMixerChanged(); mixer->listener.OnMixerChanged();
} }
@ -46,10 +46,10 @@ audio_output_enable_index(MultipleOutputs &outputs,
} }
bool bool
audio_output_disable_index(MultipleOutputs &outputs, audio_output_disable_index(Partition &partition,
MixerMemento &mixer_memento,
unsigned idx) unsigned idx)
{ {
auto &outputs = partition.outputs;
if (idx >= outputs.Size()) if (idx >= outputs.Size())
return false; return false;
@ -57,12 +57,12 @@ audio_output_disable_index(MultipleOutputs &outputs,
if (!ao.LockSetEnabled(false)) if (!ao.LockSetEnabled(false))
return true; return true;
idle_add(IDLE_OUTPUT); partition.EmitIdle(IDLE_OUTPUT);
auto *mixer = ao.GetMixer(); auto *mixer = ao.GetMixer();
if (mixer != nullptr) { if (mixer != nullptr) {
mixer->LockClose(); mixer->LockClose();
mixer_memento.InvalidateHardwareVolume(); partition.mixer_memento.InvalidateHardwareVolume();
mixer->listener.OnMixerChanged(); mixer->listener.OnMixerChanged();
} }
@ -74,22 +74,22 @@ audio_output_disable_index(MultipleOutputs &outputs,
} }
bool bool
audio_output_toggle_index(MultipleOutputs &outputs, audio_output_toggle_index(Partition &partition,
MixerMemento &mixer_memento,
unsigned idx) unsigned idx)
{ {
auto &outputs = partition.outputs;
if (idx >= outputs.Size()) if (idx >= outputs.Size())
return false; return false;
auto &ao = outputs.Get(idx); auto &ao = outputs.Get(idx);
const bool enabled = ao.LockToggleEnabled(); const bool enabled = ao.LockToggleEnabled();
idle_add(IDLE_OUTPUT); partition.EmitIdle(IDLE_OUTPUT);
if (!enabled) { if (!enabled) {
auto *mixer = ao.GetMixer(); auto *mixer = ao.GetMixer();
if (mixer != nullptr) { if (mixer != nullptr) {
mixer->LockClose(); mixer->LockClose();
mixer_memento.InvalidateHardwareVolume(); partition.mixer_memento.InvalidateHardwareVolume();
mixer->listener.OnMixerChanged(); mixer->listener.OnMixerChanged();
} }
} }

View File

@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project // Copyright The Music Player Daemon Project
#pragma once
/* /*
* Glue functions for controlling the audio outputs over the MPD * Glue functions for controlling the audio outputs over the MPD
* protocol. These functions perform extra validation on all * protocol. These functions perform extra validation on all
@ -8,19 +10,14 @@
* *
*/ */
#ifndef MPD_OUTPUT_COMMAND_HXX struct Partition;
#define MPD_OUTPUT_COMMAND_HXX
class MultipleOutputs;
class MixerMemento;
/** /**
* Enables an audio output. Returns false if the specified output * Enables an audio output. Returns false if the specified output
* does not exist. * does not exist.
*/ */
bool bool
audio_output_enable_index(MultipleOutputs &outputs, audio_output_enable_index(Partition &partition,
MixerMemento &mixer_memento,
unsigned idx); unsigned idx);
/** /**
@ -28,8 +25,7 @@ audio_output_enable_index(MultipleOutputs &outputs,
* does not exist. * does not exist.
*/ */
bool bool
audio_output_disable_index(MultipleOutputs &outputs, audio_output_disable_index(Partition &partition,
MixerMemento &mixer_memento,
unsigned idx); unsigned idx);
/** /**
@ -37,8 +33,5 @@ audio_output_disable_index(MultipleOutputs &outputs,
* does not exist. * does not exist.
*/ */
bool bool
audio_output_toggle_index(MultipleOutputs &outputs, audio_output_toggle_index(Partition &partition,
MixerMemento &mixer_memento,
unsigned idx); unsigned idx);
#endif