GeekFunkLabs / fluidpatcher

A performance-oriented patch interface for FluidSynth
MIT License
123 stars 15 forks source link

MIDI messages not being received by headlesspi.py #78

Closed Stooovie closed 1 year ago

Stooovie commented 1 year ago

No matter what I do, doesn't work for me. I did copy the router_rules section from bank1.yaml that works for me, and the init section on the bottom, i did put the proper filename into squishboxconf.yaml (currentbank: fluid_gmbank.yaml), paths are unchanged, yet upon reboot it just doesn't play. The file looks like this and produces no sound at all at any channel or patch number:

router_rules:
  - {type: cc, chan: 1=2-16, par1: 7}
  - {type: cc, chan: 1=2-6, par1: 1}
  - {type: cc, chan: 1=2-6, par1: 64}
  - {type: cc, chan: 1=2-6, par1: 91}
  - {type: pbend, chan: 1=2-6}

patches:
  Yamaha Grand Piano:
    1: FluidR3_GM.sf2:000:000
  Bright Yamaha Grand:
    1: FluidR3_GM.sf2:000:001
  Electric Piano:
    1: FluidR3_GM.sf2:000:002
  Honky Tonk:
    1: FluidR3_GM.sf2:000:003
  Rhodes EP:
    1: FluidR3_GM.sf2:000:004
  Legend EP 2:
    1: FluidR3_GM.sf2:000:005
  Harpsichord:
    1: FluidR3_GM.sf2:000:006
  Clavinet:
    1: FluidR3_GM.sf2:000:007
  Celesta:
    1: FluidR3_GM.sf2:000:008
  Glockenspiel:
    1: FluidR3_GM.sf2:000:009
  Music Box:
    1: FluidR3_GM.sf2:000:010
  Vibraphone:
    1: FluidR3_GM.sf2:000:011
  Marimba:
    1: FluidR3_GM.sf2:000:012
  Xylophone:
    1: FluidR3_GM.sf2:000:013
  Tubular Bells:
    1: FluidR3_GM.sf2:000:014
  Dulcimer:
    1: FluidR3_GM.sf2:000:015
  DrawbarOrgan:
    1: FluidR3_GM.sf2:000:016
  Percussive Organ:
    1: FluidR3_GM.sf2:000:017
  Rock Organ:
    1: FluidR3_GM.sf2:000:018
  Church Organ:
    1: FluidR3_GM.sf2:000:019
  Reed Organ:
    1: FluidR3_GM.sf2:000:020
  Accordian:
    1: FluidR3_GM.sf2:000:021
  Harmonica:
    1: FluidR3_GM.sf2:000:022
  Bandoneon:
    1: FluidR3_GM.sf2:000:023
  Nylon String Guitar:
    1: FluidR3_GM.sf2:000:024
  Steel String Guitar:
    1: FluidR3_GM.sf2:000:025
  Jazz Guitar:
    1: FluidR3_GM.sf2:000:026
  Clean Guitar:
    1: FluidR3_GM.sf2:000:027
  Palm Muted Guitar:
    1: FluidR3_GM.sf2:000:028
  Overdrive Guitar:
    1: FluidR3_GM.sf2:000:029
  Distortion Guitar:
    1: FluidR3_GM.sf2:000:030
  Guitar Harmonics:
    1: FluidR3_GM.sf2:000:031
  Acoustic Bass:
    1: FluidR3_GM.sf2:000:032
  Fingered Bass:
    1: FluidR3_GM.sf2:000:033
  Picked Bass:
    1: FluidR3_GM.sf2:000:034
  Fretless Bass:
    1: FluidR3_GM.sf2:000:035
  Slap Bass:
    1: FluidR3_GM.sf2:000:036
  Pop Bass:
    1: FluidR3_GM.sf2:000:037
  Synth Bass 1:
    1: FluidR3_GM.sf2:000:038
  Synth Bass 2:
    1: FluidR3_GM.sf2:000:039
  Violin:
    1: FluidR3_GM.sf2:000:040
  Viola:
    1: FluidR3_GM.sf2:000:041
  Cello:
    1: FluidR3_GM.sf2:000:042
  Contrabass:
    1: FluidR3_GM.sf2:000:043
  Tremolo:
    1: FluidR3_GM.sf2:000:044
  Pizzicato Section:
    1: FluidR3_GM.sf2:000:045
  Harp:
    1: FluidR3_GM.sf2:000:046
  Timpani:
    1: FluidR3_GM.sf2:000:047
  Strings:
    1: FluidR3_GM.sf2:000:048
  Slow Strings:
    1: FluidR3_GM.sf2:000:049
  Synth Strings 1:
    1: FluidR3_GM.sf2:000:050
  Synth Strings 2:
    1: FluidR3_GM.sf2:000:051
  Ahh Choir:
    1: FluidR3_GM.sf2:000:052
  Ohh Voices:
    1: FluidR3_GM.sf2:000:053
  Synth Voice:
    1: FluidR3_GM.sf2:000:054
  Orchestra Hit:
    1: FluidR3_GM.sf2:000:055
  Trumpet:
    1: FluidR3_GM.sf2:000:056
  Trombone:
    1: FluidR3_GM.sf2:000:057
  Tuba:
    1: FluidR3_GM.sf2:000:058
  Muted Trumpet:
    1: FluidR3_GM.sf2:000:059
  French Horns:
    1: FluidR3_GM.sf2:000:060
  Brass Section:
    1: FluidR3_GM.sf2:000:061
  Synth Brass 1:
    1: FluidR3_GM.sf2:000:062
  Synth Brass 2:
    1: FluidR3_GM.sf2:000:063
  Soprano Sax:
    1: FluidR3_GM.sf2:000:064
  Alto Sax:
    1: FluidR3_GM.sf2:000:065
  Tenor Sax:
    1: FluidR3_GM.sf2:000:066
  Baritone Sax:
    1: FluidR3_GM.sf2:000:067
  Oboe:
    1: FluidR3_GM.sf2:000:068
  English Horn:
    1: FluidR3_GM.sf2:000:069
  Bassoon:
    1: FluidR3_GM.sf2:000:070
  Clarinet:
    1: FluidR3_GM.sf2:000:071
  Piccolo:
    1: FluidR3_GM.sf2:000:072
  Flute:
    1: FluidR3_GM.sf2:000:073
  Recorder:
    1: FluidR3_GM.sf2:000:074
  Pan Flute:
    1: FluidR3_GM.sf2:000:075
  Bottle Chiff:
    1: FluidR3_GM.sf2:000:076
  Shakuhachi:
    1: FluidR3_GM.sf2:000:077
  Whistle:
    1: FluidR3_GM.sf2:000:078
  Ocarina:
    1: FluidR3_GM.sf2:000:079
  Square Lead:
    1: FluidR3_GM.sf2:000:080
  Saw Wave:
    1: FluidR3_GM.sf2:000:081
  Calliope Lead:
    1: FluidR3_GM.sf2:000:082
  Chiffer Lead:
    1: FluidR3_GM.sf2:000:083
  Charang:
    1: FluidR3_GM.sf2:000:084
  Solo Vox:
    1: FluidR3_GM.sf2:000:085
  Fifth Sawtooth Wave:
    1: FluidR3_GM.sf2:000:086
  Bass & Lead:
    1: FluidR3_GM.sf2:000:087
  Fantasia:
    1: FluidR3_GM.sf2:000:088
  Warm Pad:
    1: FluidR3_GM.sf2:000:089
  Polysynth:
    1: FluidR3_GM.sf2:000:090
  Space Voice:
    1: FluidR3_GM.sf2:000:091
  Bowed Glass:
    1: FluidR3_GM.sf2:000:092
  Metal Pad:
    1: FluidR3_GM.sf2:000:093
  Halo Pad:
    1: FluidR3_GM.sf2:000:094
  Sweep Pad:
    1: FluidR3_GM.sf2:000:095
  Ice Rain:
    1: FluidR3_GM.sf2:000:096
  Soundtrack:
    1: FluidR3_GM.sf2:000:097
  Crystal:
    1: FluidR3_GM.sf2:000:098
  Atmosphere:
    1: FluidR3_GM.sf2:000:099
  Brightness:
    1: FluidR3_GM.sf2:000:100
  Goblin:
    1: FluidR3_GM.sf2:000:101
  Echo Drops:
    1: FluidR3_GM.sf2:000:102
  Star Theme:
    1: FluidR3_GM.sf2:000:103
  Sitar:
    1: FluidR3_GM.sf2:000:104
  Banjo:
    1: FluidR3_GM.sf2:000:105
  Shamisen:
    1: FluidR3_GM.sf2:000:106
  Koto:
    1: FluidR3_GM.sf2:000:107
  Kalimba:
    1: FluidR3_GM.sf2:000:108
  BagPipe:
    1: FluidR3_GM.sf2:000:109
  Fiddle:
    1: FluidR3_GM.sf2:000:110
  Shenai:
    1: FluidR3_GM.sf2:000:111
  Tinker Bell:
    1: FluidR3_GM.sf2:000:112
  Agogo:
    1: FluidR3_GM.sf2:000:113
  Steel Drums:
    1: FluidR3_GM.sf2:000:114
  Woodblock:
    1: FluidR3_GM.sf2:000:115
  Taiko Drum:
    1: FluidR3_GM.sf2:000:116
  Melodic Tom:
    1: FluidR3_GM.sf2:000:117
  Synth Drum:
    1: FluidR3_GM.sf2:000:118
  Reverse Cymbal:
    1: FluidR3_GM.sf2:000:119
  Fret Noise:
    1: FluidR3_GM.sf2:000:120
  Breath Noise:
    1: FluidR3_GM.sf2:000:121
  Sea Shore:
    1: FluidR3_GM.sf2:000:122
  Bird Tweet:
    1: FluidR3_GM.sf2:000:123
  Telephone:
    1: FluidR3_GM.sf2:000:124
  Helicopter:
    1: FluidR3_GM.sf2:000:125
  Applause:
    1: FluidR3_GM.sf2:000:126
  Gun Shot:
    1: FluidR3_GM.sf2:000:127
  Detuned EP 1:
    1: FluidR3_GM.sf2:008:004
  Detuned EP 2:
    1: FluidR3_GM.sf2:008:005
  Coupled Harpsichord:
    1: FluidR3_GM.sf2:008:006
  Church Bell:
    1: FluidR3_GM.sf2:008:014
  Detuned Organ 1:
    1: FluidR3_GM.sf2:008:016
  Detuned Organ 2:
    1: FluidR3_GM.sf2:008:017
  Church Organ 2:
    1: FluidR3_GM.sf2:008:019
  Italian Accordion:
    1: FluidR3_GM.sf2:008:021
  Ukulele:
    1: FluidR3_GM.sf2:008:024
  12 String Guitar:
    1: FluidR3_GM.sf2:008:025
  Hawaiian Guitar:
    1: FluidR3_GM.sf2:008:026
  Funk Guitar:
    1: FluidR3_GM.sf2:008:028
  Feedback Guitar:
    1: FluidR3_GM.sf2:008:030
  Guitar Feedback:
    1: FluidR3_GM.sf2:008:031
  Synth Bass 3:
    1: FluidR3_GM.sf2:008:038
  Synth Bass 4:
    1: FluidR3_GM.sf2:008:039
  Slow Violin:
    1: FluidR3_GM.sf2:008:040
  Orchestral Pad:
    1: FluidR3_GM.sf2:008:048
  Synth Strings 3:
    1: FluidR3_GM.sf2:008:050
  Brass 2:
    1: FluidR3_GM.sf2:008:061
  Synth Brass 3:
    1: FluidR3_GM.sf2:008:062
  Synth Brass 4:
    1: FluidR3_GM.sf2:008:063
  Sine Wave:
    1: FluidR3_GM.sf2:008:080
  Taisho Koto:
    1: FluidR3_GM.sf2:008:107
  Castanets:
    1: FluidR3_GM.sf2:008:115
  Concert Bass Drum:
    1: FluidR3_GM.sf2:008:116
  Melo Tom 2:
    1: FluidR3_GM.sf2:008:117
  808 Tom:
    1: FluidR3_GM.sf2:008:118
  Burst Noise:
    1: FluidR3_GM.sf2:009:125
  Mandolin:
    1: FluidR3_GM.sf2:016:025
  Standard:
    1: FluidR3_GM.sf2:128:000
  Standard 1:
    1: FluidR3_GM.sf2:128:001
  Standard 2:
    1: FluidR3_GM.sf2:128:002
  Standard 3:
    1: FluidR3_GM.sf2:128:003
  Standard 4:
    1: FluidR3_GM.sf2:128:004
  Standard 5:
    1: FluidR3_GM.sf2:128:005
  Standard 6:
    1: FluidR3_GM.sf2:128:006
  Standard 7:
    1: FluidR3_GM.sf2:128:007
  Room:
    1: FluidR3_GM.sf2:128:008
  Room 1:
    1: FluidR3_GM.sf2:128:009
  Room 2:
    1: FluidR3_GM.sf2:128:010
  Room 3:
    1: FluidR3_GM.sf2:128:011
  Room 4:
    1: FluidR3_GM.sf2:128:012
  Room 5:
    1: FluidR3_GM.sf2:128:013
  Room 6:
    1: FluidR3_GM.sf2:128:014
  Room 7:
    1: FluidR3_GM.sf2:128:015
  Power:
    1: FluidR3_GM.sf2:128:016
  Power 1:
    1: FluidR3_GM.sf2:128:017
  Power 2:
    1: FluidR3_GM.sf2:128:018
  Power 3:
    1: FluidR3_GM.sf2:128:019
  Electronic:
    1: FluidR3_GM.sf2:128:024
  TR-808:
    1: FluidR3_GM.sf2:128:025
  Jazz:
    1: FluidR3_GM.sf2:128:032
  Jazz 1:
    1: FluidR3_GM.sf2:128:033
  Jazz 2:
    1: FluidR3_GM.sf2:128:034
  Jazz 3:
    1: FluidR3_GM.sf2:128:035
  Jazz 4:
    1: FluidR3_GM.sf2:128:036
  Brush:
    1: FluidR3_GM.sf2:128:040
  Brush 1:
    1: FluidR3_GM.sf2:128:041
  Brush 2:
    1: FluidR3_GM.sf2:128:042
  Orchestra Kit:
    1: FluidR3_GM.sf2:128:048

