-
Notifications
You must be signed in to change notification settings - Fork 1
/
ladspa_plugins.py
97 lines (81 loc) · 3.28 KB
/
ladspa_plugins.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
import subprocess
import time
class LadspaPlugins(object):
"""LadspaPlugins patching stuff"""
def __init__(self, jackClient, jackspa_path, all_positions, dry_run=False):
super(LadspaPlugins, self).__init__()
self.jackClient = jackClient
self.jackspa_path = jackspa_path
self.all_positions = all_positions
self.dry_run = dry_run
def get_panning_positions(self, number_of_clients):
if number_of_clients == 2:
return self.all_positions[5:7]
if number_of_clients == 3:
return [
self.all_positions[0],
self.all_positions[5],
self.all_positions[6],
(self.all_positions[5] - 0.01),
(self.all_positions[6] + 0.01),
]
if number_of_clients % 2 == 0:
positions = []
else:
positions = [self.all_positions[0]]
if number_of_clients < 6:
return positions + self.all_positions[3:7]
if number_of_clients < 8:
return positions + self.all_positions[1:3] + self.all_positions[5:9]
if number_of_clients < 10:
return positions + self.all_positions[1:9]
if number_of_clients < 12:
return positions + self.all_positions[1:11]
def generate_port_name(self, panning_position):
"""Returns a ladspa port name"""
if panning_position == 0:
return "ladspa-centre"
elif panning_position < 0:
return "ladspa-left-" + str(int(abs(panning_position * 100)))
else:
return "ladspa-right-" + str(int(panning_position * 100))
def get_port(self, panning_position, all_ladspa_ports):
"""Start a ladspa plugin if it isn't running and return port name"""
port_name = self.generate_port_name(panning_position)
if port_name not in [port.name.split(":")[0] for port in all_ladspa_ports]:
print("No ladspa port for panning position", panning_position)
print("Starting", port_name, "now")
self.start_plugin(panning_position)
return port_name
def get_ports(self, no_of_clients, all_ladspa_ports):
panning_positions = self.get_panning_positions(no_of_clients)
ladspa_ports = [
self.get_port(position, all_ladspa_ports) for position in panning_positions
]
return ladspa_ports
def generate_subprocess_cmd(self, panning_position):
port_name = self.generate_port_name(panning_position)
return [
self.jackspa_path,
"-j",
port_name,
"-i",
"0:0:0:" + str(panning_position) + ":0:0",
"/usr/lib/ladspa/inv_input.so",
"3301",
]
def kill_plugins(self):
"""kill ladspa plugins"""
if self.dry_run:
print("Kill ladspa plugins")
return
subprocess.call(["killall", "jackspa-cli"])
time.sleep(0.5)
def start_plugin(self, panning_position):
"""start ladspa plugins for 2 and above clients of clients"""
if self.dry_run:
print("Start ladspa plugin for position:", panning_position)
return
cmd = self.generate_subprocess_cmd(panning_position)
subprocess.Popen(cmd)
time.sleep(0.5)