From d5682e1cf9c42cd442ca83f20ae022427c12e54f Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Fri, 11 May 2012 11:55:05 -0400 Subject: clamp volumes between 0 and 150 --- pulsemix.c | 15 ++++++++++++--- 1 file 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); -- cgit v1.2.3