From 5a91f5b3205c98431a87cfa1d22c8df9cfb667b0 Mon Sep 17 00:00:00 2001 From: David Isaksson Date: Fri, 17 Sep 2021 20:33:21 +0200 Subject: [PATCH] Utilities: Fix asctl volume units A while back the internal volume representation was changed from int to double, but asctl was apparently never changed. This patch fixes that issue. --- Userland/Utilities/asctl.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Userland/Utilities/asctl.cpp b/Userland/Utilities/asctl.cpp index e3e023a9b4c..c2ffe42db82 100644 --- a/Userland/Utilities/asctl.cpp +++ b/Userland/Utilities/asctl.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, kleines Filmröllchen + * Copyright (c) 2021, David Isaksson * * SPDX-License-Identifier: BSD-2-Clause */ @@ -12,6 +13,7 @@ #include #include #include +#include #include #include @@ -63,9 +65,9 @@ int main(int argc, char** argv) for (auto to_print : values_to_print) { switch (to_print) { case AudioVariable::Volume: { - i16 volume = audio_client->get_main_mix_volume(); + auto volume = static_cast(round(audio_client->get_main_mix_volume() * 100)); if (human_mode) - outln("Volume: {:3d}%", volume); + outln("Volume: {}%", volume); else out("{} ", volume); break; @@ -105,6 +107,10 @@ int main(int argc, char** argv) warnln("Error: {} is not an integer volume", arguments[i - 1]); return 1; } + if (volume.value() < 0 || volume.value() > 100) { + warnln("Error: {} is not between 0 and 100", arguments[i - 1]); + return 1; + } values_to_set.set(AudioVariable::Volume, volume.value()); } else if (variable.is_one_of("m"sv, "mute"sv)) { String& mute_text = arguments[++i]; @@ -135,7 +141,7 @@ int main(int argc, char** argv) switch (to_set.key) { case AudioVariable::Volume: { int& volume = to_set.value.get(); - audio_client->set_main_mix_volume(volume); + audio_client->set_main_mix_volume(static_cast(volume) / 100); break; } case AudioVariable::Mute: {