Python RTMidi Bindings
Project description
supriya-midi
Supriya MIDI is a nanobind-based Python binding for the C++ RtMidi library, providing a simple cross-platform API for realtime MIDI input and output.
This library is heavily inspired by the venerable python-rtmidi library, which, at the time of this writing, hasn't seen a release in a number of years. I started this library so that I could have pre-compiled binary wheels for Python 3.13+.
I've tried to keep this library's API very close to its inspiration's, but there are some minor differences:
- Supriya MIDI uses integer enums for the API and error type constants.
- Supriya MIDI's MIDI message callback takes three arguments (message, timestamp, data) vs python-rtmidi's two argument callback (message/timestamp pair, data).
- Supriya MIDI has a single custom exception class vs python-rtmidi's variety of exceptions.
Most code that works with python-rtmidi should be easily adaptable to Supriya MIDI.
Installation
Via pip:
pip install supriya-midi
Usage
Open an output port and send MIDI messages to it:
import time
from supriya_midi import MidiOut
midi_out = MidiOut()
if midi_out.get_ports():
midi_out.open_port(0)
else:
midi_out.open_virtual_port("My virtual output")
with midi_out:
note_on = [0x90, 60, 112] # channel 1, middle C, velocity 112
note_off = [0x80, 60, 0]
midi_out.send_message(note_on)
time.sleep(0.5)
midi_out.send_message(note_off)
time.sleep(0.1)
del midi_out
Open an input port and handle incoming MIDI messages with a custom callback:
from supriya_midi import MidiIn
def callback(message, timestamp, data=None):
print(f"Received {message=}")
midi_in = MidiIn()
midi_in.set_callback(callback)
if midi_in.get_ports():
midi_in.open_port(0)
else:
midi_in.open_virtual_port("My virtual output")
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
File details
Details for the file supriya_midi-26.4b0.tar.gz.
File metadata
- Download URL: supriya_midi-26.4b0.tar.gz
- Upload date:
- Size: 76.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f900e0c6653c39365b0f17a469701a3f19dd2624e9d70452b8e27123739698af
|
|
| MD5 |
c08146c122016611552a1065337f873f
|
|
| BLAKE2b-256 |
c5d105eb01135da1e234c209b8598f46741c6550c82060c2e5b152a66000645a
|
Provenance
The following attestation bundles were made for supriya_midi-26.4b0.tar.gz:
Publisher:
publish.yaml on supriya-project/supriya-midi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
supriya_midi-26.4b0.tar.gz -
Subject digest:
f900e0c6653c39365b0f17a469701a3f19dd2624e9d70452b8e27123739698af - Sigstore transparency entry: 1339402788
- Sigstore integration time:
-
Permalink:
supriya-project/supriya-midi@064312a9e210850e153e76e710071c554b368543 -
Branch / Tag:
refs/tags/v26.4b0 - Owner: https://github.com/supriya-project
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@064312a9e210850e153e76e710071c554b368543 -
Trigger Event:
release
-
Statement type: