Skip to main content

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


Usage Examples

rtmidi2 uses a very similar API as RtMidi

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for rtmidi2, version 0.9.3
Filename, size File type Python version Upload date Hashes
Filename, size rtmidi2-0.9.3-cp38-cp38-macosx_10_9_x86_64.whl (158.5 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size rtmidi2-0.9.3-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.4 MB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size rtmidi2-0.9.3-cp38-cp38-win32.whl (113.0 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size rtmidi2-0.9.3-cp38-cp38-win_amd64.whl (130.4 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size rtmidi2-0.9.3-cp39-cp39-macosx_10_9_x86_64.whl (159.6 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size rtmidi2-0.9.3-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.3 MB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size rtmidi2-0.9.3-cp39-cp39-win32.whl (113.0 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size rtmidi2-0.9.3-cp39-cp39-win_amd64.whl (130.1 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size rtmidi2-0.9.3.tar.gz (181.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page