diff options
author | Dave Reisner <dreisner@archlinux.org> | 2012-08-13 16:51:11 -0400 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2012-08-13 16:51:11 -0400 |
commit | 58ffb2e6f35ae2528d55ce92f79b42b8bc17be9c (patch) | |
tree | 54629bfd4189d500942a5de72c8209174a579c0f | |
parent | c874ebb5389424e2d04be0c64350c9146b8f8d49 (diff) | |
download | mirror-ponymix-58ffb2e6f35ae2528d55ce92f79b42b8bc17be9c.tar.gz mirror-ponymix-58ffb2e6f35ae2528d55ce92f79b42b8bc17be9c.tar.bz2 mirror-ponymix-58ffb2e6f35ae2528d55ce92f79b42b8bc17be9c.zip |
add adj-balance verb for incremental balance changes
This is useful if you ever wanted to script balance adjustment, since it
would otherwise require 2 invocations (get + set).
-rw-r--r-- | pulsemix.1 | 4 | ||||
-rw-r--r-- | pulsemix.c | 9 | ||||
-rwxr-xr-x | runtests | 6 |
3 files changed, 17 insertions, 2 deletions
@@ -39,6 +39,10 @@ Get the balance of the target. .IP "\fBset-balance\fR \fIVALUE\fR" Set the balance of the target. VALUE is an integer from -100 (all left) to 100 (all right). +.IP "\fBadj-balance\fR \fIVALUE\fR" +Adjust balance by the integer increment VALUE. The resulting balance has the same +bounds as those set by \fBset-balance\fR. The end-of-options indicator (\fI--\fR) is +required when passing a negative increment. .IP "\fBincrease\fR \fIVALUE\fR" Increase the volume percentage of target device or application by integer VALUE. Increasing the volume in this way is capped at 100. @@ -65,6 +65,7 @@ enum action { ACTION_SETVOL, ACTION_GETBAL, ACTION_SETBAL, + ACTION_ADJBAL, ACTION_INCREASE, ACTION_DECREASE, ACTION_MUTE, @@ -626,6 +627,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out) fputs(" set-volume VALUE set volume for device\n", out); fputs(" get-balance get balance for device\n", out); fputs(" set-balance VALUE set balance for device\n", out); + fputs(" adj-balance VALUE increase or decrease balance for device\n", out); fputs(" increase VALUE increase volume\n", out); fputs(" decrease VALUE decrease volume\n", out); fputs(" mute mute device\n", out); @@ -658,6 +660,8 @@ static enum action string_to_verb(const char *string) return ACTION_GETBAL; else if (strcmp(string, "set-balance") == 0) return ACTION_SETBAL; + else if (strcmp(string, "adj-balance") == 0) + return ACTION_ADJBAL; else if (strcmp(string, "increase") == 0) return ACTION_INCREASE; else if (strcmp(string, "decrease") == 0) @@ -692,8 +696,10 @@ static int do_verb(struct pulseaudio_t *pulse, enum action verb, int value) printf("%d\n", pulse->head->balance); return 0; case ACTION_SETBAL: + return set_balance(pulse, pulse->head, CLAMP(value, -100, 100)); + case ACTION_ADJBAL: return set_balance(pulse, pulse->head, - CLAMP(value, -100, 100)); + CLAMP(pulse->head->balance + value, -100, 100)); case ACTION_INCREASE: return set_volume(pulse, pulse->head, CLAMP(pulse->head->volume_percent + value, 0, 100)); @@ -781,6 +787,7 @@ int main(int argc, char *argv[]) switch (verb) { case ACTION_SETVOL: case ACTION_SETBAL: + case ACTION_ADJBAL: case ACTION_INCREASE: case ACTION_DECREASE: if (optind == argc) @@ -19,7 +19,7 @@ do_test() { (( ++testno )) - result=$("$pulsemix" "$verb" ${arg+"$arg"} 2>/dev/null) + result=$("$pulsemix" "$verb" -- ${arg+"$arg"} 2>/dev/null) if [[ $result != $expected ]]; then printf '==> test %d FAIL: expected %s, got %s\n' "$testno" "$expected" "$result" (( ++fail )) @@ -40,7 +40,11 @@ do_test '' 'decrease' bar # balance do_test 30 'set-balance' 30 +do_test 30 'get-balance' do_test 100 'set-balance' 9001 +do_test -5 'adj-balance' -105 +do_test 45 'adj-balance' 50 +do_test 100 'adj-balance' 9001 do_test 0 'set-balance' 0 if (( ! fail )); then |