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.3.tar.gz
(181.9 kB
view hashes)
Built Distributions
rtmidi2-0.9.3-cp39-cp39-win_amd64.whl
(130.1 kB
view hashes)
rtmidi2-0.9.3-cp39-cp39-win32.whl
(113.0 kB
view hashes)
rtmidi2-0.9.3-cp38-cp38-win_amd64.whl
(130.4 kB
view hashes)
rtmidi2-0.9.3-cp38-cp38-win32.whl
(113.0 kB
view hashes)
Close
Hashes for rtmidi2-0.9.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7df4cc322100b7be87b51bc8fb7b82dbd042c57bca81be8bf90e45420c2fa33 |
|
MD5 | fe19e34e294e0d8299926d35c0152c0f |
|
BLAKE2b-256 | c6342ded7a6f4626eef51de7b8d98131349d81dcf404eae490d4bf3b9ec64c6e |
Close
Hashes for rtmidi2-0.9.3-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6935204884d53a21f6bd95ff8ad8da0d2068a6c9a9b3882e175167cf9cdfa327 |
|
MD5 | 3d4682f25df51ea187ffaffc782913d0 |
|
BLAKE2b-256 | 5030e4df10716395e35e92f9ee0e12e74536cd1577a93fccf968c6b39e387598 |
Close
Hashes for rtmidi2-0.9.3-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6ac217ed6ccd25621ea14a3572d8ea55917fdb8defc104e42b1926baac409f1 |
|
MD5 | 8d35cc68151aba97a73e736bdbd354cc |
|
BLAKE2b-256 | f5c17cd10e13aecc8d4c9f268ec05d692b2ba99d6ac95810e1ab061f3be552a0 |
Close
Hashes for rtmidi2-0.9.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cb9a3a71d75d21c89588ddaf3a13ac1ea92d6cc24978f17336f338b3ec4eeab |
|
MD5 | f61863b017996c764493ef98da0a4390 |
|
BLAKE2b-256 | fc79965bb0c3f408484c3a8d3faf1a494003e7e0364a431a959714500cb62dd4 |
Close
Hashes for rtmidi2-0.9.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31b1045ed86b6d6786315499c3dee44484721b46b0be21bca3f3847bc784210b |
|
MD5 | 8cada80231d48f9ca96072bfc2df7ca3 |
|
BLAKE2b-256 | fcca136ab4a5836996beed0e1889d7405e52b4bf7f34924ee8275a02347201e7 |
Close
Hashes for rtmidi2-0.9.3-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 615355c3e5e328230c93fef6d100ff19d94e4d250db02ca4828716e0e47269da |
|
MD5 | 5105202bc954e1281c014aed9f1b0511 |
|
BLAKE2b-256 | 7bc22f33ab385a2d760d27a311a3005eecd1730aed6032cf20ae1790280b0a79 |
Close
Hashes for rtmidi2-0.9.3-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47249a4bc9a25eb31f4692b09b79f092d060a1c28e6a0d08ebe96b35c5a6a647 |
|
MD5 | d671e134e14c1b77ce09f01f1c507cf8 |
|
BLAKE2b-256 | 3fe6bdd7999d28b9b7db4f0fdbae5221b527564989184a75259b375a7178c859 |
Close
Hashes for rtmidi2-0.9.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3b18fb7f35b6299f305e0d634cafc9179c163b2ad11da9bfc623ab267706d05 |
|
MD5 | 833fa983410697c40b1a5373be91aa00 |
|
BLAKE2b-256 | 2c838370473c204104d2cfd2ebdeb7dfa7ad538f510fd0a412e59e3adaada2a6 |