I'm trying to set up a little soundfont player for my usb MIDI keyboard with my Raspberry Pi 3B+ (Raspbian Lite 4.18). I'm using Fluidsynth for that.
At startup this script is ran via cronjob:
#!/bin/bash
echo "Starting"
/usr/bin/fluidsynth -is -a alsa --gain 3 /usr/share/sounds/sf2/FluidR3_GM.sf2 &
echo "Fluidsynth started"
while true; do if [[ $(/usr/bin/aconnect -o ) = *FLUID* ]]; then break; fi; sleep 2; done
/usr/bin/aconnect 20 128
echo "Connected"
And Fluidsynth doesn't make a noise until I kill the process manually and I start it again. Then everything works.
Happens the same when I start it manually. First time, nothing; but second time works perfectly. I tried to run it from the first time with other users, and plugging/unplugging the connection between the keyboard and the synth.
Any ideas? Thank you.