tmidi
MIDI library for CircuitPython
Author(s): Tod Kurt, with code from Alethea Flowers for Winterbloom
Portions of this library come from Winterbloom_SmolMIDI: https://github.com/wntrblm/Winterbloom_SmolMIDI
Hardware:
Native USB for USB MIDI
UART for Serial MIDI
PIO-USB or MAX3421E USB Host for USB Host MIDI
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
Active Sensing
Aftertouch
BUS Select
Channel Pressure
Clock
Continue
Controller Change
MIDI Parser, receiver and sender midi_in
or midi_out
must be set or both together.
midi_in – an object which implements read(length)
, set to usb_midi.ports[0]
for USB MIDI, default None.
midi_out – an object which implements write(buffer, length)
, set to usb_midi.ports[1]
for USB MIDI, default None.
enable_running_status (bool) – Allow running status messages to work, default False.
Example of sending MIDI over USB:
import usb_midi import tmidi midi_usb = tmidi.MIDI(midi_out=usb_midi.ports[1]) msg_on = tmidi.Message(tmidi.NOTE_ON, notenum, velocity) midi_usb.send(msg_on)
Example of sending MIDI over UART (TRS or 5-pin):
import board import busio import tmidi uart = busio.UART(tx=board.TX, rx=board.RX, timeout=0.001) midi_uart = tmidi.MIDI(midi_out=uart) msg_on = tmidi.Message(tmidi.NOTE_ON, notenum, velocity) midi_uart.send(msg_on)
Example of receiving MIDI:
import board import busio import usb_midi import tmidi uart = busio.UART(tx=board.TX, rx=board.RX, timeout=0.001) midi_uart = tmidi.MIDI(midi_in=uart, midi_out=uart) midi_usb = tmidi.MIDI(midi_in=usb_midi.ports[0], midi_out=usb_midi.ports[1]) while True: if msg := midi_usb.receive(): print("usb midi:", msg) if msg := midi_uart.receive(): print("uart midi:", msg)
Number of errors encountered when parsing received messages
Read message from MIDI port, parse that data and return the first MIDI message (event). This maintains the blocking characteristics of the midi_in port. Relies on the port to buffer the incoming unread MIDI messages.
Returns object or None for nothing.
Send a MIDI message.
msg – Either a Message object or a sequence (list) of Message objects. The channel property will be updated as a side-effect of sending message(s).
channel (int) – Channel number, if not set, the msg’s channel will be used.
MIDI Message.
mtype – The type of message, e.g. tmidi.NOTE_ON.
data0 – The first data byte for this message, e.g. the note number as an int
(0-127) for NOTE_ON messages.
data1 – The second data byte for this message, e.g. the velocity (0-127) for NOTE_ON messages.
channel – The MIDI channel for this message, if applicable (0-15)
Example of creating Messages:
# create Note On middle-C message on ch 1 (0-indexed) m = Message(tmidi.NOTE_ON, 60, 127, channel=0) # create CC 74 with val 63 on ch 4 m = Message(tmidi.CC, 74, 63, channel=4-1) # create a pitch bend full up on ch 1 m = Message(tmidi.PITCH_BEND, 8191)
Example of creating accessing Message attributes:
if msg := midi.receive(): if msg.type == tmidi.NOTE_ON: print("note on:", msg.note, msg.velocity) elif msg.type == tmidi.NOTE_OFF: print("note off:", msg.note, msg.velocity) elif msg.type == tmidi.PROGRAM_CHANGE: print("program change:", msg.value)
MIDI note number of message (only valid for NOTE_ON/NOTE_OFF msgs)
Pitch bend value of message (only valid for PITCH_BEND msgs)
Message value, only valid for len1 messages (Program Change, etc)
MIDI velocity of message (only valid for NOTE_ON/NOTE_OFF msgs)
Note Off
Note On
Pitch Bend
Program Change
Song Position
Song Select
Start
Stop
Sysex End
Sysex
System Reset
Tick
Tune Request
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4