From 7e4bc4ebe25b03c95c24297b659750c0406b40bf Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 3 Dec 2023 23:51:18 +0100 Subject: [PATCH] Dynamic handling of mod-external client Signed-off-by: falkTX --- mod/host.py | 35 ++++++++++++++++++++++++----------- utils/utils_jack.cpp | 6 +++--- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/mod/host.py b/mod/host.py index 5965429e..6094f00d 100644 --- a/mod/host.py +++ b/mod/host.py @@ -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_" @@ -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): @@ -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): @@ -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)) @@ -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) @@ -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: @@ -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]) diff --git a/utils/utils_jack.cpp b/utils/utils_jack.cpp index e9494ad6..0f6fb5c6 100644 --- a/utils/utils_jack.cpp +++ b/utils/utils_jack.cpp @@ -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 // -------------------------------------------------------------------------------------------------------- @@ -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;