Skip to content

Commit 3b78622

Browse files
jofemodomgeier
authored andcommitted
Implement Port.alias() property. (#45)
1 parent 0817d0d commit 3b78622

File tree

3 files changed

+82
-3
lines changed

3 files changed

+82
-3
lines changed

examples/aliases.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python3
2+
3+
"""Create a JACK client and test port-alias functionality.
4+
5+
This client test the 3 functions related with port-aliases
6+
7+
"""
8+
9+
import jack
10+
11+
print("starting TestAlias client")
12+
13+
client = jack.Client('TestAlias')
14+
15+
if client.status.server_started:
16+
print("JACK server was started")
17+
else:
18+
print("JACK server was already running")
19+
if client.status.name_not_unique:
20+
print("unique client name generated: {}".format(client.name))
21+
22+
ports = client.get_ports()
23+
24+
print("Testing set_alias() ...")
25+
for i, port in enumerate(ports):
26+
alias_name = "Alias Name {}".format(i)
27+
print("port '{}' => set_alias('{}')".format(port.shortname,alias_name))
28+
port.set_alias(alias_name)
29+
30+
print('Testing aliases property ...')
31+
for port in ports:
32+
for i, alias in enumerate(port.aliases):
33+
print("port '{}', alias {} => '{}'".format(port.shortname,i,alias))
34+
35+
print('Testing unset_alias() ...')
36+
for i, port in enumerate(ports):
37+
alias_name = "Alias Name {}".format(i)
38+
print("port '{}' => unset_alias('{}')".format(port.shortname,alias_name))
39+
port.unset_alias(alias_name)
40+
41+
print('Testing aliases property ...')
42+
for port in ports:
43+
for i, alias in enumerate(port.aliases):
44+
print("port '{}', alias {} => '{}'".format(port.shortname,i,alias))

jack_build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@
141141
/* deprecated: jack_port_tie */
142142
/* deprecated: jack_port_untie */
143143
int jack_port_set_name(jack_port_t* port, const char* port_name);
144-
/* TODO: jack_port_set_alias */
145-
/* TODO: jack_port_unset_alias */
146-
/* TODO: jack_port_get_aliases */
144+
int jack_port_set_alias(jack_port_t *port, const char *alias);
145+
int jack_port_unset_alias(jack_port_t *port, const char *alias);
146+
int jack_port_get_aliases(const jack_port_t * port, char *const aliases[2]);
147147
int jack_port_request_monitor(jack_port_t *port, int onoff);
148148
/* not implemented (use jack_port_request_monitor): jack_port_request_monitor_by_name */
149149
/* TODO: jack_port_ensure_monitor */

src/jack.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,40 @@ def shortname(self, shortname):
14451445
_check(_lib.jack_port_set_name(self._ptr, shortname.encode()),
14461446
'Error setting port name')
14471447

1448+
@property
1449+
def aliases(self):
1450+
"""Returns a list of strings with the aliases for the JACK port."""
1451+
ctype = "char[{}]".format(_lib.jack_port_name_size())
1452+
aliases = [_ffi.new(ctype), _ffi.new(ctype)]
1453+
aliasesptr = _ffi.new("char *[]", aliases)
1454+
result = []
1455+
if _lib.jack_port_get_aliases(self._ptr, aliasesptr) > 0:
1456+
for i in 0, 1:
1457+
alias = _ffi.string(aliases[i]).decode()
1458+
if alias:
1459+
result.append(alias)
1460+
1461+
return result
1462+
1463+
def set_alias(self, alias):
1464+
"""Set an alias for the JACK port.
1465+
1466+
Ports can have up to two aliases. If both are already set,
1467+
this function will return an error.
1468+
1469+
"""
1470+
_check(_lib.jack_port_set_alias(self._ptr, alias.encode()),
1471+
'Error setting port alias')
1472+
1473+
def unset_alias(self, alias):
1474+
"""Remove an alias for the JACK port.
1475+
1476+
If the alias doesn't exist this function will return an error.
1477+
1478+
"""
1479+
_check(_lib.jack_port_unset_alias(self._ptr, alias.encode()),
1480+
'Error unsetting port alias')
1481+
14481482
@property
14491483
def uuid(self):
14501484
"""The UUID of the JACK port."""
@@ -2427,6 +2461,7 @@ def callback_wrapper(msg):
24272461
_keepalive[setter] = callback_wrapper
24282462
setter(callback_wrapper)
24292463

2464+
24302465
_keepalive = {}
24312466

24322467

0 commit comments

Comments
 (0)