You are not logged in.

#1 2016-05-22 13:21:18

jakobcreutzfeldt
Member
Registered: 2011-05-12
Posts: 1,041

USB MIDI devices sending mouse/keyboard events

I've searched a lot but I haven't found anyone with a similar problem. I have two MIDI devices (Native Instruments Audio Kontrol 1 & Maschine).  When I plug them in, they have similar behavior: they both only send mouse and/or keyboard events. The AK1 is simpler, so I'll only describe that. It's an audio interface (which works fine in that regard) that also has basic MIDI controls in the form of a single large knob and three buttons. After plugging in the device, rotating the knob moves the mouse horizontally, while pressing each of the three buttons results in a letter being typed.

$ uname -a
Linux naga 4.5.4-1-ARCH #1 SMP PREEMPT Wed May 11 22:21:28 CEST 2016 x86_64 GNU/Linux

The device is recognized as a MIDI input:

$ aconnect -i
client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 20: 'Audio Kontrol 1' [type=kernel]
    0 'Audio Kontrol 1-0'
    1 'Audio Kontrol 1-1'

Running aseqdump on 20:0 or 20:1 and manipulating the controls shows no MIDI signals being caught.

dmesg shows it being caught as an input device and shows the relevant audio interface driver being loaded.

$ dmesg
...
[  197.605419] usb 3-2: new high-speed USB device number 2 using xhci_hcd
[  197.779798] usb 3-2: language id specifier not provided by device, defaulting to English
[  197.794555] input: Audio Kontrol 1 as /devices/pci0000:00/0000:00:14.0/usb3/3-2/input/input19
[  197.794850] usbcore: registered new interface driver snd-usb-caiaq
...

The journal shows where things are probably going wrong:

# journalctl -b
...
May 22 13:43:15 naga kernel: usb 3-2: new high-speed USB device number 3 using xhci_hcd
May 22 13:43:15 naga kernel: usb 3-2: language id specifier not provided by device, defaulting to English
May 22 13:43:15 naga mtp-probe[2368]: checking bus 3, device 3: "/sys/devices/pci0000:00/0000:00:14.0/usb3/3-2"
May 22 13:43:15 naga mtp-probe[2368]: bus: 3, device: 3 was not an MTP device
May 22 13:43:15 naga kernel: input: Audio Kontrol 1 as /devices/pci0000:00/0000:00:14.0/usb3/3-2/input/input20
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (II) config/udev: Adding input device Audio Kontrol 1 (/dev/input/js0)
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (**) Audio Kontrol 1: Applying InputClass "system-keyboard"
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (II) No input driver specified, ignoring this device.
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (II) This device may have been added with another device file.
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (II) config/udev: Adding input device Audio Kontrol 1 (/dev/input/event12)
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (**) Audio Kontrol 1: Applying InputClass "evdev keyboard catchall"
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (**) Audio Kontrol 1: Applying InputClass "system-keyboard"
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (II) systemd-logind: got fd for /dev/input/event12 13:76 fd 27 paused 0
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (II) Using input driver 'evdev' for 'Audio Kontrol 1'
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (**) Audio Kontrol 1: always reports core events
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (**) evdev: Audio Kontrol 1: Device: "/dev/input/event12"
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (--) evdev: Audio Kontrol 1: Vendor 0x17cc Product 0x815
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (--) evdev: Audio Kontrol 1: Found absolute axes
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (II) evdev: Audio Kontrol 1: Forcing absolute x/y axes to exist.
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (--) evdev: Audio Kontrol 1: Found keys
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (II) evdev: Audio Kontrol 1: Forcing relative x/y axes to exist.
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (II) evdev: Audio Kontrol 1: Configuring as mouse
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (II) evdev: Audio Kontrol 1: Configuring as keyboard
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (**) Option "config_info" "udev:/sys/devices/pci0000:00/0000:00:14.0/usb3/3-2/input/input20/event12"
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (II) XINPUT: Adding extended input device "Audio Kontrol 1" (type: KEYBOARD, id 12)
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (**) Option "xkb_rules" "evdev"
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (**) Option "xkb_layout" "us,us,es,gr"
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (**) Option "xkb_variant" "dvorak,,dvorak,"
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (II) evdev: Audio Kontrol 1: initialized for absolute axes.
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (**) Audio Kontrol 1: (accel) keeping acceleration scheme 1
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (**) Audio Kontrol 1: (accel) acceleration profile 0
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (**) Audio Kontrol 1: (accel) acceleration factor: 2.000
May 22 13:43:15 naga /usr/lib/gdm/gdm-x-session[755]: (**) Audio Kontrol 1: (accel) acceleration threshold: 4
...

So, the device is being caught by evdev and having the system-keyboard class applied to it:

$ cat /etc/X11/xorg.conf.d/00-keyboard.conf 
# Read and parsed by systemd-localed. It's probably wise not to edit this file
# manually too freely.
Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbLayout" "us,us,es,gr"
        Option "XkbVariant" "dvorak,,dvorak,"
EndSection

OK, so that looks like the culprit.  That was made via localectl.  However, I'm really not sure where to start on trying to make that InputClass only apply to keyboards-for-typing and not keyboards-for-music-noodling. Also, I'm not quite clear on how/where the mouse class is being applied.  I'm assuming I need to make a new entry in /etc/X11/xorg.conf.d, but I might be wrong, so I'd rather ask before going down the Xorg configuration rabbit hole.

I've seen something similar with joysticks/gamepads:

Section "InputClass"
        Identifier "joystick catchall"
        MatchIsJoystick "on"
        MatchDevicePath "/dev/input/event*"
        Driver "joystick"
        Option "StartKeysEnabled" "False"       #Disable mouse
        Option "StartMouseEnabled" "False"      #support
EndSection

I'm not sure which driver is supposed to be used for MIDI keyboards, though.

Can anyone give some insight / prods in the right direction here?  Thanks!

Edit:

OK, I sort of winged it and tried this, but it didn't work:

Section "InputClass"
        Identifier "native instruments midi"
	MatchVendor "Native Instruments"
	MatchProduct "Audio Kontrol 1|Maschine"
        Driver "snd-usb-caiaq"
EndSection

(in a file called /etc/X11/xorg.conf.d/10-native-instruments-midi.conf)

I had hoped that I could specify a different driver, but as I said, I have no idea what the driver might be called so I took an uneducated guess and put the kernel module name.  I haven't been able to find any info on what input drivers are available/used for USB MIDI input devices.

Not sure if I'm on the right track at all.

Last edited by jakobcreutzfeldt (2016-05-23 08:26:00)

Offline

#2 2016-05-23 07:15:18

mich41
Member
Registered: 2012-06-22
Posts: 796

Re: USB MIDI devices sending mouse/keyboard events

Try googling or asking at some place dedicated to Linux audio.

You can tell Xorg to ignore certain input devices, but I know nothing about software to convert keypresses to MIDI events (which is how the vendor's Windows software probably works).

BTW, I'm almost sure that any such software won't be part of Xorg, because Xorg doesn't deal with MIDI at all, and that it won't be any snd_usb_anything kernel module, because kernel devs would want this stuff in userspace, using the kernel's existing keyboard driver. Oh, and I'm absolutely sure that writing kernel driver names to Xorg configuration is pointless smile

Last edited by mich41 (2016-05-23 07:25:09)

Offline

#3 2016-05-23 08:35:35

jakobcreutzfeldt
Member
Registered: 2011-05-12
Posts: 1,041

Re: USB MIDI devices sending mouse/keyboard events

mich41 wrote:

Try googling or asking at some place dedicated to Linux audio.

You can tell Xorg to ignore certain input devices, but I know nothing about software to convert keypresses to MIDI events (which is how the vendor's Windows software probably works).

BTW, I'm almost sure that any such software won't be part of Xorg, because Xorg doesn't deal with MIDI at all, and that it won't be any snd_usb_anything kernel module, because kernel devs would want this stuff in userspace, using the kernel's existing keyboard driver. Oh, and I'm absolutely sure that writing kernel driver names to Xorg configuration is pointless smile

I've done a lot of searching on the web, to no avail yet.

I'm a bit hazy on this part of the system plumbing, but from what I can understand from the logs, the kernel detects the device, then udev assigns it as an input and loads evdev as the driver, and finally the device is added as an XINPUT. Everything outside of the kernel is happening under the auspices of gdm-x-session, so Xorg is playing a role here somehow.  Afterall, the InputClass being assigned to the device is defined in an xorg.conf file.  Whether or not it should be playing a role is a different question.

The kernel module was, as I said, an uneducated guess. The only thing informing it was that Native Instruments also lists snd-usb-caiaq as a required module for the Maschine, which is strictly a MIDI device (no audio interface) so I thought maybe they sneaked their MIDI drivers into that module.

Offline

Board footer

Powered by FluxBB