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.0.tar.gz
(183.1 kB
view hashes)
Built Distributions
rtmidi2-1.1.0-cp310-cp310-win32.whl
(104.9 kB
view hashes)
rtmidi2-1.1.0-cp39-cp39-win_amd64.whl
(117.7 kB
view hashes)
rtmidi2-1.1.0-cp39-cp39-win32.whl
(104.8 kB
view hashes)
rtmidi2-1.1.0-cp38-cp38-win_amd64.whl
(117.8 kB
view hashes)
rtmidi2-1.1.0-cp38-cp38-win32.whl
(104.7 kB
view hashes)
Close
Hashes for rtmidi2-1.1.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14daba37ade9f0f887752b004e1620e071ab451974be3623757b60c43cae0dbc |
|
MD5 | 568a2b4ca8f34aa93266bc5e03a032c0 |
|
BLAKE2b-256 | 7d0552eb98c4d76e36130d721a1c1a6d13394580df57fc88b95a6608276de7bb |
Close
Hashes for rtmidi2-1.1.0-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 888fa75937dd5509c49628625d5d4195b0bb83ff7277a4b2b4aee4f6501aa136 |
|
MD5 | b6aac546477888ad019379b4b9d857bc |
|
BLAKE2b-256 | 323e14c6695cfb7fedf365fcd30ac531803d2e6da623da14b09517f14192d164 |
Close
Hashes for rtmidi2-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 655d2d00535dd0b5bb6b33e9c4197a784beb0ff9d5c6bb57925414502e0b3f8f |
|
MD5 | 79c403c98e30a2d0f29e08c012c67de7 |
|
BLAKE2b-256 | 1de572a9d7af326aa6c345cb45e1733cce57aebe115163cf8de3e84d2530ac85 |
Close
Hashes for rtmidi2-1.1.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1188f506d90ea6046a772ac36ebc5fbfc217b02ac25487fcff6f1ea07f73b7f |
|
MD5 | de671ea05f532048aab02bc0fdcec91a |
|
BLAKE2b-256 | cd0c28735c1119e7c836949884d05d2d2d2811686328e0f2c30ad6a88affea88 |
Close
Hashes for rtmidi2-1.1.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ede9ea0db7966566ec83d37efeb1ea69ec5326869e30e0d330166162ea895e57 |
|
MD5 | 18cde867862aedc16b5c117d7c34f8ff |
|
BLAKE2b-256 | 5c2f7d13e09a3b1132f1b164a12d8bb457f6057add89a5fdde15b62ec316c6d1 |
Close
Hashes for rtmidi2-1.1.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebaffb6663c3f36490c54786d29d0fc6bcdf0bf05b9a2279b719f16c3d7b3057 |
|
MD5 | a1d4722c5d9f3d0abda6b505127364c0 |
|
BLAKE2b-256 | 503dfb1eda59ca54bdba567210a6eccaea9990b1379f9bd91d8d4b92e45eb0a5 |
Close
Hashes for rtmidi2-1.1.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd74765d7cd8c5b3932ba0cdf51951bf12b8acad03d2f547f5bccfbd65b07974 |
|
MD5 | 45b73bafbd2f3bb72c65b4d9f5152917 |
|
BLAKE2b-256 | a6a2fc5f3293464d9e7f48100c90c119fe04ae2db39e561fd88eb48ea4143b1f |
Close
Hashes for rtmidi2-1.1.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a1fefb6483bb2ce8a5713930dad544c509c2e8f07a8a6df21c9b0c567ae86ec |
|
MD5 | 188835642bbdb9065a7e75acdbf38de5 |
|
BLAKE2b-256 | f4c8bd2c7a7f03557a211d124a74339c8064e3bbf8a0f5ac3bb5ddcf84505e47 |
Close
Hashes for rtmidi2-1.1.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70cb18001d06fec0a3b4eebafb7bae8c1e155f4b464213d138b2740cd57867da |
|
MD5 | 30bf276a00aeb39c8331c74886b184ee |
|
BLAKE2b-256 | 9a951769c9485965fa7bb05156bc21518ef982d93961cdc4f3a2a2ecb2c246ee |