Skip to content

Instantly share code, notes, and snippets.

@sinewalker
Last active March 25, 2021 00:57
Show Gist options
  • Save sinewalker/f8a47f1b45b01d7a56d5484260e609d2 to your computer and use it in GitHub Desktop.
Save sinewalker/f8a47f1b45b01d7a56d5484260e609d2 to your computer and use it in GitHub Desktop.
How to use Sonic Pi Snippets

Sonic Pi has an experimental, undocumented feature to support snippets, which autoexpand with the TAB key.

Here's the issue: sonic-pi-net/sonic-pi#587

Specifically, Sam's comment: sonic-pi-net/sonic-pi#587 (comment)

... [T]o play with it now (with the caveat that it all may drastically change) you just need to create a file with the contents of your snippet with an .sps extension in a directory somewhere on your machine. You might want to create a snippets directory for your own personal snippets. The name of the file doesn't matter. You then load all the snippets in a given directory with:

load_snippets("/path/to/snippets/dir")

At the top of the file you'll need to put some metadata telling Sonic Pi when to trigger your snippet and where to leave the cursor.

Here's an example of a complete snippet (from here: https://github.com/samaaron/sonic-pi/blob/master/etc/snippets/fx/fx_reverb.sps):

# key: fx r
# point_line: 1
# point_index: 2
# --
with_fx :reverb do

end

# key: tells Sonic Pi which letters to look for prior to point (the cursor) when tab is hit.
# point_line: tells Sonic Pi which line to place the point on (relative to the snippet). This is 0 indexed
# point_index: tells Sonic Pi which position on the line to place the po I int (also 0 indexed). This is also relative to the snippet.

Some example snippets:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment