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.3.1a.tar.gz
$ tar xzf python-rtmidi-0.3.1a.tar.gz
$ cd python-rtmidi-0.3.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. 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.3.1a.zip (90.7 kB view details)

Uploaded Source

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

Uploaded Source

python-rtmidi-0.3.1a.tar.bz2 (64.6 kB view details)

Uploaded Source

Built Distributions

python-rtmidi-0.3.1a.win32-py3.3.exe (244.4 kB view details)

Uploaded Source

python-rtmidi-0.3.1a.win32-py3.2.exe (246.5 kB view details)

Uploaded Source

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

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for python-rtmidi-0.3.1a.zip
Algorithm Hash digest
SHA256 a514a5fcb3379d005e9215c9c6cd0c5b8c793c49475d4d52b4fbeb5b297493a0
MD5 d1bfa796c1e7f4a9405bd2a76206c1ef
BLAKE2b-256 7de4429bb49a81d2536b9af215add687b49bae44d856b477d5facd336aff6bce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python-rtmidi-0.3.1a.tar.gz
Algorithm Hash digest
SHA256 5f86e4676a8ce748df92a5cfbbaabee76755b540f778cdfa6f04e4c60932d857
MD5 df03477797814de2ae63f6e8fec8d0df
BLAKE2b-256 2f6fb3aab882d8f8d177c7189f3be704952e45375ef66afb1ee912da2633e77a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python-rtmidi-0.3.1a.tar.bz2
Algorithm Hash digest
SHA256 a23040a869cb5b3c0e2e76e643704e7baede85ac8b5c102dd22c5741d94ad0da
MD5 6f4f162b24d2eefcb80a2359a844a988
BLAKE2b-256 22cb6c4b7daa2d7c7251eb8c3c50e3978d732a280431b5a6da0c5ed244bb9ae4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rtmidi-0.3.1a-py3.3-macosx-10.6-intel.egg
Algorithm Hash digest
SHA256 acb1d9849b59ef4f09c3a714d088e46af05dc8e257d69e435b0d9a307d69e45a
MD5 220250359a42188031e4cf01e122a102
BLAKE2b-256 457b4cfca608b0f5b3c00c1d7d1d13b5741043a62d28b967c02f66a3025ebaf7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_rtmidi-0.3.1a-py2.7-macosx-10.6-intel.egg
Algorithm Hash digest
SHA256 7bc73155dd3362138f2167bf85d4008928b975a863f296cf4d2f1d000dbd3962
MD5 b64b6aa353e674e114fe8e98689320ee
BLAKE2b-256 e42698d45704d9c0243a2f1aef5c63127dfe99f382acefff158ea51de9130e44

See more details on using hashes here.

File details

Details for the file python-rtmidi-0.3.1a.win32-py3.3.exe.

File metadata

File hashes

Hashes for python-rtmidi-0.3.1a.win32-py3.3.exe
Algorithm Hash digest
SHA256 8a57ab7427729c695cd6bc5c779a274e8cbe50b13ad76f855ce330d171df545e
MD5 a9adbe0725a4d88be1294013164643cd
BLAKE2b-256 3bb5604a5e5167e73737ecf25cf11537d178bc4f73714cdf8695ee32483ac6f9

See more details on using hashes here.

File details

Details for the file python-rtmidi-0.3.1a.win32-py3.2.exe.

File metadata

File hashes

Hashes for python-rtmidi-0.3.1a.win32-py3.2.exe
Algorithm Hash digest
SHA256 03aae7ee21ef18d38498e50ca9ca98d6078995b2f3a9f262cad7c43d52b1ef56
MD5 9aa8be391eec7ca8ec6a86c0c79f5560
BLAKE2b-256 ddfe1353f6d58d5f939d6d7831057ceed5fa5625e837edc32ce9ccfde86560b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python-rtmidi-0.3.1a.win32-py2.7.exe
Algorithm Hash digest
SHA256 77cd6a1d9e25d27aa03a167166a5873fc7461ab5c5a1a16e39f1b783f740acf2
MD5 44a426071b187bc345b0c8ec8d2a0c4d
BLAKE2b-256 c64039670b28a719cbbe1586494f00638d4307aa3abddd1d0d8cd78ec8facc78

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