-
Notifications
You must be signed in to change notification settings - Fork 0
/
change_mixer.py
102 lines (78 loc) · 2.36 KB
/
change_mixer.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import lxml.etree as etree
filein = './mixer_paths_0.xml'
fileout = './mixer_paths_0_python.xml'
def volume(val_str, mic_gain):
val = int(val_str)
return f'{val*mic_gain}'
def boost(val_str, mic_boost):
val = int(val_str)
return f'{val+mic_boost}'
def main(mic1_gain, mic2_gain):
do_volume = False
do_boost = False
if mic1_gain != -1:
do_mic1 = True
do_volume = True
else:
do_mic1 = False
if mic2_gain != -1:
do_mic2 = True
do_volume = True
else:
do_mic2 = False
# breakpoint()
parser = etree.XMLParser(remove_blank_text=False)
root = etree.parse(filein, parser)
# breakpoint()
if do_volume:
if do_mic1:
for mic in root.xpath("//ctl[@name='MIC1 Volume']"):
attr = mic.attrib
attr['value'] = volume(attr['value'], mic1_gain)
if do_mic2:
for mic in root.xpath("//ctl[@name='MIC2 Volume']"):
attr = mic.attrib
attr['value'] = volume(attr['value'], mic2_gain)
if do_boost:
if do_mic1:
for mic in root.xpath("//ctl[@name='MIC1 Boost Volume']"):
attr = mic.attrib
attr['value'] = boost(attr['value'], 1)
if do_mic2:
for mic in root.xpath("//ctl[@name='MIC2 Boost Volume']"):
attr = mic.attrib
attr['value'] = boost(attr['value'], 1)
# print(etree.tostring(root, pretty_print=True))
root.write(fileout, encoding="UTF-8", pretty_print=False,
strip_text=False, with_tail=True)
if __name__ == "__main__":
import argparse
# from six import text_type
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
'-m', '--mic1_gain',
dest='mic1_gain',
type=int,
default=-1,
help='specifies the gain for mic 1',
)
parser.add_argument(
'-M', '--mic2_gain',
dest='mic2_gain',
type=int,
default=-1,
help='specifies the gain for mic 2',
)
args, unknown = parser.parse_known_args()
try:
main(
args.mic1_gain,
args.mic2_gain,
)
except KeyboardInterrupt:
pass
finally:
print("Done\n")