USB MIDI Keyboard support - OpenBSD.

Today we are on a quest to get replace PianoTeq,

which is not packaged for OpenBSD,

for use with a midi keyboard.

Physical Connection

First things first, connect your MIDI keyboard via USB-A to USB-B/C cable.

Verify Detection

Let's run dmesg to check if the system detects the keyboard.

In our case the Kawai keyboard was detected:

	:: dmesg | tail

	uhidev6 detached
	wskbd5: disconnecting from wsdisplay0
	wskbd5 detached
	ukbd2 detached
	uhidev7 detached
	ugen2 detached
	umidi1 at uhub0 port 9 configuration 1 interface 0 "KAWAI USB-MIDI" rev 2.00/1.00 addr 7
	umidi1: (genuine USB-MIDI)
	umidi1: out=1, in=1
	midi1 at umidi1: <USB MIDI I/F>

Check Device Nodes

Let's see what MIDI devices show up in /dev:

	:: ls /dev/ | grep midi

	rmidi0
	rmidi1
	rmidi2
	rmidi3
	rmidi4
	rmidi5
	rmidi6
	rmidi7

Check Permissions

Now let's check who can access these devices:

	:: ls -l /dev/rmidi*

	crw-rw----  1 root  _sndiop  52, 0 Aug 27 19:14 /dev/rmidi0
	crw-rw----  1 root  _sndiop  52, 1 Aug 27 19:14 /dev/rmidi1
	crw-rw----  1 root  _sndiop  52, 2 Aug 27 19:14 /dev/rmidi2
	crw-rw----  1 root  _sndiop  52, 3 Aug 27 19:14 /dev/rmidi3
	crw-rw----  1 root  _sndiop  52, 4 Aug 27 19:14 /dev/rmidi4
	crw-rw----  1 root  _sndiop  52, 5 Aug 27 19:14 /dev/rmidi5
	crw-rw----  1 root  _sndiop  52, 6 Aug 27 19:14 /dev/rmidi6
	crw-rw----  1 root  _sndiop  52, 7 Aug 27 19:14 /dev/rmidi7

Configure User Permissions

Let's see if our user is in the right group:

	:: cat /etc/group  | grep sndio

	_sndio:*:99:

Doesn't look like we're in the _sndiop group yet,

let's fix that:

	:: usermod -G  _sndiop username

We need to log out & back in for this to take effect.

After logging back in, let's confirm it worked:

	:: cat /etc/group  | grep sndio

	_sndio:*:99:
	_sndiop:*:110:username

Identify MIDI Port

Let's check our dmesg output again,

noting which MIDI port we need:

	:: dmesg | tail | grep midi

	umidi1 at uhub0 port 9 configuration 1 interface 0 "KAWAI USB-MIDI" rev 2.00/1.00 addr 7
	umidi1: (genuine USB-MIDI)
	umidi1: out=1, in=1
	midi1 at umidi1: <USB MIDI I/F>

Looks like I need to use midi/1 for my keyboard.

My soundcard seems to be using midi0.

Make sure to check which port your own device is on!

Set Up MIDI Routing

Alright, let's route.

We'll run this command and then try pressing some keys.

With any luck we should see some MIDI data show up:

	:: midicat -d -q midi/1 -q midithru/0

	90 5d 32
	90 5d 00

Ramblings

Many moons ago, my music making journey looked as following:

LSDJ -> Electribe EMX -> Reason -> Studio One.

Back then Studio One was still in beta, and the developers listened to users.

Per-note fx & auto track bouncing was absolutely game-changing for my garbage hardware circa 2008, this was no thinkpad :(

I wasn't deep into Unix back then. Today we're looking for something open source that works on OpenBSD.

Since we haven't found time to port protrekkr yet, we'll use LMMS.

Calf gives us some plugins to play with:

	:: pkg_add lmms calf

Method 1: Configure LMMS

For me, LMMS was already set up to use sndio.

& then ...

I decided to play Liszt's Un Sospiro with a TB303 emulator.

Fairly sure they hadn't discovered acid in the 1700s,

but I like to think Liszt would have appreciated my interpretation if they had.

Method 2: Fluidsynth & sf2

If we want to play sf2 files,

while not as good as sfz,

they sound much better than the prebuild sound of my Kawai MP8

Fluidsynth is already packaged for OpenBSD & the cli works nicely.

	pkg_add fluidsynth
	fluidsynth -a sndio -m sndio -g 2.0 steinway_concert_piano.sf2

Method 3: Porting sfz programs to OpenBSD

That's all Folks!