Skip to content

Commit

Permalink
Dynamic handling of mod-external client
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Dec 3, 2023
1 parent b4a5ca8 commit 7e4bc4e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
35 changes: 24 additions & 11 deletions mod/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ def __init__(self, hmi, prefs, msg_callback):
# clients at the end of the chain, all managed by mod-host
self.jack_hw_capture_prefix = "mod-host:out" if self.descriptor.get('has_noisegate', False) else "system:capture_"

# used for network-manager
self.jack_slave_prefix = "mod-slave"
# used for external connections
self.jack_external_prefix = "mod-external"

# used for usb gadget, MUST have "c" or "p" after this prefix
self.jack_usbgadget_prefix = "mod-usbgadget_"
Expand Down Expand Up @@ -551,8 +551,8 @@ def jack_port_appeared(self, name, isOutput):
name = charPtrToString(name)
isOutput = bool(isOutput)

if name.startswith(self.jack_slave_prefix+":"):
name = name.replace(self.jack_slave_prefix+":","")
if name.startswith(self.jack_external_prefix+":"):
name = name.replace(self.jack_external_prefix+":","")
if name.startswith("midi_"):
ptype = "midi"
elif name.startswith(CV_PREFIX):
Expand All @@ -563,6 +563,12 @@ def jack_port_appeared(self, name, isOutput):
index = 100 + int(name.rsplit("_",1)[-1])
title = name.title().replace(" ","_")
self.msg_callback("add_hw_port /graph/%s %s %i %s %i" % (name, ptype, int(isOutput), title, index))

if ptype == "audio":
if isOutput:
self.audioportsOut.append(name)
else:
self.audioportsIn.append(name)
return

if name.startswith(self.jack_usbgadget_prefix):
Expand Down Expand Up @@ -643,6 +649,13 @@ def jack_port_deleted(self, name):

self.msg_callback("remove_hw_port /graph/%s" % (name.split(":",1)[-1]))

if name.startswith(self.jack_external_prefix+":"):
name = name.replace(self.jack_external_prefix+":","")
if name in self.audioportsIn:
self.audioportsIn.remove(name)
if name in self.audioportsOut:
self.audioportsOut.remove(name)

def true_bypass_changed(self, left, right):
self.msg_callback("truebypass %i %i" % (left, right))

Expand Down Expand Up @@ -2086,7 +2099,7 @@ def report_current_state(self, websocket):
ports = get_jack_hardware_ports(False, False)
for i in range(len(ports)):
name = ports[i]
if name not in midiports and not name.startswith("%s:midi_" % self.jack_slave_prefix):
if name not in midiports and not name.startswith("%s:midi_" % self.jack_external_prefix):
continue
alias = get_jack_port_alias(name)

Expand All @@ -2109,7 +2122,7 @@ def report_current_state(self, websocket):
ports = get_jack_hardware_ports(False, True)
for i in range(len(ports)):
name = ports[i]
if name not in midiports and not name.startswith("%s:midi_" % self.jack_slave_prefix):
if name not in midiports and not name.startswith("%s:midi_" % self.jack_external_prefix):
continue
alias = get_jack_port_alias(name)
if alias:
Expand Down Expand Up @@ -3339,11 +3352,11 @@ def _fix_host_connection_port(self, port):
if num in monitorportnums:
return "mod-monitor:in_" + num

if data[2].startswith(("audio_from_slave_",
"audio_to_slave_",
"midi_from_slave_",
"midi_to_slave_")):
return "%s:%s" % (self.jack_slave_prefix, data[2])
if data[2].startswith(("audio_from_external_",
"audio_to_external_",
"midi_from_external_",
"midi_to_external_")):
return "%s:%s" % (self.jack_external_prefix, data[2])

if data[2].startswith("USB_Audio_Capture_"):
return "%s:%s" % (self.jack_usbgadget_prefix+"c", data[2])
Expand Down
6 changes: 3 additions & 3 deletions utils/utils_jack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#define ALSA_CONTROL_SPDIF_ENABLE "SPDIF Enable"
#define ALSA_CONTROL_MASTER_VOLUME "DAC"

#define JACK_SLAVE_PREFIX "mod-slave"
#define JACK_SLAVE_PREFIX_LEN 9
#define JACK_EXTERNAL_PREFIX "mod-external"
#define JACK_EXTERNAL_PREFIX_LEN 9

// --------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -101,7 +101,7 @@ static void JackPortRegistration(jack_port_id_t port_id, int reg, void*)
if (const char* const port_name = jack_port_name(port))
{
if (strncmp(port_name, "system:midi_", 12) != 0 &&
strncmp(port_name, JACK_SLAVE_PREFIX ":", JACK_SLAVE_PREFIX_LEN + 1) != 0 &&
strncmp(port_name, JACK_EXTERNAL_PREFIX ":", JACK_EXTERNAL_PREFIX_LEN + 1) != 0 &&
strncmp(port_name, "nooice", 5) != 0)
return;

Expand Down

0 comments on commit 7e4bc4e

Please sign in to comment.