Setting up Ubuntu Linux for audio and MIDI is relatively quick and straightforward these days. This will cover setting up your audio system with JACK Audio and then your MIDI keyboard.
This quick write up is on simply quickly getting a MIDI controller keyboard, which is pretty much any keyboard with USB port these days to play virtual instrument installed on your computer.
sudo apt install ubuntustudio-audio linux-lowlatency
This should get you everything you need, especially the Ubuntu Studio Setup Utility and low latency kernel. Reboot.
Understanding Configuring JACK and Pulseaudio
Usually one would have a USB Audio Interface like a Steinberg UR22 or Focusrite, but we will use our built-in sound device in this article.
JACK Audio Connection Kit is the audio system that allows us to connect different audio sources and outputs out, with low latency. The delay between say pressing a key or recording in mic and the audio that comes out of your computer speakers. If it’s too high, the delay is noticeable and confusing, like trying to talk in a video call where you can hear your delayed voice from someone else using speakers and not muting.
Try to get this as low as possible, while still having everything work and without Xruns. Xruns are when your CPU cannot keep up with the audio data, and it will result in crackling and pops. A buffer size of 256 would give you about 10ms of latency which would be good enough for playing keyboards. For my generic sound card, I’ve gotten it down to 128 buffers and 3 periods, which is about 8ms.
Get your other devices working
Under Extra Devices tab, you will probably want to enable Bridge USB Devices to Jack. Usually this is the microphone from your webcam or USB microphone, which is the case if you don’t have a USB audio interface.