Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: December 14, 2024
MIDI stands for Musical Instrument Digital Interface. It’s a technical standard that facilitates communication between electronic musical instruments and computers. A MIDI keyboard is an electronic device with piano keys (or other keys) that can send musical notes to a connected device when the keys are pressed.
The MIDI keyboard doesn’t make any sound by itself. It only sends the played musical notes as electronic signals and the receiving device decides what to do with these signals. It can play the corresponding audio, record the notes, or do both.
A MIDI setup in Linux is very modular and hence can be confusing to configure and operate. In this tutorial, let’s look at how to connect a MIDI keyboard to a PC running Linux, and operate it, step by step.
Most MIDI keyboards come with a USB connector, which we can connect to the USB port of our PC. If our keyboard has only a standard MIDI plug, we can use a MIDI to USB adapter. Common Linux distributions, such as Ubuntu, already have the required drivers and other software to receive MIDI input. Hence, using a MIDI keyboard is as simple as plugging in a USB mouse or keyboard.
Once we’ve plugged in the MIDI keyboard to our PC’s USB port, we can check if the OS detects it as an input, using the aconnect command:
$ aconnect -i
client 0: 'System' [type=kernel]
0 'Timer '
1 'Announce '
client 14: 'Midi Through' [type=kernel]
0 'Midi Through Port-0'
client 24: 'Oxygen Pro Mini' [type=kernel,card=2]
0 'Oxygen Pro Mini USB MIDI'
1 'Oxygen Pro Mini MIDI DIN'
2 'Oxygen Pro Mini Mackie/HUI'
3 'Oxygen Pro Mini Editor'
From the above output, we can see that the device ‘Oxygen Pro Mini’ has been detected and assigned as client 24. It also has four input ports, corresponding to the piano keys, drum pads, and various knobs. The hardware setup is shown in the picture below:
Next, let’s see how to detect events that are received when we press keys on the keyboard.
Each time we press or release a key on our MIDI keyboard, it sends a signal to the PC via the USB connection. The signal contains a MIDI event, which can represent a key press or release, with additional data, such as note frequency and loudness. The receiver can use this data to play a corresponding note on any available musical instrument sample or take some other action.
Before we proceed to play any music, let’s ensure that our OS can receive these MIDI events. For this, we’ll use the aseqdump command, specifying the client and port number. To see MIDI events, we have to run the command and press some keys on our keyboard:
$ aseqdump -p 24:0
Waiting for data. Press Ctrl+C to end.
Source Event Ch Data
24:0 Note on 0, note 48, velocity 40
24:0 Note off 0, note 48, velocity 0
24:0 Note on 0, note 48, velocity 125
24:0 Note off 0, note 48, velocity 0
In the above snippet, we asked aseqdump to dump MIDI events detected on client 24, port 0, which corresponds to our MIDI keyboard, as we saw earlier. After starting the command, we can see detected MIDI events every time we press and release a key on the keyboard. The event data contains a note number corresponding to piano notes C3, D3, E3, etc., and a velocity corresponding to how hard the key is pressed. This shows that our connection is working. Next, let’s play some music!
The quickest way to take the MIDI keyboard for a spin is to use a web-based Virtual Instrument that takes MIDI input. One such website is virtualpiano.eu. However, our browser needs to support Web MIDI API for this to work. Of the popular browsers, Chrome, Edge, and Firefox do support this, while Safari doesn’t. After we open the website, we simply have to select “Oxygen Pro Mini USB MIDI” as the External MIDI keyboard and start playing. The following screenshot shows the key features of the website:
In the above screenshot, we have selected our MIDI keyboard on the menu in the top-right corner. It also shows various other options, including a drop-down menu to change the instrument.
Apart from web-based virtual instruments, there are also sophisticated synthesizer applications that we can use with a MIDI Keyboard. Essentially, a synthesizer is an application or a device that lets us create or emulate a musical instrument electronically. Some of these software are also open-source. We can install and use these on most Linux systems. Let’s see a brief list of popular open-source synthesizers below:
We can also explore our distro’s package repository or app store to find more synthesizers or even program our own synthesizer to produce sounds based on MIDI input.
In addition to synthesizers, we can also use MIDI keyboards with Digital Audio Workstation software (DAWs). Professional music producers use DAWs to record, mix, and render music using several instruments, tracks, audio clips, and synthesizers. Some free and open-source DAWs that we can use on Linux systems are LMMS, Ardour, Zrythm, and Rosegarden. A screenshot of LMMS is below:
The above screenshot shows a list of instruments and there’s also a piano roll to add notes.
A MIDI Keyboard is an essential device for anyone trying to make music – as a hobby or professionally. While most MIDI Keyboard manufacturers provide software and documentation for Windows and MacOS, they usually don’t mention Linux. However, we don’t need to worry if we’re Linux users. The MIDI standard is OS-independent, and Linux offers a varied set of modular tools that will help us make the best out of our MIDI device.
In this article, we looked at how to set up a MIDI keyboard to use with a Linux PC. We first ensured that our OS detects our MIDI keyboard and receives the MIDI events. Then, we tested our setup by playing music on a web-based virtual instrument and discussed how we could use the MIDI controller with a synthesizer or a DAW.