Skip to main content

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


Download files

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

Source Distribution

supriya_midi-26.4b0.tar.gz (76.1 kB view details)

Uploaded Source

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

Hashes for supriya_midi-26.4b0.tar.gz
Algorithm Hash digest
SHA256 f900e0c6653c39365b0f17a469701a3f19dd2624e9d70452b8e27123739698af
MD5 c08146c122016611552a1065337f873f
BLAKE2b-256 c5d105eb01135da1e234c209b8598f46741c6550c82060c2e5b152a66000645a

See more details on using hashes here.

Provenance

The following attestation bundles were made for supriya_midi-26.4b0.tar.gz:

Publisher: publish.yaml on supriya-project/supriya-midi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page