![]() |
VISR
0.12.0
Versatile Interactive Scene Renderer
|
The VISR framework aims at a seamless integration with Python. This supports four different ways (which can be combined arbitrarily): Controlling VISR signal flows from Python, e.g., starting, pausing and stopping processing. Simulating the run of signal flows interactively in a Python development environment. Extending and creating new signal flows by combining existing components in Python Implementing new components in Python, which can be freely mixed and composed with other components.
This is achieved by providing the core VISR functionality, which is implemented in C++, as a set of Python modules, plus additional Python modules.
This page describes how to use the Python bindings and how to build them on a development machine.
To use the Python integration, a working Python environment must be installed both on a development system and on systems which use installed VISR binaries. We highly recommend Python 3 (although the code should compile and run with Python 2 (provided that it is built correctly). No testing is performed for that combination. On Linux, the versions provided by the package manager (python3-dev, python3-*, spyder3) are fine. On Windows, we recommend the Anaconda distribution https://www.continuum.io/ (Python 3, 64 Bit). On Mac OS X, we also recommend Anaconda. The default distribution of the OS image is outdated (Python 2.7)
When using a VISR installation package, make sure that the Python major and minor version (e.g. Python 3.6) matches that of the installer. Failure to do so will result in errors when loading the external modules.
The following steps are required regardless whether the externals were built on the computer itself, or whether they were installed using an installation package (differences are noted). The Python modules are located in a directory, either within the build directory or the installation root directory. If the VISR framework has been installed using an installation package, the Python modules are in $VISR_INSTALLATION_ROOT/python
:
C:\Program Files`VISR-X.X.X/python
/Applicatons/VISR-X.X.X-python3.X-Darwin/python
/usr/python/
If the code has been built on the present machine, the extensions are located in $VISR_BUILD_DIRECTORY/python
. In development environments that support multiple configurations (e.g., Visual Studio and MacOS XCode), their is a subdirectory Debug/ or Release/ within python. Choose the build configuration you want to use (Release/ is typically faster, but does not yield sensible information when used with a debugger). This path must be known to Python in order to find these extension modules.To enable the Python interpreter to find the VISR modules, the above path must be contained in the $PYTHONPATH
environment variable. This is explained below.
In addition, if Python code is to be called from within a non-Python application, e.g, a DAW, Max/MSP or the python_runner
described below, the environment variable $PYTHONHOME
must be set to the root of the Python installation (see https://docs.python.org/3/using/cmdline.html#envvar-PYTHONHOME).
PYTHONPATH
and PYTHONHOME
in "Control Center"->"System"->"Advanced system settings"->" -
Environment Variables". Setting it as a user variable is preferred if you want to use the VISR only as the current user. On Linux system, add this line to the file $HOME/.profile The $PYTHONHOME
can be set in the same way.
However, this will rarely be necessary because on Linux it is advisable in most cases to use the system-provided Python 3 installation.
launchctl
mechanism. The following setup procedure works for both MacOS X 10.9 and erlier, and for MacOS X 10.10+. The VISR_environment_build_install_X.X.X.plist
file listed below is a MacOS X LaunchAgent
which is activated when the user logs in, and which sets and load the desired variables. If you don't have that file already, create a file with that name and with the following content: path_to_extension_modules
${HOME}/anaconda
There are three steps to install the environment variables.
VISR_environment_build_install_X.X.X.plist
into ${HOME}/Library/LaunchAgents
/Applications/Utilities
.plist
file takes effect after the next reboot. To see the effect, it is necessary to close and restart relevant applications (terminal, Spyder, etc.)Another, operating system-independent, way is to set the module search path within Python. To do so, add the line
to a script. Obviously, that makes it less easy to pass scripts between different places because the paths are hardcoded. On Windows, we must also ensure that the shared libraries (DLLs) used by the Python extensions are in a directory contained in the PATH variable. See @ users)
That is, the $PATH
variable variable must contain this directory: $VISR_INSTALLATION_ROOT/lib
if an installer package has been used, or $VISR_BUILD_DIRECTORY/lib/{Debug|Release}
if the VISR has been built from the source. Match that the build configuration Debug or Release matches that used in the $PYTHONPATH
variable.
While it is possible to run Python components directly from a Python interpreter, there are also use cases where a signal flow defined in Python is preferably run as a standalone audio application. The application python_runner, installed as part of the VISR package, can be used. This binary is started as a command-line application and runs the specified VISR component as a real-time rendering process using a specified audio interface.
The command line arguments are displayed by the –help option:
Description:
-option-file
(or @[file]) Specify a text file that contains the command line options-D
The audio interface to use (e.g., "PortAudio" or "Jack")–audio-ifc-options
Interface-dependent set of options provided as a string (typically in JSON format)–audio-ifc-option-file
Alternative way to provide interface-specific options within a text file.-f
Sampling frequency in Hz-m
Full path to the Python module (including file name and extension)-c
Name of the Python class to be instantiated. The class has to be defined in the named module, and has to be a subclass of visr.Component
(atomic or composite).-n
Name of the top-level component. Used in status and error messages. Can be chosen freely. Default "Pythonflow"-a
Positional (non-keyword) arguments passed to the top-level component. Provided as a Python tuple, i.e, comma-separated values. If there is only one value, it has to be trailed by a comma, otherwise the trailing comma is optional. The whole paremter can be enclosed in quotes, e.g., if it contains spaces.-k
Keyword arguments, provided as a Python dictionary. That is, a set of 'key':value pairs separated by commas and enclosed in brackets: "{'key1':val1, 'key2':val2, ... }"
. A Python keyword argument sequence key1=val1, key2=val2, ...
can be straightforwardly converted into a dictionary by quoting the keys, replacing "=" by ":" and enclosing the whole argument in quotes and braces"{...}"
.The main limitation of VISR flows started from the python_runner
is that all constructor parameters must be expressable on the command line. Constructing complex objects, such as reading matrices, which is possible within a Python scripts, cannot be performed. One way to work around this limitation is to wrap the signal flow in a new composite component which performs this complex initialisation from arguments that fit into the command line arguments.
To start an atomic Python summation component, use
To build the code on a development machine, the follwoing options must be set in CMAKE: Activate the option BUILD_PYTHON_BINDINGS
. After running "Configure", check the settings in the newly appeared group PYTHON
: The setting PYTHON_INCLUDE_DIR
must point to the include directory of the Python distribution. Amongst others, this directory must contain the main Python header Python.h. If that is not the case, set the entry to this directory. On the development systems, the following directories are set:
/usr/include/python3.4m
C:/Program Files/Anaconda3/include
/Users/<loginname>/anaconda/include/python3.5m
The setting PYTHON_LIBRARY
must point to the main Python library. This file is located within the directory root of the installed Python distribution (or in case of Linux, a standard library directory. On our test systems, the file names are as follows:
/usr/lib/x86_64-linux-gnu/libpython3.4m.so
C:/Program Files/Anaconda3/libs/python35.lib
In CMake, call "Configure" again and run "Generate" Build the project (the Python externals are distributed over several targets, so "Build all" is the best option.