Step-by-step to run a midi keyboard input device? 12.04

85,981

Solution 1

If you just want to get your keyboard to play sound, this is very simple, and you won't need JACK nor Rosegarden for that. These tools are great if you want to record MIDI signal, write notes, and route audio between separate applications, but you don't need that to play sound with your keyborard.

My step-by-step would be to:

  1. Plug in your MIDI device to your computer. If that's a USB MIDI keyboard, just plug the USB, if it has only MIDI plug, you may want to use a MIDI to USB device.

  2. Download/Install a synthesizer. There is a large variety of sound synthesing applications for Ubuntu. You may like ZynAddSubFX (really powerful one), FluidSynth or QSynth (support soundfonts), AMSynth, AMS. Make sure to browse Ubuntu Software Center for synthesizer that will grab your interest.

  3. Launch the synthesizer. Of course it has to be running to produce sound.

  4. Tell the system to pass data from your keyboard to the synthesizer. You need to create a link between your keyboard and your synthesizer, so that MIDI signal is passed to it. You can either use aconnect tool, or one of it's graphical backends (which are simpler to use), like aconnectgui or kaconnect. While aconnect is installed by default, you can get the other two from Software Center. Once you connect your keyboard, and synthesizer, follow to the final step...

  5. Press a key on your keyboard. You will hear some sound! If not, make sure if your system sound is not muted, and that our speakers are connected. Also, some synthesizers require you to choose an instrument before they produce any sound.

  6. Fine tune your synthesizer settings. You will most likely not enjoy the initial sound of the synthesizer. In case of ZynAddSubFX, this will be a plain sine wave, boring! However, you can easily browse a great collection of timbres, and you can customize them fully. All synthesizers provide you lots of customisation, it's worth to spend some time choosing what you like most.

  7. Proceed to play. Good luck and have fun!

I have also once written an article on general workflow for music production with external keyboard on Ubuntu, it should be useful in your case. Here's the link.

Solution 2

MIDI on Linux is highly modular and, as a result, initially overwhelming. It's nice to have a low-complexity solution working before you bother with optimizations, but unfortunately Ubuntu doesn't come with a default working configuration. Here's the simplest way that I have found...

sudo apt install qsynth vmpk ## install components
qsynth & vmpk ## launch
  • Qsynth -> Setup -> Sountfonts -> Open : FluidR3_GM.sf2
  • Virtual MIDI Piano Keyboard -> Edit -> Connections ->
    • Enable MIDI Thru on MIDI Output : (checked)
    • Input MIDI Connection : (Your Controller)
    • Output MIDI Connection : FLUID Synth

