-
Notifications
You must be signed in to change notification settings - Fork 1
/
patcher_callback.py
73 lines (53 loc) · 1.89 KB
/
patcher_callback.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
#!/usr/bin/env python3
"""Create a JACK client that prints a lot of information.
This client registers all possible callbacks (except the process
callback and the timebase callback, which would be just too much noise)
and prints some information whenever they are called.
NICKED FROM chatty_client.py
"""
from __future__ import print_function # only needed for Python 2.x
import jack
from time import sleep
import jacktrip_pypatcher as jtp
from pathlib import Path
def check_for_jacktrip_client(name):
if name.startswith("..") or name.startswith("__"):
return True
return False
def main():
print("setting error/info functions")
@jack.set_error_function
def error(msg):
print("Error:", msg)
@jack.set_info_function
def info(msg):
print("Info:", msg)
print("starting chatty client")
client = jack.Client("Chatty-Client")
if client.status.server_started:
print("JACK server was started")
else:
print("JACK server was already running")
if client.status.name_not_unique:
print("unique client name generated:", client.name)
print("registering callbacks")
@client.set_client_registration_callback
def client_registration(name, register):
isJacktripClient = check_for_jacktrip_client(name)
print("client", repr(name), ["unregistered", "registered"][register])
print(
name, " starts with '..' or '__' ? (therefore JT client?)", isJacktripClient
)
if isJacktripClient:
print("touching")
touch_path = Path("/var/tmp/jacktrip_pypatcher")
touch_path.touch()
@client.set_port_connect_callback
def port_connect(a, b, connect):
print(["disconnected", "connected"][connect], a, "and", b)
print("activating JACK")
with client:
while True:
sleep(0.1)
if __name__ == "__main__":
main()