Controlling GIMP with MIDI devices
Since version 2.2, GIMP comes with a module that allows to control it using MIDI devices. Currently this is only supported on GNU/Linux with either the OSS or the ALSA sound drivers. It might work on other platforms as well if there is a way to access the raw MIDI stream by opening a device.
Enabling the MIDI Module
To make the UI of GIMP's MIDI controller visible you need to edit a configuration file when GIMP is not running. Open ~/.gimp-2.2/controllerrc in an editor and add the following lines to the end of the file:
(GimpControllerInfo "MIDI" (enabled yes) (debug-events yes) (controller "ControllerMidi" (device "alsa") (channel -1)) (mapping))
Then start GIMP from a shell (so that you can see textual output we need later), open the preferences, go to the "Input Controllers" page in the "Input Devices" section and select the newly appeared "MIDI" Tab.
Configuring the MIDI Source
Enter "alsa" in the "Device" entry in the configuration. GIMP then sets up an Alsa-Output-Port (check with "aconnect -lo"). You can then use your preferred tool to configure Alsa to connect a MIDI source to GIMP. When your MIDI device e.g. provides an Input-Port 72:0 and GIMP provides the Output-Port 128:0 you can connect the two Ports with "aconnect 72:0 128:0".
The Open Sound System provides a device file for the raw MIDI events. You need to enter the name of this device file into the "Device" entry in the configuration (e.g. "/dev/midi00").
The MIDI channel
Each MIDI source sends events on a specific "Channel" (0 to 15, sometimes also referred as 1 to 16). You can configure if GIMP should listen to all channels (-1) or to just a specific channel.
If your MIDI setup works correctly and the "Dump events from this controller" is enabled as well as "Enable this controller" you should see some text scrolling by when you hit some keys or turn some controllers on your midi device, describing the Event that just happened.
Assigning Actions to Events
You can now use this information to map MIDI Events to Actions in GIMP. At the bottom of the configuration page is a list with all events that GIMP can recognize. Scroll to the event that you want to assign an action to and doubleclick its entry. Then select an Action from the dialog that pops up and doubleclick its entry. Now this action gets invoked when the specific MIDI event happens.
Please note that some actions fit perfectly to some MIDI Events: Actions like "context-background-blue-set" can immediately use the numerical value provided by midi controller events.