-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoundmonitor.py
More file actions
74 lines (69 loc) · 1.67 KB
/
soundmonitor.py
File metadata and controls
74 lines (69 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/env python3
#main.py
#Imports
import alsaaudio
#END imports
#Volume functions
#Reset volume
def reset_volume(mx, rv):
#Mixer, Reset Volume
cond1 = isinstance(rv, int) and rv != None
cond2 = isinstance(mx, alsaaudio.Mixer) and mx != None
if cond1 and cond2:
#Configuration is too high
if rv > 100:
mx.setvolume(100)
#Configuration is too low
elif rv < 0:
mx.setvolume(0)
else: #Configuration is valid
mx.setvolume(rv)
return True
else:
return False
#Mute volume
def mute_volume(mx, muv, mav):
#Mixer, Mute Volume, Max Volume
cond1 = isinstance(muv, int) and muv != None
cond2 = isinstance(mav, int) and mav != None
cond3 = isinstance(mx, alsaaudio.Mixer) and mx != None
if cond1 and cond2 and cond3:
if mav > 0:
muv = mav
mx.setvolume(0)
else:
mx.setvolume(muv)
return muv
else:
return muv
#Increase volume
def inc_volume(mx, mav, step):
#Mixer, Mute Volume, Max Volume
cond1 = isinstance(step, int) and step != None
cond2 = isinstance(mav, int) and mav != None
cond3 = isinstance(mx, alsaaudio.Mixer) and mx != None
if cond1 and cond2 and cond3:
#Highest channel + step exceeds max volume
if mav > (100 - step):
mx.setvolume(100)
else:
mx.setvolume(mav + step)
return True
else:
return False
#Decrease volume
def dec_volume(mx, miv, step):
#Mixer, Mute Volume, Max Volume
cond1 = isinstance(step, int) and step != None
cond2 = isinstance(miv, int) and miv != None
cond3 = isinstance(mx, alsaaudio.Mixer) and mx != None
if cond1 and cond2 and cond3:
#Lowering by one step is less than muted
if miv < step:
mx.setvolume(0)
else:
mx.setvolume(miv - step)
return True
else:
return False
#END volume functions