Is there a way to list active MIDI devices using code?

I’m using Sonic Pi without the GUI and I need to quickly test if my MIDI devices are connected or not. Is there any way to print it using internal functions?

Thanks for the help!