STM32 as a MIDI device (I'm lost)
The MIDI class is not supported by the STMCube HAL but it is well known and implemented, you just need to google a bit.
I am currently doing a stm32 project with midi as well and I am using these two projects as reference:

https://github.com/spectran/stm32f103-usb-midi
https://github.com/ripxorip/stm32_usb_midi
https://github.com/arneboe/con.trol

Both have the midi usb class there one for stm32f1xx and another for stm32f4xx. For those I had made it work in a stm32f411CE (Blackpill board) with cont.trol configuring first the project as USB Audio class and later adding the MIDI class and initializing MIDI class Instead of AUDIO.