Skip to content

Commit f60d6a9

Browse files
committed
Documentation update
1 parent bde0a1e commit f60d6a9

2 files changed

Lines changed: 90 additions & 45 deletions

File tree

‎README.rst‎

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ JACK Audio Connection Kit (JACK) Client for Python
44
This Python module provides bindings for the JACK_ library.
55

66
Documentation:
7-
http://jackclient-python.rtfd.org/
7+
http://jackclient-python.rtfd.org/
88

99
Code:
10-
http://github.com/spatialaudio/jackclient-python/
10+
http://github.com/spatialaudio/jackclient-python/
1111

1212
Python Package Index:
13-
http://pypi.python.org/pypi/JACK-Client/
13+
http://pypi.python.org/pypi/JACK-Client/
1414

1515
Requirements
1616
------------
@@ -102,48 +102,90 @@ First, import the module:
102102

103103
>>> import jack
104104

105-
Then, you most likely want to create a new JACK client:
105+
Then, you most likely want to create a new `jack.Client`:
106106

107107
>>> client = jack.Client("MyGreatClient")
108108

109-
You probably want to create some input and output ports, too:
109+
You probably want to create some audio input and output ports, too:
110110

111111
>>> client.inports.register("input_1")
112112
jack.OwnPort('MyGreatClient:input_1')
113113
>>> client.outports.register("output_1")
114114
jack.OwnPort('MyGreatClient:output_1')
115115

116-
As you can see, these functions return the newly created port, so you can save
117-
it for later:
116+
As you can see, these functions return the newly created port.
117+
If you want, you can save it for later:
118118

119119
>>> in2 = client.inports.register("input_2")
120120
>>> out2 = client.outports.register("output_2")
121121

122122
To see what you can do with the returned objects, have a look at the
123123
documentation of the class `jack.OwnPort`.
124124

125-
You can also check what other JACK ports are available (your output may have
126-
additional ports in it):
125+
In case you forgot, you should remind yourself about the ports you just created:
126+
127+
>>> client.inports
128+
[jack.OwnPort('MyGreatClient:input_1'), jack.OwnPort('MyGreatClient:input_2')]
129+
>>> client.outports
130+
[jack.OwnPort('MyGreatClient:output_1'), jack.OwnPort('MyGreatClient:output_2')]
131+
132+
Have a look at the documentation of the class `jack.Ports` to get more detailed
133+
information about these lists of ports.
134+
135+
If you have selected an appropriate driver in your JACK settings, you can also
136+
create MIDI ports:
137+
138+
>>> client.midi_inports.register("midi_in")
139+
jack.OwnMidiPort('MyGreatClient:midi_in')
140+
>>> client.midi_outports.register("midi_out")
141+
jack.OwnMidiPort('MyGreatClient:midi_out')
142+
143+
You can check what other JACK ports are available (your output may be
144+
different):
127145

128146
>>> client.get_ports() # doctest: +SKIP
129147
[jack.Port('system:capture_1'),
130148
jack.Port('system:capture_2'),
131149
jack.Port('system:playback_1'),
132150
jack.Port('system:playback_2'),
151+
jack.MidiPort('system:midi_capture_1'),
152+
jack.MidiPort('system:midi_playback_1'),
133153
jack.OwnPort('MyGreatClient:input_1'),
134154
jack.OwnPort('MyGreatClient:output_1'),
135155
jack.OwnPort('MyGreatClient:input_2'),
136-
jack.OwnPort('MyGreatClient:output_2')]
156+
jack.OwnPort('MyGreatClient:output_2'),
157+
jack.OwnMidiPort('MyGreatClient:midi_in'),
158+
jack.OwnMidiPort('MyGreatClient:midi_out')]
159+
160+
Note that the ports you created yourself are of type `jack.OwnPort` and
161+
`jack.OwnMidiPort`, while other ports are merely of type `jack.Port` and
162+
`jack.MidiPort`, respectively.
137163

138-
If you want, you can also set all kinds of callback functions, for details see
139-
the API documentation for the class `jack.Client`.
164+
You can also be more specific when looking for ports:
165+
166+
>>> client.get_ports(is_audio=True, is_output=True, is_physical=True)
167+
[jack.Port('system:capture_1'), jack.Port('system:capture_2')]
168+
169+
You can even use regular expressions to search for ports:
170+
171+
>>> client.get_ports("Great.*2$")
172+
[jack.OwnPort('MyGreatClient:input_2'), jack.OwnPort('MyGreatClient:output_2')]
173+
174+
If you want, you can also set all kinds of callback functions for your client.
175+
For details see the documentation for the class `jack.Client` and the example
176+
applications in the ``examples/`` directory. The methods
177+
`jack.OwnPort.get_buffer()` and `jack.OwnPort.get_array()` shall only be called
178+
from within the process callback (see `jack.Client.set_process_callback()`).
179+
`jack.OwnMidiPort` has a few additional methods which should only be used in
180+
the process callback. Have a look at the example applications
181+
``examples/midi_*.py`` to see how that works.
140182