init:
  messages: [cc:4:37:60, cc:4:65:127, cc:4:68:127,
             cc:5:71:0, cc:5:73:0, cc:5:74:0, cc:5:78:40, cc:5:79:40, cc:5:80:80, cc:5:81:127, cc:5:82:80, 
             cc:5:71:0, cc:5:73:0, cc:5:74:0, cc:5:78:40, cc:5:79:40, cc:5:80:80, cc:5:81:127, cc:5:82:80, 
             cc:6:100:0, cc:6:101:0, cc:6:6:12, cc:6:38:0]

I don't see any functional difference to the default bank#.yaml files, yet those play and this doesn't. Permissions are the same. Any clues?

albedozero commented 1 year ago

When I run this in the GUI I get an error about a tab character at the start of line 390 (right where you added the init block). According to the YAML spec, which bank files are based on, tabs can't be used at the beginning of lines.

You don't need that init block, or the router_rules block - bank0.yaml uses the init block to set some initial control change values for instruments on different channels, and the router rules allow a keyboard sending notes on channel 1 to also talk to those other channels. The gmbank you're using just uses the default values for all instruments, so everything can be on channel 1.

Stooovie commented 1 year ago

Still, even with your own fluid_gmbank.yaml from https://gist.github.com/albedozero/721442c1d112839c71fd8f7d9ce1a98b I'm not getting anything.

