The right approach for using MIDI on Linux depends on which version of JACK you use. The world divides into:
-X alsa_midi
server argument. To support legacy control
applications, you can also use the -X seq argument to the ALSA
backend of JACK and get the exact same results.a2jmidid is an application that bridges between the system MIDI ports and JACK.
First you should make sure that there is no ALSA sequencer support enabled in JACK. To do that open QJackCtl's Setup window.
Set Settings > MIDI Driver to none.
Then uncheck the Misc > Enable ALSA Sequencer
support option.
Now it's time to restart your jack server before going on.
First, check whether a2jmidid is already installed in your system. After starting your JACK server, go to the command line and type
a2jmidid -eIf a2jmidid does not exist, install it with the software manager of your Linux distribution and try again.
If you have correctly configured JACK for MIDI, then your MIDI ports should appear in qjackctl under Connections > MIDI .
Once you've verified that the ports appear in JACK as expected, you can make this happen whenever you start JACK.
If you use a newer version of JACK 1, just make sure the -X alsa_midi or -X seq options are enabled for whatever technique you use to start JACK.
For other versions of JACK, add a2jmidid -e & as an "after start-up" script in the Setup > Options tab of QJackCtl, so that it is started automatically whenever you start JACK.