From c1872f0fc911c5f27ae774af0155af4787e9ca8b Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 17 May 2020 11:58:34 +0200 Subject: Better handle mono devices/sink inputs --- inter.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/inter.py b/inter.py index 9d44062..5abd210 100644 --- a/inter.py +++ b/inter.py @@ -91,7 +91,7 @@ def mainloop(): thing = get_selected() kind = "sink" if type(thing) == pa.Sink else "input" vol = thing.volume() - if vol[0] != vol[1]: + if len(vol) >= 2 and vol[0] != vol[1]: show_message( "Warning: current volume of this " + kind + " is asymmetric!") @@ -140,7 +140,8 @@ def mainloop(): T.bel() continue - vol = sum(thing.volume()) / 2 + vol = thing.volume() + vol = sum(vol) / len(vol) vol = min(1, max(0, vol + incr)) wrap_pacmd(lambda: thing.set_volume(vol)) @@ -249,13 +250,18 @@ def print_prefix(thing, selected): T.tprint(" ") def fmt_volume(vol): - res = ["", ""] - for i in range(2): - res[i] = str(round(100 * vol[i])) + "%" - if vol[0] == vol[1]: - return res[0] + res = [str(round(100 * value)) + "%" for value in vol] + if len(vol) > 2: + return res[0] + "/" + res[1] + " (? len(vol)==" + str(len(vol)) + ")" + elif len(vol) == 2: + if vol[0] == vol[1]: + return res[0] + else: + return res[0] + "/" + res[1] + elif len(vol) == 1: + return res[0] + " (mono)" else: - return res[0] + "/" + res[1] + return "? (len(vol)==0)" def print_volume(thing): T.setfg(6) -- cgit v1.2.3-70-g09d2