diff --git a/examples/aliases.py b/examples/aliases.py new file mode 100755 index 0000000..7615c1c --- /dev/null +++ b/examples/aliases.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +"""Create a JACK client and test port-alias functionality. + +This client test the 3 functions related with port-aliases + +""" + +import jack + +print("starting TestAlias client") + +client = jack.Client('TestAlias') + +if client.status.server_started: + print("JACK server was started") +else: + print("JACK server was already running") + if client.status.name_not_unique: + print("unique client name generated: {}".format(client.name)) + +ports = client.get_ports() + +print("Testing set_alias() ...") +for i, port in enumerate(ports): + alias_name = "Alias Name {}".format(i) + print("port '{}' => set_alias('{}')".format(port.shortname,alias_name)) + port.set_alias(alias_name) + +print('Testing aliases property ...') +for port in ports: + for i, alias in enumerate(port.aliases): + print("port '{}', alias {} => '{}'".format(port.shortname,i,alias)) + +print('Testing unset_alias() ...') +for i, port in enumerate(ports): + alias_name = "Alias Name {}".format(i) + print("port '{}' => unset_alias('{}')".format(port.shortname,alias_name)) + port.unset_alias(alias_name) + +print('Testing aliases property ...') +for port in ports: + for i, alias in enumerate(port.aliases): + print("port '{}', alias {} => '{}'".format(port.shortname,i,alias)) diff --git a/jack_build.py b/jack_build.py index 7d367b5..928bb28 100644 --- a/jack_build.py +++ b/jack_build.py @@ -141,9 +141,9 @@ /* deprecated: jack_port_tie */ /* deprecated: jack_port_untie */ int jack_port_set_name(jack_port_t* port, const char* port_name); -/* TODO: jack_port_set_alias */ -/* TODO: jack_port_unset_alias */ -/* TODO: jack_port_get_aliases */ +int jack_port_set_alias(jack_port_t *port, const char *alias); +int jack_port_unset_alias(jack_port_t *port, const char *alias); +int jack_port_get_aliases(const jack_port_t * port, char *const aliases[2]); int jack_port_request_monitor(jack_port_t *port, int onoff); /* not implemented (use jack_port_request_monitor): jack_port_request_monitor_by_name */ /* TODO: jack_port_ensure_monitor */ diff --git a/src/jack.py b/src/jack.py index a28d88e..f701c8e 100644 --- a/src/jack.py +++ b/src/jack.py @@ -1445,6 +1445,40 @@ def shortname(self, shortname): _check(_lib.jack_port_set_name(self._ptr, shortname.encode()), 'Error setting port name') + @property + def aliases(self): + """Returns a list of strings with the aliases for the JACK port.""" + ctype = "char[{}]".format(_lib.jack_port_name_size()) + aliases = [_ffi.new(ctype), _ffi.new(ctype)] + aliasesptr = _ffi.new("char *[]", aliases) + result = [] + if _lib.jack_port_get_aliases(self._ptr, aliasesptr) > 0: + for i in 0, 1: + alias = _ffi.string(aliases[i]).decode() + if alias: + result.append(alias) + + return result + + def set_alias(self, alias): + """Set an alias for the JACK port. + + Ports can have up to two aliases. If both are already set, + this function will return an error. + + """ + _check(_lib.jack_port_set_alias(self._ptr, alias.encode()), + 'Error setting port alias') + + def unset_alias(self, alias): + """Remove an alias for the JACK port. + + If the alias doesn't exist this function will return an error. + + """ + _check(_lib.jack_port_unset_alias(self._ptr, alias.encode()), + 'Error unsetting port alias') + @property def uuid(self): """The UUID of the JACK port.""" @@ -2427,6 +2461,7 @@ def callback_wrapper(msg): _keepalive[setter] = callback_wrapper setter(callback_wrapper) + _keepalive = {}