././@PaxHeader0000000000000000000000000000003300000000000011451 xustar000000000000000027 mtime=1603273938.527674 JACK-Client-0.5.3/0000755000175000017500000000000000000000000012474 5ustar00mgmg00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603104715.0 JACK-Client-0.5.3/CONTRIBUTING.rst0000644000175000017500000000313300000000000015135 0ustar00mgmg00000000000000Contributing ------------ If you find bugs, errors, omissions or other things that need improvement, please create an issue or a pull request at https://github.com/spatialaudio/jackclient-python. Contributions are always welcome! Instead of pip-installing the latest release from PyPI, you should get the newest development version from Github_:: git clone https://github.com/spatialaudio/jackclient-python.git cd jackclient-python python3 -m pip install -e . ... where ``-e`` stands for ``--editable``. This way, your installation always stays up-to-date, even if you pull new changes from the Github repository. .. _Github: https://github.com/spatialaudio/jackclient-python/ .. note:: Whenever the file ``jack_build.py`` changes (either because you edited it or it was updated by pulling from Github or switching branches), you have to run the last command again. If you make changes to the documentation, you can locally re-create the HTML pages using Sphinx_. You can install it and a few other necessary packages with:: python3 -m pip install -r doc/requirements.txt To create the HTML pages, use:: python3 setup.py build_sphinx The generated files will be available in the directory ``build/sphinx/html/``. .. _Sphinx: https://www.sphinx-doc.org/ There are no proper tests (yet?), but the code examples from the README file can be verified with pytest_. If you haven't installed it already, you can install it with:: python3 -m pip install pytest As soon as pytest_ is installed, you can run the (rudimentary) tests with:: python3 -m pytest .. _pytest: https://pytest.org/ ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1581428317.0 JACK-Client-0.5.3/LICENSE0000644000175000017500000000204700000000000013504 0ustar00mgmg00000000000000Copyright (c) 2014-2020 Matthias Geier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1535274665.0 JACK-Client-0.5.3/MANIFEST.in0000644000175000017500000000022200000000000014226 0ustar00mgmg00000000000000include LICENSE include jack_build.py include *.rst include doc/requirements.txt recursive-include doc *.rst *.py recursive-include examples *.py ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603273843.0 JACK-Client-0.5.3/NEWS.rst0000644000175000017500000001247000000000000014006 0ustar00mgmg00000000000000Version 0.5.3 -- 2020-10-21 -- PyPI__ -- docs__ -- diff__ * use ``jack_port_rename()`` instead of deprecated ``jack_port_set_name()`` __ https://pypi.org/project/JACK-Client/0.5.3/ __ https://jackclient-python.readthedocs.io/en/0.5.3/ __ https://github.com/spatialaudio/jackclient-python/compare/0.5.2...0.5.3 Version 0.5.2 -- 2020-02-11 -- PyPI__ -- docs__ -- diff__ * new module constants: ``jack.POSITION_*`` * new examples: ``timebase_master.py`` and ``transporter.py``, thanks to Christopher Arndt * new `jack.JackError` subclasses: `jack.JackErrorCode` and `jack.JackOpenError`, thanks to Christopher Arndt __ https://pypi.org/project/JACK-Client/0.5.2/ __ https://jackclient-python.readthedocs.io/en/0.5.2/ __ https://github.com/spatialaudio/jackclient-python/compare/0.5.1...0.5.2 Version 0.5.1 -- 2019-11-07 -- PyPI__ -- docs__ -- diff__ * `jack.Client.release_timebase()`, thanks to Christopher Arndt __ https://pypi.org/project/JACK-Client/0.5.1/ __ https://jackclient-python.readthedocs.io/en/0.5.1/ __ https://github.com/spatialaudio/jackclient-python/compare/0.5.0...0.5.1 Version 0.5.0 -- 2019-07-18 -- PyPI__ -- docs__ -- diff__ * drop Python 2 support * support for metadata API, with the help of Christopher Arndt * support for slow-sync clients __ https://pypi.org/project/JACK-Client/0.5.0/ __ https://jackclient-python.readthedocs.io/en/0.5.0/ __ https://github.com/spatialaudio/jackclient-python/compare/0.4.6...0.5.0 Version 0.4.6 -- 2019-02-09 -- PyPI__ -- docs__ -- diff__ * ``midi_file_player.py`` example __ https://pypi.org/project/JACK-Client/0.4.6/ __ https://jackclient-python.readthedocs.io/en/0.4.6/ __ https://github.com/spatialaudio/jackclient-python/compare/0.4.5...0.4.6 Version 0.4.5 -- 2018-09-02 -- PyPI__ -- docs__ -- diff__ * Fix issue #54; other minor improvements __ https://pypi.org/project/JACK-Client/0.4.5/ __ https://jackclient-python.readthedocs.io/en/0.4.5/ __ https://github.com/spatialaudio/jackclient-python/compare/0.4.4...0.4.5 Version 0.4.4 -- 2018-02-19 -- PyPI__ -- docs__ -- diff__ * `Port.set_alias()`, `Port.unset_alias()` and `Port.aliases`, thanks to Jośe Fernando Moyano __ https://pypi.org/project/JACK-Client/0.4.4/ __ https://jackclient-python.readthedocs.io/en/0.4.4/ __ https://github.com/spatialaudio/jackclient-python/compare/0.4.3...0.4.4 Version 0.4.3 -- 2017-12-30 -- PyPI__ -- docs__ -- diff__ * switch to CFFI out-of-line ABI mode (to reduce import time) __ https://pypi.org/project/JACK-Client/0.4.3/ __ https://jackclient-python.readthedocs.io/en/0.4.3/ __ https://github.com/spatialaudio/jackclient-python/compare/0.4.2...0.4.3 Version 0.4.2 -- 2016-11-05 -- PyPI__ -- docs__ -- diff__ * new examples: ``showtime.py``, ``midi_sine_numpy.py`` and ``play_file.py`` * new option ``only_available`` for port callbacks __ https://pypi.org/project/JACK-Client/0.4.2/ __ https://jackclient-python.readthedocs.io/en/0.4.2/ __ https://github.com/spatialaudio/jackclient-python/compare/0.4.1...0.4.2 Version 0.4.1 -- 2016-05-24 -- PyPI__ -- docs__ -- diff__ * new property `jack.Client.transport_frame`, deprecating `jack.Client.transport_locate()` __ https://pypi.org/project/JACK-Client/0.4.1/ __ https://jackclient-python.readthedocs.io/en/0.4.1/ __ https://github.com/spatialaudio/jackclient-python/compare/0.4.0...0.4.1 Version 0.4.0 -- 2015-09-17 -- PyPI__ -- docs__ -- diff__ * new argument to xrun callback (see `jack.Client.set_xrun_callback()`), ``jack.Client.xrun_delayed_usecs`` was removed * `jack.Client.transport_reposition_struct()` * callbacks no longer have to return anything, instead they can raise `jack.CallbackExit` on error * ``midi_sine.py`` example __ https://pypi.org/project/JACK-Client/0.4.0/ __ https://jackclient-python.readthedocs.io/en/0.4.0/ __ https://github.com/spatialaudio/jackclient-python/compare/0.3.0...0.4.0 Version 0.3.0 -- 2015-07-16 -- PyPI__ -- docs__ -- diff__ * `jack.RingBuffer`, implemented by Alexandru Stan * `jack.Client.set_timebase_callback()`, `jack.Client.transport_query()`, `jack.Client.transport_query_struct()`, with the help of Julien Acroute * `jack.Client.transport_state`, `jack.STOPPED`, `jack.ROLLING`, `jack.STARTING`, `jack.NETSTARTING`, `jack.position2dict()` * the *userdata* argument was removed from all callbacks * compatibility with the official JACK installer for Windows, thanks to Julien Acroute __ https://pypi.org/project/JACK-Client/0.3.0/ __ https://jackclient-python.readthedocs.io/en/0.3.0/ __ https://github.com/spatialaudio/jackclient-python/compare/0.2.0...0.3.0 Version 0.2.0 -- 2015-02-23 -- PyPI__ -- docs__ -- diff__ * MIDI support (`jack.MidiPort`, `jack.OwnMidiPort`, `jack.Client.midi_inports`, `jack.Client.midi_outports`, ...) * ignore errors in `jack.Client.deactivate()` by default, can be overridden * optional argument to `jack.OwnPort.disconnect()` * several examples (``chatty_client.py``, ``thru_client.py``, ``midi_monitor.py`` and ``midi_chords.py``) * `jack.Port.is_physical`, courtesy of Alexandru Stan * `jack.Status` __ https://pypi.org/project/JACK-Client/0.2.0/ __ https://jackclient-python.readthedocs.io/en/0.2.0/ __ https://github.com/spatialaudio/jackclient-python/compare/0.1.0...0.2.0 Version 0.1.0 -- 2014-12-15 -- PyPI__ -- docs__ Initial release __ https://pypi.org/project/JACK-Client/0.1.0/ __ https://jackclient-python.readthedocs.io/en/0.1.0/ ././@PaxHeader0000000000000000000000000000003300000000000011451 xustar000000000000000027 mtime=1603273938.527674 JACK-Client-0.5.3/PKG-INFO0000644000175000017500000000224700000000000013576 0ustar00mgmg00000000000000Metadata-Version: 2.1 Name: JACK-Client Version: 0.5.3 Summary: JACK Audio Connection Kit (JACK) Client for Python Home-page: http://jackclient-python.readthedocs.io/ Author: Matthias Geier Author-email: Matthias.Geier@gmail.com License: MIT Description: JACK Audio Connection Kit (JACK) Client for Python ================================================== This Python module (named ``jack``) provides bindings for the JACK_ library. Documentation: https://jackclient-python.readthedocs.io/ Source code and issue tracker: https://github.com/spatialaudio/jackclient-python/ License: MIT -- see the file ``LICENSE`` for details. .. _JACK: https://jackaudio.org/ Keywords: JACK,audio,low-latency,multi-channel Platform: any Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3 :: Only Classifier: Topic :: Multimedia :: Sound/Audio Requires-Python: >=3 Provides-Extra: NumPy ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603104715.0 JACK-Client-0.5.3/README.rst0000644000175000017500000000064300000000000014166 0ustar00mgmg00000000000000JACK Audio Connection Kit (JACK) Client for Python ================================================== This Python module (named ``jack``) provides bindings for the JACK_ library. Documentation: https://jackclient-python.readthedocs.io/ Source code and issue tracker: https://github.com/spatialaudio/jackclient-python/ License: MIT -- see the file ``LICENSE`` for details. .. _JACK: https://jackaudio.org/ ././@PaxHeader0000000000000000000000000000003300000000000011451 xustar000000000000000027 mtime=1603273938.523674 JACK-Client-0.5.3/doc/0000755000175000017500000000000000000000000013241 5ustar00mgmg00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603104715.0 JACK-Client-0.5.3/doc/api.rst0000644000175000017500000000013200000000000014540 0ustar00mgmg00000000000000API Documentation ================= .. automodule:: jack :members: :undoc-members: ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603104715.0 JACK-Client-0.5.3/doc/conf.py0000644000175000017500000000520300000000000014540 0ustar00mgmg00000000000000# Configuration file for Sphinx, # see https://www.sphinx-doc.org/en/master/usage/configuration.html import sys import os from subprocess import check_output sys.path.insert(0, os.path.abspath('../src')) sys.path.insert(0, os.path.abspath('.')) # Fake import to avoid actually loading CFFI and the JACK library import fake__jack sys.modules['_jack'] = sys.modules['fake__jack'] # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. needs_sphinx = '1.3' # for sphinx.ext.napoleon extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.viewcode', 'sphinx.ext.napoleon', # support for NumPy-style docstrings 'sphinx_last_updated_by_git', ] autoclass_content = 'init' autodoc_member_order = 'bysource' napoleon_google_docstring = False napoleon_numpy_docstring = True napoleon_include_private_with_doc = False napoleon_include_special_with_doc = False napoleon_use_admonition_for_examples = False napoleon_use_admonition_for_notes = False napoleon_use_admonition_for_references = False napoleon_use_ivar = False napoleon_use_param = False napoleon_use_rtype = False authors = 'Matthias Geier' project = 'JACK Audio Connection Kit (JACK) Client for Python' copyright = '2020, ' + authors nitpicky = True try: release = check_output(['git', 'describe', '--tags', '--always']) release = release.decode().strip() except Exception: release = '' try: today = check_output(['git', 'show', '-s', '--format=%ad', '--date=short']) today = today.decode().strip() except Exception: today = '' default_role = 'any' # -- Options for HTML output ---------------------------------------------- html_theme = 'insipid' html_title = 'JACK Client for Python, version ' + release html_domain_indices = False html_show_copyright = False html_add_permalinks = '\N{SECTION SIGN}' html_copy_source = False # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). 'papersize': 'a4paper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', 'printindex': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [('index', 'JACK-Client.tex', project, authors, 'howto')] latex_show_urls = 'footnote' latex_domain_indices = False # -- Options for epub output ---------------------------------------------- epub_author = authors epub_use_index = False ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603104715.0 JACK-Client-0.5.3/doc/contributing.rst0000644000175000017500000000004100000000000016475 0ustar00mgmg00000000000000.. include:: ../CONTRIBUTING.rst ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603104715.0 JACK-Client-0.5.3/doc/examples.rst0000644000175000017500000000251100000000000015610 0ustar00mgmg00000000000000Example Programs ================ Chatty Client ------------- :download:`chatty_client.py <../examples/chatty_client.py>` .. literalinclude:: ../examples/chatty_client.py Pass-Through Client ------------------- :download:`thru_client.py <../examples/thru_client.py>` .. literalinclude:: ../examples/thru_client.py Sound File Playback ------------------- :download:`play_file.py <../examples/play_file.py>` .. literalinclude:: ../examples/play_file.py "Showtime" Client ----------------- :download:`showtime.py <../examples/showtime.py>` .. literalinclude:: ../examples/showtime.py MIDI Monitor ------------ :download:`midi_monitor.py <../examples/midi_monitor.py>` .. literalinclude:: ../examples/midi_monitor.py MIDI Chord Generator -------------------- :download:`midi_chords.py <../examples/midi_chords.py>` .. literalinclude:: ../examples/midi_chords.py MIDI File Player ---------------- :download:`midi_file_player.py <../examples/midi_file_player.py>` .. literalinclude:: ../examples/midi_file_player.py Simple MIDI Synth ----------------- :download:`midi_sine.py <../examples/midi_sine.py>` .. literalinclude:: ../examples/midi_sine.py Simple MIDI Synth (NumPy Edition) --------------------------------- :download:`midi_sine_numpy.py <../examples/midi_sine_numpy.py>` .. literalinclude:: ../examples/midi_sine_numpy.py ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1580122877.0 JACK-Client-0.5.3/doc/fake__jack.py0000644000175000017500000000142100000000000015646 0ustar00mgmg00000000000000"""Mock module for Sphinx autodoc.""" import ctypes.util old_find_library = ctypes.util.find_library def new_find_library(name): if 'jack' in name.lower(): return NotImplemented return old_find_library(name) # Monkey-patch ctypes to disable searching for JACK ctypes.util.find_library = new_find_library class Fake(object): NULL = NotImplemented JackTransportStopped = 0 JackTransportRolling = 1 JackTransportStarting = 3 JackTransportNetStarting = 4 PropertyCreated = 0 PropertyChanged = 1 PropertyDeleted = 2 JackPositionBBT = 0x10 JackPositionTimecode = 0x20 JackBBTFrameOffset = 0x40 JackAudioVideoRatio = 0x80 JackVideoFrameOffset = 0x100 def dlopen(self, _): return self ffi = Fake() ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603104715.0 JACK-Client-0.5.3/doc/index.rst0000644000175000017500000000026400000000000015104 0ustar00mgmg00000000000000.. include:: ../README.rst ---- .. toctree:: installation usage examples api contributing version-history other-modules .. only:: html :ref:`genindex` ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603104715.0 JACK-Client-0.5.3/doc/installation.rst0000644000175000017500000000675700000000000016513 0ustar00mgmg00000000000000Installation ============ .. image:: https://badge.fury.io/py/JACK-Client.svg :target: https://pypi.org/project/JACK-Client/ You can use ``pip`` to install the ``jack`` module:: python3 -m pip install JACK-Client Depending on your Python installation (see `Requirements`_ below), you may have to use ``python`` instead of ``python3``. If you have installed the module already, you can use the ``--upgrade`` flag to get the newest release. To un-install, use:: python3 -m pip uninstall JACK-Client Requirements ------------ You'll need some software packages in order to install and use the ``jack`` module. Some of those might already be installed on your system and some are automatically installed when you use the aforementioned ``pip`` command. Python: Of course, you'll need Python_. More specifically, you'll need Python 3. If you don't have Python installed yet, you should get one of the distributions which already include CFFI and NumPy (and many other useful things), e.g. Anaconda_ or WinPython_. pip/setuptools: Those are needed for the installation of the Python module and its dependencies. Most systems will have these installed already, but if not, you should install it with your package manager or you can download and install ``pip`` and ``setuptools`` as described on the `pip installation`_ page. If you happen to have ``pip`` but not ``setuptools``, use this command:: python3 -m pip install setuptools To upgrade to a newer version of an already installed package (including ``pip`` itself), use the ``--upgrade`` flag. CFFI: The `C Foreign Function Interface for Python`_ is used to access the C-API of the JACK library from within Python. It is supported on CPython and is distributed with PyPy_. It will be automatically installed when installing the ``JACK-Client`` package with ``pip``. If you prefer, you can also install it with your package manager (the package might be called ``python3-cffi`` or similar). JACK library: The JACK_ library must be installed on your system (and CFFI must be able to find it). Again, you should use your package manager to install it. Make sure you install the JACK daemon (called ``jackd``). This will also install the JACK library package. If you don't have a package manager, you can try one of the binary installers from the `JACK download page`_. If you prefer, you can of course also download the sources and compile everything locally. NumPy (optional): NumPy_ is only needed if you want to access the input and output buffers in the process callback as NumPy arrays. The only place where NumPy is needed is `jack.OwnPort.get_array()` (and you can use `jack.OwnPort.get_buffer()` as a NumPy-less alternative). If you need NumPy, you can install it with your package manager or use a Python distribution that already includes NumPy (see above). You can also install NumPy with ``pip``, but depending on your platform, this might require a compiler and several additional libraries:: python3 -m pip install NumPy .. _JACK: https://jackaudio.org/ .. _NumPy: https://numpy.org/ .. _Python: https://www.python.org/ .. _Anaconda: https://www.anaconda.com/products/individual#Downloads .. _WinPython: http://winpython.github.io/ .. _C Foreign Function Interface for Python: https://cffi.readthedocs.org/ .. _PyPy: https://www.pypy.org/ .. _JACK download page: https://jackaudio.org/downloads/ .. _pip installation: https://pip.pypa.io/en/latest/installing/ ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603104715.0 JACK-Client-0.5.3/doc/other-modules.rst0000644000175000017500000000036700000000000016570 0ustar00mgmg00000000000000Other Python Modules for JACK ============================= PyJack https://sourceforge.net/projects/py-jack/ jacklib from Cadence https://github.com/falkTX/Cadence/blob/master/src/jacklib.py jacker https://github.com/fphammerle/jacker ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603104715.0 JACK-Client-0.5.3/doc/requirements.txt0000644000175000017500000000006200000000000016523 0ustar00mgmg00000000000000insipid-sphinx-theme sphinx-last-updated-by-git ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603104715.0 JACK-Client-0.5.3/doc/usage.rst0000644000175000017500000000766300000000000015113 0ustar00mgmg00000000000000Usage ===== First, import the module: >>> import jack Then, you most likely want to create a new `jack.Client`: >>> client = jack.Client('MyGreatClient') You probably want to create some audio input and output ports, too: >>> client.inports.register('input_1') jack.OwnPort('MyGreatClient:input_1') >>> client.outports.register('output_1') jack.OwnPort('MyGreatClient:output_1') As you can see, these functions return the newly created port. If you want, you can save it for later: >>> in2 = client.inports.register('input_2') >>> out2 = client.outports.register('output_2') To see what you can do with the returned objects, have a look at the documentation of the class `jack.OwnPort`. In case you forgot, you should remind yourself about the ports you just created: >>> client.inports [jack.OwnPort('MyGreatClient:input_1'), jack.OwnPort('MyGreatClient:input_2')] >>> client.outports [jack.OwnPort('MyGreatClient:output_1'), jack.OwnPort('MyGreatClient:output_2')] Have a look at the documentation of the class `jack.Ports` to get more detailed information about these lists of ports. If you have selected an appropriate driver in your JACK settings, you can also create MIDI ports: >>> client.midi_inports.register('midi_in') jack.OwnMidiPort('MyGreatClient:midi_in') >>> client.midi_outports.register('midi_out') jack.OwnMidiPort('MyGreatClient:midi_out') You can check what other JACK ports are available (your output may be different): >>> client.get_ports() # doctest: +SKIP [jack.Port('system:capture_1'), jack.Port('system:capture_2'), jack.Port('system:playback_1'), jack.Port('system:playback_2'), jack.MidiPort('system:midi_capture_1'), jack.MidiPort('system:midi_playback_1'), jack.OwnPort('MyGreatClient:input_1'), jack.OwnPort('MyGreatClient:output_1'), jack.OwnPort('MyGreatClient:input_2'), jack.OwnPort('MyGreatClient:output_2'), jack.OwnMidiPort('MyGreatClient:midi_in'), jack.OwnMidiPort('MyGreatClient:midi_out')] Note that the ports you created yourself are of type `jack.OwnPort` and `jack.OwnMidiPort`, while other ports are merely of type `jack.Port` and `jack.MidiPort`, respectively. You can also be more specific when looking for ports: >>> client.get_ports(is_audio=True, is_output=True, is_physical=True) [jack.Port('system:capture_1'), jack.Port('system:capture_2')] You can even use regular expressions to search for ports: >>> client.get_ports('Great.*2$') [jack.OwnPort('MyGreatClient:input_2'), jack.OwnPort('MyGreatClient:output_2')] If you want, you can also set all kinds of callback functions for your client. For details see the documentation for the class `jack.Client` and the example applications in the ``examples/`` directory. Once you are ready to run, you should activate your client: >>> client.activate() As soon as the client is activated, you can make connections (this isn't possible before activating the client): >>> client.connect('system:capture_1', 'MyGreatClient:input_1') >>> client.connect('MyGreatClient:output_1', 'system:playback_1') You can also use the port objects from before instead of port names: >>> client.connect(out2, 'system:playback_2') >>> in2.connect('system:capture_2') Use `jack.Client.get_all_connections()` to find out which other ports are connected to a given port. If you own the port, you can also use `jack.OwnPort.connections`. >>> client.get_all_connections('system:playback_1') [jack.OwnPort('MyGreatClient:output_1')] >>> out2.connections [jack.Port('system:playback_2')] Of course you can also disconnect ports, there are again several possibilities: >>> client.disconnect('system:capture_1', 'MyGreatClient:input_1') >>> client.disconnect(out2, 'system:playback_2') >>> in2.disconnect() # disconnect all connections with in2 If you don't need your ports anymore, you can un-register them: >>> in2.unregister() >>> client.outports.clear() # unregister all audio output ports Finally, you can de-activate your JACK client and close it: >>> client.deactivate() >>> client.close() ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603104715.0 JACK-Client-0.5.3/doc/version-history.rst0000644000175000017500000000007200000000000017156 0ustar00mgmg00000000000000Version History =============== .. include:: ../NEWS.rst ././@PaxHeader0000000000000000000000000000003300000000000011451 xustar000000000000000027 mtime=1603273938.527674 JACK-Client-0.5.3/examples/0000755000175000017500000000000000000000000014312 5ustar00mgmg00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1580122877.0 JACK-Client-0.5.3/examples/aliases.py0000755000175000017500000000241000000000000016305 0ustar00mgmg00000000000000#!/usr/bin/env python3 """Create a JACK client and test port-alias functionality. This client test the 3 functions related with port-aliases """ import jack print('starting TestAlias client') client = jack.Client('TestAlias') if client.status.server_started: print('JACK server was started') else: print('JACK server was already running') if client.status.name_not_unique: print('unique client name generated: {}'.format(client.name)) ports = client.get_ports() print('Testing set_alias() ...') for i, port in enumerate(ports): alias_name = 'Alias Name {}'.format(i) print("port '{}' => set_alias('{}')".format(port.shortname,alias_name)) port.set_alias(alias_name) print('Testing aliases property ...') for port in ports: for i, alias in enumerate(port.aliases): print("port '{}', alias {} => '{}'".format(port.shortname,i,alias)) print('Testing unset_alias() ...') for i, port in enumerate(ports): alias_name = 'Alias Name {}'.format(i) print("port '{}' => unset_alias('{}')".format(port.shortname,alias_name)) port.unset_alias(alias_name) print('Testing aliases property ...') for port in ports: for i, alias in enumerate(port.aliases): print("port '{}', alias {} => '{}'".format(port.shortname,i,alias)) ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1561575862.0 JACK-Client-0.5.3/examples/chatty_client.py0000755000175000017500000000551100000000000017523 0ustar00mgmg00000000000000#!/usr/bin/env python3 """Create a JACK client that prints a lot of information. This client registers all possible callbacks (except the process callback and the timebase callback, which would be just too much noise) and prints some information whenever they are called. """ from __future__ import print_function # only needed for Python 2.x import jack print('setting error/info functions') @jack.set_error_function def error(msg): print('Error:', msg) @jack.set_info_function def info(msg): print('Info:', msg) print('starting chatty client') client = jack.Client('Chatty-Client') if client.status.server_started: print('JACK server was started') else: print('JACK server was already running') if client.status.name_not_unique: print('unique client name generated:', client.name) print('registering callbacks') @client.set_shutdown_callback def shutdown(status, reason): print('JACK shutdown!') print('status:', status) print('reason:', reason) @client.set_freewheel_callback def freewheel(starting): print(['stopping', 'starting'][starting], 'freewheel mode') @client.set_blocksize_callback def blocksize(blocksize): print('setting blocksize to', blocksize) @client.set_samplerate_callback def samplerate(samplerate): print('setting samplerate to', samplerate) @client.set_client_registration_callback def client_registration(name, register): print('client', repr(name), ['unregistered', 'registered'][register]) @client.set_port_registration_callback def port_registration(port, register): print(repr(port), ['unregistered', 'registered'][register]) @client.set_port_connect_callback def port_connect(a, b, connect): print(['disconnected', 'connected'][connect], a, 'and', b) try: @client.set_port_rename_callback def port_rename(port, old, new): print('renamed', port, 'from', repr(old), 'to', repr(new)) except AttributeError: print('Could not register port rename callback (not available on JACK1).') @client.set_graph_order_callback def graph_order(): print('graph order changed') @client.set_xrun_callback def xrun(delay): print('xrun; delay', delay, 'microseconds') try: @client.set_property_change_callback def property_change(subject, key, changed): print('subject {}: '.format(subject), end='') if not key: assert changed == jack.PROPERTY_DELETED print('all properties were removed') return print('property {!r} was {}'.format(key, { jack.PROPERTY_CREATED: 'created', jack.PROPERTY_CHANGED: 'changed', jack.PROPERTY_DELETED: 'removed', }[changed])) except jack.JackError as e: print(e) print('activating JACK') with client: print('#' * 80) print('press Return to quit') print('#' * 80) input() print('closing JACK') ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1561575862.0 JACK-Client-0.5.3/examples/metadata.py0000755000175000017500000000151400000000000016450 0ustar00mgmg00000000000000#!/usr/bin/env python3 """Set/get/remove client/port metadata.""" from pprint import pprint import jack client = jack.Client('Metadata-Client') port = client.inports.register('input') client.set_property(client, jack.METADATA_PRETTY_NAME, 'Best Client Ever') print('Client "pretty" name:', jack.get_property(client, jack.METADATA_PRETTY_NAME)) client.set_property( port, jack.METADATA_PRETTY_NAME, b'a good port', 'text/plain') print('Port "pretty" name:', jack.get_property(port, jack.METADATA_PRETTY_NAME)) print('All client properties:') pprint(jack.get_properties(client)) print('All port properties:') pprint(jack.get_properties(port)) print('All properties:') pprint(jack.get_all_properties()) client.remove_property(port, jack.METADATA_PRETTY_NAME) client.remove_properties(client) client.remove_all_properties() ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1513848505.0 JACK-Client-0.5.3/examples/midi_chords.py0000755000175000017500000000213600000000000017155 0ustar00mgmg00000000000000#!/usr/bin/env python3 """JACK client that creates minor triads from single MIDI notes. All MIDI events are passed through. Two additional events are created for each NoteOn and NoteOff event. """ import jack import struct # First 4 bits of status byte: NOTEON = 0x9 NOTEOFF = 0x8 INTERVALS = 3, 7 # minor triad client = jack.Client('MIDI-Chord-Generator') inport = client.midi_inports.register('input') outport = client.midi_outports.register('output') @client.set_process_callback def process(frames): outport.clear_buffer() for offset, indata in inport.incoming_midi_events(): # Note: This may raise an exception: outport.write_midi_event(offset, indata) # pass through if len(indata) == 3: status, pitch, vel = struct.unpack('3B', indata) if status >> 4 in (NOTEON, NOTEOFF): for i in INTERVALS: # Note: This may raise an exception: outport.write_midi_event(offset, (status, pitch + i, vel)) with client: print('#' * 80) print('press Return to quit') print('#' * 80) input() ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1548173901.0 JACK-Client-0.5.3/examples/midi_file_player.py0000755000175000017500000000330700000000000020167 0ustar00mgmg00000000000000#!/usr/bin/env python3 """Play a MIDI file. This uses the "mido" module for handling MIDI: https://mido.readthedocs.io/ Pass the MIDI file name as first command line argument. If a MIDI port name is passed as second argument, a connection is made. """ import sys import threading import jack from mido import MidiFile argv = iter(sys.argv) next(argv) filename = next(argv, '') connect_to = next(argv, '') if not filename: sys.exit('Please specify a MIDI file') try: mid = iter(MidiFile(filename)) except Exception as e: sys.exit(type(e).__name__ + ' while loading MIDI: ' + str(e)) client = jack.Client('MIDI-File-Player') port = client.midi_outports.register('output') event = threading.Event() msg = next(mid) fs = None # sampling rate offset = 0 @client.set_process_callback def process(frames): global offset global msg port.clear_buffer() while True: if offset >= frames: offset -= frames return # We'll take care of this in the next block ... # Note: This may raise an exception: port.write_midi_event(offset, msg.bytes()) try: msg = next(mid) except StopIteration: event.set() raise jack.CallbackExit offset += round(msg.time * fs) @client.set_samplerate_callback def samplerate(samplerate): global fs fs = samplerate @client.set_shutdown_callback def shutdown(status, reason): print('JACK shutdown:', reason, status) event.set() with client: if connect_to: port.connect(connect_to) print('Playing', repr(filename), '... press Ctrl+C to stop') try: event.wait() except KeyboardInterrupt: print('\nInterrupted by user') ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1513848505.0 JACK-Client-0.5.3/examples/midi_monitor.py0000755000175000017500000000102400000000000017355 0ustar00mgmg00000000000000#!/usr/bin/env python3 """JACK client that prints all received MIDI events.""" import jack import binascii client = jack.Client('MIDI-Monitor') port = client.midi_inports.register('input') @client.set_process_callback def process(frames): for offset, data in port.incoming_midi_events(): print('{0}: 0x{1}'.format(client.last_frame_time + offset, binascii.hexlify(data).decode())) with client: print('#' * 80) print('press Return to quit') print('#' * 80) input() ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1513848505.0 JACK-Client-0.5.3/examples/midi_sine.py0000755000175000017500000000757000000000000016640 0ustar00mgmg00000000000000#!/usr/bin/env python3 """Very basic MIDI synthesizer. This only works in Python 3.x because it uses memoryview.cast() and a few other sweet Python-3-only features. This is inspired by the JACK example program "jack_midisine": http://github.com/jackaudio/jack2/blob/master/example-clients/midisine.c But it is actually better: + ASR envelope + unlimited polyphony (well, "only" limited by CPU and memory) + arbitrarily many MIDI events per block + can handle NoteOn and NoteOff event of the same pitch in one block It is also worse: - horribly inefficient (dynamic allocations, sample-wise processing) - unpredictable because of garbage collection (?) It sounds a little better than the original, but still quite boring. """ import jack import math import operator import threading # First 4 bits of status byte: NOTEON = 0x9 NOTEOFF = 0x8 attack = 0.01 # seconds release = 0.2 # seconds fs = None voices = {} client = jack.Client('MIDI-Sine') midiport = client.midi_inports.register('midi_in') audioport = client.outports.register('audio_out') event = threading.Event() def m2f(note): """Convert MIDI note number to frequency in Hertz. See https://en.wikipedia.org/wiki/MIDI_Tuning_Standard. """ return 2 ** ((note - 69) / 12) * 440 class Voice: def __init__(self, pitch): self.time = 0 self.time_increment = m2f(pitch) / fs self.weight = 0 self.target_weight = 0 self.weight_step = 0 self.compare = None def trigger(self, vel): if vel: dur = attack * fs else: dur = release * fs self.target_weight = vel / 127 self.weight_step = (self.target_weight - self.weight) / dur self.compare = operator.ge if self.weight_step > 0 else operator.le def update(self): """Increment weight.""" if self.weight_step: self.weight += self.weight_step if self.compare(self.weight, self.target_weight): self.weight = self.target_weight self.weight_step = 0 @client.set_process_callback def process(frames): """Main callback.""" events = {} buf = memoryview(audioport.get_buffer()).cast('f') for offset, data in midiport.incoming_midi_events(): if len(data) == 3: status, pitch, vel = bytes(data) # MIDI channel number is ignored! status >>= 4 if status == NOTEON and vel > 0: events.setdefault(offset, []).append((pitch, vel)) elif status in (NOTEON, NOTEOFF): # NoteOff velocity is ignored! events.setdefault(offset, []).append((pitch, 0)) else: pass # ignore else: pass # ignore for i in range(len(buf)): buf[i] = 0 try: eventlist = events[i] except KeyError: pass else: for pitch, vel in eventlist: if pitch not in voices: if not vel: break voices[pitch] = Voice(pitch) voices[pitch].trigger(vel) for voice in voices.values(): voice.update() if voice.weight > 0: buf[i] += voice.weight * math.sin(2 * math.pi * voice.time) voice.time += voice.time_increment if voice.time >= 1: voice.time -= 1 dead = [k for k, v in voices.items() if v.weight <= 0] for pitch in dead: del voices[pitch] @client.set_samplerate_callback def samplerate(samplerate): global fs fs = samplerate voices.clear() @client.set_shutdown_callback def shutdown(status, reason): print('JACK shutdown:', reason, status) event.set() with client: print('Press Ctrl+C to stop') try: event.wait() except KeyboardInterrupt: print('\nInterrupted by user') ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1513848505.0 JACK-Client-0.5.3/examples/midi_sine_numpy.py0000755000175000017500000000775400000000000020074 0ustar00mgmg00000000000000#!/usr/bin/env python3 """Very basic MIDI synthesizer. This does the same as midi_sine.py, but it uses NumPy and block processing. It is therefore much more efficient. But there are still many allocations and dynamically growing and shrinking data structures. """ import jack import numpy as np import threading # First 4 bits of status byte: NOTEON = 0x9 NOTEOFF = 0x8 attack_seconds = 0.01 release_seconds = 0.2 attack = None release = None fs = None voices = {} client = jack.Client('MIDI-Sine-NumPy') midiport = client.midi_inports.register('midi_in') audioport = client.outports.register('audio_out') event = threading.Event() def m2f(note): """Convert MIDI note number to frequency in Hertz. See https://en.wikipedia.org/wiki/MIDI_Tuning_Standard. """ return 2 ** ((note - 69) / 12) * 440 def update_envelope(envelope, begin, target, vel): """Helper function to calculate envelopes. envelope: array of velocities, will be mutated begin: sample index where ramp begins target: sample index where *vel* shall be reached vel: final velocity value If the ramp goes beyond the blocksize, it is supposed to be continued in the next block. A reference to *envelope* is returned, as well as the (unchanged) *vel* and the target index of the following block where *vel* shall be reached. """ blocksize = len(envelope) old_vel = envelope[begin] slope = (vel - old_vel) / (target - begin + 1) ramp = np.arange(min(target, blocksize) - begin) + 1 envelope[begin:target] = ramp * slope + old_vel if target < blocksize: envelope[target:] = vel target = 0 else: target -= blocksize return envelope, vel, target @client.set_process_callback def process(blocksize): """Main callback.""" # Step 1: Update/delete existing voices from previous block # Iterating over a copy because items may be deleted: for pitch in list(voices): envelope, vel, target = voices[pitch] if any([vel, target]): envelope[0] = envelope[-1] voices[pitch] = update_envelope(envelope, 0, target, vel) else: del voices[pitch] # Step 2: Create envelopes from the MIDI events of the current block for offset, data in midiport.incoming_midi_events(): if len(data) == 3: status, pitch, vel = bytes(data) # MIDI channel number is ignored! status >>= 4 if status == NOTEON and vel > 0: try: envelope, _, _ = voices[pitch] except KeyError: envelope = np.zeros(blocksize) voices[pitch] = update_envelope( envelope, offset, offset + attack, vel) elif status in (NOTEON, NOTEOFF): # NoteOff velocity is ignored! try: envelope, _, _ = voices[pitch] except KeyError: print('NoteOff without NoteOn (ignored)') continue voices[pitch] = update_envelope( envelope, offset, offset + release, 0) else: pass # ignore else: pass # ignore # Step 3: Create sine tones, apply envelopes, add to output buffer buf = audioport.get_array() buf.fill(0) for pitch, (envelope, _, _) in voices.items(): t = (np.arange(blocksize) + client.last_frame_time) / fs tone = np.sin(2 * np.pi * m2f(pitch) * t) buf += tone * envelope / 127 @client.set_samplerate_callback def samplerate(samplerate): global fs, attack, release fs = samplerate attack = int(attack_seconds * fs) release = int(release_seconds * fs) voices.clear() @client.set_shutdown_callback def shutdown(status, reason): print('JACK shutdown:', reason, status) event.set() with client: print('Press Ctrl+C to stop') try: event.wait() except KeyboardInterrupt: print('\nInterrupted by user') ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1554399965.0 JACK-Client-0.5.3/examples/play_file.py0000755000175000017500000000735500000000000016645 0ustar00mgmg00000000000000#!/usr/bin/env python3 """Play a sound file. This only reads a certain number of blocks at a time into memory, therefore it can handle very long files and also files with many channels. NumPy and the soundfile module (http://PySoundFile.rtfd.io/) must be installed for this to work. """ from __future__ import division from __future__ import print_function import argparse try: import queue # Python 3.x except ImportError: import Queue as queue # Python 2.x import sys import threading parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('filename', help='audio file to be played back') parser.add_argument( '-b', '--buffersize', type=int, default=20, help='number of blocks used for buffering (default: %(default)s)') parser.add_argument('-c', '--clientname', default='file player', help='JACK client name') parser.add_argument('-m', '--manual', action='store_true', help="don't connect to output ports automatically") args = parser.parse_args() if args.buffersize < 1: parser.error('buffersize must be at least 1') q = queue.Queue(maxsize=args.buffersize) event = threading.Event() def print_error(*args): print(*args, file=sys.stderr) def xrun(delay): print_error("An xrun occured, increase JACK's period size?") def shutdown(status, reason): print_error('JACK shutdown!') print_error('status:', status) print_error('reason:', reason) event.set() def stop_callback(msg=''): if msg: print_error(msg) for port in client.outports: port.get_array().fill(0) event.set() raise jack.CallbackExit def process(frames): if frames != blocksize: stop_callback('blocksize must not be changed, I quit!') try: data = q.get_nowait() except queue.Empty: stop_callback('Buffer is empty: increase buffersize?') if data is None: stop_callback() # Playback is finished for channel, port in zip(data.T, client.outports): port.get_array()[:] = channel try: import jack import soundfile as sf client = jack.Client(args.clientname) blocksize = client.blocksize samplerate = client.samplerate client.set_xrun_callback(xrun) client.set_shutdown_callback(shutdown) client.set_process_callback(process) with sf.SoundFile(args.filename) as f: for ch in range(f.channels): client.outports.register('out_{0}'.format(ch + 1)) block_generator = f.blocks(blocksize=blocksize, dtype='float32', always_2d=True, fill_value=0) for _, data in zip(range(args.buffersize), block_generator): q.put_nowait(data) # Pre-fill queue with client: if not args.manual: target_ports = client.get_ports( is_physical=True, is_input=True, is_audio=True) if len(client.outports) == 1 and len(target_ports) > 1: # Connect mono file to stereo output client.outports[0].connect(target_ports[0]) client.outports[0].connect(target_ports[1]) else: for source, target in zip(client.outports, target_ports): source.connect(target) timeout = blocksize * args.buffersize / samplerate for data in block_generator: q.put(data, timeout=timeout) q.put(None, timeout=timeout) # Signal end of file event.wait() # Wait until playback is finished except KeyboardInterrupt: parser.exit('\nInterrupted by user') except (queue.Full): # A timeout occured, i.e. there was an error in the callback parser.exit(1) except Exception as e: parser.exit(type(e).__name__ + ': ' + str(e)) ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1513848505.0 JACK-Client-0.5.3/examples/showtime.py0000755000175000017500000000324000000000000016525 0ustar00mgmg00000000000000#!/usr/bin/env python3 """Display information about time, transport state et cetera. This is somewhat modeled after the "showtime.c" example of JACK. https://github.com/jackaudio/example-clients/blob/master/showtime.c https://github.com/jackaudio/jack2/blob/master/example-clients/showtime.c """ from contextlib import suppress import time import sys import jack try: client = jack.Client('showtime') except jack.JackError: sys.exit('JACK server not running?') def showtime(): state, pos = client.transport_query() items = [] items.append('frame = {} frame_time = {} usecs = {} '.format( pos['frame'], client.frame_time, pos['usecs'])) items.append('state: {}'.format(state)) with suppress(KeyError): items.append('BBT: {bar:3}|{beat}|{tick:04}'.format(**pos)) with suppress(KeyError): items.append('TC: ({frame_time:.6f}, {next_time:.6f})'.format(**pos)) with suppress(KeyError): items.append('BBT offset: ({bbt_offset})'.format(**pos)) with suppress(KeyError): items.append( 'audio/video: ({audio_frames_per_video_frame})'.format(**pos)) with suppress(KeyError): video_offset = pos['video_offset'] if video_offset: items.append(' video@: ({})'.format(video_offset)) else: items.append(' no video'); print(*items, sep='\t') @client.set_shutdown_callback def shutdown(status, reason): sys.exit('JACK shut down, exiting ...') with client: try: while True: time.sleep(0.00002) showtime() except KeyboardInterrupt: print('signal received, exiting ...', file=sys.stderr) sys.exit(0) ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1561575876.0 JACK-Client-0.5.3/examples/slow_sync.py0000755000175000017500000000505500000000000016714 0ustar00mgmg00000000000000#!/usr/bin/env python3 """Show how slow-sync clients work.""" import time import jack slow = jack.Client('Slow') slow.pos = 0 slow.ready_at = None slow.seek_time = 0.1 @slow.set_sync_callback def slow_sync_callback(state, pos): now = time.time() print(jack.TransportState(state), pos.frame, end=' ') if state == jack.STOPPED: if slow.pos == pos.frame: print('ready') return True if slow.ready_at is None: slow.ready_at = now + slow.seek_time if slow.ready_at < now: print('just got ready') slow.pos = pos.frame slow.ready_at = None return True print('will be ready in {:.2f} seconds'.format(slow.ready_at - now)) elif state == jack.STARTING: if slow.pos == pos.frame: print('ready') return True if slow.ready_at is None: slow.ready_at = now + slow.seek_time if slow.ready_at < now: print('just got ready') slow.pos = pos.frame slow.ready_at = None return True print('will be ready in {:.2f} seconds'.format(slow.ready_at - now)) return False elif state == jack.ROLLING: assert slow.pos != pos.frame assert slow.ready_at is not None if slow.ready_at < now: print('just caught up') slow.pos = pos.frame slow.ready_at = None return True print('will catch up in {:.2f} seconds'.format(slow.ready_at - now)) return False else: assert False return False # Make sure transport is stopped and at 0 initially slow.transport_stop() slow.transport_frame = 0 print('== setting custom sync timeout') slow.set_sync_timeout(int(0.5 * slow.seek_time * 1000 * 1000)) with slow: time.sleep(0.1) # Time to show STOPPED print('== starting transport') slow.transport_start() time.sleep(0.1) # Time to show STARTING print('== stopping transport') slow.transport_stop() print('== seeking to 123') slow.transport_frame = 123 time.sleep(0.5 * slow.seek_time) print('== starting transport') slow.transport_start() time.sleep(slow.seek_time) print('== stopping transport') slow.transport_stop() print('== setting default sync timeout') slow.set_sync_timeout(2 * 1000 * 1000) print('== seeking to 123') slow.transport_frame = 123 time.sleep(0.5 * slow.seek_time) print('== starting transport') slow.transport_start() time.sleep(slow.seek_time) slow.transport_stop() ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1513848505.0 JACK-Client-0.5.3/examples/thru_client.py0000755000175000017500000000611000000000000017205 0ustar00mgmg00000000000000#!/usr/bin/env python3 """Create a JACK client that copies input audio directly to the outputs. This is somewhat modeled after the "thru_client.c" example of JACK 2: http://github.com/jackaudio/jack2/blob/master/example-clients/thru_client.c If you have a microphone and loudspeakers connected, this might cause an acoustical feedback! """ import sys import signal import os import jack import threading if sys.version_info < (3, 0): # In Python 2.x, event.wait() cannot be interrupted with Ctrl+C. # Therefore, we disable the whole KeyboardInterrupt mechanism. # This will not close the JACK client properly, but at least we can # use Ctrl+C. signal.signal(signal.SIGINT, signal.SIG_DFL) else: # If you use Python 3.x, everything is fine. pass argv = iter(sys.argv) # By default, use script name without extension as client name: defaultclientname = os.path.splitext(os.path.basename(next(argv)))[0] clientname = next(argv, defaultclientname) servername = next(argv, None) client = jack.Client(clientname, servername=servername) if client.status.server_started: print('JACK server started') if client.status.name_not_unique: print('unique name {0!r} assigned'.format(client.name)) event = threading.Event() @client.set_process_callback def process(frames): assert len(client.inports) == len(client.outports) assert frames == client.blocksize for i, o in zip(client.inports, client.outports): o.get_buffer()[:] = i.get_buffer() @client.set_shutdown_callback def shutdown(status, reason): print('JACK shutdown!') print('status:', status) print('reason:', reason) event.set() # create two port pairs for number in 1, 2: client.inports.register('input_{0}'.format(number)) client.outports.register('output_{0}'.format(number)) with client: # When entering this with-statement, client.activate() is called. # This tells the JACK server that we are ready to roll. # Our process() callback will start running now. # Connect the ports. You can't do this before the client is activated, # because we can't make connections to clients that aren't running. # Note the confusing (but necessary) orientation of the driver backend # ports: playback ports are "input" to the backend, and capture ports # are "output" from it. capture = client.get_ports(is_physical=True, is_output=True) if not capture: raise RuntimeError('No physical capture ports') for src, dest in zip(capture, client.inports): client.connect(src, dest) playback = client.get_ports(is_physical=True, is_input=True) if not playback: raise RuntimeError('No physical playback ports') for src, dest in zip(client.outports, playback): client.connect(src, dest) print('Press Ctrl+C to stop') try: event.wait() except KeyboardInterrupt: print('\nInterrupted by user') # When the above with-statement is left (either because the end of the # code block is reached, or because an exception was raised inside), # client.deactivate() and client.close() are called automatically. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1580807162.0 JACK-Client-0.5.3/examples/timebase_master.py0000755000175000017500000001141000000000000020030 0ustar00mgmg00000000000000#!/usr/bin/env python3 """A simple JACK timebase master.""" import argparse from threading import Event import jack class TimebaseMasterClient(jack.Client): def __init__(self, name, *, bpm=120.0, beats_per_bar=4, beat_type=4, ticks_per_beat=1920, conditional=False, debug=False, **kw): super().__init__(name, **kw) self.beats_per_bar = beats_per_bar self.beat_type = beat_type self.bpm = bpm self.conditional = conditional self.debug = debug self.ticks_per_beat = ticks_per_beat self.stop_event = Event() self.set_shutdown_callback(self.shutdown_callback) def shutdown_callback(self, status, reason): print('JACK shutdown:', reason, status) self.stop_event.set() def timebase_callback(self, state, nframes, pos, new_pos): if self.debug and new_pos: print('New pos:', jack.position2dict(pos)) # Adapted from: # https://github.com/jackaudio/jack2/blob/develop/example-clients/transport.c#L66 if new_pos: pos.beats_per_bar = self.beats_per_bar pos.beats_per_minute = self.bpm pos.beat_type = self.beat_type pos.ticks_per_beat = self.ticks_per_beat pos.valid = jack.POSITION_BBT minutes = pos.frame / (pos.frame_rate * 60.0) abs_tick = minutes * self.bpm * self.ticks_per_beat abs_beat = abs_tick / self.ticks_per_beat pos.bar = int(abs_beat / self.beats_per_bar) pos.beat = int(abs_beat - (pos.bar * self.beats_per_bar) + 1) pos.tick = int(abs_tick - (abs_beat * self.ticks_per_beat)) pos.bar_start_tick = ( pos.bar * self.beats_per_bar * self.ticks_per_beat) pos.bar += 1 # adjust start to bar 1 else: assert pos.valid & jack.POSITION_BBT # Compute BBT info based on previous period. pos.tick += int(nframes * pos.ticks_per_beat * pos.beats_per_minute / (pos.frame_rate * 60)) while pos.tick >= pos.ticks_per_beat: pos.tick -= int(pos.ticks_per_beat) pos.beat += 1 if pos.beat > pos.beats_per_bar: pos.beat = 1 pos.bar += 1 pos.bar_start_tick += pos.beats_per_bar * pos.ticks_per_beat if self.debug: print('Pos:', jack.position2dict(pos)) def become_timebase_master(self, conditional=None): if conditional is None: conditiona = self.conditional return self.set_timebase_callback(self.timebase_callback, conditional) def main(args=None): ap = argparse.ArgumentParser(description=__doc__) ap.add_argument( '-d', '--debug', action='store_true', help='enable debug messages') ap.add_argument( '-c', '--conditional', action='store_true', help='exit if another timebase master is already active') ap.add_argument( '-n', '--client-name', metavar='NAME', default='timebase', help='JACK client name (default: %(default)s)') ap.add_argument( '-m', '--meter', default='4/4', help='meter as / (default: %(default)s)') ap.add_argument( '-t', '--ticks-per-beat', type=int, metavar='NUM', default=1920, help='ticks per beat (default: %(default)s)') ap.add_argument( 'tempo', nargs='?', type=float, default=120.0, help='tempo in beats per minute (default: %(default)s)') args = ap.parse_args(args) try: beats_per_bar, beat_type = map(float, args.meter.split('/')) except ValueError: ap.error('Invalid meter: ' + args.meter) try: tbmaster = TimebaseMasterClient( args.client_name, bpm=args.tempo, beats_per_bar=beats_per_bar, beat_type=beat_type, ticks_per_beat=args.ticks_per_beat, debug=args.debug) except jack.JackError as exc: ap.exit('Could not create timebase master JACK client: {}'.format(exc)) with tbmaster: if tbmaster.become_timebase_master(args.conditional): try: print('Press Ctrl-C to quit...') tbmaster.stop_event.wait() except KeyboardInterrupt: print('') finally: try: tbmaster.release_timebase() except jack.JackError: # another JACK client might have grabbed timebase master pass else: ap.exit('Timebase master already present. Exiting...') if __name__ == '__main__': main() ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1580807162.0 JACK-Client-0.5.3/examples/transporter.py0000755000175000017500000000334500000000000017257 0ustar00mgmg00000000000000#!/usr/bin/env python3 """Query or change the JACK transport state.""" import argparse import string import jack def main(args=None): ap = argparse.ArgumentParser(description=__doc__) ap.add_argument( '-c', '--client-name', metavar='NAME', default='transporter', help='JACK client name (default: %(default)s)') ap.add_argument( 'command', nargs='?', default='status', choices=['query', 'rewind', 'start', 'status', 'stop', 'toggle'], help='transport command') args = ap.parse_args(args) try: client = jack.Client(args.client_name) except jack.JackError as exc: ap.exit('Could not create JACK client: {}'.format(exc)) state = client.transport_state result = 0 if args.command == 'status': print('JACK transport state is {}.'.format(state)) result = 1 if state == jack.STOPPED else 0 elif args.command == 'query': print('State: {}'.format(state)) info = client.transport_query()[1] for field in sorted(info): label = string.capwords(field.replace('_', ' ')) print('{}: {}'.format(label, info[field])) result = 1 if state == jack.STOPPED else 0 elif args.command == 'start': if state == jack.STOPPED: client.transport_start() elif args.command == 'stop': if state != jack.STOPPED: client.transport_stop() elif args.command == 'toggle': if state == jack.STOPPED: client.transport_start() else: client.transport_stop() elif args.command == 'rewind': client.transport_frame = 0 client.close() ap.exit(result) if __name__ == '__main__': main() ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602535552.0 JACK-Client-0.5.3/jack_build.py0000644000175000017500000003424700000000000015147 0ustar00mgmg00000000000000from cffi import FFI ffibuilder = FFI() ffibuilder.set_source('_jack', None) ffibuilder.cdef(""" /* types.h */ typedef uint64_t jack_uuid_t; typedef uint32_t jack_nframes_t; typedef uint64_t jack_time_t; typedef struct _jack_port jack_port_t; typedef struct _jack_client jack_client_t; typedef uint32_t jack_port_id_t; typedef uint32_t jack_port_type_id_t; enum JackOptions { JackNullOption = 0x00, JackNoStartServer = 0x01, JackUseExactName = 0x02, JackServerName = 0x04, JackLoadName = 0x08, JackLoadInit = 0x10, JackSessionID = 0x20 }; typedef enum JackOptions jack_options_t; enum JackStatus { JackFailure = 0x01, JackInvalidOption = 0x02, JackNameNotUnique = 0x04, JackServerStarted = 0x08, JackServerFailed = 0x10, JackServerError = 0x20, JackNoSuchClient = 0x40, JackLoadFailure = 0x80, JackInitFailure = 0x100, JackShmFailure = 0x200, JackVersionError = 0x400, JackBackendError = 0x800, JackClientZombie = 0x1000 }; typedef enum JackStatus jack_status_t; typedef int (*JackProcessCallback)(jack_nframes_t nframes, void* arg); typedef int (*JackGraphOrderCallback)(void* arg); typedef int (*JackXRunCallback)(void* arg); typedef int (*JackBufferSizeCallback)(jack_nframes_t nframes, void* arg); typedef int (*JackSampleRateCallback)(jack_nframes_t nframes, void* arg); typedef void (*JackPortRegistrationCallback)(jack_port_id_t port, int /* register */, void* arg); typedef void (*JackClientRegistrationCallback)(const char* name, int /* register */, void* arg); typedef void (*JackPortConnectCallback)(jack_port_id_t a, jack_port_id_t b, int connect, void* arg); typedef int (*JackPortRenameCallback)(jack_port_id_t port, const char* old_name, const char* new_name, void* arg); typedef void (*JackFreewheelCallback)(int starting, void* arg); /* not implemented: JackShutdownCallback (only JackInfoShutdownCallback is used) */ typedef void (*JackInfoShutdownCallback)(jack_status_t code, const char* reason, void* arg); /* JACK_DEFAULT_AUDIO_TYPE: see _AUDIO */ /* JACK_DEFAULT_MIDI_TYPE: see _MIDI */ /* not implemented: jack_default_audio_sample_t (hard-coded as float) */ enum JackPortFlags { JackPortIsInput = 0x1, JackPortIsOutput = 0x2, JackPortIsPhysical = 0x4, JackPortCanMonitor = 0x8, JackPortIsTerminal = 0x10, }; typedef enum { JackTransportStopped = 0, JackTransportRolling = 1, JackTransportLooping = 2, /* deprecated */ JackTransportStarting = 3, JackTransportNetStarting = 4, } jack_transport_state_t; typedef uint64_t jack_unique_t; typedef enum { JackPositionBBT = 0x10, JackPositionTimecode = 0x20, JackBBTFrameOffset = 0x40, JackAudioVideoRatio = 0x80, JackVideoFrameOffset = 0x100, } jack_position_bits_t; /* _jack_position: see below in "packed" section */ typedef struct _jack_position jack_position_t; typedef void (*JackTimebaseCallback)(jack_transport_state_t state, jack_nframes_t nframes, jack_position_t *pos, int new_pos, void *arg); typedef int (*JackSyncCallback)(jack_transport_state_t state, jack_position_t *pos, void *arg); /* deprecated: jack_transport_bits_t */ /* deprecated: jack_transport_info_t */ /* jack.h */ void jack_get_version(int* major_ptr, int* minor_ptr, int* micro_ptr, int* proto_ptr); const char* jack_get_version_string(); jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...); /* deprecated: jack_client_new */ int jack_client_close(jack_client_t* client); int jack_client_name_size(void); char* jack_get_client_name(jack_client_t* client); char* jack_get_uuid_for_client_name(jack_client_t* client, const char* client_name); char* jack_get_client_name_by_uuid(jack_client_t* client, const char* client_uuid); /* deprecated: jack_internal_client_new */ /* deprecated: jack_internal_client_close */ int jack_activate(jack_client_t* client); int jack_deactivate(jack_client_t* client); int jack_get_client_pid(const char* name); /* not implemented: jack_client_thread_id */ int jack_is_realtime(jack_client_t* client); /* deprecated: jack_thread_wait */ /* not implemented: jack_cycle_wait */ /* not implemented: jack_cycle_signal */ /* not implemented: jack_set_process_thread */ /* not implemented: jack_set_thread_init_callback */ /* not implemented (jack_on_info_shutdown is used): jack_on_shutdown */ void jack_on_info_shutdown(jack_client_t* client, JackInfoShutdownCallback shutdown_callback, void* arg); int jack_set_process_callback(jack_client_t* client, JackProcessCallback process_callback, void* arg); int jack_set_freewheel_callback(jack_client_t* client, JackFreewheelCallback freewheel_callback, void* arg); int jack_set_buffer_size_callback(jack_client_t* client, JackBufferSizeCallback bufsize_callback, void* arg); int jack_set_sample_rate_callback(jack_client_t* client, JackSampleRateCallback srate_callback, void* arg); int jack_set_client_registration_callback(jack_client_t* client, JackClientRegistrationCallback registration_callback, void* arg); int jack_set_port_registration_callback(jack_client_t* client, JackPortRegistrationCallback registration_callback, void* arg); int jack_set_port_connect_callback(jack_client_t* client, JackPortConnectCallback connect_callback, void* arg); int jack_set_port_rename_callback(jack_client_t* client, JackPortRenameCallback rename_callback, void* arg); int jack_set_graph_order_callback(jack_client_t* client, JackGraphOrderCallback graph_callback, void*); int jack_set_xrun_callback(jack_client_t* client, JackXRunCallback xrun_callback, void* arg); /* TODO: jack_set_latency_callback */ int jack_set_freewheel(jack_client_t* client, int onoff); int jack_set_buffer_size(jack_client_t* client, jack_nframes_t nframes); jack_nframes_t jack_get_sample_rate(jack_client_t*); jack_nframes_t jack_get_buffer_size(jack_client_t*); /* deprecated: jack_engine_takeover_timebase */ float jack_cpu_load(jack_client_t* client); jack_port_t* jack_port_register(jack_client_t* client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size); int jack_port_unregister(jack_client_t* client, jack_port_t* port); void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t); jack_uuid_t jack_port_uuid(const jack_port_t* port); const char* jack_port_name(const jack_port_t* port); const char* jack_port_short_name(const jack_port_t* port); int jack_port_flags(const jack_port_t* port); const char* jack_port_type(const jack_port_t* port); /* not implemented: jack_port_type_id */ int jack_port_is_mine(const jack_client_t* client, const jack_port_t* port); int jack_port_connected(const jack_port_t* port); int jack_port_connected_to(const jack_port_t* port, const char* port_name); const char** jack_port_get_connections(const jack_port_t* port); const char** jack_port_get_all_connections(const jack_client_t* client, const jack_port_t* port); /* deprecated: jack_port_tie */ /* deprecated: jack_port_untie */ int jack_port_set_name(jack_port_t* port, const char* port_name); /* deprecated */ int jack_port_rename(jack_client_t* client, jack_port_t* port, const char* port_name); int jack_port_set_alias(jack_port_t *port, const char *alias); int jack_port_unset_alias(jack_port_t *port, const char *alias); int jack_port_get_aliases(const jack_port_t * port, char *const aliases[2]); int jack_port_request_monitor(jack_port_t *port, int onoff); /* not implemented (use jack_port_request_monitor): jack_port_request_monitor_by_name */ /* TODO: jack_port_ensure_monitor */ /* TODO: jack_port_monitoring_input */ int jack_connect(jack_client_t* client, const char* source_port, const char* destination_port); int jack_disconnect(jack_client_t* client, const char* source_port, const char* destination_port); int jack_port_disconnect(jack_client_t* client, jack_port_t* port); int jack_port_name_size(void); /* not implemented: jack_port_type_size */ /* not implemented: jack_port_type_get_buffer_size */ /* TODO: jack_port_set_latency */ /* TODO: jack_port_get_latency_range */ /* TODO: jack_port_set_latency_range */ /* TODO: jack_recompute_total_latencies */ /* TODO: jack_port_get_latency */ /* TODO: jack_port_get_total_latency */ /* TODO: jack_recompute_total_latency */ const char** jack_get_ports(jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags); jack_port_t* jack_port_by_name(jack_client_t* client, const char* port_name); jack_port_t* jack_port_by_id(jack_client_t* client, jack_port_id_t port_id); jack_nframes_t jack_frames_since_cycle_start(const jack_client_t*); jack_nframes_t jack_frame_time(const jack_client_t*); jack_nframes_t jack_last_frame_time(const jack_client_t* client); /* TODO: jack_get_cycle_times */ /* TODO: jack_frames_to_time */ /* TODO: jack_time_to_frames */ /* TODO: jack_get_time */ void jack_set_error_function(void (*func)(const char*)); void jack_set_info_function(void (*func)(const char*)); void jack_free(void* ptr); /* ringbuffer.h */ typedef struct { char* buf; size_t len; } jack_ringbuffer_data_t; typedef struct { char* buf; volatile size_t write_ptr; volatile size_t read_ptr; size_t size; size_t size_mask; int mlocked; } jack_ringbuffer_t; jack_ringbuffer_t* jack_ringbuffer_create(size_t sz); void jack_ringbuffer_free(jack_ringbuffer_t* rb); void jack_ringbuffer_get_read_vector(const jack_ringbuffer_t* rb, jack_ringbuffer_data_t* vec); void jack_ringbuffer_get_write_vector(const jack_ringbuffer_t* rb, jack_ringbuffer_data_t* vec); size_t jack_ringbuffer_read(jack_ringbuffer_t* rb, char* dest, size_t cnt); size_t jack_ringbuffer_peek(jack_ringbuffer_t* rb, char* dest, size_t cnt); void jack_ringbuffer_read_advance(jack_ringbuffer_t* rb, size_t cnt); size_t jack_ringbuffer_read_space(const jack_ringbuffer_t* rb); int jack_ringbuffer_mlock(jack_ringbuffer_t* rb); void jack_ringbuffer_reset(jack_ringbuffer_t* rb); void jack_ringbuffer_reset_size (jack_ringbuffer_t* rb, size_t sz); /* Note: "char*" was changed to "unsigned char*" to support iterables of int */ size_t jack_ringbuffer_write(jack_ringbuffer_t* rb, const unsigned char* src, size_t cnt); void jack_ringbuffer_write_advance(jack_ringbuffer_t* rb, size_t cnt); size_t jack_ringbuffer_write_space(const jack_ringbuffer_t* rb); /* transport.h */ int jack_release_timebase(jack_client_t* client); int jack_set_sync_callback(jack_client_t* client, JackSyncCallback sync_callback, void* arg); int jack_set_sync_timeout(jack_client_t* client, jack_time_t timeout); int jack_set_timebase_callback(jack_client_t* client, int conditional, JackTimebaseCallback timebase_callback, void* arg); int jack_transport_locate(jack_client_t* client, jack_nframes_t frame); jack_transport_state_t jack_transport_query(const jack_client_t* client, jack_position_t* pos); jack_nframes_t jack_get_current_transport_frame(const jack_client_t* client); int jack_transport_reposition(jack_client_t* client, const jack_position_t* pos); void jack_transport_start(jack_client_t* client); void jack_transport_stop(jack_client_t* client); /* deprecated: jack_get_transport_info */ /* deprecated: jack_set_transport_info */ /* statistics.h */ float jack_get_xrun_delayed_usecs(jack_client_t* client); /* midiport.h */ typedef unsigned char jack_midi_data_t; typedef struct _jack_midi_event { jack_nframes_t time; size_t size; jack_midi_data_t* buffer; } jack_midi_event_t; uint32_t jack_midi_get_event_count(void* port_buffer); int jack_midi_event_get(jack_midi_event_t* event, void* port_buffer, uint32_t event_index); void jack_midi_clear_buffer(void* port_buffer); /* not implemented: jack_midi_reset_buffer */ size_t jack_midi_max_event_size(void* port_buffer); jack_midi_data_t* jack_midi_event_reserve(void* port_buffer, jack_nframes_t time, size_t data_size); int jack_midi_event_write(void* port_buffer, jack_nframes_t time, const jack_midi_data_t* data, size_t data_size); uint32_t jack_midi_get_lost_event_count(void* port_buffer); /* session.h */ char* jack_client_get_uuid(jack_client_t* client); /* uuid.h */ extern int jack_uuid_parse(const char* buf, jack_uuid_t*); /* metadata.h */ typedef struct { const char* key; const char* data; const char* type; } jack_property_t; int jack_set_property(jack_client_t*, jack_uuid_t subject, const char* key, const char* value, const char* type); int jack_get_property(jack_uuid_t subject, const char* key, char** value, char** type); typedef struct { jack_uuid_t subject; uint32_t property_cnt; jack_property_t* properties; uint32_t property_size; } jack_description_t; void jack_free_description(jack_description_t* desc, int free_description_itself); int jack_get_properties(jack_uuid_t subject, jack_description_t* desc); int jack_get_all_properties(jack_description_t** descs); int jack_remove_property(jack_client_t* client, jack_uuid_t subject, const char* key); int jack_remove_properties(jack_client_t* client, jack_uuid_t subject); int jack_remove_all_properties(jack_client_t* client); typedef enum { PropertyCreated, PropertyChanged, PropertyDeleted, } jack_property_change_t; typedef void (*JackPropertyChangeCallback)(jack_uuid_t subject, const char* key, jack_property_change_t change, void* arg); int jack_set_property_change_callback(jack_client_t* client, JackPropertyChangeCallback callback, void* arg); extern const char* JACK_METADATA_CONNECTED; extern const char* JACK_METADATA_EVENT_TYPES; extern const char* JACK_METADATA_HARDWARE; extern const char* JACK_METADATA_ICON_LARGE; extern const char* JACK_METADATA_ICON_NAME; extern const char* JACK_METADATA_ICON_SMALL; extern const char* JACK_METADATA_ORDER; extern const char* JACK_METADATA_PORT_GROUP; extern const char* JACK_METADATA_PRETTY_NAME; extern const char* JACK_METADATA_SIGNAL_TYPE; """) # Packed structure ffibuilder.cdef(""" struct _jack_position { jack_unique_t unique_1; jack_time_t usecs; jack_nframes_t frame_rate; jack_nframes_t frame; jack_position_bits_t valid; int32_t bar; int32_t beat; int32_t tick; double bar_start_tick; float beats_per_bar; float beat_type; double ticks_per_beat; double beats_per_minute; double frame_time; double next_time; jack_nframes_t bbt_offset; float audio_frames_per_video_frame; jack_nframes_t video_offset; int32_t padding[7]; jack_unique_t unique_2; }; """, packed=True) if __name__ == '__main__': ffibuilder.compile(verbose=True) ././@PaxHeader0000000000000000000000000000003300000000000011451 xustar000000000000000027 mtime=1603273938.527674 JACK-Client-0.5.3/setup.cfg0000644000175000017500000000011100000000000014306 0ustar00mgmg00000000000000[metadata] license_file = LICENSE [egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1557486823.0 JACK-Client-0.5.3/setup.py0000644000175000017500000000220400000000000014204 0ustar00mgmg00000000000000from setuptools import setup __version__ = 'unknown' # "import" __version__ for line in open('src/jack.py'): if line.startswith('__version__'): exec(line) break setup( name='JACK-Client', version=__version__, package_dir={'': 'src'}, py_modules=['jack'], setup_requires=['CFFI>=1.0'], install_requires=['CFFI>=1.0'], python_requires='>=3', extras_require={'NumPy': ['NumPy']}, cffi_modules=['jack_build.py:ffibuilder'], author='Matthias Geier', author_email='Matthias.Geier@gmail.com', description='JACK Audio Connection Kit (JACK) Client for Python', long_description=open('README.rst').read(), license='MIT', keywords='JACK audio low-latency multi-channel'.split(), url='http://jackclient-python.readthedocs.io/', platforms='any', classifiers=[ 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3 :: Only', 'Topic :: Multimedia :: Sound/Audio', ], zip_safe=True, ) ././@PaxHeader0000000000000000000000000000003300000000000011451 xustar000000000000000027 mtime=1603273938.527674 JACK-Client-0.5.3/src/0000755000175000017500000000000000000000000013263 5ustar00mgmg00000000000000././@PaxHeader0000000000000000000000000000003300000000000011451 xustar000000000000000027 mtime=1603273938.527674 JACK-Client-0.5.3/src/JACK_Client.egg-info/0000755000175000017500000000000000000000000016763 5ustar00mgmg00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603273938.0 JACK-Client-0.5.3/src/JACK_Client.egg-info/PKG-INFO0000644000175000017500000000224700000000000020065 0ustar00mgmg00000000000000Metadata-Version: 2.1 Name: JACK-Client Version: 0.5.3 Summary: JACK Audio Connection Kit (JACK) Client for Python Home-page: http://jackclient-python.readthedocs.io/ Author: Matthias Geier Author-email: Matthias.Geier@gmail.com License: MIT Description: JACK Audio Connection Kit (JACK) Client for Python ================================================== This Python module (named ``jack``) provides bindings for the JACK_ library. Documentation: https://jackclient-python.readthedocs.io/ Source code and issue tracker: https://github.com/spatialaudio/jackclient-python/ License: MIT -- see the file ``LICENSE`` for details. .. _JACK: https://jackaudio.org/ Keywords: JACK,audio,low-latency,multi-channel Platform: any Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3 :: Only Classifier: Topic :: Multimedia :: Sound/Audio Requires-Python: >=3 Provides-Extra: NumPy ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603273938.0 JACK-Client-0.5.3/src/JACK_Client.egg-info/SOURCES.txt0000644000175000017500000000153500000000000020653 0ustar00mgmg00000000000000CONTRIBUTING.rst LICENSE MANIFEST.in NEWS.rst README.rst jack_build.py setup.cfg setup.py doc/api.rst doc/conf.py doc/contributing.rst doc/examples.rst doc/fake__jack.py doc/index.rst doc/installation.rst doc/other-modules.rst doc/requirements.txt doc/usage.rst doc/version-history.rst examples/aliases.py examples/chatty_client.py examples/metadata.py examples/midi_chords.py examples/midi_file_player.py examples/midi_monitor.py examples/midi_sine.py examples/midi_sine_numpy.py examples/play_file.py examples/showtime.py examples/slow_sync.py examples/thru_client.py examples/timebase_master.py examples/transporter.py src/jack.py src/JACK_Client.egg-info/PKG-INFO src/JACK_Client.egg-info/SOURCES.txt src/JACK_Client.egg-info/dependency_links.txt src/JACK_Client.egg-info/requires.txt src/JACK_Client.egg-info/top_level.txt src/JACK_Client.egg-info/zip-safe././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603273938.0 JACK-Client-0.5.3/src/JACK_Client.egg-info/dependency_links.txt0000644000175000017500000000000100000000000023031 0ustar00mgmg00000000000000 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603273938.0 JACK-Client-0.5.3/src/JACK_Client.egg-info/requires.txt0000644000175000017500000000003100000000000021355 0ustar00mgmg00000000000000CFFI>=1.0 [NumPy] NumPy ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603273938.0 JACK-Client-0.5.3/src/JACK_Client.egg-info/top_level.txt0000644000175000017500000000001300000000000021507 0ustar00mgmg00000000000000_jack jack ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1535875903.0 JACK-Client-0.5.3/src/JACK_Client.egg-info/zip-safe0000644000175000017500000000000100000000000020413 0ustar00mgmg00000000000000 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1603273843.0 JACK-Client-0.5.3/src/jack.py0000644000175000017500000031031500000000000014550 0ustar00mgmg00000000000000# Copyright (c) 2014-2020 Matthias Geier # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. """JACK Client for Python. http://jackclient-python.readthedocs.io/ """ __version__ = '0.5.3' from ctypes.util import find_library as _find_library import errno as _errno import platform as _platform import warnings as _warnings from _jack import ffi as _ffi if _platform.system() == 'Windows': if _platform.architecture()[0] == '64bit': _libname = _find_library('libjack64') else: _libname = _find_library('libjack') else: _libname = _find_library('jack') if _libname is None: raise OSError('JACK library not found') _lib = _ffi.dlopen(_libname) _AUDIO = b'32 bit float mono audio' _MIDI = b'8 bit raw midi' STOPPED = _lib.JackTransportStopped """Transport halted.""" ROLLING = _lib.JackTransportRolling """Transport playing.""" STARTING = _lib.JackTransportStarting """Waiting for sync ready.""" NETSTARTING = _lib.JackTransportNetStarting """Waiting for sync ready on the network.""" PROPERTY_CREATED = _lib.PropertyCreated """A property was created. See `Client.set_property_change_callback()`.""" PROPERTY_CHANGED = _lib.PropertyChanged """A property was changed. See `Client.set_property_change_callback()`.""" PROPERTY_DELETED = _lib.PropertyDeleted """A property was deleted. See `Client.set_property_change_callback()`.""" POSITION_BBT = _lib.JackPositionBBT """Bar, Beat, Tick.""" POSITION_TIMECODE = _lib.JackPositionTimecode """External timecode.""" POSITION_BBT_FRAME_OFFSET = _lib.JackBBTFrameOffset """Frame offset of BBT information.""" POSITION_AUDIO_VIDEO_RATIO = _lib.JackAudioVideoRatio """Audio frames per video frame.""" POSITION_VIDEO_FRAME_OFFSET = _lib.JackVideoFrameOffset """Frame offset of first video frame.""" _SUCCESS = 0 _FAILURE = 1 def _decode(cdata): return _ffi.string(cdata).decode() # Get metadata constants from library for name in dir(_lib): if name.startswith('JACK_METADATA_'): try: globals()[name[5:]] = _decode(getattr(_lib, name)) except _ffi.error: pass else: del name class JackError(Exception): """Exception for all kinds of JACK-related errors.""" class JackErrorCode(JackError): def __init__(self, message, code): """Exception for JACK errors with an error code. Subclass of `JackError`. The following attributes are available: Attributes ---------- message Error message. code The error code returned by the JACK library function which resulted in this exception being raised. """ self.message = message self.code = code def __str__(self): return '{} ({})'.format(self.message, self.code) class JackOpenError(JackError): def __init__(self, name, status): """Exception raised for errors while creating a JACK client. Subclass of `JackError`. The following attributes are available: Attributes ---------- name Requested client name. status A :class:`Status` instance representing the status information received by the ``jack_client_open()`` JACK library call. """ self.name = name self.status = status def __str__(self): return 'Error initializing "{}": {}'.format(self.name, self.status) class Client(object): """A client that can connect to the JACK audio server.""" def __init__(self, name, use_exact_name=False, no_start_server=False, servername=None, session_id=None): """Create a new JACK client. A client object is a *context manager*, i.e. it can be used in a *with statement* to automatically call `activate()` in the beginning of the statement and `deactivate()` and `close()` on exit. Parameters ---------- name : str The desired client name of at most `client_name_size()` characters. The name scope is local to each server. Unless forbidden by the *use_exact_name* option, the server will modify this name to create a unique variant, if needed. Other Parameters ---------------- use_exact_name : bool Whether an error should be raised if *name* is not unique. See `Status.name_not_unique`. no_start_server : bool Do not automatically start the JACK server when it is not already running. This option is always selected if ``JACK_NO_START_SERVER`` is defined in the calling process environment. servername : str Selects from among several possible concurrent server instances. Server names are unique to each user. If unspecified, use ``'default'`` unless ``JACK_DEFAULT_SERVER`` is defined in the process environment. session_id : str Pass a SessionID Token. This allows the sessionmanager to identify the client again. Raises ------ JackOpenError If the session with the JACK server could not be opened. """ status = _ffi.new('jack_status_t*') options = _lib.JackNullOption optargs = [] if use_exact_name: options |= _lib.JackUseExactName if no_start_server: options |= _lib.JackNoStartServer if servername: options |= _lib.JackServerName optargs.append(_ffi.new('char[]', servername.encode())) if session_id: options |= _lib.JackSessionID optargs.append(_ffi.new('char[]', session_id.encode())) self._ptr = _lib.jack_client_open(name.encode(), options, status, *optargs) self._status = Status(status[0]) if not self._ptr: raise JackOpenError(name, self._status) self._inports = Ports(self, _AUDIO, _lib.JackPortIsInput) self._outports = Ports(self, _AUDIO, _lib.JackPortIsOutput) self._midi_inports = Ports(self, _MIDI, _lib.JackPortIsInput) self._midi_outports = Ports(self, _MIDI, _lib.JackPortIsOutput) self._keepalive = [] self._position = _ffi.new('jack_position_t*') # Avoid confusion if something goes wrong before opening the client: _ptr = _ffi.NULL def __enter__(self): self.activate() return self def __exit__(self, *args): self.deactivate() self.close() def __del__(self): """Close JACK client on garbage collection.""" self.close() @property def name(self): """The name of the JACK client (read-only).""" return _decode(_lib.jack_get_client_name(self._ptr)) @property def uuid(self): """The UUID of the JACK client (read-only). Raises ------ JackError If getting the UUID fails. """ uuid = _ffi.gc(_lib.jack_client_get_uuid(self._ptr), _lib.jack_free) if not uuid: raise JackError('Unable to get UUID') return _decode(uuid) @property def samplerate(self): """The sample rate of the JACK system (read-only).""" return _lib.jack_get_sample_rate(self._ptr) @property def blocksize(self): """The JACK block size (must be a power of two). The current maximum size that will ever be passed to the process callback. It should only be queried *before* `activate()` has been called. This size may change, clients that depend on it must register a callback with `set_blocksize_callback()` so they will be notified if it does. Changing the blocksize stops the JACK engine process cycle, then calls all registered callback functions (see `set_blocksize_callback()`) before restarting the process cycle. This will cause a gap in the audio flow, so it should only be done at appropriate stopping points. """ return _lib.jack_get_buffer_size(self._ptr) @blocksize.setter def blocksize(self, blocksize): _check(_lib.jack_set_buffer_size(self._ptr, blocksize), 'Error setting JACK blocksize') @property def status(self): """JACK client status. See `Status`.""" return self._status @property def realtime(self): """Whether JACK is running with ``-R`` (``--realtime``).""" return bool(_lib.jack_is_realtime(self._ptr)) @property def frames_since_cycle_start(self): """Time since start of audio block. The estimated time in frames that has passed since the JACK server began the current process cycle. """ return _lib.jack_frames_since_cycle_start(self._ptr) @property def frame_time(self): """The estimated current time in frames. This is intended for use in other threads (not the process callback). The return value can be compared with the value of `last_frame_time` to relate time in other threads to JACK time. """ return _lib.jack_frame_time(self._ptr) @property def last_frame_time(self): """The precise time at the start of the current process cycle. This may only be used from the process callback (see `set_process_callback()`), and can be used to interpret timestamps generated by `frame_time` in other threads with respect to the current process cycle. This is the only jack time function that returns exact time: when used during the process callback it always returns the same value (until the next process callback, where it will return that value + `blocksize`, etc). The return value is guaranteed to be monotonic and linear in this fashion unless an xrun occurs (see `set_xrun_callback()`). If an xrun occurs, clients must check this value again, as time may have advanced in a non-linear way (e.g. cycles may have been skipped). """ return _lib.jack_last_frame_time(self._ptr) @property def inports(self): """A list of audio input `Ports`. New ports can be created and added to this list with `inports.register() `. When :meth:`~OwnPort.unregister` is called on one of the items in this list, this port is removed from the list. `inports.clear() ` can be used to unregister all audio input ports at once. See Also -------- Ports, OwnPort """ return self._inports @property def outports(self): """A list of audio output :class:`Ports`. New ports can be created and added to this list with `outports.register() `. When :meth:`~OwnPort.unregister` is called on one of the items in this list, this port is removed from the list. `outports.clear() ` can be used to unregister all audio output ports at once. See Also -------- Ports, OwnPort """ return self._outports @property def midi_inports(self): """A list of MIDI input :class:`Ports`. New MIDI ports can be created and added to this list with `midi_inports.register() `. When :meth:`~OwnPort.unregister` is called on one of the items in this list, this port is removed from the list. `midi_inports.clear() ` can be used to unregister all MIDI input ports at once. See Also -------- Ports, OwnMidiPort """ return self._midi_inports @property def midi_outports(self): """A list of MIDI output :class:`Ports`. New MIDI ports can be created and added to this list with `midi_outports.register() `. When :meth:`~OwnPort.unregister` is called on one of the items in this list, this port is removed from the list. `midi_outports.clear() ` can be used to unregister all MIDI output ports at once. See Also -------- Ports, OwnMidiPort """ return self._midi_outports def owns(self, port): """Check if a given port belongs to *self*. Parameters ---------- port : str or Port Full port name or `Port`, `MidiPort`, `OwnPort` or `OwnMidiPort` object. """ port = self._get_port_ptr(port) return bool(_lib.jack_port_is_mine(self._ptr, port)) def activate(self): """Activate JACK client. Tell the JACK server that the program is ready to start processing audio. """ _check(_lib.jack_activate(self._ptr), 'Error activating JACK client') def deactivate(self, ignore_errors=True): """De-activate JACK client. Tell the JACK server to remove *self* from the process graph. Also, disconnect all ports belonging to it, since inactive clients have no port connections. """ err = _lib.jack_deactivate(self._ptr) if not ignore_errors: _check(err, 'Error deactivating JACK client') def cpu_load(self): """Return the current CPU load estimated by JACK. This is a running average of the time it takes to execute a full process cycle for all clients as a percentage of the real time available per cycle determined by `blocksize` and `samplerate`. """ return _lib.jack_cpu_load(self._ptr) def close(self, ignore_errors=True): """Close the JACK client.""" if self._ptr: err = _lib.jack_client_close(self._ptr) self._ptr = _ffi.NULL if not ignore_errors: _check(err, 'Error closing JACK client') def connect(self, source, destination): """Establish a connection between two ports. When a connection exists, data written to the source port will be available to be read at the destination port. Audio ports can obviously not be connected with MIDI ports. Parameters ---------- source : str or Port One end of the connection. Must be an output port. destination : str or Port The other end of the connection. Must be an input port. See Also -------- OwnPort.connect, disconnect Raises ------ JackError If there is already an existing connection between *source* and *destination* or the connection can not be established. """ if isinstance(source, Port): source = source.name if isinstance(destination, Port): destination = destination.name err = _lib.jack_connect(self._ptr, source.encode(), destination.encode()) if err == _errno.EEXIST: raise JackErrorCode('Connection {0!r} -> {1!r} ' 'already exists'.format(source, destination), err) _check(err, 'Error connecting {0!r} -> {1!r}'.format(source, destination)) def disconnect(self, source, destination): """Remove a connection between two ports. Parameters ---------- source, destination : str or Port See `connect()`. """ if isinstance(source, Port): source = source.name if isinstance(destination, Port): destination = destination.name _check(_lib.jack_disconnect( self._ptr, source.encode(), destination.encode()), "Couldn't disconnect {0!r} -> {1!r}".format(source, destination)) def transport_start(self): """Start JACK transport.""" _lib.jack_transport_start(self._ptr) def transport_stop(self): """Stop JACK transport.""" _lib.jack_transport_stop(self._ptr) @property def transport_state(self): """JACK transport state. This is one of `STOPPED`, `ROLLING`, `STARTING`, `NETSTARTING`. See Also -------- transport_query """ return TransportState(_lib.jack_transport_query(self._ptr, _ffi.NULL)) @property def transport_frame(self): """Get/set current JACK transport frame. Return an estimate of the current transport frame, including any time elapsed since the last transport positional update. Assigning a frame number repositions the JACK transport. """ return _lib.jack_get_current_transport_frame(self._ptr) @transport_frame.setter def transport_frame(self, frame): _check(_lib.jack_transport_locate(self._ptr, frame), 'Error locating JACK transport') def transport_locate(self, frame): """ .. deprecated:: 0.4.1 Use `transport_frame` instead """ _warnings.warn( 'transport_locate() is deprecated, use transport_frame', DeprecationWarning) self.transport_frame = frame def transport_query(self): """Query the current transport state and position. This is a convenience function that does the same as `transport_query_struct()`, but it only returns the valid fields in an easy-to-use ``dict``. Returns ------- state : TransportState The transport state can take following values: `STOPPED`, `ROLLING`, `STARTING` and `NETSTARTING`. position : dict A dictionary containing only the valid fields of the structure returned by `transport_query_struct()`. See Also -------- :attr:`transport_state`, transport_query_struct """ state, pos = self.transport_query_struct() return TransportState(state), position2dict(pos) def transport_query_struct(self): """Query the current transport state and position. This function is realtime-safe, and can be called from any thread. If called from the process thread, the returned position corresponds to the first frame of the current cycle and the state returned is valid for the entire cycle. Returns ------- state : int The transport state can take following values: `STOPPED`, `ROLLING`, `STARTING` and `NETSTARTING`. position : jack_position_t See the `JACK transport documentation`__ for the available fields. __ https://jackaudio.org/api/structjack__position__t.html See Also -------- transport_query, transport_reposition_struct """ state = _lib.jack_transport_query(self._ptr, self._position) return state, self._position def transport_reposition_struct(self, position): """Request a new transport position. May be called at any time by any client. The new position takes effect in two process cycles. If there are slow-sync clients and the transport is already rolling, it will enter the `STARTING` state and begin invoking their sync callbacks (see `set_sync_callback()`) until ready. This function is realtime-safe. Parameters ---------- position : jack_position_t Requested new transport position. This is the same structure as returned by `transport_query_struct()`. See Also -------- transport_query_struct, transport_locate """ _check(_lib.jack_transport_reposition(self._ptr, position), 'Error re-positioning transport') def set_sync_timeout(self, timeout): """Set the timeout value for slow-sync clients. This timeout prevents unresponsive slow-sync clients from completely halting the transport mechanism. The default is two seconds. When the timeout expires, the transport starts rolling, even if some slow-sync clients are still unready. The *sync callbacks* of these clients continue being invoked, giving them a chance to catch up. Parameters ---------- timeout : int Delay (in microseconds) before the timeout expires. See Also -------- set_sync_callback """ _check(_lib.jack_set_sync_timeout(self._ptr, timeout), 'Error setting sync timeout') def set_freewheel(self, onoff): """Start/Stop JACK's "freewheel" mode. When in "freewheel" mode, JACK no longer waits for any external event to begin the start of the next process cycle. As a result, freewheel mode causes "faster than realtime" execution of a JACK graph. If possessed, real-time scheduling is dropped when entering freewheel mode, and if appropriate it is reacquired when stopping. IMPORTANT: on systems using capabilities to provide real-time scheduling (i.e. Linux kernel 2.4), if onoff is zero, this function must be called from the thread that originally called `activate()`. This restriction does not apply to other systems (e.g. Linux kernel 2.6 or OS X). Parameters ---------- onoff : bool If ``True``, freewheel mode starts. Otherwise freewheel mode ends. See Also -------- set_freewheel_callback """ _check(_lib.jack_set_freewheel(self._ptr, onoff), 'Error setting freewheel mode') def set_shutdown_callback(self, callback): """Register shutdown callback. Register a function (and optional argument) to be called if and when the JACK server shuts down the client thread. The function must be written as if it were an asynchonrous POSIX signal handler -- use only async-safe functions, and remember that it is executed from another thread. A typical function might set a flag or write to a pipe so that the rest of the application knows that the JACK client thread has shut down. .. note:: Clients do not need to call this. It exists only to help more complex clients understand what is going on. It should be called before `activate()`. Parameters ---------- callback : callable User-supplied function that is called whenever the JACK daemon is shutdown. It must have this signature:: callback(status: Status, reason: str) -> None The argument *status* is of type `jack.Status`. .. note:: The *callback* should typically signal another thread to correctly finish cleanup by calling `close()` (since it cannot be called directly in the context of the thread that calls the shutdown callback). After server shutdown, the client is *not* deallocated by JACK, the user (that's you!) is responsible to properly use `close()` to release client ressources. Alternatively, the `Client` object can be used as a *context manager* in a *with statement*, which takes care of activating, deactivating and closing the client automatically. .. note:: Same as with most callbacks, no functions that interact with the JACK daemon should be used here. """ @self._callback('JackInfoShutdownCallback') def callback_wrapper(code, reason, _): callback(Status(code), _decode(reason)) _lib.jack_on_info_shutdown(self._ptr, callback_wrapper, _ffi.NULL) def set_process_callback(self, callback): """Register process callback. Tell the JACK server to call *callback* whenever there is work be done. The code in the supplied function must be suitable for real-time execution. That means that it cannot call functions that might block for a long time. This includes malloc, free, printf, pthread_mutex_lock, sleep, wait, poll, select, pthread_join, pthread_cond_wait, etc, etc. .. warning:: Most Python interpreters use a `global interpreter lock (GIL)`__, which violates the above real-time requirement. Furthermore, Python's `garbage collector`__ might become active at an inconvenient time and block the process callback for some time. Because of this, Python is not really suitable for real-time processing. If you want to implement a *reliable* real-time audio/MIDI application, you should use a different programming language, such as C or C++. If you can live with some random audio drop-outs now and then, feel free to continue using Python! __ https://en.wikipedia.org/wiki/Global_Interpreter_Lock __ https://en.wikipedia.org/wiki/Garbage_collection_(computer_science) .. note:: This function cannot be called while the client is activated (after `activate()` has been called). Parameters ---------- callback : callable User-supplied function that is called by the engine anytime there is work to be done. It must have this signature:: callback(frames: int) -> None The argument *frames* specifies the number of frames that have to be processed in the current audio block. It will be the same number as `blocksize` and it will be a power of two. As long as the client is active, the *callback* will be called once in each process cycle. However, if an exception is raised inside of a *callback*, it will not be called anymore. The exception `CallbackExit` can be used to silently prevent further callback invocations, all other exceptions will print an error message to *stderr*. """ @self._callback('JackProcessCallback', error=_FAILURE) def callback_wrapper(frames, _): try: callback(frames) except CallbackExit: return _FAILURE return _SUCCESS _check(_lib.jack_set_process_callback( self._ptr, callback_wrapper, _ffi.NULL), 'Error setting process callback') def set_freewheel_callback(self, callback): """Register freewheel callback. Tell the JACK server to call *callback* whenever we enter or leave "freewheel" mode. The argument to the callback will be ``True`` if JACK is entering freewheel mode, and ``False`` otherwise. All "notification events" are received in a separated non RT thread, the code in the supplied function does not need to be suitable for real-time execution. .. note:: This function cannot be called while the client is activated (after `activate()` has been called). Parameters ---------- callback : callable User-supplied function that is called whenever JACK starts or stops freewheeling. It must have this signature:: callback(starting: bool) -> None The argument *starting* is ``True`` if we start to freewheel, ``False`` otherwise. .. note:: Same as with most callbacks, no functions that interact with the JACK daemon should be used here. See Also -------- set_freewheel """ @self._callback('JackFreewheelCallback') def callback_wrapper(starting, _): callback(bool(starting)) _check(_lib.jack_set_freewheel_callback( self._ptr, callback_wrapper, _ffi.NULL), 'Error setting freewheel callback') def set_blocksize_callback(self, callback): """Register blocksize callback. Tell JACK to call *callback* whenever the size of the the buffer that will be passed to the process callback is about to change. Clients that depend on knowing the buffer size must supply a *callback* before activating themselves. All "notification events" are received in a separated non RT thread, the code in the supplied function does not need to be suitable for real-time execution. .. note:: This function cannot be called while the client is activated (after `activate()` has been called). Parameters ---------- callback : callable User-supplied function that is invoked whenever the JACK engine buffer size changes. It must have this signature:: callback(blocksize: int) -> None The argument *blocksize* is the new buffer size. The *callback* is supposed to raise `CallbackExit` on error. .. note:: Although this function is called in the JACK process thread, the normal process cycle is suspended during its operation, causing a gap in the audio flow. So, the *callback* can allocate storage, touch memory not previously referenced, and perform other operations that are not realtime safe. .. note:: Same as with most callbacks, no functions that interact with the JACK daemon should be used here. See Also -------- :attr:`blocksize` """ @self._callback('JackBufferSizeCallback', error=_FAILURE) def callback_wrapper(blocksize, _): try: callback(blocksize) except CallbackExit: return _FAILURE return _SUCCESS _check(_lib.jack_set_buffer_size_callback( self._ptr, callback_wrapper, _ffi.NULL), 'Error setting blocksize callback') def set_samplerate_callback(self, callback): """Register samplerate callback. Tell the JACK server to call *callback* whenever the system sample rate changes. All "notification events" are received in a separated non RT thread, the code in the supplied function does not need to be suitable for real-time execution. .. note:: This function cannot be called while the client is activated (after `activate()` has been called). Parameters ---------- callback : callable User-supplied function that is called when the engine sample rate changes. It must have this signature:: callback(samplerate: int) -> None The argument *samplerate* is the new engine sample rate. The *callback* is supposed to raise `CallbackExit` on error. .. note:: Same as with most callbacks, no functions that interact with the JACK daemon should be used here. See Also -------- :attr:`samplerate` """ @self._callback('JackSampleRateCallback', error=_FAILURE) def callback_wrapper(samplerate, _): try: callback(samplerate) except CallbackExit: return _FAILURE return _SUCCESS _check(_lib.jack_set_sample_rate_callback( self._ptr, callback_wrapper, _ffi.NULL), 'Error setting samplerate callback') def set_client_registration_callback(self, callback): """Register client registration callback. Tell the JACK server to call *callback* whenever a client is registered or unregistered. All "notification events" are received in a separated non RT thread, the code in the supplied function does not need to be suitable for real-time execution. .. note:: This function cannot be called while the client is activated (after `activate()` has been called). Parameters ---------- callback : callable User-supplied function that is called whenever a client is registered or unregistered. It must have this signature:: callback(name: str, register: bool) -> None The first argument contains the client name, the second argument is ``True`` if the client is being registered and ``False`` if the client is being unregistered. .. note:: Same as with most callbacks, no functions that interact with the JACK daemon should be used here. """ @self._callback('JackClientRegistrationCallback') def callback_wrapper(name, register, _): callback(_decode(name), bool(register)) _check(_lib.jack_set_client_registration_callback( self._ptr, callback_wrapper, _ffi.NULL), 'Error setting client registration callback') def set_port_registration_callback(self, callback=None, only_available=True): """Register port registration callback. Tell the JACK server to call *callback* whenever a port is registered or unregistered. All "notification events" are received in a separated non RT thread, the code in the supplied function does not need to be suitable for real-time execution. .. note:: This function cannot be called while the client is activated (after `activate()` has been called). .. note:: Due to JACK 1 behavior, it is not possible to get the pointer to an unregistering JACK Port if it already existed before `activate()` was called. This will cause the callback not to be called if *only_available* is ``True``, or called with ``None`` as first argument (see below). To avoid this, call `Client.get_ports()` just after `activate()`, allowing the module to store pointers to already existing ports and always receive a `Port` argument for this callback. Parameters ---------- callback : callable User-supplied function that is called whenever a port is registered or unregistered. It must have this signature:: callback(port: Port, register: bool) -> None The first argument is a `Port`, `MidiPort`, `OwnPort` or `OwnMidiPort` object, the second argument is ``True`` if the port is being registered, ``False`` if the port is being unregistered. .. note:: Same as with most callbacks, no functions that interact with the JACK daemon should be used here. only_available : bool, optional If ``True``, the *callback* is not called if the port in question is not available anymore (after another JACK client has unregistered it). If ``False``, it is called nonetheless, but the first argument of the *callback* will be ``None`` if the port is not available anymore. See Also -------- Ports.register """ if callback is None: return lambda cb: self.set_port_registration_callback( cb, only_available) @self._callback('JackPortRegistrationCallback') def callback_wrapper(port_id, register, _): port_ptr = _lib.jack_port_by_id(self._ptr, port_id) if port_ptr: port = self._wrap_port_ptr(port_ptr) elif only_available: return else: port = None callback(port, bool(register)) _check(_lib.jack_set_port_registration_callback( self._ptr, callback_wrapper, _ffi.NULL), 'Error setting port registration callback') def set_port_connect_callback(self, callback=None, only_available=True): """Register port connect callback. Tell the JACK server to call *callback* whenever a port is connected or disconnected. All "notification events" are received in a separated non RT thread, the code in the supplied function does not need to be suitable for real-time execution. .. note:: This function cannot be called while the client is activated (after `activate()` has been called). .. note:: Due to JACK 1 behavior, it is not possible to get the pointer to an unregistering JACK Port if it already existed before `activate()` was called. This will cause the callback not to be called if *only_available* is ``True``, or called with ``None`` as first argument (see below). To avoid this, call `Client.get_ports()` just after `activate()`, allowing the module to store pointers to already existing ports and always receive a `Port` argument for this callback. Parameters ---------- callback : callable User-supplied function that is called whenever a port is connected or disconnected. It must have this signature:: callback(a: Port, b: Port, connect: bool) -> None The first and second arguments contain `Port`, `MidiPort`, `OwnPort` or `OwnMidiPort` objects of the ports which are connected or disconnected. The third argument is ``True`` if the ports were connected and ``False`` if the ports were disconnected. .. note:: Same as with most callbacks, no functions that interact with the JACK daemon should be used here. only_available : bool, optional See `set_port_registration_callback()`. If ``False``, the first and/or the second argument to the *callback* may be ``None``. See Also -------- Client.connect, OwnPort.connect """ if callback is None: return lambda cb: self.set_port_connect_callback( cb, only_available) @self._callback('JackPortConnectCallback') def callback_wrapper(a, b, connect, _): port_ids = a, b ports = [None, None] for idx in 0, 1: ptr = _lib.jack_port_by_id(self._ptr, port_ids[idx]) if ptr: ports[idx] = self._wrap_port_ptr(ptr) elif only_available: return else: pass # Do nothing, port is already None callback(ports[0], ports[1], bool(connect)) _check(_lib.jack_set_port_connect_callback( self._ptr, callback_wrapper, _ffi.NULL), 'Error setting port connect callback') def set_port_rename_callback(self, callback=None, only_available=True): """Register port rename callback. Tell the JACK server to call *callback* whenever a port is renamed. All "notification events" are received in a separated non RT thread, the code in the supplied function does not need to be suitable for real-time execution. .. note:: This function cannot be called while the client is activated (after `activate()` has been called). Parameters ---------- callback : callable User-supplied function that is called whenever the port name has been changed. It must have this signature:: callback(port: Port, old: str, new: str) -> None The first argument is the port that has been renamed (a `Port`, `MidiPort`, `OwnPort` or `OwnMidiPort` object); the second and third argument is the old and new name, respectively. The *callback* is supposed to raise `CallbackExit` on error. .. note:: Same as with most callbacks, no functions that interact with the JACK daemon should be used here. only_available : bool, optional See `set_port_registration_callback()`. See Also -------- :attr:`Port.shortname` Notes ----- The port rename callback is not available in JACK 1! See and `this commit message`__. __ https://github.com/jackaudio/jack1/commit/ 94c819accfab2612050e875c24cf325daa0fd26d """ if callback is None: return lambda cb: self.set_port_rename_callback(cb, only_available) @self._callback('JackPortRenameCallback', error=_FAILURE) def callback_wrapper(port_id, old_name, new_name, _): port_ptr = _lib.jack_port_by_id(self._ptr, port_id) if port_ptr: port = self._wrap_port_ptr(port_ptr) elif only_available: return else: port = None try: callback(port, _decode(old_name), _decode(new_name)) except CallbackExit: return _FAILURE return _SUCCESS _check(_lib.jack_set_port_rename_callback( self._ptr, callback_wrapper, _ffi.NULL), 'Error setting port rename callback') def set_graph_order_callback(self, callback): """Register graph order callback. Tell the JACK server to call *callback* whenever the processing graph is reordered. All "notification events" are received in a separated non RT thread, the code in the supplied function does not need to be suitable for real-time execution. .. note:: This function cannot be called while the client is activated (after :meth:`activate` has been called). Parameters ---------- callback : callable User-supplied function that is called whenever the processing graph is reordered. It must have this signature:: callback() -> None The *callback* is supposed to raise `CallbackExit` on error. .. note:: Same as with most callbacks, no functions that interact with the JACK daemon should be used here. """ @self._callback('JackGraphOrderCallback', error=_FAILURE) def callback_wrapper(_): try: callback() except CallbackExit: return _FAILURE return _SUCCESS _check(_lib.jack_set_graph_order_callback( self._ptr, callback_wrapper, _ffi.NULL), 'Error setting graph order callback') def set_xrun_callback(self, callback): """Register xrun callback. Tell the JACK server to call *callback* whenever there is an xrun. All "notification events" are received in a separated non RT thread, the code in the supplied function does not need to be suitable for real-time execution. .. note:: This function cannot be called while the client is activated (after `activate()` has been called). Parameters ---------- callback : callable User-supplied function that is called whenever an xrun has occured. It must have this signature:: callback(delayed_usecs: float) -> None The callback argument is the delay in microseconds due to the most recent XRUN occurrence. The *callback* is supposed to raise `CallbackExit` on error. .. note:: Same as with most callbacks, no functions that interact with the JACK daemon should be used here. """ @self._callback('JackXRunCallback', error=_FAILURE) def callback_wrapper(_): try: callback(_lib.jack_get_xrun_delayed_usecs(self._ptr)) except CallbackExit: return _FAILURE return _SUCCESS _check(_lib.jack_set_xrun_callback( self._ptr, callback_wrapper, _ffi.NULL), 'Error setting xrun callback') def set_sync_callback(self, callback): """Register (or unregister) as a slow-sync client. A slow-sync client is one that cannot respond immediately to transport position changes. The *callback* will be invoked at the first available opportunity after its registration is complete. If the client is currently active this will be the following process cycle, otherwise it will be the first cycle after calling `activate()`. After that, it runs whenever some client requests a new position, or the transport enters the `STARTING` state. While the client is active, this callback is invoked just before the *process callback* (see `set_process_callback()`) in the same thread. Clients that don't set a *sync callback* are assumed to be ready immediately any time the transport wants to start. Parameters ---------- callback : callable or None User-supplied function that returns ``True`` when the slow-sync client is ready. This realtime function must not wait. It must have this signature:: callback(state: int, pos: jack_position_t) -> bool The *state* argument will be: - `STOPPED` when a new position is requested; - `STARTING` when the transport is waiting to start; - `ROLLING` when the timeout has expired, and the position is now a moving target. The *pos* argument holds the new transport position using the same structure as returned by `transport_query_struct()`. Setting *callback* to ``None`` declares that this client no longer requires slow-sync processing. See Also -------- set_sync_timeout """ if callback is None: callback_wrapper = _ffi.NULL else: @self._callback('JackSyncCallback', error=False) def callback_wrapper(state, pos, _): return callback(state, pos) _check( _lib.jack_set_sync_callback( self._ptr, callback_wrapper, _ffi.NULL), 'Error setting sync callback') def release_timebase(self): """De-register as timebase master. Should be called by the current timebase master to release itself from that responsibility and to stop the callback registered with `set_timebase_callback()` from being called. If the timebase master releases the timebase or leaves the JACK graph for any reason, the JACK engine takes over at the start of the next process cycle. The transport state does not change. If rolling, it continues to play, with frame numbers as the only available position information. Raises ------ JackError If the client is not the current timebase master or releasing the timebase failed for another reason See Also -------- set_timebase_callback """ _check( _lib.jack_release_timebase(self._ptr), 'Error releasing timebase') def set_timebase_callback(self, callback=None, conditional=False): """Register as timebase master for the JACK subsystem. The timebase master registers a callback that updates extended position information such as beats or timecode whenever necessary. Without this extended information, there is no need for this function. There is never more than one master at a time. When a new client takes over, the former callback is no longer called. Taking over the timebase may be done conditionally, so that *callback* is not registered if there was a master already. Parameters ---------- callback : callable Realtime function that returns extended position information. Its output affects all of the following process cycle. This realtime function must not wait. It is called immediately after the process callback (see `set_process_callback()`) in the same thread whenever the transport is rolling, or when any client has requested a new position in the previous cycle. The first cycle after `set_timebase_callback()` is also treated as a new position, or the first cycle after `activate()` if the client had been inactive. The *callback* must have this signature:: callback( state: int, blocksize: int, pos: jack_position_t, new_pos: bool, ) -> None state The current transport state. See `transport_state`. blocksize The number of frames in the current period. See `blocksize`. pos The position structure for the next cycle; ``pos.frame`` will be its frame number. If *new_pos* is ``False``, this structure contains extended position information from the current cycle. If *new_pos* is ``True``, it contains whatever was set by the requester. The *callback*'s task is to update the extended information here. See `transport_query_struct()` for details about ``jack_position_t``. new_pos ``True`` for a newly requested *pos*, or for the first cycle after the timebase callback is defined. .. note:: The *pos* argument must not be used to set ``pos.frame``. To change position, use `transport_reposition_struct()` or `transport_locate()`. These functions are realtime-safe, the timebase callback can call them directly. conditional : bool Set to ``True`` for a conditional request. Returns ------- bool ``True`` if the timebase callback was registered. ``False`` if a conditional request failed because another timebase master is already registered. """ if callback is None: return lambda cb: self.set_timebase_callback(cb, conditional) @self._callback('JackTimebaseCallback') def callback_wrapper(state, blocksize, pos, new_pos, _): callback(state, blocksize, pos, bool(new_pos)) err = _lib.jack_set_timebase_callback(self._ptr, conditional, callback_wrapper, _ffi.NULL) # Because of a bug in JACK2 version <= 1.9.10, we also check for -1. # See https://github.com/jackaudio/jack2/pull/123 if conditional and err in (_errno.EBUSY, -1): return False _check(err, 'Error setting timebase callback') return True def set_property_change_callback(self, callback): """Register property change callback. Tell the JACK server to call *callback* whenever a property is created, changed or deleted. Parameters ---------- callback : callable User-supplied function that is called whenever a property is created, changed or deleted. It must have this signature:: callback(subject: int, key: str, change: int) -> None The first and second arguments are the *subject* and *key*, respectively. See `set_property()` for details. The third argument has one of the values `PROPERTY_CREATED`, `PROPERTY_CHANGED` or `PROPERTY_DELETED`, which should be self-explanatory. """ @self._callback('JackPropertyChangeCallback') def callback_wrapper(subject, key, change, _): callback(subject, _decode(key) if key else '', change) _check(_lib.jack_set_property_change_callback( self._ptr, callback_wrapper, _ffi.NULL), 'Error setting property change callback') def get_uuid_for_client_name(self, name): """Get the session ID for a client name. The session manager needs this to reassociate a client name to the session ID. Raises ------ JackError If no client with the given name exists. """ uuid = _ffi.gc(_lib.jack_get_uuid_for_client_name( self._ptr, name.encode()), _lib.jack_free) if not uuid: raise JackError('Unable to get session ID for {0!r}'.format(name)) return _decode(uuid) def get_client_name_by_uuid(self, uuid): """Get the client name for a session ID. In order to snapshot the graph connections, the session manager needs to map session IDs to client names. Raises ------ JackError If no client with the given UUID exists. """ name = _ffi.gc(_lib.jack_get_client_name_by_uuid( self._ptr, uuid.encode()), _lib.jack_free) if not name: raise JackError('Unable to get client name for {0!r}'.format(uuid)) return _decode(name) def get_port_by_name(self, name): """Get port by name. Given a full port name, this returns a `Port`, `MidiPort`, `OwnPort` or `OwnMidiPort` object. Raises ------ JackError If no port with the given name exists. """ port_ptr = _lib.jack_port_by_name(self._ptr, name.encode()) if not port_ptr: raise JackError('Port {0!r} not available'.format(name)) return self._wrap_port_ptr(port_ptr) def get_all_connections(self, port): """Return a list of ports which the given port is connected to. This differs from `OwnPort.connections` (also available on `OwnMidiPort`) in two important respects: 1) You may not call this function from code that is executed in response to a JACK event. For example, you cannot use it in a graph order callback. 2) You need not be the owner of the port to get information about its connections. """ port = self._get_port_ptr(port) names = _ffi.gc(_lib.jack_port_get_all_connections(self._ptr, port), _lib.jack_free) return self._port_list_from_pointers(names) def get_ports(self, name_pattern='', is_audio=False, is_midi=False, is_input=False, is_output=False, is_physical=False, can_monitor=False, is_terminal=False): """Return a list of selected ports. Parameters ---------- name_pattern : str A regular expression used to select ports by name. If empty, no selection based on name will be carried out. is_audio, is_midi : bool Select audio/MIDI ports. If neither of them is ``True``, both types of ports are selected. is_input, is_output, is_physical, can_monitor, is_terminal : bool Select ports by their flags. If none of them are ``True``, no selection based on flags will be carried out. Returns ------- list of Port/MidiPort/OwnPort/OwnMidiPort All ports that satisfy the given conditions. """ if is_audio and not is_midi: type_pattern = _AUDIO elif is_midi and not is_audio: type_pattern = _MIDI else: type_pattern = b'' flags = 0x0 if is_input: flags |= _lib.JackPortIsInput if is_output: flags |= _lib.JackPortIsOutput if is_physical: flags |= _lib.JackPortIsPhysical if can_monitor: flags |= _lib.JackPortCanMonitor if is_terminal: flags |= _lib.JackPortIsTerminal names = _ffi.gc(_lib.jack_get_ports( self._ptr, name_pattern.encode(), type_pattern, flags), _lib.jack_free) return self._port_list_from_pointers(names) def set_property(self, subject, key, value, type=''): """Set a metadata property on *subject*. Parameters ---------- subject : int or str The subject (UUID) to set the property on. UUIDs can be obtained with `Client.uuid`, `Port.uuid` and `Client.get_uuid_for_client_name()`. key : str The key (URI) of the property. Some predefined keys are available as ``jack.METADATA_*`` module constants. value : str or bytes The value of the property. type : str, optional The type of the property, either a MIME type or URI. If *type* is empty, the *value* is assumed to be a UTF-8 encoded string (``'text/plain'``). Example values: - ``'image/png;base64'`` (base64 encoded PNG image) - ``'http://www.w3.org/2001/XMLSchema#int'`` (integer) Official types are preferred, but clients may use any syntactically valid MIME type (which start with a type and slash, like ``'text/...'``). If a URI type is used, it must be a complete absolute URI (which start with a scheme and colon, like ``'http:'``). See Also -------- get_property get_properties get_all_properties remove_property remove_properties remove_all_properties set_property_change_callback """ subject = _uuid_parse(subject) if isinstance(value, str): value = value.encode() if isinstance(type, str): type = type.encode() if _lib.jack_set_property( self._ptr, subject, key.encode(), value, type) != 0: raise ValueError('Unable to set property {!r} for subject {!r}' .format(key, subject)) def remove_property(self, subject, key): """Remove a single metadata property on *subject*. Parameters ---------- subject : int or str The subject (UUID) to remove the property from. UUIDs can be obtained with `Client.uuid`, `Port.uuid` and `Client.get_uuid_for_client_name()`. key : str The key of the property to be removed. See Also -------- set_property get_property get_properties get_all_properties remove_properties remove_all_properties set_property_change_callback """ subject = _uuid_parse(subject) if _lib.jack_remove_property(self._ptr, subject, key.encode()) != 0: raise ValueError('Unable to remove property {!r} for subject {!r}' .format(key, subject)) def remove_properties(self, subject): """Remove all metadata properties on *subject*. Parameters ---------- subject : int or str The subject (UUID) to remove all properties from. UUIDs can be obtained with `Client.uuid`, `Port.uuid` and `Client.get_uuid_for_client_name()`. Returns ------- int The number of properties removed. See Also -------- set_property get_property get_properties get_all_properties remove_property remove_all_properties set_property_change_callback """ subject = _uuid_parse(subject) number = _lib.jack_remove_properties(self._ptr, subject) if number < 0: raise RuntimeError( 'Unable to remove properties for subject {!r}'.format(subject)) return number def remove_all_properties(self): """Remove all metadata properties. .. warning:: This deletes all metadata managed by a running JACK server. Data lost cannot be recovered (though it can be recreated by new calls to `set_property()`). See Also -------- set_property get_property get_properties get_all_properties remove_property remove_properties set_property_change_callback """ if _lib.jack_remove_all_properties(self._ptr) != 0: raise RuntimeError('Unable to remove properties') def _callback(self, cdecl, **kwargs): """Wrapper for ffi.callback() that keeps callback alive.""" def callback_decorator(python_callable): function_ptr = _ffi.callback(cdecl, python_callable, **kwargs) self._keepalive.append(function_ptr) return function_ptr return callback_decorator def _register_port(self, name, porttype, is_terminal, is_physical, flags): """Create a new port. Raises ------ JackError If the port can not be registered, e.g. because the name is non-unique or too long. """ if is_terminal: flags |= _lib.JackPortIsTerminal if is_physical: flags |= _lib.JackPortIsPhysical port_ptr = _lib.jack_port_register(self._ptr, name.encode(), porttype, flags, 0) if not port_ptr: raise JackError( '{0!r}: port registration failed'.format(name)) return self._wrap_port_ptr(port_ptr) def _port_list_from_pointers(self, names): """Get list of Port objects from char**.""" ports = [] if names: idx = 0 while True: name = names[idx] if not name: break ports.append(self.get_port_by_name(_decode(name))) idx += 1 return ports def _get_port_ptr(self, port): """Get port pointer from Port object or string or port pointer.""" if isinstance(port, Port): port = port._ptr elif isinstance(port, str): port = self.get_port_by_name(port)._ptr return port def _wrap_port_ptr(self, ptr): """Create appropriate port object for a given port pointer.""" porttype = _ffi.string(_lib.jack_port_type(ptr)) if porttype == _AUDIO: cls = OwnPort if self.owns(ptr) else Port elif porttype == _MIDI: cls = OwnMidiPort if self.owns(ptr) else MidiPort else: assert False return cls(ptr, self) class Port(object): """A JACK audio port. This class cannot be instantiated directly. Instead, instances of this class are returned from `Client.get_port_by_name()`, `Client.get_ports()`, `Client.get_all_connections()` and `OwnPort.connections`. In addition, instances of this class are available in the callbacks which are set with `Client.set_port_registration_callback()`, `Client.set_port_connect_callback()` or `Client.set_port_rename_callback`. Note, however, that if the used `Client` owns the respective port, instances of `OwnPort` (instead of `Port`) will be created. In case of MIDI ports, instances of `MidiPort` or `OwnMidiPort` are created. Besides being the type of non-owned JACK audio ports, this class also serves as base class for all other port classes (`OwnPort`, `MidiPort` and `OwnMidiPort`). New JACK audio/MIDI ports can be created with the :meth:`~Ports.register` method of `Client.inports`, `Client.outports`, `Client.midi_inports` and `Client.midi_outports`. """ def __init__(self, port_ptr, client): self._ptr = port_ptr self._client = client def __repr__(self): return "jack.{0.__class__.__name__}('{0.name}')".format(self) def __eq__(self, other): """Ports are equal if their underlying port pointers are.""" return self._ptr == other._ptr def __ne__(self, other): """This should be implemented whenever __eq__() is implemented.""" return not self.__eq__(other) @property def name(self): """Full name of the JACK port (read-only).""" return _decode(_lib.jack_port_name(self._ptr)) @property def shortname(self): """Short name of the JACK port, not including the client name. Must be unique among all ports owned by a client. May be modified at any time. If the resulting full name (including the ``client_name:`` prefix) is longer than `port_name_size()`, it will be truncated. """ return _decode(_lib.jack_port_short_name(self._ptr)) @shortname.setter def shortname(self, shortname): _check(_lib.jack_port_rename(self._client._ptr, self._ptr, shortname.encode()), 'Error setting port name') @property def aliases(self): """Returns a list of strings with the aliases for the JACK port.""" ctype = 'char[{}]'.format(_lib.jack_port_name_size()) aliases = [_ffi.new(ctype), _ffi.new(ctype)] aliasesptr = _ffi.new('char *[]', aliases) result = [] if _lib.jack_port_get_aliases(self._ptr, aliasesptr) > 0: for i in 0, 1: alias = _decode(aliases[i]) if alias: result.append(alias) return result def set_alias(self, alias): """Set an alias for the JACK port. Ports can have up to two aliases. If both are already set, this function will return an error. """ _check(_lib.jack_port_set_alias(self._ptr, alias.encode()), 'Error setting port alias') def unset_alias(self, alias): """Remove an alias for the JACK port. If the alias doesn't exist this function will return an error. """ _check(_lib.jack_port_unset_alias(self._ptr, alias.encode()), 'Error unsetting port alias') @property def uuid(self): """The UUID of the JACK port.""" return _lib.jack_port_uuid(self._ptr) is_audio = property(lambda self: True, doc='This is always ``True``.') is_midi = property(lambda self: False, doc='This is always ``False``.') @property def is_input(self): """Can the port receive data?""" return self._hasflag(_lib.JackPortIsInput) @property def is_output(self): """Can data be read from this port?""" return self._hasflag(_lib.JackPortIsOutput) @property def is_physical(self): """Does it correspond to some kind of physical I/O connector?""" return self._hasflag(_lib.JackPortIsPhysical) @property def can_monitor(self): """Does a call to `request_monitor()` make sense?""" return self._hasflag(_lib.JackPortCanMonitor) @property def is_terminal(self): """Is the data consumed/generated?""" return self._hasflag(_lib.JackPortIsTerminal) def request_monitor(self, onoff): """Set input monitoring. If `can_monitor` is ``True``, turn input monitoring on or off. Otherwise, do nothing. Parameters ---------- onoff : bool If ``True``, switch monitoring on; if ``False``, switch it off. """ _check(_lib.jack_port_request_monitor(self._ptr, onoff), 'Unable to switch monitoring on/off') def _hasflag(self, flag): """Helper method for is_*().""" return bool(_lib.jack_port_flags(self._ptr) & flag) class MidiPort(Port): """A JACK MIDI port. This class is derived from `Port` and has exactly the same attributes and methods. This class cannot be instantiated directly (see `Port`). New JACK audio/MIDI ports can be created with the :meth:`~Ports.register` method of `Client.inports`, `Client.outports`, `Client.midi_inports` and `Client.midi_outports`. See Also -------- Port, OwnMidiPort """ is_audio = property(lambda self: False, doc='This is always ``False``.') is_midi = property(lambda self: True, doc='This is always ``True``.') class OwnPort(Port): """A JACK audio port owned by a `Client`. This class is derived from `Port`. `OwnPort` objects can do everything that `Port` objects can, plus a lot more. This class cannot be instantiated directly (see `Port`). New JACK audio/MIDI ports can be created with the :meth:`~Ports.register` method of `Client.inports`, `Client.outports`, `Client.midi_inports` and `Client.midi_outports`. """ @property def number_of_connections(self): """Number of connections to or from port.""" return _lib.jack_port_connected(self._ptr) @property def connections(self): """List of ports which the port is connected to.""" names = _ffi.gc(_lib.jack_port_get_connections(self._ptr), _lib.jack_free) return self._client._port_list_from_pointers(names) def is_connected_to(self, port): """Am I *directly* connected to *port*? Parameters ---------- port : str or Port Full port name or port object. """ if isinstance(port, Port): port = port.name return bool(_lib.jack_port_connected_to(self._ptr, port.encode())) def connect(self, port): """Connect to given port. Parameters ---------- port : str or Port Full port name or port object. See Also -------- Client.connect """ if not isinstance(port, Port): port = self._client.get_port_by_name(port) if self.is_output: source = self if not port.is_input: raise ValueError('Input port expected') destination = port elif self.is_input: destination = self if not port.is_output: raise ValueError('Output port expected') source = port else: assert False self._client.connect(source.name, destination.name) def disconnect(self, other=None): """Disconnect this port. Parameters ---------- other : str or Port Port to disconnect from. By default, disconnect from all connected ports. """ if other is None: _check(_lib.jack_port_disconnect(self._client._ptr, self._ptr), 'Error disconnecting {0!r}'.format(self.name)) else: if self.is_output: args = self, other elif self.is_input: args = other, self self._client.disconnect(*args) def unregister(self): """Unregister port. Remove the port from the client, disconnecting any existing connections. This also removes the port from `Client.inports`, `Client.outports`, `Client.midi_inports` or `Client.midi_outports`. """ if self.is_audio: listname = '' elif self.is_midi: listname = 'midi_' if self.is_input: listname += 'inports' elif self.is_output: listname += 'outports' ports = getattr(self._client, listname) ports._portlist.remove(self) _check(_lib.jack_port_unregister(self._client._ptr, self._ptr), 'Error unregistering {0!r}'.format(self.name)) def get_buffer(self): """Get buffer for audio data. This returns a buffer holding the memory area associated with the specified port. For an output port, it will be a memory area that can be written to; for an input port, it will be an area containing the data from the port's connection(s), or zero-filled. If there are multiple inbound connections, the data will be mixed appropriately. Caching output ports is DEPRECATED in JACK 2.0, due to some new optimization (like "pipelining"). Port buffers have to be retrieved in each callback for proper functioning. This method shall only be called from within the process callback (see `Client.set_process_callback()`). """ blocksize = self._client.blocksize return _ffi.buffer(_lib.jack_port_get_buffer(self._ptr, blocksize), blocksize * _ffi.sizeof('float')) def get_array(self): """Get audio buffer as NumPy array. Make sure to ``import numpy`` before calling this, otherwise the first call might take a long time. This method shall only be called from within the process callback (see `Client.set_process_callback()`). See Also -------- get_buffer """ import numpy as np return np.frombuffer(self.get_buffer(), dtype=np.float32) class OwnMidiPort(MidiPort, OwnPort): """A JACK MIDI port owned by a `Client`. This class is derived from `OwnPort` and `MidiPort`, which are themselves derived from `Port`. It has the same attributes and methods as `OwnPort`, but `get_buffer()` and `get_array()` are disabled. Instead, it has methods for sending and receiving MIDI events (to be used only from within the process callback -- see `Client.set_process_callback()`). This class cannot be instantiated directly (see `Port`). New JACK audio/MIDI ports can be created with the :meth:`~Ports.register` method of `Client.inports`, `Client.outports`, `Client.midi_inports` and `Client.midi_outports`. """ def __init__(self, *args, **kwargs): OwnPort.__init__(self, *args, **kwargs) self._event = _ffi.new('jack_midi_event_t*') def get_buffer(self): """Not available for MIDI ports.""" raise NotImplementedError('get_buffer() not available on MIDI ports') def get_array(self): """Not available for MIDI ports.""" raise NotImplementedError('get_array() not available on MIDI ports') @property def max_event_size(self): """Get the size of the largest event that can be stored by the port. This returns the current space available, taking into account events already stored in the port. """ return _lib.jack_midi_max_event_size( _lib.jack_port_get_buffer(self._ptr, self._client.blocksize)) @property def lost_midi_events(self): """Get the number of events that could not be written to the port. This being a non-zero value implies that the port is full. Currently the only way this can happen is if events are lost on port mixdown. """ return _lib.jack_midi_get_lost_event_count( _lib.jack_port_get_buffer(self._ptr, self._client.blocksize)) def incoming_midi_events(self): """Return generator for incoming MIDI events. JACK MIDI is normalised, the MIDI events yielded by this generator are guaranteed to be complete MIDI events (the status byte will always be present, and no realtime events will be interspersed with the events). Yields ------ time : int Time (in samples) relative to the beginning of the current audio block. event : buffer The actual MIDI event data. .. warning:: The buffer is re-used (and therefore overwritten) between iterations. If you want to keep the data beyond the current iteration, please make a copy. """ event = self._event buf = _lib.jack_port_get_buffer(self._ptr, self._client.blocksize) for i in range(_lib.jack_midi_get_event_count(buf)): err = _lib.jack_midi_event_get(event, buf, i) if err: break yield event.time, _ffi.buffer(event.buffer, event.size) def clear_buffer(self): """Clear an event buffer. This should be called at the beginning of each process cycle before calling `reserve_midi_event()` or `write_midi_event()`. This function may not be called on an input port. """ _lib.jack_midi_clear_buffer( _lib.jack_port_get_buffer(self._ptr, self._client.blocksize)) def write_midi_event(self, time, event): """Create an outgoing MIDI event. Clients must write normalised MIDI data to the port - no running status and no (one-byte) realtime messages interspersed with other messages (realtime messages are fine when they occur on their own, like other messages). Events must be written in order, sorted by their sample offsets. JACK will not sort the events for you, and will refuse to store out-of-order events. Parameters ---------- time : int Time (in samples) relative to the beginning of the current audio block. event : bytes or buffer or sequence of int The actual MIDI event data. .. note:: Buffer objects are only supported for CFFI >= 0.9. Raises ------ JackError If MIDI event couldn't be written. """ try: event = _ffi.from_buffer(event) except AttributeError: pass # from_buffer() not supported except TypeError: pass # input is not a buffer _check(_lib.jack_midi_event_write( _lib.jack_port_get_buffer(self._ptr, self._client.blocksize), time, event, len(event)), 'Error writing MIDI event') def reserve_midi_event(self, time, size): """Get a buffer where an outgoing MIDI event can be written to. Clients must write normalised MIDI data to the port - no running status and no (one-byte) realtime messages interspersed with other messages (realtime messages are fine when they occur on their own, like other messages). Events must be written in order, sorted by their sample offsets. JACK will not sort the events for you, and will refuse to store out-of-order events. Parameters ---------- time : int Time (in samples) relative to the beginning of the current audio block. size : int Number of bytes to reserve. Returns ------- buffer A buffer object where MIDI data bytes can be written to. If no space could be reserved, an empty buffer is returned. """ buf = _lib.jack_midi_event_reserve( _lib.jack_port_get_buffer(self._ptr, self._client.blocksize), time, size) return _ffi.buffer(buf, size if buf else 0) class Ports(object): """A list of input/output ports. This class is not meant to be instantiated directly. It is only used as `Client.inports`, `Client.outports`, `Client.midi_inports` and `Client.midi_outports`. The ports can be accessed by indexing or by iteration. New ports can be added with `register()`, existing ports can be removed by calling their :meth:`~OwnPort.unregister` method. """ def __init__(self, client, porttype, flag): self._client = client self._type = porttype self._flag = flag self._portlist = [] def __len__(self): return self._portlist.__len__() def __getitem__(self, name): return self._portlist.__getitem__(name) # No __setitem__! def __iter__(self): return self._portlist.__iter__() def __repr__(self): return self._portlist.__repr__() def register(self, shortname, is_terminal=False, is_physical=False): """Create a new input/output port. The new `OwnPort` or `OwnMidiPort` object is automatically added to `Client.inports`, `Client.outports`, `Client.midi_inports` or `Client.midi_outports`. Parameters ---------- shortname : str Each port has a short name. The port's full name contains the name of the client concatenated with a colon (:) followed by its short name. The `port_name_size()` is the maximum length of this full name. Exceeding that will cause the port registration to fail. The port name must be unique among all ports owned by this client. If the name is not unique, the registration will fail. is_terminal : bool For an input port: If ``True``, the data received by the port will not be passed on or made available at any other port. For an output port: If ``True``, the data available at the port does not originate from any other port Audio synthesizers, I/O hardware interface clients, HDR systems are examples of clients that would set this flag for their ports. is_physical : bool If ``True`` the port corresponds to some kind of physical I/O connector. Returns ------- Port A new `OwnPort` or `OwnMidiPort` instance. """ port = self._client._register_port( shortname, self._type, is_terminal, is_physical, self._flag) self._portlist.append(port) return port def clear(self): """Unregister all ports in the list. See Also -------- OwnPort.unregister """ while self._portlist: self._portlist[0].unregister() class RingBuffer(object): """JACK's lock-free ringbuffer.""" def __init__(self, size): """Create a lock-free ringbuffer. A ringbuffer is a good way to pass data between threads (e.g. between the main program and the process callback), when streaming realtime data to slower media, like audio file playback or recording. The key attribute of a ringbuffer is that it can be safely accessed by two threads simultaneously -- one reading from the buffer and the other writing to it -- without using any synchronization or mutual exclusion primitives. For this to work correctly, there can only be a single reader and a single writer thread. Their identities cannot be interchanged. Parameters ---------- size : int Size in bytes. JACK will allocate a buffer of at least this size (rounded up to the next power of 2), but one byte is reserved for internal use. Use `write_space` to determine the actual size available for writing. Raises ------ JackError If the rightbufefr could not be allocated. """ ptr = _lib.jack_ringbuffer_create(size) if not ptr: raise JackError('Could not create RingBuffer') self._ptr = _ffi.gc(ptr, _lib.jack_ringbuffer_free) @property def write_space(self): """The number of bytes available for writing.""" return _lib.jack_ringbuffer_write_space(self._ptr) def write(self, data): """Write data into the ringbuffer. Parameters ---------- data : buffer or bytes or iterable of int Bytes to be written to the ringbuffer. Returns ------- int The number of bytes written, which could be less than the length of *data* if there was no more space left (see `write_space`). See Also -------- :attr:`write_space`, :attr:`write_buffers` """ try: data = _ffi.from_buffer(data) except AttributeError: pass # from_buffer() not supported except TypeError: pass # input is not a buffer return _lib.jack_ringbuffer_write(self._ptr, data, len(data)) @property def write_buffers(self): """Contains two buffer objects that can be written to directly. Two are needed because the space available for writing may be split across the end of the ringbuffer. Either of them could be 0 length. This can be used as a no-copy version of `write()`. When finished with writing, `write_advance()` should be used. .. note:: After an operation that changes the write pointer (`write()`, `write_advance()`, `reset()`), the buffers are no longer valid and one should use this property again to get new ones. """ vectors = _ffi.new('jack_ringbuffer_data_t[2]') _lib.jack_ringbuffer_get_write_vector(self._ptr, vectors) return ( _ffi.buffer(vectors[0].buf, vectors[0].len), _ffi.buffer(vectors[1].buf, vectors[1].len) ) def write_advance(self, size): """Advance the write pointer. After data has been written to the ringbuffer using `write_buffers`, use this method to advance the buffer pointer, making the data available for future read operations. Parameters ---------- size : int The number of bytes to advance. """ _lib.jack_ringbuffer_write_advance(self._ptr, size) @property def read_space(self): """The number of bytes available for reading.""" return _lib.jack_ringbuffer_read_space(self._ptr) def read(self, size): """Read data from the ringbuffer. Parameters ---------- size : int Number of bytes to read. Returns ------- buffer A buffer object containing the requested data. If no more data is left (see `read_space`), a smaller (or even empty) buffer is returned. See Also -------- peek, :attr:`read_space`, :attr:`read_buffers` """ data = _ffi.new('unsigned char[]', size) size = _lib.jack_ringbuffer_read(self._ptr, data, size) return _ffi.buffer(data, size) def peek(self, size): """Peek at data from the ringbuffer. Opposed to `read()` this function does not move the read pointer. Thus it's a convenient way to inspect data in the ringbuffer in a continuous fashion. The price is that the data is copied into a newly allocated buffer. For "raw" non-copy inspection of the data in the ringbuffer use `read_buffers`. Parameters ---------- size : int Number of bytes to peek. Returns ------- buffer A buffer object containing the requested data. If no more data is left (see `read_space`), a smaller (or even empty) buffer is returned. See Also -------- read, :attr:`read_space`, :attr:`read_buffers` """ data = _ffi.new('unsigned char[]', size) size = _lib.jack_ringbuffer_peek(self._ptr, data, size) return _ffi.buffer(data, size) @property def read_buffers(self): """Contains two buffer objects that can be read directly. Two are needed because the data to be read may be split across the end of the ringbuffer. Either of them could be 0 length. This can be used as a no-copy version of `peek()` or `read()`. When finished with reading, `read_advance()` should be used. .. note:: After an operation that changes the read pointer (`read()`, `read_advance()`, `reset()`), the buffers are no longer valid and one should use this property again to get new ones. """ vectors = _ffi.new('jack_ringbuffer_data_t[2]') _lib.jack_ringbuffer_get_read_vector(self._ptr, vectors) return ( _ffi.buffer(vectors[0].buf, vectors[0].len), _ffi.buffer(vectors[1].buf, vectors[1].len) ) def read_advance(self, size): """Advance the read pointer. After data has been read from the ringbuffer using `read_buffers` or `peek()`, use this method to advance the buffer pointers, making that space available for future write operations. Parameters ---------- size : int The number of bytes to advance. """ _lib.jack_ringbuffer_read_advance(self._ptr, size) def mlock(self): """Lock a ringbuffer data block into memory. Uses the ``mlock()`` system call. This prevents the ringbuffer's memory from being paged to the swap area. .. note:: This is not a realtime operation. """ _check(_lib.jack_ringbuffer_mlock(self._ptr), 'Error mlocking the RingBuffer data') def reset(self, size=None): """Reset the read and write pointers, making an empty buffer. .. note:: This is not thread safe. Parameters ---------- size : int, optional The new size for the ringbuffer. Must be less than allocated size. """ if size is None: _lib.jack_ringbuffer_reset(self._ptr) else: _lib.jack_ringbuffer_reset_size(self._ptr, size) @property def size(self): """The number of bytes in total used by the buffer. See Also -------- :attr:`read_space`, :attr:`write_space` """ return self._ptr.size class Status(object): """Representation of the JACK status bits.""" __slots__ = '_code' def __init__(self, code): self._code = code def __repr__(self): flags = ', '.join(name for name in dir(self) if not name.startswith('_') and getattr(self, name)) if not flags: flags = 'no flags set' return ''.format(self._code, flags) @property def failure(self): """Overall operation failed.""" return self._hasflag(_lib.JackFailure) @property def invalid_option(self): """The operation contained an invalid or unsupported option.""" return self._hasflag(_lib.JackInvalidOption) @property def name_not_unique(self): """The desired client name was not unique. With the *use_exact_name* option of `Client`, this situation is fatal. Otherwise, the name is modified by appending a dash and a two-digit number in the range "-01" to "-99". `Client.name` will return the exact string that was used. If the specified *name* plus these extra characters would be too long, the open fails instead. """ return self._hasflag(_lib.JackNameNotUnique) @property def server_started(self): """The JACK server was started for this `Client`. Otherwise, it was running already. """ return self._hasflag(_lib.JackServerStarted) @property def server_failed(self): """Unable to connect to the JACK server.""" return self._hasflag(_lib.JackServerFailed) @property def server_error(self): """Communication error with the JACK server.""" return self._hasflag(_lib.JackServerError) @property def no_such_client(self): """Requested client does not exist.""" return self._hasflag(_lib.JackNoSuchClient) @property def load_failure(self): """Unable to load internal client.""" return self._hasflag(_lib.JackLoadFailure) @property def init_failure(self): """Unable to initialize client.""" return self._hasflag(_lib.JackInitFailure) @property def shm_failure(self): """Unable to access shared memory.""" return self._hasflag(_lib.JackShmFailure) @property def version_error(self): """Client's protocol version does not match.""" return self._hasflag(_lib.JackVersionError) @property def backend_error(self): """Backend error.""" return self._hasflag(_lib.JackBackendError) @property def client_zombie(self): """Client zombified failure.""" return self._hasflag(_lib.JackClientZombie) def _hasflag(self, flag): """Helper function for Status properties.""" return bool(self._code & flag) class TransportState(object): """Representation of the JACK transport state. See Also -------- `Client.transport_state`, :meth:`Client.transport_query` """ __slots__ = '_code' def __init__(self, code): self._code = code def __eq__(self, other): return self._code == other def __hash__(self): return hash(self._code) def __repr__(self): return 'jack.' + { _lib.JackTransportStopped: 'STOPPED', _lib.JackTransportRolling: 'ROLLING', _lib.JackTransportStarting: 'STARTING', _lib.JackTransportNetStarting: 'NETSTARTING', }[self._code] class CallbackExit(Exception): """To be raised in a callback function to signal failure. See Also -------- :meth:`Client.set_process_callback` :meth:`Client.set_blocksize_callback` :meth:`Client.set_samplerate_callback` :meth:`Client.set_port_rename_callback` :meth:`Client.set_graph_order_callback` :meth:`Client.set_xrun_callback` """ pass def _uuid_parse(uuid): if isinstance(uuid, (Client, Port)): uuid = uuid.uuid if isinstance(uuid, int): return uuid elif isinstance(uuid, str): uuid_ptr = _ffi.new('jack_uuid_t*') if _lib.jack_uuid_parse(uuid.encode(), uuid_ptr) != 0: raise ValueError('Unable to parse UUID: {!r}'.format(uuid)) return uuid_ptr[0] raise TypeError('Invalid UUID: {!r}'.format(uuid)) def _description_to_dict(desc): assert desc != _ffi.NULL prop_dict = {} for i in range(desc.property_cnt): prop = desc.properties[i] key = _decode(prop.key) prop_dict[key] = ( _ffi.string(prop.data), _decode(prop.type) if prop.type else '') free_description_itself = 0 _lib.jack_free_description(desc, free_description_itself) return prop_dict def get_property(subject, key): """Get a metadata property on *subject*. Parameters ---------- subject : int or str The subject (UUID) to get the property from. UUIDs can be obtained with `Client.uuid`, `Port.uuid` and `Client.get_uuid_for_client_name()`. key : str The key of the property. Returns ------- (bytes, str) or None A tuple containing the value of the property and the type of the property. If *subject* doesn't have the property *key*, ``None`` is returned. See Also -------- Client.set_property get_properties get_all_properties Client.remove_property Client.remove_properties Client.remove_all_properties Client.set_property_change_callback """ subject = _uuid_parse(subject) data = _ffi.new('char**') type = _ffi.new('char**') if _lib.jack_get_property(subject, key.encode(), data, type) != 0: return None data = _ffi.gc(data[0], _lib.jack_free) type = _ffi.gc(type[0], _lib.jack_free) return _ffi.string(data), _decode(type) if type else '' def get_properties(subject): """Get all metadata properties of *subject*. Parameters ---------- subject : int or str The subject (UUID) to get all properties of. UUIDs can be obtained with `Client.uuid`, `Port.uuid` and `Client.get_uuid_for_client_name()`. Returns ------- dict A dictionary mapping property names to ``(value, type)`` tuples. See Also -------- Client.set_property get_property get_all_properties Client.remove_property Client.remove_properties Client.remove_all_properties Client.set_property_change_callback """ subject = _uuid_parse(subject) desc = _ffi.new('jack_description_t*') number = _lib.jack_get_properties(subject, desc) if number < 0: raise RuntimeError( 'Unable to get properties for subject {!r}'.format(subject)) assert number == desc.property_cnt return _description_to_dict(desc) def get_all_properties(): """Get all properties for all subjects with metadata. Returns ------- dict A dictionary mapping UUIDs to nested dictionaries as returned by `get_properties()`. See Also -------- Client.set_property get_property get_properties Client.remove_property Client.remove_properties Client.remove_all_properties Client.set_property_change_callback """ descs = _ffi.new('jack_description_t**') number = _lib.jack_get_all_properties(descs) if number < 0: raise RuntimeError('Error getting all properties') descs = _ffi.gc(descs[0], _lib.jack_free) prop_dict = {} for idx in range(number): desc = descs + idx assert desc.subject not in prop_dict prop_dict[desc.subject] = _description_to_dict(desc) return prop_dict def position2dict(pos): """Convert CFFI position struct to a dict.""" assert pos.unique_1 == pos.unique_2 keys = ['usecs', 'frame_rate', 'frame'] if pos.valid & _lib.JackPositionBBT: keys += ['bar', 'beat', 'tick', 'bar_start_tick', 'beats_per_bar', 'beat_type', 'ticks_per_beat', 'beats_per_minute'] if pos.valid & _lib.JackPositionTimecode: keys += ['frame_time', 'next_time'] if pos.valid & _lib.JackBBTFrameOffset: keys += ['bbt_offset'] if pos.valid & _lib.JackAudioVideoRatio: keys += ['audio_frames_per_video_frame'] if pos.valid & _lib.JackVideoFrameOffset: keys += ['video_offset'] return dict((k, getattr(pos, k)) for k in keys) def version(): """Get tuple of major/minor/micro/protocol version.""" v = _ffi.new('int[4]') _lib.jack_get_version(v+0, v+1, v+2, v+3) return tuple(v) def version_string(): """Get human-readable JACK version.""" return _decode(_lib.jack_get_version_string()) def client_name_size(): """Return the maximum number of characters in a JACK client name. This includes the final NULL character. This value is a constant. """ return _lib.jack_client_name_size() def port_name_size(): """Maximum length of port names. The maximum number of characters in a full JACK port name including the final NULL character. This value is a constant. A port's full name contains the owning client name concatenated with a colon (:) followed by its short name and a NULL character. """ return _lib.jack_port_name_size() def set_error_function(callback=None): """Set the callback for error message display. Set it to ``None`` to restore the default error callback function (which prints the error message plus a newline to stderr). The *callback* function must have this signature:: callback(message: str) -> None """ _set_error_or_info_function(callback, _lib.jack_set_error_function) def set_info_function(callback=None): """Set the callback for info message display. Set it to ``None`` to restore default info callback function (which prints the info message plus a newline to stderr). The *callback* function must have this signature:: callback(message: str) -> None """ _set_error_or_info_function(callback, _lib.jack_set_info_function) def client_pid(name): """Return PID of a JACK client. Parameters ---------- name : str Name of the JACK client whose PID shall be returned. Returns ------- int PID of *name*. If not available, 0 will be returned. """ return _lib.jack_get_client_pid(name.encode()) def _set_error_or_info_function(callback, setter): """Helper for set_error_function() and set_info_function().""" if callback is None: callback_wrapper = _ffi.NULL else: @_ffi.callback('void (*)(const char*)') def callback_wrapper(msg): callback(_decode(msg)) _keepalive[setter] = callback_wrapper setter(callback_wrapper) _keepalive = {} def _check(error_code, msg): """Check error code and raise JackError if non-zero.""" if error_code: raise JackErrorCode(msg, error_code)