def connect(self, max_attempts=None): if max_attempts is None: max_attempts = self.connect_max_attempts tries = 0 while True: log.debug("Attempting to connect to JACK server...") status = jacklib.jack_status_t(0x0) self.client = jacklib.client_open(self.client_name, jacklib.JackNoStartServer, status) tries += 1 if status.value: err = get_jack_status_error_string(status) if status.value & jacklib.JackNameNotUnique: log.debug(err) elif status.value & jacklib.JackServerStarted: # Should not happen, since we use the JackNoStartServer option log.warning("Unexpected JACK status: %s", err) else: log.warning("JACK connection error (attempt %i): %s", tries, err) if self.client: break if max_attempts and tries >= max_attempts: log.error( "Maximum number (%i) of connection attempts reached. Aborting.", max_attempts) raise RuntimeError(err) log.debug("Waiting %.2f seconds to connect again...", self.connect_interval) sleep(self.connect_interval) name = jacklib.get_client_name(self.client) if name is not None: self.client_name = name.decode() else: raise RuntimeError("Could not get JACK client name.") jacklib.on_shutdown(self.client, self.shutdown_callback, None) log.debug( "Client connected, name: %s UUID: %s", self.client_name, jacklib.client_get_uuid(self.client), ) jacklib.set_port_registration_callback(self.client, self.port_reg_callback, None) jacklib.set_port_rename_callback(self.client, self.port_rename_callback, None) jacklib.set_property_change_callback(self.client, self.property_callback, None) jacklib.activate(self.client)
def jack_client(): status = jacklib.jack_status_t() client = jacklib.client_open("pyjacklib", jacklib.JackNoStartServer, status) if status.value: err = get_jack_status_error_string(status) if status.value & jacklib.JackNameNotUnique: print(f"Non-fatal JACK status: {err}", file=sys.stderr) elif status.value & jacklib.JackServerStarted: # Should not happen, since we use the JackNoStartServer option print(f"Unexpected JACK status: {err}", file=sys.stderr) else: raise OSError(f"Error creating JACK client: {err}") yield client jacklib.client_close(client)
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import jacklib from jacklib.helpers import get_jack_status_error_string if len(sys.argv) == 3: portname = sys.argv[1] pretty_name = sys.argv[2] else: sys.exit("Usage: %s <port name> <pretty-name>" % sys.argv[0]) status = jacklib.jack_status_t() client = jacklib.client_open("set-port-pretty-name", jacklib.JackNoStartServer, status) err = get_jack_status_error_string(status) if status.value: if status.value & jacklib.JackNameNotUnique: print("Non-fatal JACK status: %s" % err, file=sys.stderr) elif status.value & jacklib.JackServerStarted: # Should not happen, since we use the JackNoStartServer option print("Unexpected JACK status: %s" % err, file=sys.stderr) else: sys.exit("Error connecting to JACK server: %s" % err) res = jacklib.set_port_pretty_name(client, portname, pretty_name) if res != -1: print("Pretty name for port '%s' is now '%s'." % (portname, pretty_name))