From af8e3067e8c64ef3317dd4e108af56d5b7ad2f3e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 28 Mar 2015 18:35:20 +0100 Subject: alsa: add get_mute and set_mute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- TODO | 1 + src/plugins/alsa.py | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 1836ee5..beda40e 100644 --- a/TODO +++ b/TODO @@ -47,5 +47,6 @@ Demo plugins: vmstat weather hdparm + alsa :: get_mute, set_mute, set_volume Terminal mode diff --git a/src/plugins/alsa.py b/src/plugins/alsa.py index b955130..e9f144f 100644 --- a/src/plugins/alsa.py +++ b/src/plugins/alsa.py @@ -67,7 +67,7 @@ class ALSA: def set_volume(self, volume, channel = -1): ''' - set the volume for a channel on the mixer + Set the volume for a channel on the mixer @param volume:int? The [0, 100] volume for the channel, `None` to mute the channel @param channel:int The index of the channel, `ALSA.ALL_CHANNELS` (-1) for all channels @@ -82,6 +82,29 @@ class ALSA: pass # some mixers do not have mute switch + def get_mute(self): + ''' + Get the mute status for each channel on the mixer + + @return :list Whether mixer is muted for each channel + ''' + self.mixer = alsaaudio.Mixer(self.mixername, 0, self.cardindex) + try: + return [m == 1 for m in self.mixer.getmute()] + except: + return [False] * len(self.mixer.getvolume()) + + + def set_mute(self, mute, channel = -1): + ''' + Set the mute status on the mixer + + @param mute:bool Whether the mixer should be muted on the channel + @param channel:int The index of the channel, `ALSA.ALL_CHANNELS` (-1) for all channels + ''' + self.mixer.setmute(mute, channel) + + @staticmethod def get_cards(): ''' -- cgit v1.2.3-70-g09d2