Controlling pi top pulse with sonic pi

As programmers we often encounter these situations where a piece of code seems like it will solve a problem, or is closely related to a problem one is trying to solve. My advice is that if it isn’t somewhat obvious how to transition Robin’s example to your needs, then to use it more as a learning guide than a starting point.

As you identified, OSC will provide the foundation for communicating events from your Sonic Pi script to one running on the Pi Top. OSC is a simple, flexible way of sending messages / data back-and-forth and the Sonic Pi docs for it are here: https://sonic-pi.net/tutorial.html#section-12. On the Python side you can use: https://pypi.org/project/python-osc/

I recently added a simple example of receiving OSC events in Python from Sonic Pi: Link sonic pi to Python

For your case, the messages and values to send are whatever makes sense to define for your needs. The example you linked defines 4 custom OSC events: pulse/clear, pulse/xyrgb, pulse/setall, pulse/bright. The Python script sets up an OSC listener for those events and dispatches to the appropriate function for whichever message comes in. You can reuse this approach, but your events can be called and organized however you’d like. For example you could instead have pitop/clear, pitop/start_sequence, my_app/light_row, whatever/something_else/, etc.

In the Sonic Pi part of the script you linked, you can see in various places sending out the OSC messages. You’ll edit your Sonic Pi script similarly, to send out the events you have defined at the appropriate places.

Try to get a simple example / modification in your code working first. For example have a live_loop send out an event and set up your Python script to receive and print out a debug line or flash all the lights or something. Then you should be off and running …