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.0.0.tar.gz
(182.6 kB
view hashes)
Built Distributions
rtmidi2-1.0.0-cp310-cp310-win32.whl
(104.9 kB
view hashes)
rtmidi2-1.0.0-cp39-cp39-win_amd64.whl
(117.7 kB
view hashes)
rtmidi2-1.0.0-cp39-cp39-win32.whl
(104.8 kB
view hashes)
rtmidi2-1.0.0-cp38-cp38-win_amd64.whl
(117.8 kB
view hashes)
rtmidi2-1.0.0-cp38-cp38-win32.whl
(104.7 kB
view hashes)
Close
Hashes for rtmidi2-1.0.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed15e57ecf9d76ad85265efef83115fe1c2da88e7397113d8957b3d92bd40a9b |
|
MD5 | a60c3d25e5ab923c242542869702f28d |
|
BLAKE2b-256 | c21f38e2cbf336ea6662e01a25fc3e510d27d3b8dd60fe4bd4d5c45bb7c3a719 |
Close
Hashes for rtmidi2-1.0.0-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41921f35781e477d7c49e3a36a807e13b25517d3b093ec076b0eaf42eb66ef3d |
|
MD5 | 077c5b7ffbd3c4a2e12467630d8212eb |
|
BLAKE2b-256 | fe3e8920b6109cc67cacfd0ec375d1da071f619a8932cecb1dc736e1aacdce57 |
Close
Hashes for rtmidi2-1.0.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | baef6585495785cb4bc4f6a8c98ef41716141d06d8f3e9a2a334ec5f7d36e46e |
|
MD5 | 58efcbeb2e9f449d7f4e30ce59b8d3b8 |
|
BLAKE2b-256 | 9dc5397b06e8ba1d43d61b434c1d432241158c539319a00c7ce787296fcf6cd7 |
Close
Hashes for rtmidi2-1.0.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f986d53b65f0f6e06e97f646e776b0017c2509b97592c727d7fbd2bfd84354e9 |
|
MD5 | c98f4bbc211b1243c4e17531a82db504 |
|
BLAKE2b-256 | 1a7e4e61d304c3baa2317ca31e4f4f83c1b9c3a3fba9092d755322d70b91b751 |
Close
Hashes for rtmidi2-1.0.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9279d89eafcf963f03f0f516351a5fdf3a489c29a0aa79f7889c39e4252df476 |
|
MD5 | 2f80b56ba6e9bf33a71d21f493d57325 |
|
BLAKE2b-256 | 76d25c4448e2c1e531d0c3cea986afd6a4a1c826145411964381a008373104c9 |
Close
Hashes for rtmidi2-1.0.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 160dda56b95201fa3237b07c35aedfb25d6d8b0cd93ab4f07de76bf1199099b1 |
|
MD5 | 02358ee8ddd542c50cb31261a728e4f8 |
|
BLAKE2b-256 | d9b0a7bc7edf954de414c51474f6084eb8e5f1f02c53ab413fa86c4bbad31899 |
Close
Hashes for rtmidi2-1.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2586b1565cda4c39423e9122932a848819f54d5ba0d0d25440cb161517537888 |
|
MD5 | 62a5ee87df81a1e9a5a321f8a2c17643 |
|
BLAKE2b-256 | ffd1ef953571b104da74cb4615d57b48d4ddc81e2c771b6f8ac82d41976c53e3 |
Close
Hashes for rtmidi2-1.0.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b278d6073d1646a5b758cf4fadb2b70ea57fa34a390806ec438b994ccc9263a |
|
MD5 | 31bac71c025c1ac055f221abb6d5eeee |
|
BLAKE2b-256 | 1bc2e1e8c2a0046c9b8faef9bf0129f41a710b1066ccc643faca711edbaf322d |
Close
Hashes for rtmidi2-1.0.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 943066fbcfd1563396d00158a4924732f1c793169c3254ba5bc9b38f101881b5 |
|
MD5 | e52a48c1bc34755334bec0257320b973 |
|
BLAKE2b-256 | ea38fe91aba3421597be5df93f95585023941e268fc1bc8f9da15da1d0a3a16f |