# HG changeset patch # User František Kučera # Date 1590017003 -7200 # Node ID 418e11eb6fea78abdd18fbd08f42df9a2cd3b5d7 # Parent 72dc2469c438d7d165088c4ef10dbaf5855cb0f1 examples: Monitoring MIDI messages using JACK – relpipe-in-jack diff -r 72dc2469c438 -r 418e11eb6fea relpipe-data/examples-jack-midi-monitoring.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/relpipe-data/examples-jack-midi-monitoring.xml Thu May 21 01:23:23 2020 +0200 @@ -0,0 +1,188 @@ + + + Monitoring MIDI messages using JACK + examine events running through a JACK pipeline or bind MIDI keys to actions + bonus: Roland MT-32 + 04100 + + + +

+ A powerful audio system called JACK allows us to + build pipelines consisting of audio interfaces, players, recorders, filters and effects… + and route sound streams (both PCM and MIDI) through them. + MIDI messages can come from keyboards or other hardware MIDI controllers or from MIDI players and other software. + Sometimes it is useful to check what is happening under the hood and examine particular MIDI messages + instead of just playing them on a sound module or synthesizer. + In this example we will show how to bridge two seemingly unrelated worlds: real-time audio and relational pipes. +

+ +

+ We can join the JACK graph with relpipe-in-jack command. + It does not consume STDIN, it gets events from JACK instead, so no other input data are needed. +

+ + relpipe-in-jack | relpipe-out-gui + +

+ We are connected to the JACK daemon now, but no data are routed to us. + So we need to direct some MIDI streams to our input: +

+ + + +

+ And then incoming MIDI events will generate output like this: +

+ +
+ +

+ CSV is not the only option. Once data are in the machine-readable relational format, + we can convert them into any other format or process them using any relational transformation. + For ad-hoc monitoring, we can use relpipe-out-gui and watch MIDI messages – as they come – + in a table in GUI: +

+ + + +

+ As we can see, there are raw MIDI data and also some decoded values. + Future versions of relpipe-in-jack should provide improved decoder and other features like timing information. +

+ +

+ We can use relpipe-in-jack not only for monitoring + but we can also write a simple script that binds particular MIDI events + to actions to be executed – like starting a program or running a script on background. + So we can map some keys/buttons/knobs on our piano, mixer or other controller: +

+ + + +

+ Many audio applications have similar feature, + but we can leave this script running on the background + even when we do not want to have loaded a complex software like a DAW (Digital audio workstation). +

+ + +

Bonus: display messages on Roland MT-32

+ +

+ Maybe you remember games or MIDI files that magically displayed text messages on your + MT-32 unit + which you used to generate wonderful sounds and music from the MIDI signal. + Let us look inside and check how this magic works. +

+ +

+ We have to route the MIDI signal through JACK and fork it there (similarly to tee in shell) + so it will flow both to the MT-32 and the relpipe-in-jack process. +

+ +

+ Given that we have running the JACK daemon (can be started from GUI application like QjackCtl) + and a2j which bridges ALSA-MIDI and JACK-MIDI together. + We set up the routing (the fork) and then play a SMF (Standard MIDI file) file: +

+ +
aplaymidi --port=14:0 test.mid
+ +

Proper port number could be found here:

+ +
+ +

+ Data sent to the Midi Through port in the ALSA-MIDI emerges in the a2j in the JACK-MIDI graph + and then flows to relpipe-in-jack. + So the MT-32 will play the sounds and display messages (if any) and we will get copy of everything in + relpipe-in-jack that passes data to command like relpipe-out-gui + or relpipe-out-csv where we see decoded messages and also raw MIDI data. +

+ +

+ n.b. the Midi Through in the ALSA-MIDI graph should be connected to our audio interface + (e.g. Rubix44) + which is linked to the MT-32 using a MIDI cable. +

+ +

+ Messages that cause text to be showed on the MT-32 display are so called System Exclusive (SysEx) messages. + After executing the aplaymidi we see for example: +

+ + + +

+ And relpipe-in-jack captured and reported this SysEx message: +

+ +
f0 41 10 16 12 20 00 00 52 65 6c 61 74 69 6f 6e 61 6c 20 70 69 70 65 73 14 f7
+ +

+ The highlighted part (52 … 73) is easy – it is just the Relational pipes ASCII bytes in HEX. + But what does the rest mean? +

+ +
    +
  • f0 = start of SysEx message
  • +
  • 41 = Roland manufacturer ID. This is important because SysEx messages are vendor-specific. So devices from other manufacturers (that might be in the same MIDI daisy-chain) will know, that this message is not for them and will ignore it.
  • +
  • 10 = device ID – if we have more units with same manufacturer and model ID, we should assign them different device IDs, so we can address them individually.
  • +
  • 16 = model ID
  • +
  • 12 = command ID, 12 is set, 11 is get
  • +
  • 20 00 00 = the address of the value we want to set, 20 00 00 is the text to be displayed
  • +
  • 14 = checksum computed from the 20 00 00 … 73 part
  • +
  • f7 = end of the SysEx message
  • +
+ +

+ Only the start and end of the SysEx message and the manufacturer ID are part of the MIDI standard. + The rest of the bytes is Roland specific. SysEx messages can do much more than controlling the display – consult the documentation for particular device. +

+ + +

+ We can generate our own messages using the mt-32-display tool. + It produces SysEx messages for Roland MT-32 in hex format which can be passed directly to the amidi command (see examples in the code). + Unfortunately amidi works only with hardware ports and is unable to route through JACK. + But there is another tool called sysex2smf + which translates raw SysEx data to Standard MIDI file (*.mid). + And SMF can be played using the aplaymidi which can be routed through JACK and our pipelines. + So the 48 lines of C++ code (both tools together) is everything we need to enjoy this nice feature of our MT-32 unit. +

+ + + + +
+ +
diff -r 72dc2469c438 -r 418e11eb6fea relpipe-data/img/jack-connections-1.png Binary file relpipe-data/img/jack-connections-1.png has changed diff -r 72dc2469c438 -r 418e11eb6fea relpipe-data/img/jack-monitoring-gui-1.png Binary file relpipe-data/img/jack-monitoring-gui-1.png has changed diff -r 72dc2469c438 -r 418e11eb6fea relpipe-data/img/mt-32-display-1.jpeg Binary file relpipe-data/img/mt-32-display-1.jpeg has changed diff -r 72dc2469c438 -r 418e11eb6fea relpipe-data/img/mt-32-video-1.jpeg Binary file relpipe-data/img/mt-32-video-1.jpeg has changed