For those folks also interested in this idea, either in contributing code to or using a VS Code extension as an alternative interface to Sonic Pi, feel free to follow along with the discussion here.
This looks a nice project. I’ve never used the vscode package before but I decided to have a go and installed it on my Mac together with updated Node.js and npm. Took a bit of fiddling to get it going. I missed a vital step to start with installing vscode commands in the PATH. A cse of RTFM see https://code.visualstudio.com/docs/setup/mac
Another potential problem is setting this.rootPath in main.ts.
If you are using a packaged Sonic Pi then you need a path like. "/Users/rbn/Downloads/Sonic Pi 3.2.2release.app/Contents/Resources"
I had the release version of Sonic Pi downloaded from sonic-pi.net renamed as "Sonic Pi 3.2.2release" sitting in my Downloads folder. You have to set a path that actually points inside the .app bundle.
If you were using "Sonic Pi" installed in a Mac Applications folder you would need "/Applications/Sonic Pi.app/Contents/Resources" This is true for Sonic Pi 3.2.2 If you are using an earlier version say 3.1 the path would be "/Applications/Sonic Pi.app" You can see where you want to go by right clicking the App and selecting Show Package Contents. You then need to search for where the app folder is.
The ruby path will be this.rubyPath = this.rootPath + "/app/server/native/ruby/bin/ruby"
This is the same as for Windows just without the final .exe
One other comment. It only works at present if you open an existing file. The extension doesn’t trigger if you create a new blank file.
I look forward to further progress on this project which is very cool.
thanks a lot for your feedback, it’s probably worth adding these useful notes somewhere in the repository.
Regarding the fact that it only works when you open an existing file (it needs to be a ruby file), that’s by design at the moment, because you might be using vscode for other languages as well, and might not want to start the sonic pi server when you open the editor. But if people prefer, it is possible to make it load it at start every time vscode is open. Or it might be better to have a specific command to launch and stop the server… open to suggestions.
I’m not sure that starting the server when a Ruby file is opened is the optimal strategy, as people could also be editing Ruby that is not for Sonic Pi.
What about having a command to start it, but also starting it when the Run command is first executed (with some feedback that this is happening)?
In regards to when to activate the server, could you maybe use a different extension (.spi, for instance)? The extension can contribute a files.associations to map .spi to Ruby for editor support, and activate the server on opening any .spi file.
Also, how do you deactivate the server? I ask because for me the extension worked for a bit, but after reloading a few times I got stuck in a state where the port was blocked and the server wouldn’t start.
I think the best will to add a setting for this, so that users can choose what they want. The extension will be activated when vscode starts, but Sonic Pi will be launched based on that preference. The preference might have these options:
Launch automatically when vscode starts
Launch automatically when there is a ruby file open in the editor
Do not launch automatically (of course, we’ll add a vscode command to launch)
Launch when opening a file with these extensions: [whatever, whatever, …] (Not sure if this is possible in the settings - this fulfils @JacksonKearl’s suggestion )
Hi, @JacksonKearl, welcome to the Sonic Pi community in in-thread.
Thank you for your feedback. Can you have a look at the reply I made to @emlyn, and let me know if you like what I’m proposing there? Basically, make this a setting, so that users can choose what they prefer.
Now we just need to agree on what the best default is…
For now, I think I am going to leave the default as starting the server when you have a ruby file open in the editor, but I’m open to suggestions on this.
Make sure you configure the paths in main.ts (rootPath and rubypath) to match your own system. This will be automated in the future.
ok where is Brian ? main.ts
sonic-pi-vscode-editor-master\src
Can’t you give us the classic windows 10 path ? rootPath and rubypath ? EDIT : you did it
So please help us to use your nice extension.
i guess this is not npm update but npm install right ?
Requirements
The extension runs in development mode. Follow these steps:
Go to the extension directory (where this file is located)
run "npm update", to install the necessary node dependencies
run "code .", to open the extension directory in vscode
press F5 to run the extension
open a ruby file, which will launch Sonic Pi backend
If you run into problems, let me know, and I'll do my best to help you set this up.
[GUI] - Cleaning old sessions...
[GUI] - Discovering port numbers...
stdout: Sonic Pi server booting...
This is version 3.2.0 running on Ruby 2.7.1.
The time is 2020-05-27 13:40:15 +0200
Using primary protocol: udp
Detecting port numbers...
Listen port: 51235
- OK
Scsynth port: 51237
- OK
Scsynth send port: 51237
- OK
OSC cues port: 4560
- OK
Erlang port: 51240
- OK
OSC MIDI out port: 51238
- OK
OSC MIDI in port: 51239
- OK
Websocket port: 51241
- OK
Opening UDP Server to listen to GUI on port: 51235
stdout: Started [13532] [-] "C:\Program Files\Sonic Pi\app\server\native\scsynth.exe" -u 51237 -m 131072 -a 1024 -D 0 -R 0 -l 1 -i 16 -o 16 -U "C:/Program Files/Sonic Pi/app/server/native/plugins/" -b 4096 -B 127.0.0.1 [-] C:/Users/nlb/AppData/Local/Temp/sonic-pi-pids/13532
stdout: Started [15632] [-] "C:/Program Files/Sonic Pi/app/server/native/erlang/bin/erl.exe" -noshell -pz "C:/Program Files/Sonic Pi/app/server/erlang" -s pi_server start 51240 4560 51235 [-] C:/Users/nlb/AppData/Local/Temp/sonic-pi-pids/15632
which is strange is that This is version 3.2.0 running on Ruby 2.7.1. i use 3.2.2
Basically, check the file .../app/server/ruby/lib/sonic-pi/util.rb in your sonic pi installation directory and see what the method register_process looks like. If it says Process.wait pid, change that to Process.wait(pid, Process::WNOHANG). Make a backup copy of the file first!
Let me know if that helped.
Read the install page for your OS when installing VScode, which has useful tips.
You need to have installed Node.js first.
The npm update is in the Command Palette which is on the View Menu.
Use this after you have opened the vscode-sonic-pi-editor folder.
You start a terminal from the Terminal menu. You must use the install code command in PATH from the Command Pallete too. You open the main.ts file from the list of the source tree on the left. Lines 86 and 87 (at the time of writing) contain the two paths you need to setup. These depend on both your OS and where you have sonic -pi installed on your system. As pointed out in the comments, these will be replaced with an easier to use system later.
I wrote a note above about how to work this out on a Mac.
Once you have the PATH sorted out in the opened terminal you type code .
Then you push F5. This rather confusingly returns you to a screen similar to the start up one, although it is entitled Extension Development Host at the top and has a section at the bottom entitled interface overview. However if you now open a Sonic PI .rb file from the File Menu you should get messages to the effect that Sonic PI server is starting up, and then you can use the Sonic Pi short cut keys appropriate to your OS to run the file. Hopefully you will hear the sound and you will see the output log window of Sonic Pi at the bottom, and you can switch it to the cues window instead if you wish.
I hope to try an install on Linux soon, and may try to do a video of the setup there.
From what I can see on the images you have sent the server has been started successfully (See that it says Sonic Pi server started). Have a look at the logs inside the sonic-pi directory itself, and see if there is something in there that can explain why you are not hearing any sound?
Before doing that, try to do Alt-R on a Sonic Pi script and see if you get anything on the logs.
yep what about auto complete on use_synth with the name of synths or sample with the samples as example ? is it planned ? The ideas will be numerous
and for the snippet live_loop as the name always start with : it’s a bit boring to retype the :.