Now I'm not getting anything even out of the box (complete wipe and reinstall).

-Correct audio output is selected in the script (Pi4 headphones) -I do hear static after booting, so the output is fine -output is loud in alsamixer (correct card)

This is aconnect -i

client 0: 'System' [type=kernel]
    0 'Timer           '
    1 'Announce        '
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 20: 'Impact LX88+' [type=kernel,card=1]
    0 'Impact LX88+ MIDI1'
    1 'Impact LX88+ MIDI2'

aplay -l

card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
  Subdevices: 7/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 2: vc4hdmi0 [vc4-hdmi-0], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 3: vc4hdmi1 [vc4-hdmi-1], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

aseqdump -p 20 shows notes on Ch1 just fine

squishboxconf.yaml

soundfontdir: SquishBox/sf2
bankdir: SquishBox/banks
mfilesdir: SquishBox/midi
plugindir: /usr/lib/ladspa
currentbank: bank0.yaml

fluidsettings: # http://www.fluidsynth.org/api/fluidsettings.xml
  audio.driver: alsa
  audio.alsa.device: hw:Headphones
  audio.period-size: 64
  audio.periods: 3
  midi.autoconnect: 1
  player.reset-synth: 0
  synth.audio-groups: 16
  synth.cpu-cores: 4
  synth.ladspa.active: 1
  synth.polyphony: 128

