| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- """PipeWire link helpers used by the Rigforge mod-ui host integration."""
- import subprocess
- def boundary_connection(
- port_from,
- port_to,
- capture_port,
- playback_port,
- resolve_host_port,
- ):
- """Translate mod-ui graph boundary cables to concrete PipeWire ports."""
- if port_from == "/graph/capture_1" and capture_port:
- return capture_port, resolve_host_port(port_to)
- if port_to == "/graph/playback_1" and playback_port:
- return resolve_host_port(port_from), playback_port
- return None
- def _link_status(source, destination, runner):
- try:
- result = runner(
- ["pw-link", "-l"],
- check=False,
- capture_output=True,
- text=True,
- )
- except OSError:
- return None
- if result.returncode != 0:
- return None
- current_port = None
- for line in result.stdout.splitlines():
- if line.startswith(" |-> "):
- if current_port == source and line.removeprefix(" |-> ") == destination:
- return True
- elif line.startswith(" |<- "):
- if current_port == destination and line.removeprefix(" |<- ") == source:
- return True
- else:
- current_port = line.strip()
- return False
- def connect_link(source, destination, runner=subprocess.run):
- try:
- result = runner(
- ["pw-link", source, destination],
- check=False,
- capture_output=True,
- text=True,
- )
- except OSError:
- return False
- return result.returncode == 0 or _link_status(source, destination, runner) is True
- def disconnect_link(source, destination, runner=subprocess.run):
- try:
- result = runner(
- ["pw-link", "-d", source, destination],
- check=False,
- capture_output=True,
- text=True,
- )
- except OSError:
- return False
- return result.returncode == 0 or _link_status(source, destination, runner) is False
|