At this point, you should be able to play notes from either your external MIDI controller or from the virtual piano GUI (the GUI works even if you don't have an external controller).

From the Keyboard GUI you can select different instruments (see Program). From the Qsynth GUI you can manipulate the volume (see Gain) as well as Reverb/Chorus effects. There is also a Panic button in case the reverb goes off the rails.

This was specifically tested on clean install of Ubuntu Studio 18.04, but similar steps worked for Ubuntu MATE 16.04, with a notable automatic configuration difference being that Qsynth -> Setup -> Audio -> Audio Driver defaulted to jack in Ubuntu Studio but to alsa on Ubuntu MATE.


Glitchy static with ALSA [SOLVED]

On both 16.04 and 18.04, I have experienced weird static when Qsynth initially starts working with alsa. This static seems to affect all audio sources, but it somehow works itself out in a minute or two (at least partially).

I later tried this setup on a less powerful CPU and noticed a similar static that did not seem to resolve over time. [As an aside, I noticed that this static correlated with the ALSA plug-in [qsynth] line glitching in and out in the Applications tab of Sound Preferences].

This led me to play around with some Qsynth Settings, and I found something that seems to solve both static/glitch problems (maybe with a trade-off of a minor latency increase):

  • Qsynth -> Setup -> Audio -> Buffer Size : 128
  • Qsynth -> Setup -> Audio -> Buffer Count : 8

Apparently, the CPU can't always keep up with the required burst rate, so a little extra buffering is needed to prevent underruns. Presumably the are other settings that could also affect this.


vmpk loses its connection to Qsynth when the settings are changed. The quickest way to experiment with changing settings is to close and restart vmpk to force a reconnect.


Alternative: "Polyphone" application (not in Ubuntu repositories)

I've got my eye on Polyphone as a (nearly) all-in-one solution (essentially a superset of qsynth+vmpk). Although it isn't in the Ubuntu repositories so far (as of 19.04 Disco), it was easy to build from source on 18.04 (also, there is a pre-built Ubuntu .deb provided).

The package doesn't include a default soundfont (it is a soundfont creator/editor), but you can get one with sudo apt install fluid-soundfont-gm (at /usr/share/sounds/sf2/) -- or try downloading from the application's "Online repository" (but this may require an account).

Go to Settings->General->Input/Output and make sure the Audio/MIDI settings are sensible, then open a soundfont and select an instrument under Presets and it should be ready to play music from your MIDI controller, or from the built-in virtual keyboard.

Solution 3

I don't know about Rosegarden, but you can run qjackctl from the package manager. Amsynth is an easy little way to make sound midi->jack.

I don't know how to run jack and pulseaudio at the same time - ie running chrome through jack (looking into it right now, actually). My experience in 12.04 is easy so far to make sound.

  • Install qjackctl and amsynth from the package manager
  • Shut down any web browsers or other pulseaudio things that could be taking the sound hardware
  • Start qjackctl (you may have to fiddle with params in settings but I didn't-this time)
  • Start Amsynth
  • In the ALSA tab of qjackctl (why is it not the midi tab ?!?!) connect your usb midi device (hopefully detected automatically) to Amsynth ...
  • Make sure amsynth is connected to the audio out ...
  • Play!

Solution 4

Find out about your sound card:

aplay -l

**** List of PLAYBACK Hardware Devices ****
card 0: HDMI [HDA Intel HDMI], device 3: HDMI 0 [HDMI 0]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 0: ALC3235 Analog [ALC3235 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

We will be using card1, device0, thus hw:1,0

My pipeline scenario that finally worked, using jack-control (qjackctl) and qsynth was:

  1. Install jack-tools, jack-server, qsynth
  2. Open up qsynth and go to Setup. In MIDI tab, I select Midi Driver: alsa-seq. In Audio tab I select Audio Driver: jack.
  3. Fire up jack server with

    jackd -R -d alsa -d hw:1,0

  4. Open qjacktctl and:

4.1 Go to Connect -> ALSA. In the left column find out your keyboard and connect it to qsynth that lies in the right column. Also make sure that in the first column (AUDIO), qsynth is connected to your speakers (right column).

4.2 Back in the main qjackctl window Go to setup->settings->advanced and in the right column, choose Output Device (speakers) and Input Device (Midi keyboard)

By this step I was able to hear my keyboard. An overall screenshot of the setup follows

enter image description here

PS: In this scenario no other application can use the speakers at the same time.

Share:
85,981

Related videos on Youtube

Mittenchops
Author by

Mittenchops

Updated on September 18, 2022

Comments

  • Mittenchops
    Mittenchops over 1 year

    I have a Korg Nanokey, and I'd like to make it produce sound in ubuntu. I've read that means I should be using Rosegarden, and that Rosegarden uses JACK, but does not install it. (Although checking out Ubuntu Software Center, apparently some components of JACK are installed by default?)

    I understand there can be a lot of work setting up JACK without it fighting the default sound server. Can someone give me a step-by-step method for what I need to do to plug in my midi machine and hear music when I press keys as simply as possible (without messing up pulseaudio, ie, so I can still access Skype and ordinary desktop stuff)? I'm fine installing JACK, but I'd like to sandbox it a little if it has the chance of messing up regular desktop.

    I've looked through a couple resources, but I'm not sure what's outdated, but the following looked helpful...

  • answerSeeker
    answerSeeker about 9 years
    It's qjackctl not qjackctrl
  • answerSeeker
    answerSeeker about 9 years
    How do I set the links for aconnectgui? I accidentally connected a bunch of things together, I want to reset the links.
  • holocronweaver
    holocronweaver over 8 years
    @TatakaiWasumi Select the scissors tool and then left-click on a connection. It will 'cut' (i.e., delete) the connection.
  • holocronweaver
    holocronweaver over 8 years
    If you choose to qjackctrl, you can use the connections tab to route the synthesizer to output to the speakers (if it doesn't by default) and the USB MIDI input into the synth input. I had to do this when ZynAddSubFX failed to connect to the speaker output, and aconnectgui could not make this connection.
  • chefarov
    chefarov almost 7 years
    I had to also add qjackctl in the pipeline to make qsynth produce actual sound. qjackctl can also perform step4 so aconnect is not needed in that case. Additional step in that case is to configure input/output devices in qjackctl by going setup->settings->advanced
  • Brent Bradburn
    Brent Bradburn almost 6 years
    After you have a basic setup working, you might be interested in some of the many options described here: Ted's Linux MIDI Guide
  • Brent Bradburn
    Brent Bradburn almost 6 years
    Note to self: Some controllers need to be powered on before you can use them.
  • Brent Bradburn
    Brent Bradburn almost 6 years
    Now if I could just figure out how to transpose the controller...
  • Brent Bradburn
    Brent Bradburn over 5 years
    When using Ubuntu MATE, I've had best luck using 'alsa' rather than 'jack'. From Qsynth: Setup -> Audio -> Audio Driver -> alsa.
  • Brent Bradburn
    Brent Bradburn over 5 years
    On both 16.04 and 18.04, I experienced weird static when Qsynth initially starts working with alsa -- but it somehow works itself out in a minute or two.
  • Brent Bradburn
    Brent Bradburn almost 5 years
    Polyphone build: sudo apt install qtbase5-dev libqt5svg5-dev libasound2-dev libjack-jackd2-dev portaudio19-dev librtmidi-dev libstk0-dev libqcustomplot-dev libvorbis-dev libogg-dev libssl-dev ; ( cd sources && qmake -qt5 && time make -s -j2 && ./bin/polyphone )
  • Brent Bradburn
    Brent Bradburn almost 5 years
    Rosegarden looks like it might be powerful, but I can't recommend it for someone getting started -- talk about overwhelming you with options.
  • Brent Bradburn
    Brent Bradburn almost 5 years
    One feature of vmpk is that you can easily run multiple instances (to a single qsynth) in order to use multiple physical controllers.
  • Brent Bradburn
    Brent Bradburn almost 5 years
    Not Ubuntu-specific, but some really good-looking articles related to Linux MIDI and synthesis at sandsoftwaresound.net/qsynth-fluidsynth-raspberry-pi. This led me to an alternative way of launching: ( vmpk & ) ; fluidsynth -a alsa /usr/share/sounds/sf2/FluidR3_GM.sf2 -- with this approach, there's only one GUI to deal with. And yes, the vmpk+qsynth/fluidsynth+alsa solution seems to work on Raspberry Pi 3 B+ (with the default Raspbian OS).
  • Brent Bradburn
    Brent Bradburn almost 5 years
    An Ubuntu-specific resource for MIDI synthesis: help.ubuntu.com/community/Midi/SoftwareSynthesisHowTo. TiMidity++ may be a decent alternative to FluidSynth: timidity -iA --buffer-fragments=8,8 --reverb=0 --chorus=0 -ampling-freq=22050 --verbose=1 BTW: Timidity provides a way to transpose your controller: --adjust-key=n
  • Brent Bradburn
    Brent Bradburn almost 5 years
    A key consideration is that JACK has a tendency to make things complicated, and that it may be installed indirectly as a dependency of other components. On 18.04, qjackctl is listed as "Recommends" under vmpk -- so you may have to go out of your way to avoid installing it (see Consider recommended packages as dependencies). An alternative to vmpk is to use aconnect/acconectgui to wire the MIDI controller directly to the synth without requiring vmpk as an intermediary. P.S. I'm now running Ubuntu MATE 18.04 ARMv8/64 on Raspberry Pi 3B+.
  • Brent Bradburn
    Brent Bradburn almost 5 years
    A one-liner once you have the source/sink ID values (from aconnect --list |grep client): sudo echo ; ( sleep 2s ; aconnect 24 128 ) & sudo fluidsynth -a alsa /usr/share/sounds/sf2/FluidR3_GM.sf2 -o synth.sample-rate=11025 -o synth.audio-channels=1 -o synth.gain=0.95 -o synth.reverb.active=False -o synth.chorus.active=False -o audio.periods=4 -o synth.cpu-cores=4. It's still nice to visualize the MIDI connection with aconnectgui, but be aware that launching instances of this can affect the ID used for the synth. Tuned for low-latency on Raspberry Pi 3 B+ (Ubuntu MATE 18.04 ARMv8/64).
  • Brent Bradburn
    Brent Bradburn almost 5 years
    There are some tricks w/Raspberry PI above: I'm using external USB-DAC. Don't install jackd. Sometimes it gets bogged down with high CPU usage (esp. at startup) -- try running Sound Preferences -> Test Speakers to help it snap out.
  • Brent Bradburn
    Brent Bradburn almost 5 years
    Glitchy audio might also be improved by setting rtprio and memlock as described in my post about a command-line setup on raspberrypi.
  • Brent Bradburn
    Brent Bradburn almost 5 years
    Using JACK effectively requires a real commitment: jackaudio.org/faq/pulseaudio_and_jack.html
  • Bani
    Bani over 4 years
    Thanks for the simple answer! I was able to go from the virtual keyboard to qsynth, but pressing keys on the actual keyboard still has no results. I have a bluetooth controller (Rolland FP-30), which shows up as "Connected" under my Bluetooth devices. Any ideas what I need to do from here so that it's recognized as a bluetooth MIDI controller?
  • Brent Bradburn
    Brent Bradburn over 4 years
    @Bani, I've not yet been able to use MIDI over Bluetooth on Ubuntu. I tried again tonight with my Xkey Air but it fails to pair (Ubuntu 18.04). This might be the path forward, but I'm not up for trying at the moment. Another option that I encountered tonight is a $50 dongle called "WIDI Bud" that, I think, will automatically convert Bluetooth to MIDI. Post back if you figure it out -- I'd like to be able to do this too!
  • Bani
    Bani over 4 years
    awesome, that worked too! Now I can use it both ways: FP-30 as input or I can play at the virtual keyboard for the sound to come out at the FP-30
  • Bani
    Bani over 4 years
    weird, it stopped working as input... I could swear I tested it both ways yesterday, but after trying to use it with MuseScore it never worked again with qsynth + vmpk, even after I uninstalled MuseScore. It sill shows up on the Input list, but I can only get it to work properly as output.
  • Caleb Jay
    Caleb Jay over 3 years
    Your link to the s.fox post on your blog now links to a malware site, FYI.
  • Brent Bradburn
    Brent Bradburn over 3 years
    Ubuntu 20.04 updates vmpk to 0.7.2. This includes a built-in Sonivox EAS synth backend, therefore, qsynth is no longer required and the experience is more turn-key (only one software package needed). I haven't tested this with a from-scratch install, so YMMV.
  • Brent Bradburn
    Brent Bradburn over 3 years
    Ubuntu 20.04: Still no luck with Bluetooth for keyboard connection.
  • Brent Bradburn
    Brent Bradburn almost 3 years
    After a long period of ignoring my keyboard due to ridiculous latency, I finally found the answer. PulseAudio was the hidden culprit. You can bypass it, by going straight to the "Audio Device", but that is exclusive. Really, you need PulseAudio to mux the device, and it just needs to be tuned for acceptable latency. You can do this with by tuning the fragments. To be fair, PulseAudio isn't necessarily in the wrong, it's probably just that Qsynth fails to be "modern" as per man pulse-daemon.conf.
  • Brent Bradburn
    Brent Bradburn almost 3 years
    After killing killing/restarting pulseaudio, fiddle with "Sound Preferences" -> Hardware" -> "Profile" to reconnect the volume keys: askubuntu.com/questions/978789/volume-control-not-working
  • Brent Bradburn
    Brent Bradburn about 2 years
    Pulse Audio latency has a mind of its own. I suggest monitoring 'configured latency' over time: watch --color -n.5 'pacmd list-sinks |grep --color=always latency'
  • Brent Bradburn
    Brent Bradburn about 2 years
    I've found that PulseAudio latency self-adjusts (apparently always increasing) -- presumably to fix under-runs. This, finally, explains the magically-resolving "glitchy static" that I observed way back when. Unfortunately, some unknown situations can result in the base latency getting pushed to unacceptably large values (>100ms). Good news, I've found a way to reset this without restarting (pulseaudio -k -- which is very disruptive): Momentarily set 'Sound Preferences' 'Hardware' 'Profile' to Off, then restore it -- and watch the above latency monitor reset (and "glitchy static" return).