aboutsummaryrefslogtreecommitdiffstats
path: root/ponymix.cc
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2013-01-21 10:17:49 -0500
committerDave Reisner <dreisner@archlinux.org>2013-01-21 15:49:31 -0500
commit46f6e64539f77eb07b2886aaaab358afd72569ce (patch)
tree0cb0e0555d0ce6fb20d9683cf0ec70e233314b49 /ponymix.cc
parent2bdbd84cc41975c7d9855551cecef02ff41c2b2a (diff)
downloadmirror-ponymix-46f6e64539f77eb07b2886aaaab358afd72569ce.tar.gz
mirror-ponymix-46f6e64539f77eb07b2886aaaab358afd72569ce.tar.bz2
mirror-ponymix-46f6e64539f77eb07b2886aaaab358afd72569ce.zip
abstract volume/balance output away from ponymix
Add a Notifier virtual base class and a CommandLineNotifier implementation which handles output of volume and balance levels after a change.
Diffstat (limited to 'ponymix.cc')
-rw-r--r--ponymix.cc48
1 files changed, 13 insertions, 35 deletions
diff --git a/ponymix.cc b/ponymix.cc
index d8b62c6..d1e40e6 100644
--- a/ponymix.cc
+++ b/ponymix.cc
@@ -278,11 +278,7 @@ static int SetVolume(PulseClient& ponymix, int, char* argv[]) {
errx(1, "error: failed to convert string to integer: %s", argv[0]);
}
- if (!ponymix.SetVolume(*device, volume)) return 1;
-
- printf("%d\n", device->Volume());
-
- return 0;
+ return !ponymix.SetVolume(*device, volume);
}
static int GetBalance(PulseClient& ponymix, int, char*[]) {
@@ -301,11 +297,7 @@ static int SetBalance(PulseClient& ponymix, int, char* argv[]) {
errx(1, "error: failed to convert string to integer: %s", argv[0]);
}
- if (!ponymix.SetBalance(*device, balance)) return 1;
-
- printf("%d\n", device->Balance());
-
- return 0;
+ return !ponymix.SetBalance(*device, balance);
}
static int AdjBalance(PulseClient& ponymix, int, char* argv[]) {
@@ -318,11 +310,7 @@ static int AdjBalance(PulseClient& ponymix, int, char* argv[]) {
errx(1, "error: failed to convert string to integer: %s", argv[0]);
}
- if (!ponymix.SetBalance(*device, device->Balance() + balance)) return 1;
-
- printf("%d\n", device->Balance());
-
- return 0;
+ return !ponymix.SetBalance(*device, device->Balance() + balance);
}
static int adj_volume(PulseClient& ponymix,
@@ -338,11 +326,7 @@ static int adj_volume(PulseClient& ponymix,
}
ponymix.SetVolumeRange(0, 100);
- if (!(ponymix.*adjust)(*device, delta)) return 1;
-
- printf("%d\n", device->Volume());
-
- return 0;
+ return !(ponymix.*adjust)(*device, delta);
}
static int IncreaseVolume(PulseClient& ponymix, int, char* argv[]) {
@@ -356,31 +340,19 @@ static int DecreaseVolume(PulseClient& ponymix, int, char* argv[]) {
static int Mute(PulseClient& ponymix, int, char*[]) {
auto device = string_to_device_or_die(ponymix, opt_device, opt_devtype);
- if (!ponymix.SetMute(*device, true)) return 1;
-
- printf("%d\n", device->Volume());
-
- return 0;
+ return !ponymix.SetMute(*device, true);
}
static int Unmute(PulseClient& ponymix, int, char*[]) {
auto device = string_to_device_or_die(ponymix, opt_device, opt_devtype);
- if (!ponymix.SetMute(*device, false)) return 1;
-
- printf("%d\n", device->Volume());
-
- return 0;
+ return !ponymix.SetMute(*device, false);
}
static int ToggleMute(PulseClient& ponymix, int, char*[]) {
auto device = string_to_device_or_die(ponymix, opt_device, opt_devtype);
- if (!ponymix.SetMute(*device, !ponymix.IsMuted(*device))) return 1;
-
- printf("%d\n", device->Volume());
-
- return 0;
+ return !ponymix.SetMute(*device, !ponymix.IsMuted(*device));
}
static int IsMuted(PulseClient& ponymix, int, char*[]) {
@@ -632,6 +604,12 @@ int main(int argc, char* argv[]) {
argc -= optind;
argv += optind;
+ try {
+ ponymix.EnableNotifications(new CommandLineNotifier);
+ } catch (std::exception e) {
+ fprintf(stderr, "failed to enable notifier\n");
+ }
+
return CommandDispatch(ponymix, argc, argv);
}