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-0.9.2.tar.gz
(181.5 kB
view hashes)
Built Distributions
rtmidi2-0.9.2-cp39-cp39-win_amd64.whl
(129.0 kB
view hashes)
rtmidi2-0.9.2-cp39-cp39-win32.whl
(112.6 kB
view hashes)
rtmidi2-0.9.2-cp38-cp38-win_amd64.whl
(129.5 kB
view hashes)
rtmidi2-0.9.2-cp38-cp38-win32.whl
(112.9 kB
view hashes)
Close
Hashes for rtmidi2-0.9.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 894459efcd57ee951015f1c06f60117ce0475e1a6dfcf3d477e276fffa8f84c3 |
|
MD5 | 2706542ffd416cf96c9cc9d312a3f0b3 |
|
BLAKE2b-256 | 78f876e50473f49d7d85367897b131b619dd6b2144e78f229e8c04f3d3be30e0 |
Close
Hashes for rtmidi2-0.9.2-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c03e792a38256780e0a33a5ba35c4168ce9858f89556cf0f8f9194af989045a |
|
MD5 | b7128293d2554737227637da535e5602 |
|
BLAKE2b-256 | 4c11705366601b7ae9aea950bb826beac5168e99a9cc166db5e28c872d7b3d8a |
Close
Hashes for rtmidi2-0.9.2-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be5b9f39ee0d6a73b1d41797edd41a279cb2f183e30acdecb337ffe997e6eb54 |
|
MD5 | af75af4e657a87617885c62ec53fb265 |
|
BLAKE2b-256 | 3ffc1d721582f3eb85a5d3a290598c99fa9134a3a8eb3db35e92249c0180cd3e |
Close
Hashes for rtmidi2-0.9.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | acfc9ae7c62391aeee1b03af58f0b4c526a3359ba76399bf87140dd0e27d0aa5 |
|
MD5 | 228fe389205b1e9598ea02fcecaa806b |
|
BLAKE2b-256 | e0337146eee168d7d0366adb4d57376bccb6912a23d2d0b82e1f7c184c4ffabe |
Close
Hashes for rtmidi2-0.9.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03e7156812395128d2a2ca2bed1f24464518b67ce8316ea2fd18955bc0e12966 |
|
MD5 | e3d012d7ee5fb6952bf76d8605340d8a |
|
BLAKE2b-256 | aab4243620c187371ab4b1f092b7f6f32a81cee878251da96a0f42f8da62ee1f |
Close
Hashes for rtmidi2-0.9.2-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a853aa25d7dc427365f7d981fd26d752a024783c9c34fe0e8b42074948e29c53 |
|
MD5 | 19da6199c13ab0e4c311d1b2d75c3c09 |
|
BLAKE2b-256 | 9d066d5518df3e0e3eeaec62fe53cc95117ce29c457786878918cf4a2b53479c |
Close
Hashes for rtmidi2-0.9.2-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ae0ddbecbfea5b2799576fdf1cfbeb5243bd6cae7331ceee41e9a6f8ce847de |
|
MD5 | 11f551a116b748328d97cfab3f38b1d4 |
|
BLAKE2b-256 | 53dbab7814963cbe5a681db52367f2c3169562d95fa4b977c85174c07dd7323d |
Close
Hashes for rtmidi2-0.9.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1632ff46a97b4934d04d70e4a162e58c59755d2489df1fbeb9fc3ca1c38e4e72 |
|
MD5 | 620fb4e76dc6407816d7eb0d9bcb4600 |
|
BLAKE2b-256 | 46804468edfb12a28b0fd60e73a2ea3338fe56f608d7c67d7efa3325ba673df8 |