Skip to main content

A Python wrapper for the RtMidi C++ library written with Cython.

Project description

Overview

RtMidi is a set of C++ classes which provides a concise and simple, cross-platform API (Application Programming Interface) for realtime MIDI input/output across Linux (ALSA & JACK), Macintosh OS X (CoreMIDI & JACK), and Windows (Multimedia Library & Kernel Streaming) operating systems.

python-rtmidi is a Python binding for RtMidi implemented with Cython and provides a thin wrapper around the RtMidi C++ interface. The API is basically the same as the C++ one but with the naming scheme of classes, methods and parameters adapted to the Python PEP-8 conventions and requirements of the Python package naming structure. python-rtmidi supports Python 2 (tested with Python 2.7) and Python 3 (3.2).

Usage example

Here’s a quick example of how to use python-rtmidi to open the first available MIDI output port and send a middle C note on MIDI channel 10:

import time
import rtmidi

midiout = rtmidi.MidiOut()
available_ports = midiout.get_ports()

if available_ports:
    midiout.open_port(0)
else:
    midiout.open_virtual_port("My virtual output")

note_on = [0x99, 60, 112] # channel 10, middle C, velocity 112
note_off = [0x89, 60, 0]
midiout.send_message(note_on)
time.sleep(0.5)
midiout.send_message(note_off)

del midiout

More usage examples can be found in the tests directory of the source distribution. API documentation is available by looking at the docstrings in the Cython source code or using tools like pydoc or IPython and by reading the RtMidi documentation.

Installation

python-rtmidi is a Python C(++)-extension and therefore a C++ compiler and a build environment as well as some system-dependant libraries are needed. See “Requirements” below for details.

Installer (Windows only)

An installer with a pre-compiled version for Windows with Windows MultiMedia API support is available through PyPI for some Python versions. Download it from python-rtmidi’s PyPI page and start the installer by double-clicking.

From PyPI

If you have all the dependencies, you should be able to install the package with pip or easy_install:

$ pip install python-rtmidi

or, if you prefer setuptools:

$ easy_install python-rtmidi

This will download the source distribution, compile the extension and install it in your active Python installation. Unless you want to change the Cython source file _rtmidi.pyx, there is no need to have Cython installed.

python-rtmidi also works well with virtualenv and virtualenvwrapper. If you have both installed, creating an isolated environment for testing and using python-rtmidi is as easy as:

$ mkvirtualenv rtmidi
(rtmidi)$ pip install python-rtmidi

From the Source Distribution

Of course, you can also download the source distribution package as a Zip archive or tarball, extract it and install using the common distutils commands, e.g.:

$ wget http://chrisarndt.de/projects/python-rtmidi/download/python-rtmidi-0.3a.tar.gz
$ tar xzf python-rtmidi-0.3a.tar.gz
$ cd python-rtmidi-0.3a
$ python setup.py install

From Subversion

Lastly, you can check out the python-rtmidi source code from the Subversion repository and then install it from your working copy. Since the repository does not include the C++ module source code pre-compiled from the Cython source, you’ll also need to install Cython from its Git repository. Using virtualenv/virtualenvwrapper is strongly recommended in this scenario:

$ mkvirtualenv rtmidi
(rtmidi)$ cdvirtualenv
(rtmidi)$ git clone https://github.com/cython/cython.git
(rtmidi)$ svn co svn://svn.chrisarndt.de/projects/python-rtmidi/trunk python-rtmidi
(rtmidi)$ cd cython
(rtmidi)$ python setup.py install
(rtmidi)$ cd ../python-rtmidi
(rtmidi)$ python setup.py install

Requirements

Naturally, you’ll need a C++ compiler and a build environment. See the platform-specific hints below.

Only if you want to change the Cython source file _rtmidi.pyx or want to recompile _rtmidi.cpp with a newer Cython version, you’ll need to install Cython >= 0.17. The _rtmidi.cpp file in the source distribution was generated with Cython 0.18pre as of 2013-01-14 and Python 2.7.3.

RtMidi (and therefore python-rtmidi) supports several low-level MIDI libraries on different operating systems. Only one of the available options needs to be present on the target system, but support for more than one can be compiled in. The setup script will try to detect available libraries and should use the appropriate compilations flags automatically.

  • Linux: ALSA, JACK

  • OS X: CoreMIDI, JACK

  • Windows: MultiMedia (MM), Windows Kernel Streaming

Linux

For the C++ compiler and the pthread library install the build-essential package on debian-based systems.

Then you’ll need Python development headers and libraries. On Linux, install the python-dev package. If you use the official installers from python.org you should already have these.

To get ALSA support, you must install development files for the libasound library (debian package: libasound-dev). For JACK support, install the libjack development files (libjack-dev or libjack-jackd2-dev).

OS X

