diff --git a/jacktrip_pypatcher.py b/jacktrip_pypatcher.py index ddc8d1c..74de2e4 100644 --- a/jacktrip_pypatcher.py +++ b/jacktrip_pypatcher.py @@ -37,19 +37,6 @@ def get_current_clients(jackClient, dry_run): 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-" @@ -57,23 +44,13 @@ def autopatch(jackClient, dry_run, jacktrip_clients): 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) + ladspa = LadspaPlugins(jackClient, jackspa_path, 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)) diff --git a/ladspa_plugins.py b/ladspa_plugins.py index f91a8b9..64b61a4 100644 --- a/ladspa_plugins.py +++ b/ladspa_plugins.py @@ -1,42 +1,36 @@ import subprocess import time +import numpy as np class LadspaPlugins(object): """LadspaPlugins patching stuff""" - def __init__(self, jackClient, jackspa_path, all_positions, dry_run=False): + def __init__(self, jackClient, jackspa_path, 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 == 0: + return [] + + if number_of_clients == 1: + return [0] + if number_of_clients == 2: - return self.all_positions[5:7] + # Just map points between -0.5 and 0.5 for shallow 2 client panning + return list(np.linspace(-0.5, 0.5, number_of_clients)) + 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] + # Fixes the strange case of 3 clients + panning_positions = list(np.linspace(-0.5, 0.5, number_of_clients)) + panning_positions + (panning_positions[0] - 0.01) + panning_positions + (panning_positions[2] - 0.01) + return panning_positions + + return list(np.linspace(-1, 1, number_of_clients)) def generate_port_name(self, panning_position): """Returns a ladspa port name""" diff --git a/requirements.txt b/requirements.txt index 7aaccf2..afe7652 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ black==19.10b0 cffi==1.14.2 JACK-Client==0.5.2 +numpy==1.20.1 psutil==5.7.2 pytest==6.0.1 pytest-freezegun==0.4.2 diff --git a/test_ladspa_plugins.py b/test_ladspa_plugins.py index a5d2e53..59e0bc5 100644 --- a/test_ladspa_plugins.py +++ b/test_ladspa_plugins.py @@ -4,7 +4,7 @@ def test_generate_subprocess_cmd(position=0.3): - ladspa = LadspaPlugins(None, "jackspa-cli", [], dry_run=True) + ladspa = LadspaPlugins(None, "jackspa-cli", dry_run=True) cmd = [ "jackspa-cli", @@ -21,7 +21,7 @@ def test_generate_subprocess_cmd(position=0.3): def test_generate_port_name(): - ladspa = LadspaPlugins(None, "jackspa-cli", [], dry_run=True) + ladspa = LadspaPlugins(None, "jackspa-cli", dry_run=True) panning_positions = [0, -0.3, 0.3, -0.6, 0.6] port_names = [ "ladspa-centre", @@ -38,20 +38,7 @@ def test_generate_port_name(): def test_get_panning_positions(): - all_panning_positions = [ - 0, - -0.15, - 0.15, - -0.3, - 0.3, - -0.45, - 0.45, - -0.6, - 0.6, - -0.75, - 0.75, - ] - ladspa = LadspaPlugins(None, "jackspa-cli", all_panning_positions, dry_run=True) + ladspa = LadspaPlugins(None, "jackspa-cli", dry_run=True) positions_for_2_clients = [-0.45, 0.45] positions_for_3_clients = [0, -0.45, 0.45, -0.46, 0.46] @@ -101,7 +88,7 @@ def test_get_panning_positions(): # run pytest with -rP flag to see stdout logs showing which ports need to be started def test_get_and_check_port(): - ladspa = LadspaPlugins(None, "jackspa-cli", [], dry_run=True) + ladspa = LadspaPlugins(None, "jackspa-cli", dry_run=True) panning_positions = [0, -0.3, 0.3, -0.6, 0.6] all_existing_ladspa_ports = [Mock()] all_existing_ladspa_ports[0].name = "ladspa-centre" @@ -135,7 +122,7 @@ def test_get_ports(): -0.75, 0.75, ] - ladspa = LadspaPlugins(None, "jackspa-cli", all_panning_positions, dry_run=True) + ladspa = LadspaPlugins(None, "jackspa-cli", dry_run=True) no_of_clients = 4 all_existing_ladspa_ports = [