aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2013-01-20 18:06:02 -0500
committerDave Reisner <dreisner@archlinux.org>2013-01-20 18:06:02 -0500
commit2bdbd84cc41975c7d9855551cecef02ff41c2b2a (patch)
tree05c06d2468681e746c5998436d40a81ee15ee237
parent597ef6c0d65851fb316207bd32784b49098b19cf (diff)
downloadmirror-ponymix-2bdbd84cc41975c7d9855551cecef02ff41c2b2a.tar.gz
mirror-ponymix-2bdbd84cc41975c7d9855551cecef02ff41c2b2a.tar.bz2
mirror-ponymix-2bdbd84cc41975c7d9855551cecef02ff41c2b2a.zip
clamp volume betweem 0-100 when using increase/decrease
-rw-r--r--ponymix.cc26
1 files 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*[]) {