Skip to content

Sonic Pi Internals GUI Ruby API

rpmt edited this page Feb 14, 2016 · 2 revisions

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

/run-code agent-name 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.

/save-and-run-buffer filename code workspace

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.

/save-buffer filename code

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

/load-buffer filename

GUI requests to load the buffer contents from disk at startup

/complete-snippet-or-indent-selection filename code start-line finish-line point-line point-index

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.

/save-recording filename

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

/mixer-hpf-enable frequency

/mixer-hpf-disable

/mixer-lpf-enable frequency

/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

/multi_message run # thread name timestamp N msgType1 msg1 ... msgTypeN msgN

Add a log entry with one or more lines that occured at a given timestamp. Types are magic numbers right now, currently:

    1. default
    1. user message (print, etc.)
    1. warning
    1. serious warning
    1. highlighted (pink)
    1. highlight v2 (blue - cue -- not shown?)
    1. highlight v3 (orange - sync -- not shown?)

/info msg

Add an info log message.

/error msg

Add an error log message.

/replace-buffer id code line index first line visible

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.

/replace-lines id code start-line finish-line point-line point-index

Replace part of a buffer after auto-indent.

/exited

Server has exited, GUI shuts down too

/exited_with_boot_error message

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.