Metadata-Version: 2.4
Name: midi-udev
Version: 0.1.0
Summary: Print, filter, and react to ALSA MIDI devices appearing and disappearing as JSON
Author: readwithai
License-Expression: MIT
Project-URL: Homepage, https://github.com/talwrii/midi-udev
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Multimedia :: Sound/Audio :: MIDI
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# 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.

## Related tools
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](https://github.com/talwrii) or [X](https://x.com/readwithai).
