Sonic Pi Internals GUI Ruby API - sonic-pi-net/sonic-pi GitHub Wiki
The Sonic Pi GUI connects to the Ruby backend via OSC messages. This is an informal description of the API based on the current codebase (circa 2.6):
From GUI to Server
agent-name
code
/run-code Runs the provided code in a new Sonic Pi thread via __spider_eval_code
. Not actually used by GUI at this time, more for interoperability with other front-ends.
filename
code
workspace
/save-and-run-buffer Used by the GUI when the Run button is hit, saves the code to a file and commits it to the internal Git repo. The workspace name is passed to eval
and used to identify the code in error traces.
filename
code
/save-buffer Saves the buffer contents to a file, used when the GUI is exiting.
/exit
GUI is exiting and requests the backend to exit.
/stop-all-jobs
GUI Stop
button, kills all running threads
filename
/load-buffer GUI requests to load the buffer contents from disk at startup
filename
code
start-line
finish-line
point-line
point-index
/complete-snippet-or-indent-selection Called when TAB
is pressed in the GUI, to auto-indent the current line or selection via RBeautify, or complete a snippet (work in progress).
/beautify-buffer
The align
button, passes the entire buffer to RBeautify for cleanup
/ping
Called from the GUI at startup while waiting for the server to start, triggers an /ack
from the server.
/start-recording
Tell SuperCollider to start recording to a temporary file.
/stop-recording
Tell SuperCollider to stop recording.
/delete-recording
Discard the temporary recording file.
filename
/save-recording Save the temporary file to the given filename.
/reload
Not currently used, may be useful in development. Theoretically restarts the server and SC without needing to restart the GUI.
/mixer-invert-stereo
/mixer-standard-stereo
/mixer-stereo-mode
/mixer-mono-mode
frequency
/mixer-hpf-enable /mixer-hpf-disable
frequency
/mixer-lpf-enable /mixer-lpf-disable
SuperCollider mixer controls. HPF and LPF are not currently visible in the GUI.
/enable-update-checking
/disable-update-checking
Allow/disallow the server to check for new versions of Sonic Pi, controlled from the Prefs pane.
From Server to GUI
run #
thread name
timestamp
N
msgType1
msg1
... msgTypeN
msgN
/multi_message Add a log entry with one or more lines that occured at a given timestamp. Types are magic numbers right now, currently:
-
- default
-
- user message (print, etc.)
-
- warning
-
- serious warning
-
- highlighted (pink)
-
- highlight v2 (blue - cue -- not shown?)
-
- highlight v3 (orange - sync -- not shown?)
msg
/info Add an info log message.
msg
/error Add an error log message.
id
code
line
index
first line visible
/replace-buffer All-purpose routine for loading new buffers in, and updating buffers after beautify (Align
). Updates cursor position and scroll position so they stay the same.
id
code
start-line
finish-line
point-line
point-index
/replace-lines Replace part of a buffer after auto-indent.
/exited
Server has exited, GUI shuts down too
message
/exited_with_boot_error Server exited after a failed startup, message is hopefully informative about the startup error
/ack
Sent in response to a /ping
from the GUI, indicates server is alive.