Skip to content

Instantly share code, notes, and snippets.

@tobert
Created November 28, 2017 23:31
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tobert/881dd99b39a5555c876f94263e6f9f79 to your computer and use it in GitHub Desktop.
Save tobert/881dd99b39a5555c876f94263e6f9f79 to your computer and use it in GitHub Desktop.
MPKmini2 MIDI + fluidsynth CLI only

Akai MPK Mini 2 + Fluidsynth + Linux synthesizer

This is a quick & dirty way to attach an Akai MPK mini 2 USB MIDI controller to Linux so the Linux machine can act as its synthesizer. This approach should work for any modern USB MIDI instrument.

Rationale

I looked around on the web and, surprisingly, I didn't find any simple options for quickly starting Fluidsynth up and wiring it to a MIDI controller for simple keyboard usage. There are a few out there that involve using Qsynth which is cool but I didn't want a GUI for something relatively simple.

Shell Session

These are the basic steps. Where I use a port number, be sure to look at the aconnect -l output on your machine to see what's right for your situation. The exact values used here probably won't work.

First, start up Fluidsynth in daemon mode. I chose to route it through Pulseaudio and take the latency hit for now because this is not my primary machine and it typically only gets used to play music sometimes.

[atobey@gadget ~]$ fluidsynth -m alsa_seq -a pulseaudio -s ff6.SF2 
FluidSynth version 1.1.6
Copyright (C) 2000-2012 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of E-mu Systems, Inc.

fluidsynth: Using PulseAudio driver
Type 'help' for help topics.

> fluidsynth: warning: Failed to set thread to high priority
fluidsynth: warning: Failed to set thread to high priority

If you like, you can set that high priority by running chrt in a different terminal. (You could run Fluidsynth as root but that's anathema to my working style).

sudo chrt --rr --all-tasks --pid 50 $(pidof fluidsynth)

With your USB MIDI device plugged in, list the MIDI devices available. Modern Linux machines should load the driver and present the instrument right away.

[atobey@gadget ~]$ aconnect -l
client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 28: 'MPKmini2' [type=kernel,card=3]
    0 'MPKmini2 MIDI 1 '
client 128: 'FLUID Synth (60137)' [type=user,pid=60137]
    0 'Synth input port (60137:0)'

On my machine, the MPKmini2 input device is 28:0 and the synthesizer is 128:0 and I want events from the MPK Mini routed to Fluidsynth.

[atobey@gadget ~]$ aconnect 28:0 128:0
[atobey@gadget ~]$ aconnect -l
client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 28: 'MPKmini2' [type=kernel,card=3]
    0 'MPKmini2 MIDI 1 '
	Connecting To: 128:0
client 128: 'FLUID Synth (60137)' [type=user,pid=60137]
    0 'Synth input port (60137:0)'
	Connected From: 28:0

And that's it! I now have sound from my keyboard. There's a little more latency than I like, but I'm pretty sure that's in Pulseaudio and I'll deal with that later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment