Linux MIDI Command Line Cheatsheet

USB MIDI controllers and keyboards have come way down in price the last few years.  We really like the Akai MPK Mini mkII, and we’ve really enjoyed using the Numark Orbit because it has an accelerometer in it for sensing tilt and motion, and it is easy to send MIDI messages for changing its colors.

Use the command line to control the MIDI system


If you’re experimenting with a Raspberry Pi using USB MIDI input devices, you’ll probably get to the point where you are wondering if it is working correctly and if the MIDI information is getting into your Raspberry Pi.  This article lists some of the command line tools you can use to examine the information coming from these devices.

List Devices

$ aconnect -i -o -l

[-i] – show inputs
[-o] – show outputs
[-l] – list
Example: List the clients and ports that can be Inputs to other clients.

$ aconnect -i
client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 20: 'Launchkey 25' [type=kernel,card=1]
    0 'Launchkey 25 MIDI 1'
    1 'Launchkey 25 MIDI 2'
client 130: 'rtpmidi' [type=user,pid=3157]
    0 '__port__        '

Dump MIDI Events

$ aseqdump [-l] [-p client:port]

[-l] – show sources that can be dumped
[-p client:port] – select the client and its port to dump
Example: list all of the clients in the system that aseqdump can show.

$ aseqdump -l
 Port    Client name                      Port name
  0:0    System                           Timer
  0:1    System                           Announce
 14:0    Midi Through                     Midi Through Port-0
 20:0    Launchkey 25                     Launchkey 25 MIDI 1
 20:1    Launchkey 25                     Launchkey 25 MIDI 2
130:0    rtpmidi                          __port__

Example: Dump the MIDI events from the Launchkey-25 keyboard while a C-major scale is played.

$ aseqdump -p 20:0
Waiting for data. Press Ctrl+C to end.
Source  Event                  Ch  Data
 20:0   Note on                 0, note 60, velocity 40
 20:0   Note on                 0, note 62, velocity 48
 20:0   Note off                0, note 60, velocity 15
 20:0   Note on                 0, note 64, velocity 54
 20:0   Note off                0, note 62, velocity 43
 20:0   Note off                0, note 64, velocity 42
 20:0   Note on                 0, note 65, velocity 57
 20:0   Note on                 0, note 67, velocity 41
 20:0   Note off                0, note 65, velocity 57
 20:0   Note on                 0, note 69, velocity 56
 20:0   Note off                0, note 67, velocity 38
 20:0   Note on                 0, note 71, velocity 56
 20:0   Note off                0, note 69, velocity 31
 20:0   Note on                 0, note 72, velocity 48
 20:0   Note off                0, note 71, velocity 27
 20:0   Note off                0, note 72, velocity 53

The proc Filesystem

The ALSA system exposes many of its details through the /proc/asound filesystem. For example, fine-grain details of the ALSA Sequencer Clients may be obtained by cat-ing /proc/asound/seq/clients.

$ cat /proc/asound/seq/clients
Client info
  cur  clients : 6
  peak clients : 7
  max  clients : 192
Client   0 : "System" [Kernel]
  Port   0 : "Timer" (Rwe-)
  Port   1 : "Announce" (R-e-)
    Connecting To: 130:0
Client  14 : "Midi Through" [Kernel]
  Port   0 : "Midi Through Port-0" (RWe-)
    Connecting To: 129:0
    Connected From: 128:0
Client  20 : "Launchkey 25" [Kernel]
  Port   0 : "Launchkey 25 MIDI 1" (RWeX)
    Connecting To: 129:1
    Connected From: 128:1
  Port   1 : "Launchkey 25 MIDI 2" (RWeX)
    Connecting To: 129:2
    Connected From: 128:2
Client 128 : "osmid_midi" [User]
  Port   0 : "Midi Through Port-0" (-we-)
    Connecting To: 14:0
  Port   1 : "Launchkey 25 MIDI 1" (-we-)
    Connecting To: 20:0
  Port   2 : "Launchkey 25 MIDI 2" (-we-)
    Connecting To: 20:1
  Port   3 : "__port__" (-we-)
    Connecting To: 130:0
  Input pool :
    Pool size          : 200
    Cells in use       : 0
    Peak cells in use  : 0
    Alloc success      : 0
    Alloc failures     : 0
Client 129 : "osmid_midi" [User]
  Port   0 : "Midi Through Port-0" (-we-)
    Connected From: 14:0
  Port   1 : "Launchkey 25 MIDI 1" (-we-)
    Connected From: 20:0
  Port   2 : "Launchkey 25 MIDI 2" (-we-)
    Connected From: 20:1
  Port   3 : "__port__" (-we-)
    Connected From: 130:0
  Input pool :
    Pool size          : 200
    Cells in use       : 0
    Peak cells in use  : 0
    Alloc success      : 0
    Alloc failures     : 0
Client 130 : "rtpmidi" [User]
  Port   0 : "__port__" (RWe-)
    Connecting To: 129:3
    Connected From: 0:1, 128:3
  Output pool :
    Pool size          : 500
    Cells in use       : 0
    Peak cells in use  : 0
    Alloc success      : 0
    Alloc failures     : 0
  Input pool :
    Pool size          : 200
    Cells in use       : 0
    Peak cells in use  : 7
    Alloc success      : 98
    Alloc failures     : 0

dmesg

Use dmesg to see messages about USB devices being plugged and unplugged. Use this if you are unsure if your equipment is being recognized by your system. The [-w] option makes dmesg wait for new messages.

$ dmesg -w
[20912.575523] usb 1-1.5: urb status -32
[20912.575650] usb 1-1.5: urb status -32
[20912.575676] usb 1-1.5: USB disconnect, device number 4
[20912.575778] usb 1-1.5: urb status -32
[20912.575905] usb 1-1.5: urb status -32
[20912.576032] usb 1-1.5: urb status -32
[20912.576169] usb 1-1.5: urb status -32
[20916.708930] usb 1-1.5: new full-speed USB device number 7 using dwc_otg
[20916.871874] usb 1-1.5: New USB device found, idVendor=1235, idProduct=0030
[20916.871895] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[20916.871907] usb 1-1.5: Product: Launchkey 25
[20916.871918] usb 1-1.5: Manufacturer: Focusrite A.E. Ltd
[20916.871928] usb 1-1.5: SerialNumber: Launchkey

lsusb

Use lsusb to list the USB devices currently connected to your system. Use this if you are unsure if your keyboard or controller is being recognized as a USB device. In the example below, we see the “Focusrite-Novation” as a synonym for the “Launchkey” keyboard shown above by dmesg.

$ lsusb
Bus 001 Device 007: ID 1235:0030 Focusrite-Novation
Bus 001 Device 005: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
Bus 001 Device 006: ID 046d:c05a Logitech, Inc. M90/M100 Optical Mouse
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

 

2 thoughts on “Linux MIDI Command Line Cheatsheet”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.