Sonic Pipe: Sonic Pi from the command line (< 4.0)

Hi everyone!

In the past months, I had very interesting conversations with @amiika concerning his Ziffers library. My live coding toolset being built around the usage of Vim/Neovim, I was encouraged to develop an alternative editor for Sonic Pi that I could use from the command line to test quick Ziffers snippets.

Sonic Pipe is a new command-line based tool made possible by the recent introduction of Sonic Pi 4.0. It is written in Python (> 3.9) and meant for users willing to play with Sonic Pi from Vim/Neovim. It can also be used as a regular Python library if you wish to use Sonic Pi in your Python scripts. Sonic Pipe can now:

  • boot a headless Sonic Pi client or connect to a running Sonic Pi instance.
  • pipe code from a Vim/Neovim buffer to the Sonic Pi Server.
  • display logs, error messages and various messages emitted by Sonic Pi.
  • display custom help files, including user-made help files.
  • save/autosave a Sonic Pipe session to a .rb file. Consult history of the current session.

The new version of Sonic Pi made it possible to run headless versions of the Sonic Pi Server to be used outside of the official/main GUI. This is one of the first tools (to my knowledge) exploring this new given possibility. Feedback is much appreciated! I hacked this tool for my own use, but I am sure that a critical eye and the action of new collaborators could make this tool even better!

It is now full of bugs and corner cases issues but I already use it for making music and for fun!

3 Likes

I could ‘pip install’ it on windows.
It seems to be restricted to vim/neovim.

So just form the git doc
i do not understand how to use it just for sonic-pi ‘play :c’.
Would you mind to give some help?

Thanks.

It is not really restricted to Vim/Neovim but using it is recommended. To use Sonic Pipe, you are basically supposed to find a way to pipe text coming from a text buffer to the buffer containing a running instance of the script. I know that it is possible to accomplish something similar using Emacs or VSCode but it is currently not documented.

Sonic Pipe is not meant to be used standalone in the terminal just like the old sonic-pi-cli was. However, I believe that it is possible to write a script that will run some Sonic Pi commands. You just need to have an instance of the SonicPipe object running using a daemon like so:

from sonic_pipe import SonicPipe
pi = SonicPipe(use_daemon=True)
pi.pipe("play :c, amp: 0.25")

having the code above in the script ‘run_play_c.py’ still fails to play
under Windows 10 with the follwing

C:\Users\ab2\Documents\Sonic Pi\y2\Sonic-LP-main>python run_play_c.py
Der Befehl "ruby" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
Traceback (most recent call last):
  File "C:\Users\ab2\Documents\Sonic Pi\y2\Sonic-LP-main\run_play_c.py", line 2, in <module>
    pi = SonicPipe(use_daemon=True)
  File "c:\users\ab2\documents\sonic pi\y2\sonic_pipe-main\sonic_pipe\SonicPipe.py", line 101, in __init__
    self.boot_daemon()
  File "c:\users\ab2\documents\sonic pi\y2\sonic_pipe-main\sonic_pipe\SonicPipe.py", line 287, in boot_daemon
    while self._values is None:
<pressing ctrl-c>
Keyboard Interrupt

I can’t read german but by translating it it seems that ruby is not installed on your computer. Sonic Pi may wrap its own version of Ruby. You will need to install it by following instructions for your OS: Download Ruby

After installing ruby (which is not said to necessary in the SonicPipe Readme.md)
I am getting the following on the cmd-Line when running the script
python run_play_c.py:

ruby: No such file or directory -- C:/Program/ (LoadError)

Where does this PATH come from?
I did certainly not specify it.
And have only the following in C:\

c:\>dir Pro*
 Volume in Laufwerk C: hat keine Bezeichnung.
 Volumeseriennummer: 08C2-7BCF

 Verzeichnis von c:\

09.08.2022  01:56    <DIR>          Program Files
10.06.2022  09:52    <DIR>          Program Files (x86)
               0 Datei(en),              0 Bytes
               2 Verzeichnis(se), 520.484.720.640 Bytes frei

Yes, that’s for sure but I am warning users that the script is still very unstable and experimental for the moment. Errors were to be expected. It is also written in the README that Windows is Currently not tested and unsupported. I don’t have access to a Windows computer until the end of the month but I’ll try to make a new version that you can boot easily :slight_smile: . I would suggest looking for the alternative of running Sonic Pi with the very recent Neovim plugin that was posted on the forum a few days ago.

Actually inspired by the literate programming post
I was looking for a remote interface to Sonic PI to possibly run/play from a mdbook
edited code as in the mdbook example given there.
But this seems not to be easily available jet.