It does nothing but it should create the USB MIDI device. I get the MIDI initialized message so I assume all went fine. Anyway, lsusb does not show anything MIDI-related and even:
$ sudo modprobe snd_seq_midi
$ aseqdump -l
Port Client name Port name
0:0 System Timer
0:1 System Announce
14:0 Midi Through Midi Through Port-0
shows nothing.
Did I forget anything in the setup?
For what it's worth, the Control Surface library I maintain supports MIDI over USB on the ESP32-S3: Control Surface: MIDI over USB, version 3.0.0 of arduino-esp32 adds support for it.
before the setup() otherwise it cannot find the functions (declared below).
About the MIDI the original code works:
$ aseqdump -l
Port Client name Port name
0:0 System Timer
0:1 System Announce
14:0 Midi Through Midi Through Port-0
32:0 BPI-Leaf-S3 BPI-Leaf-S3 MIDI 1
Good catch. I never imagined that opening the serial port would interfere with the MIDI library!
By the way, I don't like at all global variables... do you see any caveat if I put all the stuff in the private section of my Foo class?
Where does the MIDI_CREATE_INSTANCE macro should be placed then?
If the global variable represents an inherently “global” resource (e.g. a hardware serial port or a MIDI interface), then keeping it as a global variable is usually not an issue (and may even be preferred).
Grouping such variables into a class or struct just to reduce the number of global variables is generally not very useful.
That being said, if you have good reasons for encapsulating the variable, you can of course do so. The MIDI_CREATE_INSTANCE macro is a simple convenience wrapper, and you don't have to use it. It is probably easier to look at its definition and use that directly in your class (IIRC, it simply defines two variables).