But I'm getting no sound.

./headlesspi.py is giving me

Connection is already subscribed
Connection is already subscribed

even AFTER running sudo systemctl stop squishbox.service

Anything else? Thanks!

albedozero commented 1 year ago

Hmm. All the settings look good. Try

aconnect -iol

to see if the keyboard is being connected to FluidSynth, and

speaker-test --device hw:Headphones

to confirm that sound is in fact working.

Stooovie commented 1 year ago

aconnect -iol gives me

client 0: 'System' [type=kernel]
    0 'Timer           '
    Connecting To: 128:0
    1 'Announce        '
    Connecting To: 128:0
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
    Connecting To: 128:0
client 20: 'Impact LX88+' [type=kernel,card=1]
    0 'Impact LX88+ MIDI1'
    Connecting To: 128:0
    1 'Impact LX88+ MIDI2'
    Connecting To: 128:0
client 128: 'FLUID Synth (396)' [type=user,pid=396]
    0 'Synth input port (396:0)'
    Connected From: 0:1, 14:0, 20:0, 20:1, 0:0

and the sound test does indeed play pink noise. This is 100% clean install. Rpi4 with 32bit Raspbian Bullseye with only the Fluidpatcher script ran after install. Only the Nektar keyboard and headphones are connected to the Pi.

