-
Notifications
You must be signed in to change notification settings - Fork 1
/
jacktrip_pypatcher.py
138 lines (110 loc) · 4.57 KB
/
jacktrip_pypatcher.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import jack
from stereo_recording import StereoRecording
import jack_client_patching as p
from ladspa_plugins import LadspaPlugins
from lounge_music import LoungeMusic
from darkice import Darkice
def disconnect(jackClient, dry_run, lounge_music_port):
"""Disconnect all autopatched ports"""
# TODO: only remove autopatched connections, not our own connections (HOW?)
all_jacktrip_receive_ports = jackClient.get_ports(".*receive.*")
all_ladspa_ports = jackClient.get_ports("ladspa-.*")
all_lounge_music_ports = jackClient.get_ports(lounge_music_port + ".*")
if dry_run:
all_lounge_music_ports = []
jcp = p.JackClientPatching(jackClient, dry_run)
for receive_port in all_jacktrip_receive_ports:
jcp.disconnect_all(receive_port)
for ladspa_port in all_ladspa_ports:
jcp.disconnect_all(ladspa_port)
for port in all_lounge_music_ports:
jcp.disconnect_all(port)
def get_current_clients(jackClient, dry_run):
"""Get an array of client jack port prefixes"""
return list(
map(lambda x: x.name.split(":")[0], jackClient.get_ports(".*receive_1"))
)
def autopatch(jackClient, dry_run, jacktrip_clients):
"""Autopatch all the things!"""
all_panning_positions = [
0,
-0.15,
0.15,
-0.3,
0.3,
-0.45,
0.45,
-0.6,
0.6,
-0.75,
0.75,
]
jackspa_path = "jackspa-cli"
lounge_music_path = "/home/sam/lounge-music.mp3"
recording_path_prefix = "/home/sam/darkice-"
lounge_music = LoungeMusic(jackClient, "lounge-music", lounge_music_path, dry_run)
stereo_recording = StereoRecording(recording_path_prefix, dry_run)
darkice = Darkice(jackClient, "darkice", dry_run)
ladspa = LadspaPlugins(jackClient, jackspa_path, all_panning_positions, dry_run)
jcp = p.JackClientPatching(jackClient, dry_run)
print("=== JackTrip clients ===")
print("client count:", len(jacktrip_clients))
print("clients:", jacktrip_clients)
max_supported_clients = len(ladspa.all_positions)
if len(jacktrip_clients) > max_supported_clients:
print(
"Unsupported number of clients, patching",
max_supported_clients,
"of",
len(jacktrip_clients),
)
jacktrip_clients = jacktrip_clients[0:max_supported_clients]
print("=== LADSPA ports ===")
all_ladspa_ports = jackClient.get_ports("ladspa-.*")
print("Current ladspa plugins:", len(all_ladspa_ports))
print("ports:", all_ladspa_ports)
if len(jacktrip_clients) <= 1 and len(all_ladspa_ports) > 0:
print("Killing LADSPA plugins")
ladspa.kill_plugins()
all_ladspa_ports = jackClient.get_ports("ladspa-.*")
print("Current ladspa plugins:", len(all_ladspa_ports))
print("=== Darkice ===")
darkice_port = darkice.get_port()
print("darkice port:", darkice_port)
print("=== Disconnecting existing connections ===")
disconnect(jackClient, dry_run, lounge_music.port)
print("=== Lounge Music ===")
if len(jacktrip_clients) != 1:
lounge_music.kill_the_music()
else:
lounge_music.start_the_music_with_retries()
if len(jacktrip_clients) == 1:
print("=== Patch", len(jacktrip_clients), "client ===")
jcp.connect_mpg123_to_centre(lounge_music.port, jacktrip_clients[0])
jcp.connect_to_centre(jacktrip_clients[0], jacktrip_clients[0])
jcp.connect_mpg123_to_darkice(lounge_music.port, darkice_port)
jcp.connect_darkice_to_centre(jacktrip_clients[0], darkice_port)
if len(jacktrip_clients) >= 2 and len(jacktrip_clients) <= 11:
print("=== Start LADSPA plugins ===")
ladspa_ports = ladspa.get_ports(len(jacktrip_clients), all_ladspa_ports)
darkice_ladspa_ports = ladspa_ports
if len(jacktrip_clients) == 3:
darkice_ladspa_ports = [ladspa_ports[0]] + ladspa_ports[3:]
jcp.set_all_connections(jacktrip_clients, ladspa_ports)
jcp.set_darkice_connections(darkice_ladspa_ports, darkice_port)
print("=== Patch", len(jacktrip_clients), "client ===")
jcp.make_all_connections()
print("=== Recording ===")
if len(jacktrip_clients) > 0:
stereo_recording.start()
else:
stereo_recording.stop()
def main(dry_run=False):
"""Do some setup, then do the autopatch"""
jackClient = jack.Client("MadwortAutoPatcher")
jacktrip_clients = get_current_clients(jackClient, dry_run)
autopatch(jackClient, dry_run, jacktrip_clients)
jackClient.deactivate()
jackClient.close()
if __name__ == "__main__":
main()