diff options
author | Dave Reisner <dreisner@archlinux.org> | 2012-05-11 11:55:05 -0400 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2012-05-11 12:08:01 -0400 |
commit | d5682e1cf9c42cd442ca83f20ae022427c12e54f (patch) | |
tree | c4414c91c10b4c9885bf65cc50521308d2e5699f | |
parent | 2bcc1a65aff1b3907210edd61cce114cd7fc3fb5 (diff) | |
download | mirror-ponymix-d5682e1cf9c42cd442ca83f20ae022427c12e54f.tar.gz mirror-ponymix-d5682e1cf9c42cd442ca83f20ae022427c12e54f.tar.bz2 mirror-ponymix-d5682e1cf9c42cd442ca83f20ae022427c12e54f.zip |
clamp volumes between 0 and 150
-rw-r--r-- | pulsemix.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -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); |