def softvolume(self, val, pl): if (val is None): absvol = mixer.volume(None) sf = pl.audio_get_volume() # sometimes the softvolume is bigger than 100 while hw volume is 100, catch that return min( 100, int(sf * 100 / absvol) ) elif ((isinstance(val, int) or val.isdigit()) and (int(val) <= 100) and (int(val) >= 0)): p = int(val) absvol = mixer.volume(None) softvol = min(absvol, round(absvol * p / 100)) pl.audio_set_volume(softvol) return(softvol) else: raise Exception('Invalid argument to softvolume: ' + str(val))
def restore_hardvolume(self): if (self.saved_hardvolume >= 0): mixer.volume(self.saved_hardvolume) return self.saved_hardvolume
def save_hardvolume(self): self.saved_hardvolume = mixer.volume(None) return self.saved_hardvolume
def volume(self, val): return mixer.volume(val)