Skip to main content

midi-udev

Run commands when a midi device connects on linux (alsa).

This is unreviewed AI-generated code.

Motivation

I wanted use fluid-synth with an autio

Alternatives and prior work

udev-cli (also mine) reacts to udev events. Here we need to wait until alsa has detected the device before connecting it. You could use a udev rules, but I have had difficulty debugging these.

It would be fairly simple to code this useful, either by connecting to udev (with some retry logic for races) or with with an alsa client.

aseqdump -p 0:1 prints the raw ALSA announce events this is built on.

Apparently, amidiminder keeps ALSA connections according to rules. Good if all you want is connections, but it doesn't run commands.

I wrote a tool called midi-exec which responds to midi events such as key presses and runs commands.

Installation

pipx install midi-udev

Needs aseqdump and aconnect (alsa-utils).

Usage

To print all MIDI clients coming and going as JSONL use: midi-udev. For hardware devices only use midi-udev -k. Clients whose name contains "keystation", including ones already plugged in: midi-udev -e -n keystation

To run a comand (the event JSON is appended as the last argument) use midi-udev -e -k -n keystation --run ./piano-handl@Ier

Events look like:

{"action": "add", "client": 24, "name": "USB Keystation 88es", "type": "kernel", "pid": null, "ports": [{"port": 0, "name": "USB Keystation 88es MIDI 1", "address": "24:0"}]}

About

I am @readwith. I am making tools for reading and agency with and without AI. I also make a lot of small tools related to productivity. If this tool is useful you might like follow me on github or X.

Metadata

Release files for midi-udev 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for midi-udev 0.1.0
File Size Uploaded
midi_udev-0.1.0.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for midi-udev 0.1.0
File Interpreter ABI Platform
midi_udev-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.8 kB

Release files / midi_udev-0.1.0.tar.gz

Download URL midi_udev-0.1.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5349bfe2df8ba5f2f354283fda58897a24445f345fb7cbd0a6c16ad6f8581cb6
BLAKE2b-256 checksum
How to use checksums
6ec14c8978a37323fe2b586544a5b0f6ca9e87900a6dbf7ed59301642a5220c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / midi_udev-0.1.0-py3-none-any.whl

Download URL midi_udev-0.1.0-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f712dc1d6a879061ffc88326093992a7dd646920a09295985f83ef7235aaf80
BLAKE2b-256 checksum
How to use checksums
6c9fd58ad9434daa3cb15fd460faa0c94cd419914965eede087434397ae936c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page