[Lancaster] fun and games with udev

andy baxter andy at earthsong.free-online.co.uk
Sat Oct 17 19:23:47 UTC 2009


I've just been trying to get my midi keyboard to automatically start up 
fluidsynth (a soft synth) when it's plugged in. You can do stuff like 
this by writing rules in files you add to /etc/udev/rules.d. It took me 
about 2 hours to work out the right way of firing a rule when a device 
is removed, so in case anyone else has had trouble with this, here are 
the rules I used:

whale:/usr/local/bin# whale:/etc/udev/rules.d# cat 85-fluidsynth-midi.rules
ACTION=="add", ATTR{manufacturer}=="EDIROL", ATTR{product}=="PCR", 
ENV{edirolmidi}="true", RUN+="/usr/local/bin/fluidrun"
ACTION=="remove", ENV{edirolmidi}=="true", RUN+="/usr/local/bin/fluidrun"

The trick is the 'ENV{edirolmidi}="true"' part - this sets a variable in 
the device's environment which can then be detected by the 'remove' rule.

The script it calls is:

whale:/usr/local/bin# cat fluidrun
#!/bin/bash
#
# fluidrun - start fluidsynth and attach to midi keyboard.
#

if [ "$ACTION" == "add" ] ; then
  start-stop-daemon --start -b -c fluidsynth -x /usr/local/bin/fluidstart
elif [ "$ACTION" == "remove" ] ; then
  pkill fluidsynth
fi


andy



More information about the Lancaster mailing list