From 2bdbd84cc41975c7d9855551cecef02ff41c2b2a Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 20 Jan 2013 18:06:02 -0500 Subject: clamp volume betweem 0-100 when using increase/decrease --- ponymix.cc | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/ponymix.cc b/ponymix.cc index 71bf64b..d8b62c6 100644 --- a/ponymix.cc +++ b/ponymix.cc @@ -325,7 +325,9 @@ static int AdjBalance(PulseClient& ponymix, int, char* argv[]) { return 0; } -static int IncreaseVolume(PulseClient& ponymix, int, char* argv[]) { +static int adj_volume(PulseClient& ponymix, + bool (PulseClient::*adjust)(Device&, long int), + char* argv[]) { auto device = string_to_device_or_die(ponymix, opt_device, opt_devtype); long delta; @@ -335,28 +337,20 @@ static int IncreaseVolume(PulseClient& ponymix, int, char* argv[]) { errx(1, "error: failed to convert string to integer: %s", argv[0]); } - if (!ponymix.IncreaseVolume(*device, delta)) return 1; + ponymix.SetVolumeRange(0, 100); + if (!(ponymix.*adjust)(*device, delta)) return 1; printf("%d\n", device->Volume()); return 0; } -static int DecreaseVolume(PulseClient& ponymix, int, char* argv[]) { - auto device = string_to_device_or_die(ponymix, opt_device, opt_devtype); - - long delta; - try { - delta = std::stol(argv[0]); - } catch (std::invalid_argument) { - errx(1, "error: failed to convert string to integer: %s", argv[0]); - } - - if (!ponymix.DecreaseVolume(*device, delta)) return 1; - - printf("%d\n", device->Volume()); +static int IncreaseVolume(PulseClient& ponymix, int, char* argv[]) { + return adj_volume(ponymix, &PulseClient::IncreaseVolume, argv); +} - return 0; +static int DecreaseVolume(PulseClient& ponymix, int, char* argv[]) { + return adj_volume(ponymix, &PulseClient::DecreaseVolume, argv); } static int Mute(PulseClient& ponymix, int, char*[]) { -- cgit v1.2.3