aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-05-11 11:55:05 -0400
committerDave Reisner <dreisner@archlinux.org>2012-05-11 12:08:01 -0400
commitd5682e1cf9c42cd442ca83f20ae022427c12e54f (patch)
treec4414c91c10b4c9885bf65cc50521308d2e5699f
parent2bcc1a65aff1b3907210edd61cce114cd7fc3fb5 (diff)
downloadmirror-ponymix-d5682e1cf9c42cd442ca83f20ae022427c12e54f.tar.gz
mirror-ponymix-d5682e1cf9c42cd442ca83f20ae022427c12e54f.tar.bz2
mirror-ponymix-d5682e1cf9c42cd442ca83f20ae022427c12e54f.zip
clamp volumes between 0 and 150
-rw-r--r--pulsemix.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/pulsemix.c b/pulsemix.c
index b4927fb..4afcc46 100644
--- a/pulsemix.c
+++ b/pulsemix.c
@@ -38,6 +38,14 @@
#define UNUSED __attribute__((unused))
+#define CLAMP(x, low, high) \
+ __extension__ ({ \
+ typeof(x) _x = (x); \
+ typeof(low) _low = (low); \
+ typeof(high) _high = (high); \
+ ((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \
+ })
+
union arg_t {
long l;
char *c;
@@ -263,7 +271,6 @@ static void set_default_sink(struct pulseaudio_t *pulse, const char *sinkname)
op = pa_context_set_default_sink(pulse->cxt, sinkname, NULL, pulse);
pulse_async_wait(pulse, op);
pa_operation_unref(op);
-
}
static void pulse_deinit(struct pulseaudio_t *pulse)
@@ -433,10 +440,12 @@ int main(int argc, char *argv[])
sink_set_volume(&pulse, pulse.sink, value.l);
break;
case ACTION_INCREASE:
- sink_set_volume(&pulse, pulse.sink, pulse.sink->volume_percent + value.l);
+ sink_set_volume(&pulse, pulse.sink,
+ CLAMP(pulse.sink->volume_percent + value.l, 0, 150));
break;
case ACTION_DECREASE:
- sink_set_volume(&pulse, pulse.sink, pulse.sink->volume_percent - value.l);
+ sink_set_volume(&pulse, pulse.sink,
+ CLAMP(pulse.sink->volume_percent - value.l, 0, 150));
break;
case ACTION_MUTE:
sink_mute(&pulse, pulse.sink);