141183
Once you are ready to run, you should activate your client:
142184

143185
>>> client.activate()
144186

145-
Once the client is activated, you can make connections (this isn't possible
146-
before activating the client):
187+
As soon as the client is activated, you can make connections (this isn't
188+
possible before activating the client):
147189

148190
>>> client.connect("system:capture_1", "MyGreatClient:input_1")
149191
>>> client.connect("MyGreatClient:output_1", "system:playback_1")
@@ -153,7 +195,16 @@ You can also use the port objects from before instead of port names:
153195
>>> client.connect(out2, "system:playback_2")
154196
>>> in2.connect("system:capture_2")
155197

156-
You can also disconnect ports, there are again several possibilities:
198+
Use `jack.Client.get_all_connections()` to find out which other ports are
199+
connected to a given port.
200+
If you own the port, you can also use `jack.OwnPort.connections`.
201+
202+
>>> client.get_all_connections("system:playback_1")
203+
[jack.OwnPort('MyGreatClient:output_1')]
204+
>>> out2.connections
205+
[jack.Port('system:playback_2')]
206+
207+
Of course you can also disconnect ports, there are again several possibilities:
157208

158209
>>> client.disconnect("system:capture_1", "MyGreatClient:input_1")
159210
>>> client.disconnect(out2, "system:playback_2")
@@ -162,7 +213,7 @@ You can also disconnect ports, there are again several possibilities:
162213
If you don't need your ports anymore, you can un-register them:
163214

164215
>>> in2.unregister()
165-
>>> client.outports.clear() # unregister all output ports
216+
>>> client.outports.clear() # unregister all audio output ports
166217

167218
Finally, you can de-activate your JACK client and close it:
168219

