@@ -1555,7 +1555,8 @@ def get_all_connections(self, port):
15551555 _lib .jack_free )
15561556 return self ._port_list_from_pointers (names )
15571557
1558- def get_ports (self , name_pattern = '' , is_audio = False , is_midi = False ,
1558+ def get_ports (self , name_pattern = '' ,
1559+ is_audio = False , is_midi = False , is_unknown = False ,
15591560 is_input = False , is_output = False , is_physical = False ,
15601561 can_monitor = False , is_terminal = False ):
15611562 """Return a list of selected ports.
@@ -1578,12 +1579,21 @@ def get_ports(self, name_pattern='', is_audio=False, is_midi=False,
15781579 All ports that satisfy the given conditions.
15791580
15801581 """
1581- if is_audio and not is_midi :
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 :
15821591 type_pattern = _AUDIO
1583- elif is_midi and not is_audio :
1592+ elif is_midi :
15841593 type_pattern = _MIDI
15851594 else :
15861595 type_pattern = b''
1596+
15871597 flags = 0x0
15881598 if is_input :
15891599 flags |= _lib .JackPortIsInput
@@ -1759,6 +1769,7 @@ def _register_port(self, name, porttype, is_terminal, is_physical, flags):
17591769 flags |= _lib .JackPortIsPhysical
17601770 port_ptr = _lib .jack_port_register (self ._ptr , name .encode (), porttype ,
17611771 flags , 0 )
1772+ print ('go for porttype' , porttype )
17621773 if not port_ptr :
17631774 raise JackError (
17641775 f'{ name !r} : port registration failed' )
@@ -1793,7 +1804,7 @@ def _wrap_port_ptr(self, ptr):
17931804 elif porttype == _MIDI :
17941805 cls = OwnMidiPort if self .owns (ptr ) else MidiPort
17951806 else :
1796- assert False
1807+ cls = UnknownPort
17971808 return cls (ptr , self )
17981809
17991810
@@ -1838,6 +1849,11 @@ def __ne__(self, other):
18381849 """This should be implemented whenever __eq__() is implemented."""
18391850 return not self .__eq__ (other )
18401851
1852+ @property
1853+ def type (self ):
1854+ """Name of the JACK port type (read-only)."""
1855+ return _decode (_lib .jack_port_type (self ._ptr ))
1856+
18411857 @property
18421858 def name (self ):
18431859 """Full name of the JACK port (read-only)."""
@@ -1972,6 +1988,17 @@ class MidiPort(Port):
19721988 is_midi = property (lambda self : True , doc = 'This is always ``True``.' )
19731989
19741990
1991+ class UnknownPort (Port ):
1992+ """A JACK port with an unknown type
1993+
1994+ This class is derived from `Port` and has exactly the same
1995+ attributes and methods.
1996+ """
1997+
1998+ is_audio = property (lambda self : False , doc = 'This is always ``False``.' )
1999+ is_midi = property (lambda self : False , doc = 'This is always ``False``.' )
2000+
2001+
19752002class OwnPort (Port ):
19762003 """A JACK audio port owned by a `Client`.
19772004
@@ -2360,7 +2387,7 @@ def register(self, shortname, is_terminal=False, is_physical=False):
23602387
23612388 """
23622389 port = self ._client ._register_port (
2363- shortname , self . _type , is_terminal , is_physical , self ._flag )
2390+ shortname , b'8 bit raw middle' , is_terminal , is_physical , self ._flag )
23642391 self ._portlist .append (port )
23652392 return port
23662393
0 commit comments