midithru - a straight-through ALSA-MIDI client with a helpful display
midithru -i Pro,Key -o TiM midithru -o Fluadity -o0 129:0 # channel zero goes to the ARP 2600 xterm -font 9x15bold -geometry 66x23-1+1 -e midithru & xterm -font 7x14bold -geometry 66x23-1-1 -e midithru -n thru-2 & xterm -font 12x24 -geometry 58x21-1+1 -e midithru -i Pro & midithru -v perldoc midithru
midithru is a simple Straight-Through ALSA-MIDI client that displays real-time information about the MIDI-channels passing through it, such as which ALSA-client they most recently came from, which Patch they have most recently been set to, and what the latest Controller-Change was. For example:
ALSA-client midithru 129:0 (in) 129:1 (out) connected from 24=ProKeys, 130=aplaymidi, 131=midikbd Channel From Patch Latest CC 0 24=ProKeys 17=Percussive Organ cc64=127 1 28=Keystation 24=Acoustic Guitar(nylon) cc11=83 2 130=aplaymidi 33=Electric Bass(finger) 3 14=MidiThrough 4=Electric Piano cc64=0 9 130=aplaymidi percussion 12 130=aplaymidi bank 5,5 patch 2 output to 20=Roland
To quit midithru, type Ctrl-C.
If bank has not been set, the patches are named by
their General-MIDI names.
Within a window 66x23 (or larger) it displays comfortably. The smallest window in which it works properly is 58x20, though it still works down to 58x19 by omitting the connected from line.
midithru is written in Lua,
and requires the modules
Because SIGWINCH is not Posix, luaposix does not support it, and indeed disables the kernel's SIGWINCH handler so that even tput, resize,
$COLS do not get updated.
Therefore midithru uses xwininfo, if it's available,
to detect changes in window size.
Set the ALSA input-client, to my ProKeys Sono 88 and my Keystation 49e in this example. As in the example, multiple input-clients may be specified, separated by commas. The clients are identified by a case-significant start-of-string match, or by their ALSA client-numbers. By default, no client is connected to the input.
Set the ALSA output-client, to TiMidity in this example.
The clients are identified by a case-significant start-of-string match,
or by their ALSA client-numbers.
As usual, a particular port within the client can be specified,
e.g. -o 14:3
Multiple output-clients may be specified, separated by commas.
By default, the environment variable ALSA_OUTPUT_PORTS is used, if it is set.
For compatibility with midifade, the -o 0 option is a special case, and means the midithru output is not connected to anything. This leaves you free to connect it later (remember that the midithru client produces its output on port 1 !) using e.g.
xterm -font 9x15bold -geometry 66x23-1+1 -e midithru -o 0 & ... aconnect midithru:1 TiMidity arecordmidi -p midithru:1 -b 60 -t 1000 /tmp/session.mid
This option sends MIDI channel 3 to an ALSA output-client
different from the default output which was set by -o.
midithru -o Fluadity -o9 MyFavoriteDrumMachine
The channels are numbered 0..15, so -o0 Roland sends channel zero to the Roland, which is quite different from -o 0 which disables the default output.
If the default output is disabled, individual channels can still be sent with the -o3 24:0 option, for example
midithru -o 0 -o0 24:0 -o13 Roland
will send channel 0 to client 24:0 and channel 13 to the Roland, and no other channels will be output.
Set the ALSA client-name, to midithru2 in this example. This is useful if you want to start up more than one midithru, and then connect to them by name with aconnect. The default client-name is midithru.
Prints version number.
To install midithru, save it to disc,
move it into your
$PATH, make it executable, and if necessary
edit the first line to reflect where lua is installed on your system.
You will also need the
2.0 20211208 handle SIGTERM to clean up properly after a kill
1.9 20211208 handle SIGINT to clean up properly after a ctrl-C
1.8 20211207 require minicurses, for lua 5.4 compatibility
1.7 20210818 add -o3 option to send a channel to its own synth
1.6 20160324 ~/.config/midithru/Synth.volumes adjusts velocities for old kbds
1.5 20150528 double-output of play-sysex fixed
1.4 20150527 secret play-sysex interpreted and not through-put
1.3 20150525 secret "}!play file.wav\xF7" sysex introduced
1.2 20140421 handles LINES=20 correctly
1.1 20140420 displays connected from; adapts somewhat to screen size
1.0 20140412 first working version
Peter J Billam pjb.com.au/comp/contact.html
apt install ncurses-doc