‎jack.py‎

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def __init__(self, name, use_exact_name=False, no_start_server=False,
289289
args.append(_ffi.new("char[]", session_id.encode()))
290290
self._ptr = _lib.jack_client_open(*args)
291291
self.status = Status(status[0])
292-
"""JACK status. See :class:`Status`."""
292+
"""JACK client status. See :class:`Status`."""
293293
if not self._ptr:
294294
raise JackError(str(self.status))
295295

@@ -537,7 +537,7 @@ def connect(self, source, destination):
537537
When a connection exists, data written to the source port will
538538
be available to be read at the destination port.
539539
540-
The port types must be identical.
540+
Audio ports can obviously not be connected with MIDI ports.
541541
542542
Parameters
543543
----------
@@ -633,7 +633,7 @@ def set_shutdown_callback(self, callback, userdata=None):
633633
Register a function (and optional argument) to be called if and
634634
when the JACK server shuts down the client thread.
635635
The function must be written as if it were an asynchonrous POSIX
636-
signal handler --- use only async-safe functions, and remember
636+
signal handler -- use only async-safe functions, and remember
637637
that it is executed from another thread.
638638
A typical function might set a flag or write to a pipe so that
639639
the rest of the application knows that the JACK client thread
@@ -708,8 +708,8 @@ def set_process_callback(self, callback, userdata=None):
708708
The `callback` must return zero on success (if `callback`
709709
shall be called again for the next audio block) and non-zero
710710
on error (if `callback` shall not be called again).
711-
You can use :data:`CALL_AGAIN` and :data:`STOP_CALLING`,
712-
respectively.
711+
You can use the module constants :data:`CALL_AGAIN` and
712+
:data:`STOP_CALLING`, respectively.
713713
userdata : anything
714714
This will be passed as second argument whenever `callback`
715715
is called.
@@ -787,8 +787,8 @@ def set_blocksize_callback(self, callback, userdata=None):
787787
callback(blocksize:int, userdata) -> int
788788
789789
The `callback` must return zero on success and non-zero on
790-
error. You can use :data:`SUCCESS` and :data:`FAILURE`,
791-
respectively.
790+
error. You can use the module constants :data:`jack.SUCCESS`
791+
and :data:`jack.FAILURE`, respectively.
792792
793793
Although this function is called in the JACK process thread,
794794
the normal process cycle is suspended during its operation,
@@ -831,8 +831,8 @@ def set_samplerate_callback(self, callback, userdata=None):
831831
832832
The argument `samplerate` is the new engine sample rate.
833833
The `callback` must return zero on success and non-zero on
834-
error. You can use :data:`SUCCESS` and :data:`FAILURE`,
835-
respectively.
834+
error. You can use the module constants :data:`jack.SUCCESS`
835+
and :data:`jack.FAILURE`, respectively.
836836
userdata : anything
837837
This will be passed as second argument whenever `callback`
838838
is called.
@@ -991,8 +991,8 @@ def set_port_rename_callback(self, callback, userdata=None):
991991
:class:`OwnMidiPort` object); the second and third argument
992992
is the old and new name, respectively.
993993
The `callback` must return zero on success and non-zero on
994-
error. You can use :data:`SUCCESS` and :data:`FAILURE`,
995-
respectively.
994+
error. You can use the module constants :data:`jack.SUCCESS`
995+
and :data:`jack.FAILURE`, respectively.
996996
userdata : anything
997997
This will be passed as fourth argument whenever `callback`
998998
is called.
@@ -1031,8 +1031,8 @@ def set_graph_order_callback(self, callback, userdata=None):
10311031
callback(userdata) -> int
10321032
10331033
The `callback` must return zero on success and non-zero on
1034-
error. You can use :data:`SUCCESS` and :data:`FAILURE`,
1035-
respectively.
1034+
error. You can use the module constants :data:`jack.SUCCESS`
1035+
and :data:`jack.FAILURE`, respectively.
10361036
userdata : anything
10371037
This will be passed as argument whenever `callback` is
10381038
called.
@@ -1068,8 +1068,8 @@ def set_xrun_callback(self, callback, userdata=None):
10681068
callback(userdata) -> int
10691069
10701070
The `callback` must return zero on success and non-zero on
1071-
error. You can use :data:`SUCCESS` and :data:`FAILURE`,
1072-
respectively.
1071+
error. You can use the module constants :data:`jack.SUCCESS`
1072+
and :data:`jack.FAILURE`, respectively.
10731073
userdata : anything
10741074
This will be passed as argument whenever `callback` is
10751075
called.
@@ -1371,6 +1371,8 @@ class MidiPort(Port):
13711371
This class is derived from :class:`Port` and has exactly the same
13721372
attributes and methods.
13731373
1374+
This class cannot be instantiated directly (see :class:`Port`).
1375+
13741376
New JACK audio/MIDI ports can be created with the
13751377
:meth:`~Ports.register` method of :attr:`Client.inports`,
13761378
:attr:`Client.outports`, :attr:`Client.midi_inports` and
@@ -1393,20 +1395,7 @@ class OwnPort(Port):
13931395
This class is derived from :class:`Port`. :class:`OwnPort` objects
13941396
can do everything that :class:`Port` objects can, plus a lot more.
13951397
1396-
This class cannot be instantiated directly. Instead, instances of
1397-
this class are returned from :meth:`Client.get_port_by_name`,
1398-
:meth:`Client.get_ports`, :meth:`Client.get_all_connections` and
1399-
:attr:`connections`.
1400-
In addition, instances of this class are available in the callbacks
1401-
which are set with :meth:`Client.set_port_registration_callback`,
1402-
:meth:`Client.set_port_connect_callback` or
1403-
:meth:`Client.set_port_rename_callback`.
1404-
1405-
Note, however, that if the used :class:`Client` doesn't own the
1406-
respective port, instances of :class:`Port` (instead of
1407-
:class:`OwnPort`) will be created.
1408-
In case of MIDI ports, instances of :class:`MidiPort` or
1409-
:class:`OwnMidiPort` are created.
1398+
This class cannot be instantiated directly (see :class:`Port`).
14101399
14111400
New JACK audio/MIDI ports can be created with the
14121401
:meth:`~Ports.register` method of :attr:`Client.inports`,
@@ -1537,6 +1526,9 @@ def get_buffer(self):
15371526
def get_array(self):
15381527
"""Get audio buffer as NumPy array.
15391528
1529+
Make sure to ``import numpy`` before calling this, otherwise the
1530+
first call might take a long time.
1531+
15401532
See Also
15411533
--------
15421534
get_buffer
@@ -1557,6 +1549,8 @@ class OwnMidiPort(MidiPort, OwnPort):
15571549
sending and receiving MIDI events (to be used from within the
15581550
process callback -- see :meth:`Client.set_process_callback`).
15591551
1552+
This class cannot be instantiated directly (see :class:`Port`).
1553+
15601554
New JACK audio/MIDI ports can be created with the
15611555
:meth:`~Ports.register` method of :attr:`Client.inports`,
15621556
:attr:`Client.outports`, :attr:`Client.midi_inports` and

0 commit comments

Comments
 (0)