View Categories

MIDI device

In this example we are using a Garagekey Groove II MIDI keyboard and make music/playback it on an Orange Pi ZERO3 trough LINE-OUT

dmesg

[ 1609.117012] usb 4-1: new full-speed USB device number 3 using ohci-platform
[ 1609.344060] usb 4-1: New USB device found, idVendor=1c75, idProduct=0204, bcdDevice= 1.00
[ 1609.344090] usb 4-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 1609.344110] usb 4-1: Product: MIDITECH
[ 1609.344127] usb 4-1: Manufacturer: **

aseqdump

sudo aseqdump -l

 Port    Client name                      Port name
  0:0    System                           Timer
  0:1    System                           Announce
 28:0    MIDITECH                         MIDITECH MIDI 1

You can see the port number: 28

Test MIDI input (note view) #

aseqdump

sudo aseqdump -p 28

Waiting for data. Press Ctrl+C to end.
Source  Event                  Ch  Data
 28:0   Note on                 0, note 64, velocity 69
 28:0   Note off                0, note 64, velocity 0
 28:0   Note on                 0, note 55, velocity 13
 28:0   Note off                0, note 55, velocity 0
 28:0   Note on                 0, note 52, velocity 13
 28:0   Note off                0, note 52, velocity 0
 28:0   Note on                 0, note 56, velocity 65
 28:0   Note off                0, note 56, velocity 0
 28:0   Control change          0, controller 77, value 46
 28:0   Control change          0, controller 77, value 45
 28:0   Control change          0, controller 77, value 44
 28:0   Control change          0, controller 77, value 42
 28:0   Control change          0, controller 77, value 41
 28:0   Control change          0, controller 77, value 39
 28:0   Control change          0, controller 77, value 38
 28:0   Control change          0, controller 77, value 37
 28:0   Control change          0, controller 77, value 35
 28:0   Control change          0, controller 77, value 34
 28:0   Control change          0, controller 77, value 33
 28:0   Control change          0, controller 77, value 32
 28:0   Control change          0, controller 77, value 31
 28:0   Control change          0, controller 1, value 4
 28:0   Control change          0, controller 1, value 11
 28:0   Control change          0, controller 1, value 23
 28:0   Control change          0, controller 1, value 39
 28:0   Control change          0, controller 1, value 47
 28:0   Control change          0, controller 1, value 55
 28:0   Pitch bend              0, value 3806
 28:0   Pitch bend              0, value 5999
 28:0   Pitch bend              0, value 5741
 28:0   Pitch bend              0, value 5612
 28:0   Pitch bend              0, value 5632
 28:0   Pitch bend              0, value 5020
 28:0   Pitch bend              0, value 4408
 28:0   Pitch bend              0, value 3796
 28:0   Pitch bend              0, value 3184
 28:0   Pitch bend              0, value 2444
 28:0   Pitch bend              0, value 1832
 28:0   Pitch bend              0, value 1220
 28:0   Pitch bend              0, value 608
 28:0   Pitch bend              0, value 0

Test MIDI input (RAW) #

amidi

sudo amidi -l

Dir Device    Name
IO  hw:3,0,0  MIDITECH MIDI 1

Here you can see the hw number 3,0,0 assigned

NOTE: you can also see the hw number if you list the /dev/snd folder:

ls /dev/snd

by-id    controlC0  controlC2  midiC3D0  pcmC2D0c  seq
by-path  controlC1  controlC3  pcmC0D0p  pcmC2D0p  timer

Here you can see midiC3D0, wich resembles hw 3,0

dump midi values

sudo amidi --port="hw:3,0,0" --dump

90390B
903B0D
903C36
903E39
803900
803B00
803C00
803E00
B04D31
B04B2D
B04B2E
B04B2F
B04B31
B04B32
B04B33
B04B35
B04B36
B04B37
B04B38
B04B39
B04B3A
B04B3B
B04B3C
B05D41
B05D40

Install MIDI synthesizer #

Fluidsynth

sudo apt install -y alsa-utils fluidsynth fluid-soundfont-gm

Test NOTE

test notes on fluidsynth

sudo fluidsynth -a alsa -m alsa_seq /usr/share/sounds/sf2/FluidR3_GM.sf2

in the console of fluidsynth type

noteon 1 60 100

You should here a note play

Test MIDI file

Download a midi file

wget https://files.khinsider.com/midifiles/snes/super-mario-world/overworld.mid -O test.mid

Check if the file is a midi file:

file test.mid

test.mid: Standard MIDI data (format 1) using 19 tracks at 1/120

Play the midi file

sudo fluidsynth -a alsa -m alsa_seq -i /usr/share/sounds/sf2/default-GM.sf2 test.mid

or

sudo fluidsynth -a alsa -m alsa_seq -i /usr/share/sounds/sf2/FluidR3_GM.sf2 test.mid

Connect and route the midi keyboard #

So if you look at the “audio” devices with:

sudo aconnect -l

You will see something like:

client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 28: 'MIDITECH' [type=kernel,card=3]
    0 'MIDITECH MIDI 1 '

Where device 28 is the midi keyboard

Now to open fluidsynth and to prevent multiple SSH sessions, because fluidsynth need to be running, we can run fluidsynth in the background with this command:

nohup sudo fluidsynth -a alsa -m alsa_seq --server /usr/share/sounds/sf2/FluidR3_GM.sf2 > fluidsynth.log 2>&1 &

And if you list the devices with aconnect you will now see:

sudo aconnect -l

client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 28: 'MIDITECH' [type=kernel,card=3]
    0 'MIDITECH MIDI 1 '
client 128: 'FLUID Synth (2506)' [type=user,pid=2506]
    0 'Synth input port (2506:0)'

Where device 128 is fluidsynth.

Now we have to redirect the input from the keyboard (device 28) to the synthesizer (device 128), with this command:

sudo aconnect 28:0 128:0

Now the devices are connected, you can check it again:

sudo aconnect -l

client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 28: 'MIDITECH' [type=kernel,card=3]
    0 'MIDITECH MIDI 1 '
        Connecting To: 128:0
client 128: 'FLUID Synth (2506)' [type=user,pid=2506]
    0 'Synth input port (2506:0)'
        Connected From: 28:0

You can see the “connecting to” and “connected from”

If you now press keys on your keyboard you will hear the sound!, enjoy!