Install the latest Xcode or g++ from MacPorts or homebrew (untested). CoreMIDI support comes with installing Xcode. For JACK support, install JACK for OS X with the full installer.

Windows

On Windows you’ll need Visual Studio 2008 (Express). Visual Studio 2010 (Express) or later editions will not work with current official Python distributions. After you have installed Visual Studio, you probably need to edit the WINLIB_DIR and WININC_DIR variables at the top of the setup.py file to point to the location of WinMM.lib and the Microsoft SDK headers.

Compiling python-rtmidi with Windows Kernel Streaming support currently does not work due to syntax errors in RtMidi.cpp. This is currently being investigated. You can exclude Windows Kernel Streaming Support by providing the --no-winks option to the setup.py invocation.

Compiling with MinGW also does not work out-of-the-box yet. If you have any useful hints, please let the author know.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

python-rtmidi-0.3a.zip (90.5 kB view details)

Uploaded Source

python-rtmidi-0.3a.tar.gz (75.8 kB view details)

Uploaded Source

python-rtmidi-0.3a.tar.bz2 (64.4 kB view details)

Uploaded Source

Built Distributions

python_rtmidi-0.3a-py3.3-macosx-10.6-intel.egg (130.4 kB view details)

Uploaded Source

python_rtmidi-0.3a-py2.7-macosx-10.6-intel.egg (130.5 kB view details)

Uploaded Source

python-rtmidi-0.3a.win32-py2.7.exe (246.9 kB view details)

Uploaded Source

File details

Details for the file python-rtmidi-0.3a.zip.

File metadata

  • Download URL: python-rtmidi-0.3a.zip
  • Upload date:
  • Size: 90.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for python-rtmidi-0.3a.zip
Algorithm Hash digest
SHA256 872bae8db2ed3238698a447103bc6a6829cd4d01ed1095c182f7c5904eee52ba
MD5 9152f5eb10abc2dc7fe36f3e48b9ac68
BLAKE2b-256 89a8092ae96a4d124a29cd48ce9e1b41fba9186f0d89576c3c44f13ae443ab56

See more details on using hashes here.

File details

Details for the file python-rtmidi-0.3a.tar.gz.

File metadata

File hashes

Hashes for python-rtmidi-0.3a.tar.gz
Algorithm Hash digest
SHA256 f9dc22a199b9c9062447f114936a8b7b83cf6038a4574e5b9892593061499736
MD5 efca6e3a8c47d600352dbda68b226944
BLAKE2b-256 d0ba8c031916796f84c58c39b6c7129045e8ae7de7eb656e2346209c042c57c5

See more details on using hashes here.

File details

Details for the file python-rtmidi-0.3a.tar.bz2.

File metadata

File hashes

Hashes for python-rtmidi-0.3a.tar.bz2
Algorithm Hash digest
SHA256 73c45a33d287aa3f361366a94e613e59a6bbbc15ca64fca1211bb62f50b247a0
MD5 a80e9ad9dbdc99682deb275cc76c70b4
BLAKE2b-256 3e2731daa92f6235a9a144f7105f7141e6090240cff41b72c418d8e74dcd75c6

See more details on using hashes here.

File details

Details for the file python_rtmidi-0.3a-py3.3-macosx-10.6-intel.egg.

File metadata

File hashes

Hashes for python_rtmidi-0.3a-py3.3-macosx-10.6-intel.egg
Algorithm Hash digest
SHA256 91eb2e2fb153a2b42f06814661ffa3caad7528f3105713df54f46212dabc628b
MD5 16d6aa2cd8c603d960ad21499ce5e66f
BLAKE2b-256 6a999d6ce75b3e5398f1b58f83353366bec12a35676370ed0b8db78a775a6b22

See more details on using hashes here.

File details

Details for the file python_rtmidi-0.3a-py2.7-macosx-10.6-intel.egg.

File metadata

File hashes

Hashes for python_rtmidi-0.3a-py2.7-macosx-10.6-intel.egg
Algorithm Hash digest
SHA256 0087827cb5725e59aa31e856576765591e2e50738cc082c92969e03c07744bb3
MD5 7a350bbcc6f8bd3caac9165531a4215f
BLAKE2b-256 c123c15755d6eb844eac574d47bff597a9468401e2dd42d9108bd1e5f669f262

See more details on using hashes here.

File details

Details for the file python-rtmidi-0.3a.win32-py2.7.exe.

File metadata

File hashes

Hashes for python-rtmidi-0.3a.win32-py2.7.exe
Algorithm Hash digest
SHA256 651eeb70eba38cd1f8ed981db826fae21770c7cc0d435e1c7094c36e462da034
MD5 e9422106b242a29b33c33881a21a9afb
BLAKE2b-256 129d8701e657ad1f2e8319c79e716e2d268df4677d8b79a6c366fb43d31580da

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page