Stooovie commented 1 year ago

I can also play audio just fine after stopping the squishbox.service with fluidsynth -a pulseaudio -m alsa_seq -l -i sf2/GeneralUser.sf2 midi/elevatorgroove.mid

But live playing does not produce any sound.

Why does running ./headlesspi.py always say "Connection is already subscribed"? Even when I stop or even disable the squishbox service. That looks suspicious.

Stooovie commented 1 year ago

Somehow, I have absolutely no idea how, I am now able to produce the basic patch on my LX88, but now I'm unable to change the patches.

The LX88 emits control messages on Ch15 but notes on Ch0. Even when I change "Chan" in headlesspi.py to 15, I can not control the patches, only play notes with the first available patch. I am testing with aseqdump -p 20:0 and the numbers I put in headlesspi.py seem to be correct.

The button I want to go to next patch is showing as this in aseqdump:

 20:0   Control change         15, controller 112, value 127
 20:0   Control change         15, controller 112, value 0

But when I set Chan to 15 and Controller to 112, and run ./headlesspi.py, pressing the button does nothing.

albedozero commented 1 year ago

Why does running ./headlesspi.py always say "Connection is already subscribed"? Even when I stop or even disable the squishbox service. That looks suspicious.

The warning is coming from fluidsynth. When fluidsynth autoconnects, the fluid_alsa_seq_autoconnect function goes through every port on your system and tries to connect it to FluidSynth, but if the port is already connected it skips it with this warning. One of them is the system:announce port, which is always connected to listen for new devices being plugged in, so maybe it's slightly slopping coding, but it doesn't cause a problem.

when I set Chan to 15 and Controller to 112, and run ./headlesspi.py, pressing the button does nothing.

MIDI channels are numbered starting from 1 according to the MIDI spec. Fluidpatcher follows this rule, since pretty much all keyboards do as well. Unfortunately some programs like aseqdump and even FluidSynth itself number starting from 0.

TLDR your keyboard is sending notes on MIDI channel 1 and control changes on MIDI channel 16, so in headlesspi.py you should set

CHAN=16
Stooovie commented 1 year ago

according to asedump the controls are sent on channel 15 (fiftenn) like this

 32:0   Note on                 0, note 48, velocity 43
 32:0   Note off                0, note 48
 32:0   Control change         15, controller 112, value 127
 32:0   Control change         15, controller 112, value 0

but changing patches indeed DOES work when I set Ch to 16 (sixteen!)

CHAN = 16

Why is that? Is channel 16 some kind of global channel? Thank you!

albedozero commented 1 year ago

but changing patches indeed DOES work when I set Ch to 16 (sixteen!)

CHAN = 16

Why is that? Is channel 16 some kind of global channel? Thank you!

aseqdump numbers MIDI channels starting from 0, which is not the accepted way. Almost all keyboards and the MIDI specification start numbering them at channel 1. So your keyboard is in fact sending control changes on MIDI channel 16 - aseqdump just reports it as 15.

Stooovie commented 1 year ago

That's crazy :) Thank you, this one is solved.

Too bad SOME of the controls send on channel 0 (the rotary knobs) and the transport buttons send on channel 15, I'd love to be able to do incremental by the transport buttons and direct by the knobs, but that's just a minor inconvenience,

albedozero commented 1 year ago

You can do it with a simple workaround. Go ahead and set CHAN = 16, but in this line of the connect_controls() function, replace CHAN with 1 for your selector knobs' channel.