Skip to content

Commit 566330d

Browse files
committed
allow string pattern for type in get_ports (for test)
1 parent 70fabb4 commit 566330d

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

src/jack.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,8 @@ def get_all_connections(self, port):
15581558
def get_ports(self, name_pattern='',
15591559
is_audio=False, is_midi=False, is_unknown=False,
15601560
is_input=False, is_output=False, is_physical=False,
1561-
can_monitor=False, is_terminal=False):
1561+
can_monitor=False, is_terminal=False,
1562+
type_pat=''):
15621563
"""Return a list of selected ports.
15631564
15641565
Parameters
@@ -1579,20 +1580,23 @@ def get_ports(self, name_pattern='',
15791580
All ports that satisfy the given conditions.
15801581
15811582
"""
1582-
if is_unknown:
1583-
# sadly JACK uses regcomp which can not support lookaheads
1584-
# to exclude a string.
1585-
# So if is_unknown is True, all port types will match
1586-
type_pattern = b''
1587-
elif is_audio and is_midi:
1588-
# pattern will match with audio and midi (but not other types)
1589-
type_pattern = f'({_AUDIO.decode()}|{_MIDI.decode()})'.encode()
1590-
elif is_audio:
1591-
type_pattern = _AUDIO
1592-
elif is_midi:
1593-
type_pattern = _MIDI
1583+
if type_pat:
1584+
type_pattern = type_pat.encode()
15941585
else:
1595-
type_pattern = b''
1586+
if is_unknown:
1587+
# sadly JACK uses regcomp which can not support lookaheads
1588+
# to exclude a string.
1589+
# So if is_unknown is True, all port types will match
1590+
type_pattern = b''
1591+
elif is_audio and is_midi:
1592+
# pattern will match with audio and midi (but not other types)
1593+
type_pattern = f'({_AUDIO.decode()}|{_MIDI.decode()})'.encode()
1594+
elif is_audio:
1595+
type_pattern = _AUDIO
1596+
elif is_midi:
1597+
type_pattern = _MIDI
1598+
else:
1599+
type_pattern = b''
15961600

15971601
flags = 0x0
15981602
if is_input:

0 commit comments

Comments
 (0)