Skip to content

Commit

Permalink
Generate panning positions with numpty
Browse files Browse the repository at this point in the history
  • Loading branch information
sandreae committed Mar 12, 2021
1 parent 55715f0 commit 75e98dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 66 deletions.
25 changes: 1 addition & 24 deletions jacktrip_pypatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,43 +37,20 @@ 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-"

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))
Expand Down
42 changes: 18 additions & 24 deletions ladspa_plugins.py
Original file line number Diff line number Diff line change
@@ -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"""
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 5 additions & 18 deletions test_ladspa_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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]
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit 75e98dc

Please sign in to comment.