-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqt_mutes.py
More file actions
86 lines (70 loc) · 2.12 KB
/
sqt_mutes.py
File metadata and controls
86 lines (70 loc) · 2.12 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
75
76
77
78
79
80
81
82
83
84
85
86
import subprocess
import sys
PORT = 9988
import os
os.chdir(os.path.dirname(os.path.realpath(__file__))) # set cwd to where the script is
import time
pipe = '.sqtmute_instructions'
out = '.sqtmute_output'
def save(mutes) -> None:
other_data = []
try:
with open("current.sav") as save_file:
save_data = save_file.readlines()
except:
pass
else:
for line in save_data:
if not line.startswith("sqtmutes"):
other_data.append(line)
save_data = other_data
save_data.append('sqtmutes ' + ' '.join(str(i) for i in mutes)+'\n')
with open("current.sav", 'w') as save_file:
save_file.writelines(save_data)
def ensure():
if not is_running():
subprocess.check_output("python3 ./muter.py &", shell=True)
time.sleep(0.5)
print("Running muter now")
def instruct(inst: str, expect: bool=False) -> str:
if expect:
with open(out, 'w'):
pass
with open(pipe, 'w') as instructions:
instructions.write(f'{inst}\n')
time.sleep(0.3)
response = ''
if expect:
with open(out) as output:
response = ''.join(output.readlines()).strip()
return response
def is_running() -> bool:
output = instruct('s',True).strip()
return bool(output)
def multi_mute(*muted_channels: int) -> None:
ensure()
instruct('a')
muteline = 't ' + ' '.join(str(chan) for chan in muted_channels)
print('SQT:',instruct(muteline, True))
if __name__ == '__main__':
# if not is_running():
# print("muter not running")
# sys.exit(1)
ensure()
muted_channels = []
try:
muted_channels = list(int(i) for i in instruct('s',True).split(' ')[1:])
except:
muted_channels = []
for i in range(16):
if i+1 in muted_channels:
print(i+1,"<- MUTED")
else:
print(i+1)
print(instruct('t '+input("\nMIDI channels 1-16: "), True))
try:
muted_channels = list(int(i) for i in instruct('s',True).split(' ')[1:])
except:
muted_channels = []
muted_channels.sort()
save(muted_channels)