How to send (REST) messages to applications outside SONIC PI?

Hi!

I had the pleasure to hear @samaaron present and perform last week at jFokus in Stockholm and that was really awesome :smiley:.
When trying Sonic PI at home I happend to see that @josephwilk is a “live coder of sound, light & poetry” Since I do stage lighting as hobby a thought struck me.

Is it possible to fire away a URL-request (or send any signal to external application) from within Sonic Pi while playing, like

live_loop :flibble do
sample :ambi_choir, rate: 0.3
sample :bd_haus, rate: 1
http://localhost:8080/trigger/105
sleep 1
end

or the other way around, trigger some part of a Sonic Pi song from another application?

I have designed a java application for stage lighting using a USB -> DMX dongle. It consist of a client based on the regular JavaFX GUI and a server based on Apache Tomcat webserver. The server calculates values for DMX channels (dimming, fading, flashing, …) and sends then to the fixtures via the dongle. The client controls the server via the REST api.
If I could send the REST api calls (like http://localhost:8080/trigger/31) from within Sonic PI I could couple lighting to the music played to Sonic PI. Or when triggering something in the lighting controler send a signal to Sonic Pi to play.

Is there a way to do this, or something similar, in Sonic PI today? I looked in the manual and forums but didn’t find any way to do it.

///Lars

1 Like

Hi @larsalf,

Sounds like an interesting project, would love to read more about it.

I’ve most commonly done this with OSC (https://github.com/samaaron/sonic-pi/blob/master/etc/doc/tutorial/12-OSC.md, https://github.com/samaaron/sonic-pi/blob/master/etc/doc/tutorial/12.2-Sending-OSC.md, https://github.com/samaaron/sonic-pi/blob/master/etc/doc/tutorial/12.1-Receiving-OSC.md) Cheap, fast and an easy way to sync comms over a network or locally.

If you want to do it via a http call, well it’s just Ruby so you could via Net::HTTP http://ruby-doc.org/stdlib-2.5.0/libdoc/net/http/rdoc/Net/HTTP.html.

With both methods you could push from SP or sync from SonicPi. A live loop awaiting data or sending.

Good luck!

1 Like