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 or 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.

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.1a.tar.gz
$ tar xzf python-rtmidi-0.1a.tar.gz
$ cd python-rtmidi-0.1a
$ 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. On debian-based Linux systems, installing the build-essential package should get you this, on Mac OS X install the latest Xcode or g++ from MacPorts or homebrew. On Windows you can use MinGW.

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.

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. Currently this version is only available via the Git respository (see Cython web site) as version 0.17pre. The rtmidi.cpp file in the source distribution was compiled with Cython 0.17pre as of 2012-07-13.

RtMidi (and therefore python-rtmidi) supports several low-level MIDI libraries on different operating systems. Only one of the available options needs to present on the target system, but support for more than one can be compiled in.

  • Linux: ALSA, JACK

  • OS X: CoreMIDI, JACK

  • Windows: MultiMedia (MM), Windows Kernel Streaming

On Linux, 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).

On OS X, CoreMIDI support comes with installing Xcode. For JACK support, install JACK for OS X from http://www.jackosx.com/ with the full installer.

On Windows, you’ll need winmm.dll for Windows MultiMedia System support and you’ll need to edit the WINLIB_DIR variable in the setup.py file to point to the location of this DLL. Support for compiling python-rtmidi with Windows Kernel Streaming is currently not provided by the setup file. Patches are welcome.

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.1a.zip (76.6 kB view details)

Uploaded Source

python-rtmidi-0.1a.tar.bz2 (57.3 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for python-rtmidi-0.1a.zip
Algorithm Hash digest
SHA256 f6bf60ec5b4a59d67c8293939f3ecd80331fa41b7b9ae577369e82a4b6a87caf
MD5 c0a12cdd150260dad02c4f2ccd6f18eb
BLAKE2b-256 a920018fa27e16827f89ea0087ff3ebdd4da2b2d8367b29b1aecff366f06f205

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python-rtmidi-0.1a.tar.bz2
Algorithm Hash digest
SHA256 cd514d1cafc0ac664dc33da1ac44ff0416b434b50241492d6c39ffd6d341adc6
MD5 4b0e155a0b9554ad89e130d123464089
BLAKE2b-256 a9a7a5b2a1335203b483b42151b1630784cda8cdc7e0e9ea987b7b130245ad2b

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