Python wrapper for RtMidi written in Cython. Allows sending raw messages, multi-port input and sending multiple messages in one call.
Project description
Python wrapper for RtMidi, the lightweight, cross-platform MIDI I/O library. For Linux, Mac OS X and Windows.
Based on rtmidi-python
Installation
pip install rtmidi2
This module is compatible with Python 3 >= 3.7
Documentation
Usage Examples
rtmidi2 uses a very similar API as RtMidi
Print all in and out ports
import rtmidi2
print(rtmidi2.get_in_ports())
print(rtmidi2.get_out_ports())
Send messages
import rtmidi2
midi_out = rtmidi2.MidiOut()
# open the first available port
midi_out.open_port(0)
# send C3 with vel. 100 on channel 1
midi_out.send_noteon(0, 48, 100)
Get incoming messages - blocking interface
midi_in = rtmidi.MidiIn()
midi_in.open_port(0)
while True:
message, delta_time = midi_in.get_message() # will block until a message is available
if message:
print(message, delta_time)
Get incoming messages using a callback – non blocking
def callback(message, time_stamp):
print(message, time_stamp)
midi_in = rtmidi2.MidiIn()
midi_in.callback = callback
midi_in.open_port(0)
Open multiple ports at once
# get messages from all available ports
midi_in = MidiInMulti()
midi_in.open_ports("*")
def callback(msg, timestamp):
msgtype, channel = splitchannel(msg[0])
print(msgtype2str(msgtype), msg[1], msg[2])
midi_in.callback = callback
You can also get the device which generated the event by changing your callback to:
def callback(src, msg, timestamp):
# src will hold the name of the device
print("got message from", src)
Send multiple notes at once
# send a cluster of ALL notes with a duration of 1 second
midi_out = MidiOut()
midi_out.open_port()
notes = range(127)
velocities = [90] * len(notes)
midi_out.send_noteon_many(0, notes, velocities)
time.sleep(1)
midi_out.send_noteon_many(0, notes, [0] * len(notes))
License
rtmidi2 is licensed under the MIT License, see LICENSE.
It uses RtMidi, licensed under a modified MIT License, see RtMidi/RtMidi.h.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rtmidi2-1.1.1.tar.gz
(183.2 kB
view hashes)
Built Distributions
rtmidi2-1.1.1-cp310-cp310-win32.whl
(103.1 kB
view hashes)
rtmidi2-1.1.1-cp39-cp39-win_amd64.whl
(118.7 kB
view hashes)
rtmidi2-1.1.1-cp39-cp39-win32.whl
(105.3 kB
view hashes)
rtmidi2-1.1.1-cp38-cp38-win_amd64.whl
(118.7 kB
view hashes)
rtmidi2-1.1.1-cp38-cp38-win32.whl
(105.2 kB
view hashes)
Close
Hashes for rtmidi2-1.1.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed1b292bb52563f764ef42905f68eed358447d934975e0898f89363d85792adb |
|
MD5 | 91d8a90701855320de406c428073de92 |
|
BLAKE2b-256 | 6217732548bd4ac819cf3a8f35d831577096625d7a9ba3feaa6f028a7db0473b |
Close
Hashes for rtmidi2-1.1.1-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 020ff7de3d6cbfaae61f8dd998807b6e3c4e87a24cc1828d3b5659264ef8b94a |
|
MD5 | ff1607fc0f21de7ff13ceadeff10d538 |
|
BLAKE2b-256 | 8513c4b50c838ea8dfe2260a381ce06eb590eebe0891e2aecf0ecd45f5f1362d |
Close
Hashes for rtmidi2-1.1.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6128f2f337e4be7ad544a7262d4b9cbebf19051553743575da054ef96163826 |
|
MD5 | 6cfa356bbd7baf32fc74c1ad1963c0ab |
|
BLAKE2b-256 | 3cffc10e169cf72d4844d1e00327d9f552c075cae186da12fc0c4865bed9e00e |
Close
Hashes for rtmidi2-1.1.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b150d4063957b10443805e1778169e24b4b06e6f83e120e08a43b7be7cf0932e |
|
MD5 | 7126893b2f8dcfc57014a8d24b351904 |
|
BLAKE2b-256 | e6da9e6fed010cf5f67a7aeb06fea897f51c01921c8cffada65b8273ddeb28e4 |
Close
Hashes for rtmidi2-1.1.1-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da5e45c4e82d55cae79bfde2cac6c1d54368ab3b7a6bb9a331243dafaa0e0a32 |
|
MD5 | c25a48cde531463fd46ebad6b6d9ef53 |
|
BLAKE2b-256 | 10267c5c3e346a389a3460fc3b4b9e66b8c4a55f86bb7253738070532072d93d |
Close
Hashes for rtmidi2-1.1.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b8618c4a33126eddbffa41197b84e8b2b76718a7f424bb921d45c82de5f4288 |
|
MD5 | 9bab11c697090c4e4caa8cc6b0a36ca6 |
|
BLAKE2b-256 | 68cbaf13e3de6f9d3d48cf01d4ba22690ef1cb2a6b6baf37615ad17c93d37f7f |
Close
Hashes for rtmidi2-1.1.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5393620f6aaad93e189b6683d936434543f1596464be6fac5cdf325bd4bf19e |
|
MD5 | 6f01a4f82d90be4fe549b64afcf9f620 |
|
BLAKE2b-256 | dc992432b285f72cbeaacdce4040a34da2fea9955639f6e14508b705a377cd8a |
Close
Hashes for rtmidi2-1.1.1-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 817610b3777f27cd8541ff21f39e74a42485470021614f6d05eb63684ceaaedc |
|
MD5 | 6549124fea988f44c492d03d0bf3fe33 |
|
BLAKE2b-256 | 73d70fe86627efb13183808225644531c6db45639ac7f27eefc462de81324ac0 |
Close
Hashes for rtmidi2-1.1.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b97b93502d71279b7a966e41583b9b24041fad5629ce0bd16b1bff7761d1f38b |
|
MD5 | 7b24ceec1b97e05057363d7146701c0c |
|
BLAKE2b-256 | 4301992d4c9d70a44f79b230557356d14d8856bba0ce1b2a5f481d6c58572588 |