mixer/Volume: refactor to class MixerMemento, per partition

Eliminate global variables, convert them to MixerMemento fields.

Closes https://github.com/MusicPlayerDaemon/MPD/issues/1583
This commit is contained in:
Max Kellermann
2022-08-08 23:15:09 +02:00
parent 615c301961
commit 4b4f47002b
13 changed files with 141 additions and 116 deletions

View File

@@ -33,7 +33,6 @@
#include "TimePrint.hxx"
#include "decoder/DecoderPrint.hxx"
#include "ls.hxx"
#include "mixer/Volume.hxx"
#include "time/ChronoUtil.hxx"
#include "util/UriUtil.hxx"
#include "util/StringAPI.hxx"
@@ -325,7 +324,7 @@ handle_getvol(Client &client, Request, Response &r)
{
auto &partition = client.GetPartition();
const auto volume = volume_level_get(partition.outputs);
const auto volume = partition.mixer_memento.GetVolume(partition.outputs);
if (volume >= 0)
r.Fmt(FMT_STRING("volume: {}\n"), volume);
@@ -337,7 +336,8 @@ handle_setvol(Client &client, Request args, Response &)
{
unsigned level = args.ParseUnsigned(0, 100);
volume_level_change(client.GetPartition().outputs, level);
auto &partition = client.GetPartition();
partition.mixer_memento.SetVolume(partition.outputs, level);
return CommandResult::OK;
}
@@ -346,9 +346,11 @@ handle_volume(Client &client, Request args, Response &r)
{
int relative = args.ParseInt(0, -100, 100);
auto &outputs = client.GetPartition().outputs;
auto &partition = client.GetPartition();
auto &outputs = partition.outputs;
auto &mixer_memento = partition.mixer_memento;
const int old_volume = volume_level_get(outputs);
const int old_volume = mixer_memento.GetVolume(outputs);
if (old_volume < 0) {
r.Error(ACK_ERROR_SYSTEM, "No mixer");
return CommandResult::ERROR;
@@ -361,7 +363,7 @@ handle_volume(Client &client, Request args, Response &r)
new_volume = 100;
if (new_volume != old_volume)
volume_level_change(outputs, new_volume);
mixer_memento.SetVolume(outputs, new_volume);
return CommandResult::OK;
}

View File

@@ -33,7 +33,11 @@ handle_enableoutput(Client &client, Request args, Response &r)
assert(args.size == 1);
unsigned device = args.ParseUnsigned(0);
if (!audio_output_enable_index(client.GetPartition().outputs, device)) {
auto &partition = client.GetPartition();
if (!audio_output_enable_index(partition.outputs,
partition.mixer_memento,
device)) {
r.Error(ACK_ERROR_NO_EXIST, "No such audio output");
return CommandResult::ERROR;
}
@@ -47,7 +51,11 @@ handle_disableoutput(Client &client, Request args, Response &r)
assert(args.size == 1);
unsigned device = args.ParseUnsigned(0);
if (!audio_output_disable_index(client.GetPartition().outputs, device)) {
auto &partition = client.GetPartition();
if (!audio_output_disable_index(partition.outputs,
partition.mixer_memento,
device)) {
r.Error(ACK_ERROR_NO_EXIST, "No such audio output");
return CommandResult::ERROR;
}
@@ -61,7 +69,11 @@ handle_toggleoutput(Client &client, Request args, Response &r)
assert(args.size == 1);
unsigned device = args.ParseUnsigned(0);
if (!audio_output_toggle_index(client.GetPartition().outputs, device)) {
auto &partition = client.GetPartition();
if (!audio_output_toggle_index(partition.outputs,
partition.mixer_memento,
device)) {
r.Error(ACK_ERROR_NO_EXIST, "No such audio output");
return CommandResult::ERROR;
}

View File

@@ -25,7 +25,6 @@
#include "SingleMode.hxx"
#include "client/Client.hxx"
#include "client/Response.hxx"
#include "mixer/Volume.hxx"
#include "Partition.hxx"
#include "Instance.hxx"
#include "IdleFlags.hxx"
@@ -131,7 +130,7 @@ handle_status(Client &client, [[maybe_unused]] Request args, Response &r)
const auto &playlist = partition.playlist;
const auto volume = volume_level_get(partition.outputs);
const auto volume = partition.mixer_memento.GetVolume(partition.outputs);
if (volume >= 0)
r.Fmt(FMT_STRING("volume: {}\n"), volume);