Skip to content

Commit 8d4b22c

Browse files
committed
Move Ports class to module namespace
1 parent 7a0283a commit 8d4b22c

1 file changed

Lines changed: 95 additions & 95 deletions

File tree

‎jack.py‎

Lines changed: 95 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -242,97 +242,6 @@ class Client(object):
242242

243243
"""A client that can connect to the JACK audio server."""
244244

245-
class Ports(object):
246-
247-
"""A list of input/output ports.
248-
249-
This class is not meant to be instantiated directly. It is only
250-
used as :attr:`Client.inports`, :attr:`Client.outports`,
251-
:attr:`Client.midi_inports` and :attr:`Client.midi_outports`.
252-
253-
The ports can be accessed by indexing or by iteration.
254-
255-
New ports can be added with :meth:`register`, existing ports can
256-
be removed by calling their :meth:`~OwnPort.unregister` method.
257-
258-
"""
259-
260-
def __init__(self, client, porttype, flag):
261-
self._client = client
262-
self._type = porttype
263-
self._flag = flag
264-
self._portlist = []
265-
266-
def __len__(self):
267-
return self._portlist.__len__()
268-
269-
def __getitem__(self, name):
270-
return self._portlist.__getitem__(name)
271-
272-
# No __setitem__!
273-
274-
def __iter__(self):
275-
return self._portlist.__iter__()
276-
277-
def __repr__(self):
278-
return self._portlist.__repr__()
279-
280-
def register(self, shortname, is_terminal=False, is_physical=False):
281-
"""Create a new input/output port.
282-
283-
The new :class:`OwnPort` or :class:`OwnMidiPort` object is
284-
automatically added to :attr:`Client.inports`,
285-
:attr:`Client.outports`, :attr:`Client.midi_inports` or
286-
:attr:`Client.midi_outports`.
287-
288-
Parameters
289-
----------
290-
shortname : str
291-
Each port has a short name. The port's full name contains
292-
the name of the client concatenated with a colon (:)
293-
followed by its short name. The :func:`port_name_size` is
294-
the maximum length of this full name. Exceeding that will
295-
cause the port registration to fail.
296-
297-
The port name must be unique among all ports owned by this
298-
client.
299-
If the name is not unique, the registration will fail.
300-
is_terminal : bool
301-
For an input port: If ``True``, the data received by the
302-
port will not be passed on or made available at any other
303-
port.
304-
For an output port: If ``True``, the data available at the
305-
port does not originate from any other port
306-
307-
Audio synthesizers, I/O hardware interface clients, HDR
308-
systems are examples of clients that would set this flag for
309-
their ports.
310-
is_physical : bool
311-
If ``True`` the port corresponds to some kind of physical
312-
I/O connector.
313-
314-
Returns
315-
-------
316-
Port
317-
A new :class:`OwnPort` or :class:`OwnMidiPort` instance.
318-
319-
"""
320-
port = self._client._register_port(
321-
shortname, self._type, is_terminal, is_physical, self._flag)
322-
self._portlist.append(port)
323-
return port
324-
325-
def clear(self):
326-
"""Unregister all ports in the list.
327-
328-
See Also
329-
--------
330-
OwnPort.unregister
331-
332-
"""
333-
while self._portlist:
334-
self._portlist[0].unregister()
335-
336245
def __init__(self, name, use_exact_name=False, no_start_server=False,
337246
servername=None, session_id=None):
338247
"""Create a new JACK client.
@@ -384,10 +293,10 @@ def __init__(self, name, use_exact_name=False, no_start_server=False,
384293
if not self._ptr:
385294
raise JackError(str(self.status))
386295

387-
self._inports = self.Ports(self, _AUDIO, _lib.JackPortIsInput)
388-
self._outports = self.Ports(self, _AUDIO, _lib.JackPortIsOutput)
389-
self._midi_inports = self.Ports(self, _MIDI, _lib.JackPortIsInput)
390-
self._midi_outports = self.Ports(self, _MIDI, _lib.JackPortIsOutput)
296+
self._inports = Ports(self, _AUDIO, _lib.JackPortIsInput)
297+
self._outports = Ports(self, _AUDIO, _lib.JackPortIsOutput)
298+
self._midi_inports = Ports(self, _MIDI, _lib.JackPortIsInput)
299+
self._midi_outports = Ports(self, _MIDI, _lib.JackPortIsOutput)
391300
self._keepalive = []
392301

393302
# Avoid confusion if something goes wrong before opening the client:
@@ -1798,6 +1707,97 @@ def reserve_midi_event(self, time, size):
17981707
return _ffi.buffer(buf, size if buf else 0)
17991708

18001709

1710+
class Ports(object):
1711+
1712+
"""A list of input/output ports.
1713+
1714+
This class is not meant to be instantiated directly. It is only
1715+
used as :attr:`Client.inports`, :attr:`Client.outports`,
1716+
:attr:`Client.midi_inports` and :attr:`Client.midi_outports`.
1717+
1718+
The ports can be accessed by indexing or by iteration.
1719+
1720+
New ports can be added with :meth:`register`, existing ports can
1721+
be removed by calling their :meth:`~OwnPort.unregister` method.
1722+
1723+
"""
1724+
1725+
def __init__(self, client, porttype, flag):
1726+
self._client = client
1727+
self._type = porttype
1728+
self._flag = flag
1729+
self._portlist = []
1730+
1731+
def __len__(self):
1732+
return self._portlist.__len__()
1733+
1734+
def __getitem__(self, name):
1735+
return self._portlist.__getitem__(name)
1736+
1737+
# No __setitem__!
1738+
1739+
def __iter__(self):
1740+
return self._portlist.__iter__()
1741+
1742+
def __repr__(self):
1743+
return self._portlist.__repr__()
1744+
1745+
def register(self, shortname, is_terminal=False, is_physical=False):
1746+
"""Create a new input/output port.
1747+
1748+
The new :class:`OwnPort` or :class:`OwnMidiPort` object is
1749+
automatically added to :attr:`Client.inports`,
1750+
:attr:`Client.outports`, :attr:`Client.midi_inports` or
1751+
:attr:`Client.midi_outports`.
1752+
1753+
Parameters
1754+
----------
1755+
shortname : str
1756+
Each port has a short name. The port's full name contains
1757+
the name of the client concatenated with a colon (:)
1758+
followed by its short name. The :func:`port_name_size` is
1759+
the maximum length of this full name. Exceeding that will
1760+
cause the port registration to fail.
1761+
1762+
The port name must be unique among all ports owned by this
1763+
client.
1764+
If the name is not unique, the registration will fail.
1765+
is_terminal : bool
1766+
For an input port: If ``True``, the data received by the
1767+
port will not be passed on or made available at any other
1768+
port.
1769+
For an output port: If ``True``, the data available at the
1770+
port does not originate from any other port
1771+
1772+
Audio synthesizers, I/O hardware interface clients, HDR
1773+
systems are examples of clients that would set this flag for
1774+
their ports.
1775+
is_physical : bool
1776+
If ``True`` the port corresponds to some kind of physical
1777+
I/O connector.
1778+
1779+
Returns
1780+
-------
1781+
Port
1782+
A new :class:`OwnPort` or :class:`OwnMidiPort` instance.
1783+
1784+
"""
1785+
port = self._client._register_port(
1786+
shortname, self._type, is_terminal, is_physical, self._flag)
1787+
self._portlist.append(port)
1788+
return port
1789+
1790+
def clear(self):
1791+
"""Unregister all ports in the list.
1792+
1793+
See Also
1794+
--------
1795+
OwnPort.unregister
1796+
1797+
"""
1798+
while self._portlist:
1799+
self._portlist[0].unregister()
1800+
18011801
class Status(object):
18021802

18031803
"""Representation of the JACK status bits."""

0 commit comments

Comments
 (0)