aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pulsemix.14
-rw-r--r--pulsemix.c9
-rwxr-xr-xruntests6
3 files changed, 17 insertions, 2 deletions
diff --git a/pulsemix.1 b/pulsemix.1
index f06e9b7..3665078 100644
--- a/pulsemix.1
+++ b/pulsemix.1
@@ -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.
diff --git a/pulsemix.c b/pulsemix.c
index 3795e1e..9a3484a 100644
--- a/pulsemix.c
+++ b/pulsemix.c
@@ -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)
diff --git a/runtests b/runtests
index 7225d07..b2fb861 100755
--- a/runtests
+++ b/runtests
@@ -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