Commandline Sonic Pi for real time bar expenditure music
I'm doing a project at the Cube to sonify the accounts - having accidentally got involved in the accounts "department" I wanted to do something interesting with the data.
Here's September's bar processed using a little Sonic Pi program. Sonic Pi is Ruby so you can do stuff like load files and so on. I mapped each daily amount to the key of C limiting it to the three octaves above middle C (lower notes sound more doomy). The visualisation is adapted from this P5.js demo, and we've been showing the July version at the Cube before films thanks to Mr Hopkinson π.
I also wanted to play it (I'm taking piano lessons) and in trying to do that I found this rather amazing programme called Lilypond, which seems to be a version of Latex specifically for music notation. So I generated this too also using the Sonic Pi code, which made the code a bit messy, but still:

It's very up and down because the Cube both shows films and puts on gigs, and the different kinds of events have very different bar incomes.
I'm going to play with this some more, maybe adding in some other data streams and whatnot. All fairly straightforward.
But also.... - we use Square for payments at the Cube and it has an API. So, what about real-time music based on the bar piped to our brand new toilets? (we have a new sound system in there). Now I did try using MidiUtil for generating music using Python, but the sounds (sound fonts?) aren't as nice as Sonic Pi's, and it's all much lower level and not as fun.
My plan was to have a Pi that I could just plug straight into the amplifier at the Cube, so it wouldn't need me to have my laptop there to play the "music". So my plan was "just" to get the Sonic Pi working headlessly, feed in the data in real time, map it out to C as before and play it out.
Of course Sonic Pi is primarily a teaching tool and real time music making platform, so the IDE is an integral part. Add to this that Raspberry Pi OS has recently changed its audio output mechansim and it took me a while to puzzle it out.
But I was in luck - turns out that others wanted to run it headlessly too, and in fact the Sonic Pi author recently made a REPL to do so. So I adapted that (there are some limitations, you're essentially sending strings so can't do everything).
However, initially I could not get a sound out of the thing, event though speakertest worked just fine.
The missing piece was figuring out Pipeline, the replacement for Pulse and Jack on Pi OS since Bookworm Pi OS. Essentially - at least for mangling Sonic Pi like this - you need to link together the input and output you want and you have to do it manually. I figured this out using pw-dot, a tool you get with pipewire. In fact this mapping is already in the code - it wasn't working because it assumed HDMI.

This helped. You can only link them up that once supercollider (the backend Sonic Pi uses) is running.
pw-top
shows you some stuff
Then you can do this sort of thing:
pw-link SuperCollider:out_1 alsa_output.usb-1395_Sennheiser_SP_20_5060490137021168-00.analog-stereo:playback_FL
pw-link SuperCollider:out_2 alsa_output.usb-1395_Sennheiser_SP_20_5060490137021168-00.analog-stereo:playback_FR
or
pw-link 72 32
pw-link 73 63
then check
pw-link -l
alsa_output.usb-1395_Sennheiser_SP_20_5060490137021168-00.analog-stereo:playback_FL |<- SuperCollider:out_1
alsa_output.usb-1395_Sennheiser_SP_20_5060490137021168-00.analog-stereo:playback_FR|<- SuperCollider:out_2
SuperCollider:out_1 |-> alsa_output.usb-1395_Sennheiser_SP_20_5060490137021168-00.analog-stereo:playback_FL
SuperCollider:out_2 |-> alsa_output.usb-1395_Sennheiser_SP_20_5060490137021168-00.analog-stereo:playback_FR

Final final thing: unlike pulse, pipewire runs as user (still using systemd), so it doesn't work until you login, so any dependencies also need to be at the user level and also don't work until you log in. This was easily solved (thank you Damian) by setting the pi to autologin π
It all works nicely. If you are lucky you might hear strange bonging noises next time you are in the Cube bogs. Buy more drinks (and then run quickly to the toilet, there's a couple of seconds lag) and you'll hear even more bongs.
Code and some more detailed instructions in github here. Lots of crud / hardcoding in there, WIP.